Exemplo n.º 1
0
        public DatabaseChanges Load(string filename)
        {
            var changes = new DatabaseChanges();
            var xDoc    = XDocument.Load(filename);

            var xMeta = xDoc.Root.Element("Metadata");

            changes.RootDatabaseFolder = xMeta.Element("RootDatabaseFolder").Value;
            changes.RootWorkItemId     = Convert.ToInt32(xMeta.Element("RootWorkItemId").Value);
            changes.GeneratedAt        = Convert.ToDateTime(xMeta.Element("GeneratedAt").Value);
            changes.LastSavedAt        = Convert.ToDateTime(xMeta.Element("LastSavedAt").Value);
            changes.DeletedSubDirName  = xMeta.Element("DeletedSubDirName").Value;

            var xChanges  = xDoc.Root.Element("Changes");
            var xIncluded = xChanges.Element("Included");
            var xExcluded = xChanges.Element("Excluded");

            xIncluded.Elements().ToList().ForEach(x => changes.IncludedChanges.Add(Change(x, changes)));
            xExcluded.Elements().ToList().ForEach(x => changes.ExcludedChanges.Add(Change(x, changes)));

            var index = 0;

            changes.IncludedChanges.ToList().ForEach(x => x.Index = ++index);

            return(changes);
        }
Exemplo n.º 2
0
        private DatabaseChange Change(XElement xChange, DatabaseChanges changes)
        {
            var xLastChangeType = xChange.Element("ChangeTypes").Elements().LastOrDefault();
            //var lastChangeType = ChangeTypes.None;
            //if (null != xLastChangeType)
            //lastChangeType = (ChangeTypes)Enum.Parse(typeof(ChangeTypes), xLastChangeType.Value);

            var filename = Path.Combine(changes.RootDatabaseFolder, xChange.Element("FilePath").Value);
            var fileType = this.KnownFileTypes.GetTypeForFilenameExt(filename);
            var ext      = fileType.GetFileExtensionForFile(filename);

            // Type is set via Extension
            // File is set via Filename
            var change = new DatabaseChange
            {
                Schema   = xChange.Attribute("Schema").Value,
                Filename = filename,
                //FilePath = filename.Replace(changes.RootDatabaseFolder, string.Empty),
                FilePath     = xChange.Element("FilePath").Value,
                Extension    = ext,
                FirstChanged = DateTime.Parse(xChange.Element("FirstChanged").Value),
                LastChanged  = DateTime.Parse(xChange.Element("LastChanged").Value),
                IsAttachment = Convert.ToBoolean(xChange.Element("IsAttachment").Value),
                IsManualAdd  = Convert.ToBoolean(xChange.Element("IsManualAdd").Value)
            };

            var xServerItem = xChange.Element("ServerItem");

            if (null != xServerItem)
            {
                change.ServerItem = xServerItem.Value;
            }

            var xChangeTypes = xChange.Element("ChangeTypes");

            xChangeTypes.Elements().ToList().ForEach(x => change.AddChangeType((ChangeTypes)Enum.Parse(typeof(ChangeTypes), x.Value)));

            var xTasks = xChange.Element("Tasks");

            xTasks.Elements().ToList().ForEach(xTask =>
            {
                var taskInfo = new WorkItemInfo
                {
                    AssignedTo = xTask.Attribute("AssignedTo").Value,
                    Id         = Convert.ToInt32(xTask.Attribute("Id").Value),
                    State      = xTask.Attribute("State").Value,
                    Title      = xTask.Attribute("Title").Value
                };
                change.AddTask(taskInfo);
            });

            return(change);
        }
Exemplo n.º 3
0
        public void Save(DatabaseChanges changes, string filename)
        {
            changes.LastSavedAt = DateTime.Now;

            var xDoc      = new XDocument();
            var xRoot     = new XElement("DatabaseChanges");
            var xMeta     = new XElement("Metadata");
            var xChanges  = new XElement("Changes");
            var xIncluded = new XElement("Included");
            var xExcluded = new XElement("Excluded");

            xMeta.Add(new XElement("RootDatabaseFolder", changes.RootDatabaseFolder));
            xMeta.Add(new XElement("GeneratedAt", changes.GeneratedAt));
            xMeta.Add(new XElement("LastSavedAt", changes.LastSavedAt));
            xMeta.Add(new XElement("RootWorkItemId", changes.RootWorkItemId));
            xMeta.Add(new XElement("DeletedSubDirName", changes.DeletedSubDirName));

            var changeCount = 0;

            if (changes.IncludedChanges != null)
            {
                var included = changes.IncludedChanges.ToList();
                included.ForEach(c => AddChange(xIncluded, c));
                xIncluded.SetAttributeValue("Count", included.Count);
                changeCount += included.Count;
            }

            if (changes.ExcludedChanges != null)
            {
                var excluded = changes.ExcludedChanges.ToList();
                excluded.ForEach(c => AddChange(xExcluded, c));
                xExcluded.SetAttributeValue("Count", excluded.Count);
                changeCount += excluded.Count;
            }

            xChanges.SetAttributeValue("Count", changeCount);

            xChanges.Add(xIncluded, xExcluded);
            xRoot.Add(xMeta, xChanges);
            xDoc.Add(xRoot);
            xDoc.Save(filename);
        }