using KristofferStrube.ActivityStreams; using Microsoft.EntityFrameworkCore; using System.Net.Mail; using Object = KristofferStrube.ActivityStreams.Object; namespace ActivityPub.Repositories; /// /// Database Context for ActivityPub objects (using EF and SQLite) /// public class ActivityPubContext : DbContext { /// /// The table to store Activities /// public DbSet Activities { get; set; } /// /// The table to store Objects /// public DbSet Objects { get; set; } /// /// The path to the sqlite database file /// public string DbPath { get; } /// /// Default constructor /// public ActivityPubContext() { var folder = Environment.SpecialFolder.LocalApplicationData; var path = Environment.GetFolderPath(folder); DbPath = System.IO.Path.Join(path, "activitypub.db"); } /// /// The following configures EF to create a Sqlite database file in the /// special "local" folder for your platform. /// /// protected override void OnConfiguring(DbContextOptionsBuilder options) { options.UseSqlite($"Data Source={DbPath}"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasMany(_ => _.Actor as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Object as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Target as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Result as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Origin as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Instrument as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Attachment as IEnumerable); modelBuilder.Entity().HasMany(_ => _.AttributedTo as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Audience as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Bcc as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Bto as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Cc as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Context as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Generator as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Icon as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Image as IEnumerable); modelBuilder.Entity().HasMany(_ => _.InReplyTo as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Location as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Tag as IEnumerable); modelBuilder.Entity().HasMany(_ => _.To as IEnumerable); modelBuilder.Entity().HasMany(_ => _.Url as IEnumerable); modelBuilder.Entity().Ignore(_ => _.ExtensionData); //modelBuilder.Entity().HasMany(_ => _.Content as IList); } }