Example #1
0
        /// <summary>
        /// 加载差异部分
        /// </summary>
        /// <param name="path"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public RealDatabase LoadDifference(string path, RealDatabase target)
        {
            RealDatabase db = new RealDatabase();

            if (System.IO.File.Exists(path))
            {
                db.UpdateTime = new System.IO.FileInfo(path).LastWriteTimeUtc.ToString();

                XElement xe = XElement.Load(path);

                db.Name    = xe.Attribute("Name").Value;
                db.Version = xe.Attribute("Version").Value;

                if (xe.Element("Tags") != null)
                {
                    foreach (var vv in xe.Element("Tags").Elements())
                    {
                        var tag = vv.LoadTagFromXML();

                        if (!target.Tags.ContainsKey(tag.Id) || !tag.Equals(target.Tags[tag.Id]))
                        {
                            db.Tags.Add(tag.Id, tag);
                        }
                    }
                    db.BuildNameMap();
                }
                if (db.Tags.Count > 0)
                {
                    db.MaxId = db.Tags.Keys.Max();
                }
            }
            db.IsDirty    = false;
            this.Database = db;
            return(db);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="database"></param>
        /// <param name="hiscompareaction"></param>
        /// <returns></returns>
        public Database LoadDifference(string name, RealDatabase database, Func <HisTag, bool> hiscompareaction)
        {
            var Dbase = LoadDatabaseSelf(PathHelper.helper.GetDataPath(name, name + ".db"));

            Dbase.Security     = new SecuritySerise().LoadByName(name);
            Dbase.RealDatabase = new RealDatabaseSerise().LoadDifferenceByName(name, database);
            Dbase.HisDatabase  = new HisDatabaseSerise().LoadDifferenceByName(name, hiscompareaction);
            return(Dbase);
        }
Example #3
0
        /// <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");
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        public RealDatabase Load(string path)
        {
            RealDatabase db = new RealDatabase();

            if (System.IO.File.Exists(path))
            {
                XElement xe = XElement.Load(path);

                db.Name    = xe.Attribute("Name").Value;
                db.Version = xe.Attribute("Version").Value;

                if (xe.Element("Tags") != null)
                {
                    foreach (var vv in xe.Element("Tags").Elements())
                    {
                        var tag = vv.LoadTagFromXML();
                        db.Tags.Add(tag.Id, tag);
                    }
                }

                Dictionary <string, TagGroup> groups  = new Dictionary <string, TagGroup>();
                Dictionary <TagGroup, string> parents = new Dictionary <TagGroup, string>();
                if (xe.Element("Groups") != null)
                {
                    foreach (var vv in xe.Element("Groups").Elements())
                    {
                        TagGroup group = new TagGroup();
                        group.Name = vv.Attribute("Name").Value;
                        string parent = vv.Attribute("Parent") != null?xe.Attribute("Parent").Value : "";

                        string fullName = vv.Attribute("FullName").Value;

                        if (!groups.ContainsKey(fullName))
                        {
                            groups.Add(fullName, group);
                        }

                        parents.Add(group, parent);
                    }
                }
                db.Groups = groups;

                foreach (var vv in parents)
                {
                    if (!string.IsNullOrEmpty(vv.Value) && db.Groups.ContainsKey(vv.Value))
                    {
                        vv.Key.Parent = db.Groups[vv.Value];
                    }
                }
                if (xe.Attribute("MaxId") != null)
                {
                    db.MaxId = int.Parse(xe.Attribute("MaxId").Value);
                }
                else
                {
                    db.MaxId = db.Tags.Keys.Max();
                }
            }
            this.Database = db;
            return(db);
        }
Example #5
0
 /// <summary>
 /// 加载差异部分
 /// </summary>
 /// <param name="name"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 public RealDatabase LoadDifferenceByName(string name, RealDatabase target)
 {
     return(LoadDifference(PathHelper.helper.GetDataPath(name, name + ".xdb"), target));
 }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        public RealDatabase Load(string path)
        {
            RealDatabase db = new RealDatabase();

            if (System.IO.File.Exists(path))
            {
                db.UpdateTime = new System.IO.FileInfo(path).LastWriteTimeUtc.ToString();

                XElement xe = XElement.Load(path);

                db.Name    = xe.Attribute("Name").Value;
                db.Version = xe.Attribute("Version").Value;

                Dictionary <string, TagGroup> groups  = new Dictionary <string, TagGroup>();
                Dictionary <TagGroup, string> parents = new Dictionary <TagGroup, string>();
                if (xe.Element("Groups") != null)
                {
                    foreach (var vv in xe.Element("Groups").Elements())
                    {
                        TagGroup group = new TagGroup();
                        group.Name = vv.Attribute("Name").Value;
                        string parent = vv.Attribute("Parent") != null?vv.Attribute("Parent").Value : "";

                        string fullName = vv.Attribute("FullName").Value;

                        if (vv.Attribute("Description") != null)
                        {
                            group.Description = vv.Attribute("Description").Value;
                        }

                        if (!groups.ContainsKey(fullName))
                        {
                            groups.Add(fullName, group);
                        }

                        parents.Add(group, parent);
                    }
                }
                db.Groups = groups;

                foreach (var vv in parents)
                {
                    if (!string.IsNullOrEmpty(vv.Value) && db.Groups.ContainsKey(vv.Value))
                    {
                        vv.Key.Parent = db.Groups[vv.Value];
                    }
                }

                if (xe.Element("Tags") != null)
                {
                    //Parallel.ForEach(xe.Element("Tags").Elements(), (vv) => {
                    //    var tag = vv.LoadTagFromXML();
                    //    lock (db.Tags)
                    //        db.Tags.Add(tag.Id, tag);
                    //});
                    foreach (var vv in xe.Element("Tags").Elements())
                    {
                        var tag = vv.LoadTagFromXML();
                        db.Tags.Add(tag.Id, tag);
                    }

                    db.BuildNameMap();
                    db.BuildGroupMap();
                }

                if (xe.Attribute("MaxId") != null)
                {
                    db.MaxId = int.Parse(xe.Attribute("MaxId").Value);
                }
                else
                {
                    if (db.Tags.Count > 0)
                    {
                        db.MaxId = db.Tags.Keys.Max();
                    }
                }

                db.MinId = db.Tags.Count > 0?db.Tags.Keys.Min():0;
            }
            db.IsDirty    = false;
            this.Database = db;
            return(db);
        }
Example #7
0
        /// <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();
        }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 private void LoadDatabase()
 {
     this.mDatabase     = new DatabaseSerise().Load(mDatabaseName);
     this.mRealDatabase = this.mDatabase.RealDatabase;
     this.mHisDatabase  = this.mDatabase.HisDatabase;
 }