Esempio n. 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);
        }
Esempio n. 2
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);
        }