Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,5 @@ paket-files/
# JetBrains Rider
.idea/
*.sln.iml
/WapProjTemplate1
/DesktopBridgeDeployment
13 changes: 13 additions & 0 deletions DatabaseLibrary/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
31 changes: 31 additions & 0 deletions DatabaseLibrary/Data/IDataProvider.cs
Original file line number Diff line number Diff line change
@@ -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<PicturePerson> GetFilesForPersonId(Guid personId);
}
}
119 changes: 119 additions & 0 deletions DatabaseLibrary/Data/IsolatedStorageDatabase.cs
Original file line number Diff line number Diff line change
@@ -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<Person> People { get; set; }
[JsonProperty(PropertyName = "PF")]
public virtual List<PictureFile> PictureFiles { get; set; }
[JsonProperty(PropertyName = "PL")]
public virtual List<PictureFileGroupLookup> PictureFileGroupLookups { get; set; }
[JsonProperty(PropertyName = "PP")]
public virtual List<PicturePerson> 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<Person>();
d.PictureFiles = new List<PictureFile>();
d.PictureFileGroupLookups = new List<PictureFileGroupLookup>();
d.PicturePersons = new List<PicturePerson>();

_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<IsolatedStorageDatabase>(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)
//{
//}
}
}
26 changes: 26 additions & 0 deletions DatabaseLibrary/Data/Person.cs
Original file line number Diff line number Diff line change
@@ -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<PicturePerson> PicturePersons { get; set; }
}
}
33 changes: 33 additions & 0 deletions DatabaseLibrary/Data/PhotosDatabase.cs
Original file line number Diff line number Diff line change
@@ -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<Person> People { get; set; }
public virtual DbSet<PictureFile> PictureFiles { get; set; }
public virtual DbSet<PictureFileGroupLookup> PictureFileGroupLookups { get; set; }
public virtual DbSet<PicturePerson> PicturePersons { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<PictureFileGroupLookup>()
.Property(e => e.LargePersonGroupId)
.IsUnicode(false);

modelBuilder.Entity<PictureFileGroupLookup>()
.HasKey(l => new { l.PictureFileId, l.LargePersonGroupId });

modelBuilder.Entity<PicturePerson>()
.HasKey(l => l.Id);
}
}
}
90 changes: 90 additions & 0 deletions DatabaseLibrary/Data/PhotosDatabase2.cs
Original file line number Diff line number Diff line change
@@ -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<PhotosDatabase2>(json);
}
catch (Exception e)
{

}
}
}
}
catch (FileNotFoundException)
{
database = null;
}
}
return database;
}

public virtual DbSet<Person> People { get; set; }
public virtual DbSet<PictureFile> PictureFiles { get; set; }
public virtual DbSet<PictureFileGroupLookup> PictureFileGroupLookups { get; set; }
public virtual DbSet<PicturePerson> PicturePersons { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<PictureFileGroupLookup>()
.Property(e => e.LargePersonGroupId)
.IsUnicode(false);

modelBuilder.Entity<PictureFileGroupLookup>()
.HasKey(l => new { l.PictureFileId, l.LargePersonGroupId });

modelBuilder.Entity<PicturePerson>()
.HasKey(l => l.Id);
}
}
}
Loading