private static TemplateInformation ParseXmlDocument(XDocument document)
        {
            var templateInformation = new TemplateInformation();
            var template = (from x in document.Elements("template") select x).FirstOrDefault();

            return ReadXmlDocument(templateInformation, template);
        }
        /// <summary>
        /// Builds the fields from the actions in the supplied template
        /// </summary>
        public void BuildFields(IEnumerable<IGeneratorAction> actions,
                                IEnumerable<Type> controls,
                                TemplateInformation template)
        {
            ediControlsPanel.Controls.Clear();

            BuildFieldsInternal(actions, controls, template);
        }
        private static TemplateInformation ReadXmlDocument(TemplateInformation templateInformation, XElement template)
        {
            var nameElement = template.Element("name");

            if (nameElement != null)
            {
                templateInformation.DisplayName = nameElement.Value;
            }
            else
            {
                throw new XmlSchemaException("Name element not present in template file");
            }

            var extensionsElement = template.Element("extensions");

            if (extensionsElement != null)
            {
                templateInformation.RenameExtensions  = ReadExtenstionList(extensionsElement.Element("renameExtensions"));
                templateInformation.ExcludeExtensions = ReadExtenstionList(extensionsElement.Element("excludeExtensions"));
                templateInformation.RemoveExtensions  = ReadExtenstionList(extensionsElement.Element("removeExtensions"));
            }
            else
            {
                throw new XmlSchemaException("Extensions element not present in template file");
            }

            var actionsElement = template.Element("actions");

            if (actionsElement != null)
            {
                templateInformation.Actions = ReadActionsList(actionsElement);
            }
            else
            {
                throw new XmlSchemaException("Actions element not present in template file");
            }

            var guidsElement = template.Element("guids");

            if (guidsElement != null)
            {
                templateInformation.Guids = guidsElement.Descendants("guid").Select(x => x.Value);
            }

            var renameElement = template.Element("renameWords");

            if (renameElement != null)
            {
                templateInformation.Words = renameElement.Descendants("word").Select(x => x.Value);
            }

            return(templateInformation);
        }
        /// <summary>
        /// Writes the template's configuration file to disk
        /// </summary>
        /// <param name="templateInformation">The template information to be written</param>
        /// <param name="xmlFile">The full path to the XML file</param>
        /// <remarks>If the XML already exists, it will be removed.</remarks>
        public static void WriteTemplateFile(TemplateInformation templateInformation, string xmlFile)
        {
            if (templateInformation == null)
                throw new ArgumentNullException("templateInformation");

            if (string.IsNullOrEmpty(xmlFile))
                throw new ArgumentNullException("xmlFile");

            if (File.Exists(xmlFile))
                File.Delete(xmlFile);

            var newDocument = GenerateXmlDocument(templateInformation);
            newDocument.Save(xmlFile);
        }
        /// <summary>
        /// Writes the template's configuration file to disk
        /// </summary>
        /// <param name="templateInformation">The template information to be written</param>
        /// <param name="xmlFile">The full path to the XML file</param>
        /// <remarks>If the XML already exists, it will be removed.</remarks>
        public static void WriteTemplateFile(TemplateInformation templateInformation, string xmlFile)
        {
            if (templateInformation == null)
            {
                throw new ArgumentNullException("templateInformation");
            }

            if (string.IsNullOrEmpty(xmlFile))
            {
                throw new ArgumentNullException("xmlFile");
            }

            if (File.Exists(xmlFile))
            {
                File.Delete(xmlFile);
            }

            var newDocument = GenerateXmlDocument(templateInformation);

            newDocument.Save(xmlFile);
        }
 private static XDocument GenerateXmlDocument(TemplateInformation templateInformation)
 {
     return
         (new XDocument(
              new XElement("template",
                           new XElement("name", templateInformation.DisplayName),
                           new XElement("extensions",
                                        GenerateExtensionList("renameExtensions", templateInformation.RenameExtensions, true),
                                        GenerateExtensionList("excludeExtensions", templateInformation.ExcludeExtensions, false),
                                        GenerateExtensionList("removeExtensions", templateInformation.RenameExtensions, false)
                                        ),
                           new XElement("guids",
                                        templateInformation.Guids.Select(x => new XElement("guid", x))
                                        ),
                           new XElement("renameWords",
                                        templateInformation.Words.Select(x => new XElement("word", x))
                                        ),
                           new XElement("actions",
                                        templateInformation.Actions.Select(GenerateAction)
                                        )
                           )
              ));
 }
 private static XDocument GenerateXmlDocument(TemplateInformation templateInformation)
 {
     return
         new XDocument(
             new XElement("template",
                 new XElement("name", templateInformation.DisplayName),
                 new XElement("extensions",
                                 GenerateExtensionList("renameExtensions", templateInformation.RenameExtensions, true),
                                 GenerateExtensionList("excludeExtensions", templateInformation.ExcludeExtensions, false),
                                 GenerateExtensionList("removeExtensions", templateInformation.RenameExtensions, false)
                             ),
                 new XElement("guids",
                                 templateInformation.Guids.Select(x => new XElement("guid", x))
                             ),
                 new XElement("renameWords",
                                 templateInformation.Words.Select(x => new XElement("word", x))
                             ),
                 new XElement("actions",
                                 templateInformation.Actions.Select(GenerateAction)
                             )
             )
         );
 }
        private static TemplateInformation ReadXmlDocument(TemplateInformation templateInformation, XElement template)
        {
            var nameElement = template.Element("name");
            if (nameElement != null)
                templateInformation.DisplayName = nameElement.Value;
            else
                throw new XmlSchemaException("Name element not present in template file");

            var extensionsElement = template.Element("extensions");
            if (extensionsElement != null)
            {
                templateInformation.RenameExtensions = ReadExtenstionList(extensionsElement.Element("renameExtensions"));
                templateInformation.ExcludeExtensions = ReadExtenstionList(extensionsElement.Element("excludeExtensions"));
                templateInformation.RemoveExtensions = ReadExtenstionList(extensionsElement.Element("removeExtensions"));
            }
            else
                throw new XmlSchemaException("Extensions element not present in template file");

            var actionsElement = template.Element("actions");
            if (actionsElement != null)
                templateInformation.Actions = ReadActionsList(actionsElement);
            else
                throw new XmlSchemaException("Actions element not present in template file");

            var guidsElement = template.Element("guids");
            if (guidsElement != null)
                templateInformation.Guids = guidsElement.Descendants("guid").Select(x => x.Value);

            var renameElement = template.Element("renameWords");
            if (renameElement != null)
                templateInformation.Words = renameElement.Descendants("word").Select(x => x.Value);

            return templateInformation;
        }
