public static StoreSetting GetSetting <TValue>(ObjectStoreParameters para) { var setting = new StoreSetting(); setting.PrimaryKey = para.PrimaryKey; var keytype = Helper.TypeHelper.GetFieldType <TValue>(setting.PrimaryKey); if (keytype != null) { setting.PrimaryKeyLen = Helper.KeyHelper.GetKeyLen(keytype, para.PrimaryKeyLength); } else { setting.PrimaryKeyLen = para.PrimaryKeyLength; } setting.MaxCacheLevel = para.MaxCacheLevel; setting.ValueTypeFullName = typeof(TValue).FullName; setting.UseDefaultNETBinaryFormater = para.UseDefaultNETBinaryFormater; setting.EnableLog = para.EnableLog; setting.EnableVersion = para.EnableVersion; setting.Columns = GetColumns <TValue>(para.ColumnList, setting.PrimaryKey, setting.PrimaryKeyLen); setting.Indexs = para.IndexList; return(setting); }
/// <summary> /// /// </summary> /// <param name="db"></param> /// <returns></returns> public static ObjectStore <Guid, NodeProgress> NodeProgress(SiteDb db) { string storename = typeof(NodeProgress).Name; ObjectStoreParameters paras = new ObjectStoreParameters(); return(db.DatabaseDb.GetOrCreateObjectStore <Guid, NodeProgress>(storename, paras)); }
public static ObjectStore <Guid, ClusterNode> ClusterNodes(SiteDb SiteDb) { string storename = typeof(ClusterNode).Name; ObjectStoreParameters paras = new ObjectStoreParameters(); return(SiteDb.DatabaseDb.GetOrCreateObjectStore <Guid, ClusterNode>(storename, paras)); }
public static ObjectStore <Guid, NodeUpdate> ClusterUpdateHistory(SiteDb db) { string storename = typeof(NodeUpdate).Name; ObjectStoreParameters paras = new ObjectStoreParameters(); paras.AddIndex <NodeUpdate>(o => o.ObjectId); paras.AddIndex <NodeUpdate>(o => o.LocalVersion); return(db.DatabaseDb.GetOrCreateObjectStore <Guid, NodeUpdate>(storename, paras)); }
public static ObjectStore <Guid, Notification> Notifications() { string storename = typeof(Notification).Name; lock (_websiteobject) { var paras = new ObjectStoreParameters(); paras.AddColumn <Notification>(o => o.Id); paras.AddColumn <Notification>(o => o.UserId); paras.AddColumn <Notification>(o => o.WebSiteId); return(Global().GetOrCreateObjectStore <Guid, Notification>(storename, paras)); } }
public static bool IsSettingChange <TValue>(string SettingFile, ObjectStoreParameters para) { if (File.Exists(SettingFile)) { var allbytes = File.ReadAllBytes(SettingFile); Kooboo.IndexedDB.Serializer.Simple.SimpleConverter <StoreSetting> converter = new Serializer.Simple.SimpleConverter <StoreSetting>(); var oldsetting = converter.FromBytes(allbytes); var newsetting = GetSetting <TValue>(para); if (!IsSameSetting(oldsetting, newsetting)) { return(true); } } return(false); }
public static List <ColumnSetting> GetColumnSetting(Type valuetype, ObjectStoreParameters parameters) { List <ColumnSetting> columnList = new List <ColumnSetting>(); int relativePosition = 0; if (parameters.ColumnList.Count > 0) { foreach (var item in parameters.ColumnList) { ColumnSetting column = new ColumnSetting(); column.FieldName = item.Key; FieldInfo fieldinfo = valuetype.GetField(item.Key); if (fieldinfo != null) { column.KeyType = fieldinfo.FieldType; column.isField = true; } else { //try get property. PropertyInfo propertyinfo = valuetype.GetProperty(item.Key); if (propertyinfo != null) { column.KeyType = propertyinfo.PropertyType; column.isProperty = true; } else { throw new Exception("field or property does not exists " + item); } } column.length = Helper.KeyHelper.GetKeyLen(column.KeyType, item.Value); column.relativePosition = relativePosition; relativePosition += column.length; columnList.Add(column); } } return(columnList); }
public static ObjectStoreSetting GetOldSetting <TValue, TKey>(ObjectStoreParameters para) { var newsettings = new ObjectStoreSetting(); newsettings.headerRemark = "store setting in binary form, do not modify"; newsettings.primaryKeyType = typeof(TKey); newsettings.MaxCacheLevel = para.MaxCacheLevel; newsettings.primaryKeyLength = Helper.KeyHelper.GetKeyLen(typeof(TKey), para.PrimaryKeyLength); newsettings.ValueType = typeof(TValue); newsettings.UseDefaultNETBinaryFormater = para.UseDefaultNETBinaryFormater; newsettings.EnableLog = para.EnableLog; newsettings.EnableVersion = para.EnableVersion; newsettings.primaryKeyFieldName = TryGuessPrimaryKey <TValue, TKey>(para.PrimaryKey); newsettings.IndexList = Helper.IndexHelper.GenerateIndexsFromParameters(newsettings.ValueType, para); newsettings.ColumnList = Helper.SettingHelper.GetColumnSetting(newsettings.ValueType, para); return(newsettings); }
public static void InitDatabase(bool CreateFolder = false) { string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; string path = Path.Combine(baseDirectory, "IpData"); if (CreateFolder) { IOHelper.EnsureDirectoryExists(path); } if (Directory.Exists(path)) { if (!CreateFolder) { string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories); if (files == null || files.Length == 0) { return; } } if (Database == null) { Database = new Database(path); } if (CityStore == null) { ObjectStoreParameters paras = new ObjectStoreParameters(); paras.SetPrimaryKeyField <CityInfo>(o => o.Id); paras.EnableLog = false; paras.EnableVersion = false; CityStore = Database.GetOrCreateObjectStore <int, CityInfo>("City", paras); } if (StateStore == null) { ObjectStoreParameters parastate = new ObjectStoreParameters(); parastate.SetPrimaryKeyField <StateInfo>(o => o.Id); parastate.EnableVersion = false; parastate.EnableLog = false; StateStore = Database.GetOrCreateObjectStore <int, StateInfo>("State", parastate); } if (IpCityStore == null) { ObjectStoreParameters paracity = new ObjectStoreParameters(); paracity.SetPrimaryKeyField <IPCity>(o => o.IpStart); paracity.AddColumn <IPCity>(o => o.IpEnd); paracity.EnableLog = false; paracity.EnableVersion = false; IpCityStore = Database.GetOrCreateObjectStore <int, IPCity>("IpCity", paracity); } if (IPCountryStore == null) { ObjectStoreParameters paracountry = new ObjectStoreParameters(); paracountry.SetPrimaryKeyField <IPCity>(o => o.IpStart); paracountry.AddColumn <IPCity>(o => o.IpEnd); paracountry.EnableVersion = false; paracountry.EnableLog = false; IPCountryStore = Database.GetOrCreateObjectStore <int, IPCountry>("IpCountry", paracountry); } } }
public static List <IndexSetting> GenerateIndexsFromParameters(Type ValueType, ObjectStoreParameters parameters) { List <IndexSetting> indexlist = new List <IndexSetting>(); // create the index setting. foreach (var item in parameters.IndexList) { IndexSetting index = new IndexSetting(); index.FieldName = item.Key; FieldInfo fieldinfo = ValueType.GetField(item.Key); if (fieldinfo != null) { index.KeyType = fieldinfo.FieldType; } else { //try get property. PropertyInfo propertyinfo = ValueType.GetProperty(item.Key); if (propertyinfo != null) { index.KeyType = propertyinfo.PropertyType; } else { throw new Exception("field or property does not exists " + item); } } index.unique = false; /// this should always be false for all additional index.unique should be checked by contraints. index.keyLength = Helper.KeyHelper.GetKeyLen(index.KeyType, index.keyLength); indexlist.Add(index); } return(indexlist); }
public static StoreSetting GetOrSetSetting <TValue, TKey>(string SettingFile, ObjectStoreParameters para) { Kooboo.IndexedDB.Serializer.Simple.SimpleConverter <StoreSetting> converter = new Serializer.Simple.SimpleConverter <StoreSetting>(); if (File.Exists(SettingFile)) { var allbytes = File.ReadAllBytes(SettingFile); return(converter.FromBytes(allbytes)); } else { var setting = GetSetting <TValue>(para); var allbytes = converter.ToBytes(setting); File.WriteAllBytes(SettingFile, allbytes); return(setting); } }