public void Format_Test_2()
        {
            var formatter = Global.ServiceProvider.GetRequiredService <IXmlFormatter>();

            var attributeFormat = new XmlAttributeFormat
            {
                AlphabeticalNameSort  = true,
                AlphabeticalValueSort = true
            };

            attributeFormat.PinPaths.Add("@pinned");

            var elementFormat = new XmlElementFormat
            {
                AlphabeticalNameSort  = true,
                AlphabeticalValueSort = true
            };

            elementFormat.PinPaths.Add("pinned");

            var format = new XmlFormat
            {
                AttributeFormat = attributeFormat,
                ElementFormat   = elementFormat
            };

            var xml = File.ReadAllText(Path.Combine(this.ResourcesDirectoryPath, "Format-Test-2", "Web.config"));

            var formatted = formatter.Format(format, xml);

            var expected = File.ReadAllText(Path.Combine(this.ResourcesDirectoryPath, "Format-Test-2", "Web.Expected-After-Formatting.config"));

            Assert.AreEqual(expected, formatted);
        }
예제 #2
0
        public void LoadLedger()
        {
            Active = null;

            Xml = XDocument.Load(File);

            //add missing total attributes
            foreach (var node in Xml.Descendants(XmlFormat.Node))
            {
                if (node.Attribute(XmlFormat.Total) == null)
                {
                    node.SetAttributeValue(XmlFormat.Total, TimeSpan.Zero);
                }
            }

            //add missing leaf values, search for default
            foreach (var node in Xml.Descendants(XmlFormat.Leaf))
            {
                if (string.IsNullOrWhiteSpace(node.Value))
                {
                    node.SetValue(TimeSpan.Zero);
                }

                if (node.Attribute(XmlFormat.Default) != null)
                {
                    active = node;
                    ActiveChanged(XmlFormat.Name(node));
                }
            }

            LedgerChanged();
        }
예제 #3
0
        IEnumerable <ToolStripMenuItem> BuildChildMenu(XElement element)
        {
            var leaves = element.Elements(XmlFormat.Leaf).Select(leaf => {
                ToolStripMenuItem item = new ToolStripMenuItem(XmlFormat.Name(leaf));
                item.Click            += delegate { controller.Select(leaf); };
                return(item);
            });
            var nodes = element.Elements(XmlFormat.Node).Select(node => new ToolStripMenuItem(XmlFormat.Name(node), null, BuildChildMenu(node).ToArray()));

            return(nodes.Concat(leaves));
        }
예제 #4
0
        public override FileFormat Match(FileFormatScanJob job)
        {
            if (!Validate(job))
            {
                return(null);
            }

            var fingerprint = new XmlFormat();

            return(fingerprint);
        }
예제 #5
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            List <Editor>  editorList      = new List <Editor>();
            XmlFormat      format          = new XmlFormat();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            SplayCodeToolWindow.Instance.Activate();

            //openFileDialog1.InitialDirectory = Environment.CurrentDirectory;
            openFileDialog1.Filter           = "XML Files (*.xml)|*.xml";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.Title            = "Load a Layout file";
            openFileDialog1.RestoreDirectory = false;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // clear the layout if it is not empty
                if ((VirtualSpaceControl)SplayCodeToolWindow.Instance.Content != null)
                {
                    BlockManager.Instance.RemoveAllBlocks();
                    UndoManager.Instance.Reset();
                    VirtualSpaceControl.Instance.Reset();
                }

                string path = openFileDialog1.FileName;
                VirtualSpaceControl.Instance.CurrentLayoutFile = path;
                XmlSerializer x      = new XmlSerializer(typeof(XmlFormat));
                StreamReader  reader = new StreamReader(path);

                // read the layout file and produce XmlFormat instance with loaded information
                format = (XmlFormat)x.Deserialize(reader);
                reader.Close();

                // get the list of editors and restore settings from the last save
                editorList = format.Editors;
                VirtualSpaceControl.Instance.LoadLayoutSettings(format.VirtualSpaceX, format.VirtualSpaceY, format.ScrollOffsetHorizontal, format.ScrollOffsetVertical, format.ZoomLevel);

                // recreate the editor windows
                for (int i = 0; i < editorList.Count; i++)
                {
                    Editor editor       = editorList[i];
                    Uri    documentPath = new Uri(editor.source);
                    BlockManager.Instance.AddBlock(documentPath.Segments[documentPath.Segments.Length - 1],
                                                   editor.source, editor.X, editor.Y, editor.height, editor.width, editor.ZIndex, editor.BlockId, false);
                    if (i != 0)
                    {
                        UndoManager.Instance.StateStack.RemoveAt(UndoManager.Instance.StateStack.Count - 1);
                    }
                }
            }
        }
