/// <summary> /// /// </summary> /// <param name="file"></param> /// <returns></returns> public HisDatabase Load(string file) { HisDatabase db = new HisDatabase(); if (System.IO.File.Exists(file)) { XElement xe = XElement.Load(file); db.Name = xe.Attribute("Name").Value; db.Version = xe.Attribute("Version").Value; if (xe.Element("Tags") != null) { Parallel.ForEach(xe.Element("Tags").Elements(), (vv) => { var tag = vv.LoadHisTagFromXML(); lock (db.HisTags) db.HisTags.Add(tag.Id, tag); }); //foreach (var vv in xe.Element("Tags").Elements()) //{ // var tag = vv.LoadHisTagFromXML(); // db.HisTags.Add(tag.Id, tag); //} } if (xe.Element("HisSetting") != null) { db.Setting = xe.Element("HisSetting").LoadHisSettingDocFromXML(); } } this.Database = db; return(db); }
/// <summary> /// /// </summary> private void LoadDatabase() { Stopwatch sw = new Stopwatch(); sw.Start(); this.mDatabase = new DatabaseSerise().Load(mDatabaseName); this.mRealDatabase = this.mDatabase.RealDatabase; this.mHisDatabase = this.mDatabase.HisDatabase; CurrentDatabaseVersion = this.mRealDatabase.Version; CurrentDatabase = mRealDatabase.Name; CurrentDatabaseLastUpdateTime = mRealDatabase.UpdateTime; sw.Stop(); LoggerService.Service.Info("LoadDatabase", "加载数据库 " + mDatabaseName + " 花费: " + sw.ElapsedMilliseconds.ToString() + " ms"); }
/// <summary> /// /// </summary> /// <param name="file"></param> /// <param name="target"></param> /// <returns></returns> public HisDatabase LoadDifference(string file, HisDatabase target) { HisDatabase db = new HisDatabase(); if (System.IO.File.Exists(file)) { XElement xe = XElement.Load(file); db.Name = xe.Attribute("Name").Value; db.Version = xe.Attribute("Version").Value; if (xe.Element("Tags") != null) { //Parallel.ForEach(xe.Element("Tags").Elements(), (vv) => //{ // var tag = vv.LoadHisTagFromXML(); // lock (db.HisTags) // db.HisTags.Add(tag.Id, tag); //}); foreach (var vv in xe.Element("Tags").Elements()) { var tag = vv.LoadHisTagFromXML(); if (!target.HisTags.ContainsKey(tag.Id) || !tag.Equals(target.HisTags[tag.Id])) { db.HisTags.Add(tag.Id, tag); } } } if (xe.Element("HisSetting") != null) { db.Setting = xe.Element("HisSetting").LoadHisSettingDocFromXML(); } } this.Database = db; return(db); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="target"></param> /// <returns></returns> public HisDatabase LoadDifferenceByName(string name, HisDatabase target) { return(LoadDifference(PathHelper.helper.GetDataPath(name, name + ".hdb"), target)); }
/// <summary> /// /// </summary> /// <param name="databaseName"></param> /// <param name="dcount"></param> /// <param name="fcount"></param> /// <param name="lcount"></param> /// <param name="icount"></param> /// <param name="bcount"></param> static void GeneratorTestDatabase(string databaseName, int dcount = 0, int fcount = 0, int lcount = 0, int icount = 0, int bcount = 0) { //Cdy.Tag.PathHelper.helper.SetDataBasePath(databaseName); Database db = Database.New(databaseName); Cdy.Tag.RealDatabase test = db.RealDatabase; db.RealDatabase = test; string address = ""; for (int i = 0; i < dcount; i++) { if (i % 3 == 0) { address = "Sim:sin"; } else if (i % 3 == 1) { address = "Sim:cos"; } else { address = "Sim:step"; } test.Append(new Cdy.Tag.DoubleTag() { Name = "Double" + i, Group = "Double", LinkAddress = address }); } for (int i = 0; i < fcount; i++) { if (i % 3 == 0) { address = "Sim:sin"; } else if (i % 3 == 1) { address = "Sim:cos"; } else { address = "Sim:step"; } test.Append(new Cdy.Tag.FloatTag() { Name = "Float" + i, Group = "Float", LinkAddress = address }); } for (int i = 0; i < lcount; i++) { test.Append(new Cdy.Tag.LongTag() { Name = "Long" + i, Group = "Long", LinkAddress = "Sim:step" }); } for (int i = 0; i < icount; i++) { test.Append(new Cdy.Tag.IntTag() { Name = "Int" + i, Group = "Int" }); } for (int i = 0; i < bcount; i++) { test.Append(new Cdy.Tag.BoolTag() { Name = "Bool" + i, Group = "Bool" }); } Cdy.Tag.HisDatabase htest = db.HisDatabase; int id = 0; for (int i = 0; i < dcount; i++) { htest.AddHisTags(new Cdy.Tag.HisTag() { Id = id, TagType = Cdy.Tag.TagType.Double, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 }); id++; } for (int i = 0; i < fcount; i++) { htest.AddHisTags(new Cdy.Tag.HisTag() { Id = id, TagType = Cdy.Tag.TagType.Float, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 }); id++; } for (int i = 0; i < lcount; i++) { htest.AddHisTags(new Cdy.Tag.HisTag() { Id = id, TagType = Cdy.Tag.TagType.Long, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 }); id++; } for (int i = 0; i < icount; i++) { htest.AddHisTags(new Cdy.Tag.HisTag() { Id = id, TagType = Cdy.Tag.TagType.Int, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 }); id++; } for (int i = 0; i < bcount; i++) { htest.AddHisTags(new Cdy.Tag.HisTag() { Id = id, TagType = Cdy.Tag.TagType.Bool, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 }); id++; } db.HisDatabase = htest; new DatabaseSerise() { Dbase = db }.Save(); }
/// <summary> /// /// </summary> private void LoadDatabase() { this.mDatabase = new DatabaseSerise().Load(mDatabaseName); this.mRealDatabase = this.mDatabase.RealDatabase; this.mHisDatabase = this.mDatabase.HisDatabase; }