public void Synchronize() { foreach (Type type in StorableTypes) { FileInfo[] files = YamlDataDirectory.GetYamlFiles(type); foreach (FileInfo file in files) { YamlData data = YamlData.Load(type, file, Logger); object dao = DaoRepository.Query("Name", data.Name).FirstOrDefault(); if (dao == null) { DaoRepository.Save(data.Data); } else { data.FileWins += (o, a) => { YamlData.YamlDataEventArgs d = (YamlData.YamlDataEventArgs)a; DaoRepository.Save(d.Type, d.Data); FireEvent(FileWins, d); }; data.DataWins += (o, a) => { YamlData.YamlDataEventArgs d = (YamlData.YamlDataEventArgs)a; YamlDataDirectory.Save(file, d.Type, d.Data); FireEvent(DataWins, d); }; data.Data = dao; data.Synchronize(type, file); } } } }
public void RepoShouldBeQueryable() { DaoRepository repo = GetTestDaoRepository(); repo.EnsureDaoAssemblyAndSchema(); House one = new House { Name = "Get This One" }; House two = new House { Name = "Get This Too" }; House three = new House { Name = "Not this one" }; repo.Save(one); repo.Save(three); repo.Save(two); House[] houses = repo.Query <House>(Query.Where("Name").StartsWith("Get")).ToArray(); Expect.AreEqual(2, houses.Length); houses.Each(house => { repo.Delete(house); }); repo.Delete(three); }
public virtual ExternalEventSubscriptionDescriptor SubscribeExternal(ExternalEventSubscriptionDescriptor subscriptionInfo) { if (string.IsNullOrWhiteSpace(subscriptionInfo.CreatedBy)) { subscriptionInfo.CreatedBy = CurrentUser.UserName; } string clientNameProp = nameof(ExternalEventSubscriptionDescriptor.ClientName); string eventNameProp = nameof(ExternalEventSubscriptionDescriptor.EventName); Args.ThrowIfNullOrEmpty(subscriptionInfo.ClientName, clientNameProp); Args.ThrowIfNullOrEmpty(subscriptionInfo.EventName, eventNameProp); ExternalEventSubscriptionDescriptor lookedUp = DaoRepository.Query <ExternalEventSubscriptionDescriptor> ( Query.Where(clientNameProp) == subscriptionInfo.ClientName && Query.Where(eventNameProp) == subscriptionInfo.EventName && Query.Where(nameof(ExternalEventSubscriptionDescriptor.CreatedBy)) == subscriptionInfo.CreatedBy ) .FirstOrDefault(); if (lookedUp != null) { return(lookedUp); } return(DaoRepository.Save(subscriptionInfo)); }
public void TestDaoRepoHbGen() { Database db = DataProvider.Current.GetAppDatabaseFor(ProcessApplicationNameProvider.Current, this); DaoRepository repo = new DaoRepository(db) { BaseNamespace = typeof(ShellDescriptor).Namespace, RequireCuid = true }; repo.AddType <ShellDescriptor>(); ShellDescriptor d = new ShellDescriptor() { AssemblyName = "Ass", NameSpace = "Ns" }; d = repo.Save(d); ShellDescriptor queried = repo.Query <ShellDescriptor>(c => c.Id == d.Id).FirstOrDefault(); Expect.IsNotNull(queried); Expect.AreEqual(d, queried); ShellDescriptor retrieved = repo.Retrieve <ShellDescriptor>(d.Id); Expect.IsNotNull(retrieved); Expect.AreEqual(d, retrieved); Pass("yay"); }
public void CanSaveToRepo() { DataPoint point = new DataPoint(); point.Description = "Description_".RandomLetters(5); DaoRepository repo = new DaoRepository(); repo.Database = new SQLiteDatabase(".\\", nameof(CanSaveToRepo)); repo.AddType <DataPoint>(); repo.AddType <DataRelationship>(); string prop1 = "Hello_".RandomLetters(8); string prop2 = "banana".RandomLetters(4); bool gender = false; point.Property("Name", prop1); point.Property("LastName", prop2); point.Property("Gender", gender); point = repo.Save(point); Expect.IsTrue(point.Cuid.Length > 0); OutLine(point.Cuid); DataPoint retrieved = repo.Query <DataPoint>(dp => dp.Cuid == point.Cuid).FirstOrDefault(); Expect.AreEqual(point.Description, retrieved.Description); Expect.AreEqual(prop1, retrieved.Property("Name").Value); Expect.AreEqual(prop2, retrieved.Property("LastName").Value); Expect.AreEqual(false, retrieved.Property("Gender").Value); Expect.AreEqual(prop1, retrieved.Property <string>("Name")); Expect.AreEqual(prop2, retrieved.Property <string>("LastName")); Expect.AreEqual(gender, retrieved.Property <bool>("Gender")); }
/// <summary> /// Write the yaml files for the specified names by /// retrieving them from the DaoRepository; they will not /// be written if they are not found in the DaoRepository /// </summary> /// <typeparam name="T"></typeparam> /// <param name="names"></param> /// <returns></returns> public IEnumerable <T> LoadYaml <T>(params string[] names) where T : class, new() { IEnumerable <T> values = DaoRepository.Query <T>(QueryFilter.Where("Name").In(names)); foreach (T value in values) { WriteYaml(typeof(T), value); } return(values); }
public override IEnumerable <object> Query(Type type, Func <object, bool> predicate) { foreach (object o in DaoRepository.Query(type, predicate)) { yield return(o); } foreach (object o in YamlDataDirectory.Load(type)) { if (predicate(o)) { yield return(o); } } }
public override IEnumerable <T> Query <T>(Func <T, bool> query) { foreach (T val in DaoRepository.Query(query)) { yield return(val); } foreach (YamlDataFile val in YamlDataDirectory.Load(typeof(T))) { T copy = val.Data.CopyAs <T>(); if (query(copy)) { yield return(copy); } } }
/// <summary> /// Load from the DaoRepository database the records /// specified in the load.names file for each storable type /// </summary> /// <returns></returns> public IEnumerable <object> LoadYaml() { // get names from YamlDataDirectory/load.names // load each one at a time and yield HashSet <string> names = new HashSet <string>(); foreach (Type type in StorableTypes) { FileInfo loadNamesFile = GetLoadNamesFile(type); if (loadNamesFile.Exists) { File.ReadAllLines(loadNamesFile.FullName).Each(n => names.Add(n)); foreach (string name in names) { object value = DaoRepository.Query(type, QueryFilter.Where("Name") == name).FirstOrDefault(); if (value != null) { WriteYaml(type, value); yield return(value); } } } } }