Beispiel #9
0
        private void TemplateComboBoxSelectedValueChanged(object sender, EventArgs e)
        {
            if (SelectedTemplate != null)
            {
                if (MessageBox.Show(this,
                                    "You've already selected a template. If you switch all input will be lost. Do you want to continue?",
                                    "Switch template", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                    return;
            }

            SelectedTemplate = TemplateComboBox.SelectedValue as TemplateInformation;
        }
        private void BuildFieldsInternal(IEnumerable<IGeneratorAction> actions,
                                         IEnumerable<Type> controls,
                                         TemplateInformation template)
        {
            var generatorActions = actions as IGeneratorAction[] ?? actions.ToArray();
            var generatorControls = controls as Type[] ?? controls.ToArray();

            foreach (var action in template.Actions)
            {
                var generatorAction = generatorActions.FirstOrDefault(x => x.GetType().AssemblyQualifiedName == action.ActionType);

                if (generatorAction == null)
                    throw new InvalidOperationException(string.Format("Could not find action ('{0}') in injected action list. Are you missing an assembly in the Actions folder?",
                                                                      action.ActionType));

                if (generatorAction.InputControl == null)
                    continue;

                var generatorControl = generatorControls.FirstOrDefault(x => x == generatorAction.InputControl);

                if (generatorControl == null)
                    throw new InvalidOperationException(string.Format("Could not find control ('{0}') in injected action list. Are you missing an assembly in the Actions folder?",
                                                                      generatorAction.InputControl.AssemblyQualifiedName));

                ediControlsPanel.Controls.Add(BuildEditControl(generatorAction, generatorControl));
            }
        }