예제 #6
0
        public static IFormat SelectSerializationFormat(int ext)
        {
            IFormat format = null;

            switch (ext)
            {
            case 1: format = new BinaryFormat(); break;

            case 2: format = new XmlFormat(); break;

            case 3: format = new JsonFormat(); break;

            case 4: format = new YamlFormat(); break;

            default:
                break;
            }

            return(format);
        }
예제 #7
0
        /// <summary>
        /// Set the resolved XML content formatting requirement for a directive.
        /// </summary>
        /// <param name="directiveKey">Key name that identifies a directive.</param>
        /// <param name="xmlFormat">Formatting required for XML content.</param>
        public void SetXmlFormat(string directiveKey, XmlFormat xmlFormat)
        {
            if (string.IsNullOrWhiteSpace(directiveKey))
            {
                throw new EsbFactsException(
                          string.Format(
                              Properties.Resources.ExceptionInvalidDirective,
                              "XML formatting of type",
                              xmlFormat));
            }

            var directive = this.GetDirective(directiveKey);

            directive.KeyName   = directiveKey;
            directive.XmlFormat = xmlFormat;

            if (xmlFormat != XmlFormat.None)
            {
                directive.DirectiveCategories |= Categories.Transformation;
            }
        }
        public void Format_Test_1()
        {
            var formatter = Global.ServiceProvider.GetRequiredService <IXmlFormatter>();

            var format = new XmlFormat
            {
                //AttributeFormat = new XmlAttributeFormat
                //{
                //	SortAlphabetically = true
                //},
                Indent        = true,
                IndentString  = "\t\t\t\t",
                NewLineString = Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine
            };

            var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><root><item /></root>";

            var formatted = formatter.Format(format, xml);

            var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + format.NewLineString + "<root>" + format.NewLineString + format.IndentString + "<item />" + format.NewLineString + "</root>";

            Assert.AreEqual(expected, formatted);
        }
예제 #9
0
        /// <summary>
        /// This function receives a file name as a parameter.
        /// The functions looks for every open editor that is open in the virtual space.
        /// Every property of the each editor and the virtual space is used
        /// to construct an XmlFormat class, which is then serialised to an xml file.
        /// </summary>
        /// <param name="fileName"></param>
        public void saveLayout(string fileName)
        {
            List <BlockControl>         chromes = BlockManager.Instance.BlockList;
            XmlFormat                   format  = new XmlFormat();
            IEnumerable <EditorControl> editors;

            //pass all the properties of the virtual space as the properties of the XmlFormat instance
            format.VirtualSpaceX          = VirtualSpaceControl.Instance.baseGrid.Width;
            format.VirtualSpaceY          = VirtualSpaceControl.Instance.baseGrid.Height;
            format.ScrollOffsetHorizontal = VirtualSpaceControl.Instance.ScrollView.HorizontalOffset;
            format.ScrollOffsetVertical   = VirtualSpaceControl.Instance.ScrollView.VerticalOffset;
            format.ZoomLevel = VirtualSpaceControl.Instance.ZoomLevel;

            //for all editor controls within the virtual space, pass their properties into
            //the constructor of the Editor class, which is then added to the list of editors under XmlFormat.
            foreach (BlockControl cc in chromes)
            {
                editors = cc.contentSpace.Children.OfType <EditorControl>();
                EditorControl editorControl = editors.First();
                string        filepath      = editorControl.FilePath;

                Editor editor = new Editor(cc.Margin.Left, cc.Margin.Top, filepath, cc.ActualHeight, cc.ActualWidth, System.Windows.Controls.Panel.GetZIndex(cc), cc.BlockId);
                format.Editors.Add(editor);
            }

            //serialise the XmlFormat class into an XML file format and save
            XmlSerializer     x        = new XmlSerializer(typeof(XmlFormat));
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = "    ";
            var xmlwriter = XmlWriter.Create(fileName, settings);

            x.Serialize(xmlwriter, format);

            xmlwriter.Close();
        }
예제 #10
0
 public void Setup()
 {
     format = new XmlFormat();
 }