Пример #1
0
        public static void SaveDelta(Delta delta, string file)
        {
            var ns = new XmlSerializerNamespaces();
            ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            ns.Add("xsd", "http://www.w3.org/2001/XMLSchema");

            var serializer = new XmlSerializer(typeof(Delta));
            
            var list = new List<ImportObject>();
            foreach (var obj in delta.Objects.Where(x => x.NeedsInclude()))
            {
                var newObj = new ImportObject();
                newObj.SourceObjectIdentifier = obj.SourceObjectIdentifier;
                newObj.TargetObjectIdentifier = obj.TargetObjectIdentifier;
                newObj.ObjectType = obj.ObjectType;
                newObj.State = obj.State;
                newObj.Changes = obj.Changes != null ? obj.Changes.Where(x => x.IsIncluded).ToArray() : null;
                newObj.AnchorPairs = obj.AnchorPairs;
                list.Add(newObj);
            }

            var newDelta = new Delta();
            newDelta.Objects = list.ToArray();

			var settings = new XmlWriterSettings();
			settings.OmitXmlDeclaration = false;
			settings.Indent = true;
            using (var w = XmlWriter.Create(file, settings))
                serializer.Serialize(w, newDelta, ns);
        }
Пример #2
0
        public AttributeNode(Delta delta, ImportObject obj, ImportChange attr)
        {
            this.delta = delta;
            this.obj = obj;
            this.attr = attr;

            this.attr.PropertyChanged += SourcePropertyChanged;
        }
Пример #3
0
        public static void LoadExclusions(Delta delta, string file)
        {
            var serializer = new XmlSerializer(typeof(List<ExclusionObject>));

            List<ExclusionObject> objectList;

            try
            {
                using (var r = XmlReader.Create(file))
                    objectList = (List<ExclusionObject>)serializer.Deserialize(r);
            }
            catch (InvalidOperationException ex)
            {
                System.Windows.MessageBox.Show(string.Format("Unable to deserialize XML. Verify that you loaded an exclusion file."));
                return;
            }

            int foundObjectCount = 0;
            int notFoundObjectCount = 0;
            int foundAttributeCount = 0;
            int notFoundAttributeCount = 0;

            foreach (ExclusionObject exclusion_object in objectList)
            {
                try
                {
                    ImportObject o = delta.Objects.First(x => x.SourceObjectIdentifier == exclusion_object.SourceObjectIdentifier && x.TargetObjectIdentifier == exclusion_object.TargetObjectIdentifier);
                    foundObjectCount++;

                    try
                    {
                        foreach (var change in exclusion_object.Changes)
                        {
                            ImportChange c = o.Changes.First(x => x.Operation == change.Operation && x.AttributeName == change.AttributeName && x.AttributeValue == change.AttributeValue);
                            c.IsIncluded = false;
                            foundAttributeCount++;
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        notFoundAttributeCount++;
                    }

                    // If there were no sub changes, exclude the parent
                    if (exclusion_object.Changes.Length == 0)
                    {
                        o.IsIncluded = false;
                    }
                }
                catch (InvalidOperationException)
                {
                    notFoundObjectCount++;
                }
            }

            System.Windows.MessageBox.Show(string.Format("Found and excluded {0} object and {1} attributes. {2} objects and {3} attributes were not found", foundObjectCount, foundAttributeCount, notFoundObjectCount, notFoundAttributeCount));
        }
Пример #4
0
        public ObjectNode(Delta delta, ImportObject obj)
        {
            this.delta = delta;
            this.obj = obj;

            this.obj.PropertyChanged += new PropertyChangedEventHandler(SourcePropertyChanged);

            this.children = null;
            if (obj.Changes != null)
                this.children = obj.Changes.Select(a => new AttributeNode(delta, obj, a) { Parent = this }).ToArray();
        }
Пример #5
0
 void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         delta = DeltaParser.ReadDelta(Settings.Default.SourceFile, Settings.Default.TargetFile, Settings.Default.DeltaFile);
         
         deltaVC = new DeltaViewController(delta);
         view.Source = deltaVC.View;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         Application.Current.Shutdown();
     }
 }
Пример #6
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            // In case the user just typed in the file names and didn't browse, we need to copy
            // the textbox values into our public properties

            if (!SourceFileName.EndsWith(SourceFileNameTextBox.Text))
            {
                SourceFileName = SourceFileNameTextBox.Text;
            }

            if (!TargetFileName.EndsWith(TargetFileNameTextBox.Text))
            {
                TargetFileName = TargetFileNameTextBox.Text;
            }

            if (!ChangesFileName.EndsWith(ChangesFileNameTextBox.Text))
            {
                ChangesFileName = ChangesFileNameTextBox.Text;
            }

            try
            {
                delta = DeltaParser.ReadDelta(SourceFileName, TargetFileName, ChangesFileName);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                MessageBox.Show(string.Format("Unable to open files: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (delta != null)
            {
                this.Close();
            }
        }
Пример #7
0
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            OpenFiles of = new OpenFiles();

            if (!string.IsNullOrEmpty(SourceFileName))
            {
                of.SourceFileName = SourceFileName;
            }

            if (!string.IsNullOrEmpty(TargetFileName))
            {
                of.TargetFileName = TargetFileName;
            }

            if (!string.IsNullOrEmpty(ChangesFileName))
            {
                of.ChangesFileName = ChangesFileName;
            }

            of.Owner = this;
            of.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            of.ShowDialog();
            if (of.delta != null)
            {
                delta = of.delta;
                deltaVC = new DeltaViewController(delta);
                view.Source = deltaVC.View;
            }
        }
Пример #8
0
 public DeltaViewController(Delta delta)
 {
     this.delta = delta;
 }
Пример #9
0
 public ReferencedByNode(Delta delta, ImportObject obj)
 {
     this.delta = delta;
     this.obj = obj;
 }
Пример #10
0
        public static void SaveExclusions(Delta delta, string file)
        {
            List<ExclusionObject> objectList = new List<ExclusionObject>();

            foreach (var deltaObject in delta.Objects)
            {

                List<ExclusionAttribueValue> excludedChangeList = new List<ExclusionAttribueValue>();
                bool allChangesExcluded = false;

                if (deltaObject.Changes != null)
                {
                    foreach (var change in deltaObject.Changes)
                    {
                        if (change.IsIncluded == false)
                        {
                            excludedChangeList.Add(new ExclusionAttribueValue(change.Operation, change.AttributeName, change.AttributeValue));
                        }
                    }

                    allChangesExcluded = (deltaObject.Changes.Length == excludedChangeList.Count);

                }

                if (excludedChangeList.Count > 0 || deltaObject.IsIncluded == false)
                {
                    ExclusionObject eo = new ExclusionObject(deltaObject.SourceObjectIdentifier, deltaObject.TargetObjectIdentifier, deltaObject.ObjectType);

                    //TODO: Consider not writing out the changes if they are all excluded. We would
                    // need to make sure that the load process would properly exclude all sub objects
                    eo.Changes = excludedChangeList.ToArray();

                    eo.AllChangesExcluded = allChangesExcluded;
                    objectList.Add(eo);
                }
            }

            var serializer = new XmlSerializer(typeof(List<ExclusionObject>));

            var settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = false;
            settings.Indent = true;
            using (var w = XmlWriter.Create(file, settings))
                serializer.Serialize(w, objectList);

            System.Windows.MessageBox.Show(string.Format("Saved {0} object exclusions.", objectList.Count));
        }