diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index 67acbf4..b15dafe 100644 --- a/.gitignore +++ b/.gitignore @@ -251,3 +251,5 @@ paket-files/ # JetBrains Rider .idea/ *.sln.iml +/WapProjTemplate1 +/DesktopBridgeDeployment diff --git a/DatabaseLibrary/App.config b/DatabaseLibrary/App.config new file mode 100644 index 0000000..2fb423e --- /dev/null +++ b/DatabaseLibrary/App.config @@ -0,0 +1,13 @@ + + + + +
+ + + + + + + + \ No newline at end of file diff --git a/DatabaseLibrary/Data/IDataProvider.cs b/DatabaseLibrary/Data/IDataProvider.cs new file mode 100644 index 0000000..0678478 --- /dev/null +++ b/DatabaseLibrary/Data/IDataProvider.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseLibrary.Data +{ + public interface IDataProvider + { + void AddFile(PictureFile file, string groupId, int processingState); + + PictureFile GetFile(string path); + + void RemoveFile(int fileId); // Must also remove any persons associated with the file + + void AddPerson(PicturePerson person); + + void RemovePerson(int personId, int fileId); + + int GetFileCountForPersonId(Guid personId); + + Person GetPerson(Guid personId); + + void AddPerson(Guid personId, string name, string userData); + + void RemovePersonsForGroup(string groupId); + + List GetFilesForPersonId(Guid personId); + } +} diff --git a/DatabaseLibrary/Data/IsolatedStorageDatabase.cs b/DatabaseLibrary/Data/IsolatedStorageDatabase.cs new file mode 100644 index 0000000..36e8edd --- /dev/null +++ b/DatabaseLibrary/Data/IsolatedStorageDatabase.cs @@ -0,0 +1,119 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.IsolatedStorage; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseLibrary.Data +{ + public class IsolatedStorageDatabase + { + private static readonly string _isolatedStorageDatabaseFileName = "Database.json"; + + private static IsolatedStorageDatabase _db; + + [JsonProperty(PropertyName = "P")] + public virtual List People { get; set; } + [JsonProperty(PropertyName = "PF")] + public virtual List PictureFiles { get; set; } + [JsonProperty(PropertyName = "PL")] + public virtual List PictureFileGroupLookups { get; set; } + [JsonProperty(PropertyName = "PP")] + public virtual List PicturePersons { get; set; } + + internal void SaveChanges() + { + saveDatabaseToIsolatedStorage(_db); + } + + public IsolatedStorageDatabase() + { + } + + public static IsolatedStorageDatabase GetInstance() + { + if (_db == null) + { + _db = getDatabaseFromIsolatedStorage(); + } + + if (_db == null) + { + var d = new IsolatedStorageDatabase(); + d.People = new List(); + d.PictureFiles = new List(); + d.PictureFileGroupLookups = new List(); + d.PicturePersons = new List(); + + _db = d; + saveDatabaseToIsolatedStorage(d); + } + + return _db; + } + + public static void saveDatabaseToIsolatedStorage(IsolatedStorageDatabase database) + { + using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) + { + using (var oStream = new IsolatedStorageFileStream(_isolatedStorageDatabaseFileName, FileMode.Create, isoStore)) + { + using (var writer = new StreamWriter(oStream)) + { + writer.Write(JsonConvert.SerializeObject(database)); + } + } + } + } + + private static IsolatedStorageDatabase getDatabaseFromIsolatedStorage() + { + IsolatedStorageDatabase database = null; + + try + { + using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) + { + using (var iStreamForEndpoint = new IsolatedStorageFileStream(_isolatedStorageDatabaseFileName, FileMode.Open, isoStore)) + { + using (var readerForEndpoint = new StreamReader(iStreamForEndpoint)) + { + var json = readerForEndpoint.ReadToEnd(); + database = JsonConvert.DeserializeObject(json, new JsonSerializerSettings { Error = deserialiseErrorEventHandler }); + } + } + } + } + catch (FileNotFoundException) + { + database = null; + } + + return database; + } + + private static void deserialiseErrorEventHandler(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs e) + { + + } + + public string GetDatabaseLocation() + { + using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) + { + return isoStore.GetType().GetField("m_RootDir", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(isoStore).ToString(); + } + + } + + // v2 use Isolated Storage like Table STorage ;) + //private void AddRow(string tableName, string alphaNumRowKey, object row) + //{ + //} + } +} diff --git a/DatabaseLibrary/Data/Person.cs b/DatabaseLibrary/Data/Person.cs new file mode 100644 index 0000000..d624729 --- /dev/null +++ b/DatabaseLibrary/Data/Person.cs @@ -0,0 +1,26 @@ +namespace DatabaseLibrary.Data +{ + using Newtonsoft.Json; + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Data.Entity.Spatial; + + [Table("Person")] + public partial class Person + { + [JsonProperty(PropertyName = "I")] + public Guid PersonId { get; set; } + + [Required] + [StringLength(300)] + [JsonProperty(PropertyName = "N")] + public string Name { get; set; } + + [JsonProperty(PropertyName = "D")] + public string UserData { get; set; } + + // public virtual ICollection PicturePersons { get; set; } + } +} diff --git a/DatabaseLibrary/Data/PhotosDatabase.cs b/DatabaseLibrary/Data/PhotosDatabase.cs new file mode 100644 index 0000000..b67bd64 --- /dev/null +++ b/DatabaseLibrary/Data/PhotosDatabase.cs @@ -0,0 +1,33 @@ +namespace DatabaseLibrary.Data +{ + using System; + using System.Data.Entity; + using System.ComponentModel.DataAnnotations.Schema; + using System.Linq; + + public partial class PhotosDatabase : DbContext + { + public PhotosDatabase(string nameOrConnectionString) + : base(nameOrConnectionString) + { + } + + public virtual DbSet People { get; set; } + public virtual DbSet PictureFiles { get; set; } + public virtual DbSet PictureFileGroupLookups { get; set; } + public virtual DbSet PicturePersons { get; set; } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + modelBuilder.Entity() + .Property(e => e.LargePersonGroupId) + .IsUnicode(false); + + modelBuilder.Entity() + .HasKey(l => new { l.PictureFileId, l.LargePersonGroupId }); + + modelBuilder.Entity() + .HasKey(l => l.Id); + } + } +} diff --git a/DatabaseLibrary/Data/PhotosDatabase2.cs b/DatabaseLibrary/Data/PhotosDatabase2.cs new file mode 100644 index 0000000..4f83ac9 --- /dev/null +++ b/DatabaseLibrary/Data/PhotosDatabase2.cs @@ -0,0 +1,90 @@ +namespace DatabaseLibrary.Data +{ + using System; + using System.Data.Entity; + using System.ComponentModel.DataAnnotations.Schema; + using System.Linq; + using System.IO.IsolatedStorage; + using System.IO; + using Newtonsoft.Json; + + public partial class PhotosDatabase2 : DbContext + { + private static readonly string _isolatedStorageDatabaseFileName = "Database2.txt"; + + public PhotosDatabase2() : base() + { + } + + public override int SaveChanges() + { + saveDatabaseToIsolatedStorage(this); + return 1; + } + + public static void saveDatabaseToIsolatedStorage(PhotosDatabase2 database) + { + using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) + { + using (var oStream = new IsolatedStorageFileStream(_isolatedStorageDatabaseFileName, FileMode.Create, isoStore)) + { + using (var writer = new StreamWriter(oStream)) + { + var settings = new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate }; + writer.Write(JsonConvert.SerializeObject(database, settings)); + } + } + } + } + + private static PhotosDatabase2 getDatabaseFromIsolatedStorage() + { + PhotosDatabase2 database = null; + + using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) + { + try + { + using (var iStreamForEndpoint = new IsolatedStorageFileStream(_isolatedStorageDatabaseFileName, FileMode.Open, isoStore)) + { + using (var readerForEndpoint = new StreamReader(iStreamForEndpoint)) + { + var json = readerForEndpoint.ReadToEnd(); + try + { + database = JsonConvert.DeserializeObject(json); + } + catch (Exception e) + { + + } + } + } + } + catch (FileNotFoundException) + { + database = null; + } + } + return database; + } + + public virtual DbSet People { get; set; } + public virtual DbSet PictureFiles { get; set; } + public virtual DbSet PictureFileGroupLookups { get; set; } + public virtual DbSet PicturePersons { get; set; } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + modelBuilder.Entity() + .Property(e => e.LargePersonGroupId) + .IsUnicode(false); + + modelBuilder.Entity() + .HasKey(l => new { l.PictureFileId, l.LargePersonGroupId }); + + modelBuilder.Entity() + .HasKey(l => l.Id); + } + } +} diff --git a/DatabaseLibrary/Data/PictureFile.cs b/DatabaseLibrary/Data/PictureFile.cs new file mode 100644 index 0000000..838923a --- /dev/null +++ b/DatabaseLibrary/Data/PictureFile.cs @@ -0,0 +1,36 @@ +namespace DatabaseLibrary.Data +{ + using Newtonsoft.Json; + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + + [Table("PictureFile")] + public partial class PictureFile + { + [Key] + [JsonProperty(PropertyName = "I")] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + + [Required] + [JsonProperty(PropertyName = "F")] + public string FilePath { get; set; } + + [JsonProperty(PropertyName = "A")] + public DateTime DateAdded { get; set; } + + [JsonProperty(PropertyName = "T")] + public DateTime? DateTaken { get; set; } + + [JsonProperty(PropertyName = "C")] + public bool IsConfirmed { get; set; } + + //[JsonIgnore] + //public virtual ICollection PicturePersons { get; set; } + + // public virtual ICollection PictureFileGroupLookups { get; set; } + + } +} diff --git a/DatabaseLibrary/Data/PictureFileGroupLookup.cs b/DatabaseLibrary/Data/PictureFileGroupLookup.cs new file mode 100644 index 0000000..d045649 --- /dev/null +++ b/DatabaseLibrary/Data/PictureFileGroupLookup.cs @@ -0,0 +1,31 @@ +namespace DatabaseLibrary.Data +{ + using Newtonsoft.Json; + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Data.Entity.Spatial; + + [Table("PictureFileGroupLookup")] + public partial class PictureFileGroupLookup + { + [Key] + [Column(Order = 0)] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + [JsonProperty(PropertyName = "I")] + public int PictureFileId { get; set; } + + [Key] + [Column(Order = 1)] + [StringLength(50)] + [JsonProperty(PropertyName = "G")] + public string LargePersonGroupId { get; set; } + + [JsonProperty(PropertyName = "S")] + public int ProcessingState { get; set; } + + [JsonIgnore] + public virtual PictureFile PictureFile { get; set; } + } +} diff --git a/DatabaseLibrary/Data/PicturePerson.cs b/DatabaseLibrary/Data/PicturePerson.cs new file mode 100644 index 0000000..60668e3 --- /dev/null +++ b/DatabaseLibrary/Data/PicturePerson.cs @@ -0,0 +1,44 @@ +namespace DatabaseLibrary.Data +{ + using Newtonsoft.Json; + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Data.Entity.Spatial; + + [Table("PicturePerson")] + public partial class PicturePerson + { + [Key] + [JsonProperty(PropertyName = "I")] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + + [JsonProperty(PropertyName = "F")] + public int PictureFileId { get; set; } + + [Required] + [StringLength(50)] + [JsonProperty(PropertyName = "G")] + public string LargePersonGroupId { get; set; } + + [JsonProperty(PropertyName = "P")] + public Guid? PersonId { get; set; } + + [JsonProperty(PropertyName = "A")] + public DateTime DateAdded { get; set; } + + [JsonProperty(PropertyName = "J")] + public string FaceJSON { get; set; } + + [JsonProperty(PropertyName = "C")] + public bool IsConfirmed { get; set; } + + [JsonIgnore] + public virtual PictureFile PictureFile { get; set; } + + [JsonIgnore] + public virtual Person Person { get; set; } + } +} diff --git a/DatabaseLibrary/DataProviderManager.cs b/DatabaseLibrary/DataProviderManager.cs new file mode 100644 index 0000000..215165e --- /dev/null +++ b/DatabaseLibrary/DataProviderManager.cs @@ -0,0 +1,163 @@ +using DatabaseLibrary; +using DatabaseLibrary.Data; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.IsolatedStorage; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseLibrary +{ + public class DataProviderManager + { + private readonly string _isolatedStorageDatabaseTypeFileName = "DatabaseType.txt"; + private readonly string _isolatedStorageConnectionStringFileName = "ConnectionString.txt"; + private readonly string _defaultConnectionString = @"data source=.\sqlexpress;initial catalog=PhotosDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"; + + private static IDataProvider _currentSingleton = null; + private static DataSourceType? _dataSourceType; + private static string _connectionString; + + private DataSourceType GetDatabaseTypeFromIsolatedStorage() + { + DataSourceType databaseType; + + using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) + { + try + { + using (var iStreamForEndpoint = new IsolatedStorageFileStream(_isolatedStorageDatabaseTypeFileName, FileMode.Open, isoStore)) + { + using (var readerForEndpoint = new StreamReader(iStreamForEndpoint)) + { + databaseType = (DataSourceType)Enum.Parse(typeof(DataSourceType),readerForEndpoint.ReadLine()); + } + } + } + catch (FileNotFoundException) + { + databaseType = DataSourceType.LocalIsolatedStorage; + } + } + return databaseType; + } + + private void SaveDatabaseTypeToIsolatedStorage(DataSourceType databaseType) + { + using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) + { + using (var oStream = new IsolatedStorageFileStream(_isolatedStorageDatabaseTypeFileName, FileMode.Create, isoStore)) + { + using (var writer = new StreamWriter(oStream)) + { + writer.WriteLine(databaseType); + } + } + } + } + + private void SaveConnectionStringToIsolatedStorage(string connectionString) + { + using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) + { + using (var oStream = new IsolatedStorageFileStream(_isolatedStorageConnectionStringFileName, FileMode.Create, isoStore)) + { + using (var writer = new StreamWriter(oStream)) + { + writer.WriteLine(connectionString); + } + } + } + } + + private string GetConnectionStringToIsolatedStorage() + { + string connectionString = null; + + using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) + { + try + { + using (var iStreamForEndpoint = new IsolatedStorageFileStream(_isolatedStorageConnectionStringFileName, FileMode.Open, isoStore)) + { + using (var readerForEndpoint = new StreamReader(iStreamForEndpoint)) + { + connectionString = readerForEndpoint.ReadLine(); + } + } + } + catch (FileNotFoundException) + { + connectionString = null; + } + } + if (string.IsNullOrEmpty(connectionString)) + { + connectionString = _defaultConnectionString; + } + return connectionString; + } + + public DataSourceType DataSourceType + { + get + { + if (_dataSourceType == null) + { + _dataSourceType = GetDatabaseTypeFromIsolatedStorage(); + } + return _dataSourceType.Value; + } + set + { + _dataSourceType = value; + SaveDatabaseTypeToIsolatedStorage(value); + } + } + + public string ConnectionString + { + get + { + if (_connectionString == null) + { + _connectionString = GetConnectionStringToIsolatedStorage(); + } + return _connectionString; + } + set + { + _connectionString = value; + SaveConnectionStringToIsolatedStorage(value); + } + } + + public static IDataProvider Current + { + get + { + if (_currentSingleton == null) + { + switch(_dataSourceType) + { + case DataSourceType.SqlConnectionString: + _currentSingleton = new SqlDataProvider("name=PhotosDatabase"); + break; + case DataSourceType.LocalIsolatedStorage: + _currentSingleton = new IsolatedStorageDataProvider(); + break; + } + } + + return _currentSingleton; + } + } + + public void ReinitialiseDatabase() + { + _currentSingleton = null; + } + } +} diff --git a/DatabaseLibrary/DataSourceType.cs b/DatabaseLibrary/DataSourceType.cs new file mode 100644 index 0000000..db9902f --- /dev/null +++ b/DatabaseLibrary/DataSourceType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseLibrary +{ + public enum DataSourceType + { + [Description("Using an SQL connection string")] + SqlConnectionString = 1, + [Description("Using local Isolated Storage")] + LocalIsolatedStorage = 2 + } +} diff --git a/DatabaseLibrary/DatabaseLibrary.csproj b/DatabaseLibrary/DatabaseLibrary.csproj new file mode 100644 index 0000000..6f57512 --- /dev/null +++ b/DatabaseLibrary/DatabaseLibrary.csproj @@ -0,0 +1,71 @@ + + + + + Debug + AnyCPU + {D7D7A8CA-8E2E-4FF3-9EB4-78DE8A514332} + Library + Properties + DatabaseLibrary + DatabaseLibrary + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\Photo-App\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll + + + ..\Photo-App\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll + + + ..\Photo-App\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DatabaseLibrary/IsolatedStorageDataProvider.cs b/DatabaseLibrary/IsolatedStorageDataProvider.cs new file mode 100644 index 0000000..f649337 --- /dev/null +++ b/DatabaseLibrary/IsolatedStorageDataProvider.cs @@ -0,0 +1,106 @@ +using DatabaseLibrary.Data; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.IsolatedStorage; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseLibrary +{ + public class IsolatedStorageDataProvider : IDataProvider + { + private static IsolatedStorageDatabase _db; + + public IsolatedStorageDataProvider() + { + _db = IsolatedStorageDatabase.GetInstance(); + } + + public void AddFile(PictureFile file, string groupId, int processingState) + { + var lastFile = _db.PictureFiles.LastOrDefault(); + if (lastFile != null) + { + file.Id = lastFile.Id + 1; // Yuk, manual indexing rush + } + else + { + file.Id = 1; // index starting from 1 + } + + _db.PictureFiles.Add(file); + _db.SaveChanges(); + + _db.PictureFileGroupLookups.Add(new PictureFileGroupLookup { LargePersonGroupId = groupId, PictureFileId = file.Id, ProcessingState = processingState }); + _db.SaveChanges(); + } + + public PictureFile GetFile(string path) + { + return _db.PictureFiles.Where(a => a.FilePath == path).SingleOrDefault(); + } + + public void AddPerson(PicturePerson person) + { + _db.PicturePersons.Add(person); + _db.SaveChanges(); + } + + public void RemoveFile(int fileId) + { + var dbFile = _db.PictureFiles.SingleOrDefault(a=>a.Id == fileId); + _db.PictureFiles.Remove(dbFile); + _db.SaveChanges(); + } + + public void RemovePerson(int personId, int fileId) + { + var dbPerson = _db.PicturePersons.SingleOrDefault(a => a.Id == fileId); + _db.PicturePersons.Remove(dbPerson); + _db.SaveChanges(); + } + + public int GetFileCountForPersonId(Guid personId) + { + var peops = _db.PicturePersons.Where(a => a.PersonId == personId); + return peops.Count(); + } + + public List GetFilesForPersonId(Guid personId) + { + var peops = _db.PicturePersons.Where(a => a.PersonId == personId).ToList(); + foreach(var person in peops) + { + person.PictureFile = _db.PictureFiles.Find(a => a.Id == person.PictureFileId); + person.Person = _db.People.Find(a => a.PersonId == person.PersonId); + } + + return peops; + } + + public Person GetPerson(Guid personId) + { + return _db.People.Where(a => a.PersonId == personId).SingleOrDefault(); + } + + public void AddPerson(Guid personId, string name, string userData) + { + _db.People.Add(new Person { Name = name, PersonId = personId, UserData = userData }); + _db.SaveChanges(); + } + + public void RemovePersonsForGroup(string groupId) + { + var persons = _db.PicturePersons.Where(a => a.LargePersonGroupId == groupId); + foreach(var p in persons) + { + _db.PicturePersons.Remove(p); + } + _db.SaveChanges(); + } + + } +} \ No newline at end of file diff --git a/DatabaseLibrary/Properties/AssemblyInfo.cs b/DatabaseLibrary/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c27f930 --- /dev/null +++ b/DatabaseLibrary/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("DatabaseLibrary")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DatabaseLibrary")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d7d7a8ca-8e2e-4ff3-9eb4-78de8a514332")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DatabaseLibrary/SqlDataProvider.cs b/DatabaseLibrary/SqlDataProvider.cs new file mode 100644 index 0000000..e73e60a --- /dev/null +++ b/DatabaseLibrary/SqlDataProvider.cs @@ -0,0 +1,89 @@ +using DatabaseLibrary.Data; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseLibrary +{ + public class SqlDataProvider : IDataProvider + { + PhotosDatabase _db; + + public SqlDataProvider(string connectionString) + { + _db = new PhotosDatabase(connectionString); + } + + public void AddFile(PictureFile file, string groupId, int processingState) + { + var lookup = new PictureFileGroupLookup + { + LargePersonGroupId = groupId, + ProcessingState = processingState, + }; + + lookup.PictureFile = file; + _db.PictureFileGroupLookups.Add(lookup); + _db.SaveChanges(); + + + //db.PictureFiles.Add(file); + //db.SaveChanges(); + //db.PictureFileGroupLookups.Add(new PictureFileGroupLookup { LargePersonGroupId = groupId, PictureFileId = }) + } + + public PictureFile GetFile(string path) + { + return _db.PictureFiles.Where(a => a.FilePath == path).SingleOrDefault(); + } + + public void AddPerson(PicturePerson person) + { + _db.PicturePersons.Add(person); + _db.SaveChanges(); + } + + public void RemoveFile(int fileId) + { + var dbFile = _db.PictureFiles.Find(fileId); + _db.PictureFiles.Remove(dbFile); + _db.SaveChanges(); + } + + public void RemovePerson(int personId, int fileId) + { + var dbPerson = _db.PicturePersons.Find(fileId); + _db.PicturePersons.Remove(dbPerson); + _db.SaveChanges(); + } + + public int GetFileCountForPersonId(Guid personId) + { + return _db.PicturePersons.Where(a => a.PersonId == personId).Count(); + } + + public List GetFilesForPersonId(Guid personId) + { + return _db.PicturePersons.Where(a => a.PersonId == personId).ToList(); + } + + public Person GetPerson(Guid personId) + { + return _db.People.Where(a => a.PersonId == personId).SingleOrDefault(); + } + + public void AddPerson(Guid personId, string name, string userData) + { + _db.People.Add(new Person { Name = name, PersonId = personId, UserData = userData }); + _db.SaveChanges(); + } + + public void RemovePersonsForGroup(string groupId) + { + _db.Database.ExecuteSqlCommand($"DELETE FROM PicturePerson WHERE LargePersonGroupId = '{groupId}'"); + } + } +} diff --git a/DatabaseLibrary/packages.config b/DatabaseLibrary/packages.config new file mode 100644 index 0000000..4b6f309 --- /dev/null +++ b/DatabaseLibrary/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Photo-App/App.config b/Photo-App/App.config new file mode 100644 index 0000000..1ff1dc8 --- /dev/null +++ b/Photo-App/App.config @@ -0,0 +1,27 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/Photo-App/App.xaml b/Photo-App/App.xaml new file mode 100644 index 0000000..f343856 --- /dev/null +++ b/Photo-App/App.xaml @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/Photo-App/App.xaml.cs b/Photo-App/App.xaml.cs new file mode 100644 index 0000000..f2de48a --- /dev/null +++ b/Photo-App/App.xaml.cs @@ -0,0 +1,28 @@ +using Photo_Detect_Catalogue_Search_WPF_App.Helpers; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Threading; + +namespace Photo_Detect_Catalogue_Search_WPF_App +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + private App() + { + this.DispatcherUnhandledException += App_DispatcherUnhandledException; + } + + private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + FileTraceWriter.LogError(e.Exception, $"UnhandledException, {e.Exception.Message}"); + } + } +} diff --git a/Photo-App/Assets/Microsoft-logo_rgb_c-gray.png b/Photo-App/Assets/Microsoft-logo_rgb_c-gray.png new file mode 100644 index 0000000..7846308 Binary files /dev/null and b/Photo-App/Assets/Microsoft-logo_rgb_c-gray.png differ diff --git a/Photo-App/Assets/default.jpg b/Photo-App/Assets/default.jpg new file mode 100644 index 0000000..00e1df8 Binary files /dev/null and b/Photo-App/Assets/default.jpg differ diff --git a/Photo-App/Controls/FaceIdentificationPage.xaml b/Photo-App/Controls/FaceIdentificationPage.xaml new file mode 100644 index 0000000..93de7a7 --- /dev/null +++ b/Photo-App/Controls/FaceIdentificationPage.xaml @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +