Пример #1
0
        private void AddChange(XElement xParent, DatabaseChange change)
        {
            var xChange = new XElement("Change",
                                       new XAttribute("File", change.File),
                                       new XAttribute("Schema", change.Schema ?? string.Empty),
                                       new XAttribute("Type", change.Type));

            xChange.Add(new XElement("FilePath", change.FilePath));
            xChange.Add(new XElement("FirstChanged", change.FirstChanged));
            xChange.Add(new XElement("IsAttachment", change.IsAttachment));
            xChange.Add(new XElement("IsManualAdd", change.IsManualAdd));
            xChange.Add(new XElement("LastChanged", change.LastChanged));
            xChange.Add(new XElement("ServerItem", change.ServerItem));

            var xChangeTypes = new XElement("ChangeTypes");

            change.ChangeTypes.ToList().ForEach(x => xChangeTypes.Add(new XElement("ChangeType", x.ToString())));
            xChange.Add(xChangeTypes);

            var xTasks = new XElement("Tasks", new XAttribute("Count", change.Tasks.Count));

            change.Tasks.ToList().ForEach(x =>
            {
                var xTask = new XElement(
                    "Task",
                    new XAttribute("Id", x.Id),
                    new XAttribute("AssignedTo", x.AssignedTo),
                    new XAttribute("State", x.State),
                    new XAttribute("Title", x.Title));
                xTasks.Add(xTask);
            });

            xChange.Add(xTasks);
            xParent.Add(xChange);
        }
Пример #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);
        }