Exemple #1
0
    private static bool UniqueNames(StylesheetCollection stylesheetCollection)
    {
        string[] names = new string[stylesheetCollection.Stylesheets.Count];

        for (int i = 0; i < stylesheetCollection.Stylesheets.Count; i++)
        {
            names[i] = stylesheetCollection.Stylesheets[i].Name;
        }

        return(GenericHelper.UniqueElements(names));
    }
Exemple #2
0
    public static StylesheetCollection XmlToStylesheetCollection(string xml)
    {
        if (string.IsNullOrEmpty(xml))
        {
            return(null);
        }

        StylesheetCollection stylesheetCollection = new StylesheetCollection();

        try
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(xml);

            XmlNode     stylesheetsNode = xmlDocument.SelectSingleNode("/stylesheets");
            XmlNodeList stylesheetNodes = xmlDocument.SelectNodes("/stylesheets/stylesheet");

            foreach (XmlElement stylesheetNode in stylesheetNodes)
            {
                string name         = stylesheetNode.Attributes["name"].Value;
                string description  = stylesheetNode.Attributes["description"].Value;
                string xslt         = stylesheetNode.Attributes["xsl"].Value;
                bool   enabled      = Convert.ToBoolean(stylesheetNode.Attributes["enabled"].Value);
                string outputFormat = stylesheetNode.Attributes["outputFormat"].Value;

                Stylesheet stylesheet = new Stylesheet(name, description, xslt, enabled, outputFormat);
                stylesheetCollection.Stylesheets.Add(stylesheet);
            }

            stylesheetCollection.Description = stylesheetsNode.Attributes["description"].Value;
        }
        catch (Exception ex)
        {
            if (ex.Message == "Object reference not set to an instance of an object.")
            {
                MessageBox.Show("Stylesheet Collection file is missing one or more elements.", GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                MessageBox.Show(string.Format("Error in converting Xml to stylesheets.\r\n\r\n{0}", ex.Message), GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return(null);
        }

        if (!UniqueNames(stylesheetCollection))
        {
            MessageBox.Show("Stylesheet Names are not unique.,", GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return(null);
        }

        return(stylesheetCollection);
    }
Exemple #3
0
    public static void LoadLastSession()
    {
        if (EnableLoadLastSessionTaskCollection)
        {
            TaskHelper.TaskCollectionFileName = RegistryHandler.ReadFromRegistry("TaskCollectionFileName");

            if (TaskHelper.TaskCollectionFileName == "")
            {
                TaskHelper.TaskCollectionFileName = null;
            }
            else
            {
                TaskCollection temporaryTaskCollection = TaskHelper.XmlToTaskCollection(XmlHelper.ReadXmlFromFile(TaskHelper.TaskCollectionFileName));

                if (temporaryTaskCollection == null)
                {
                    TaskHelper.TaskCollectionFileName = null;
                }
                else
                {
                    TaskHelper.TaskCollection = temporaryTaskCollection;
                }
            }
        }

        if (EnableLoadLastSessionStylesheetCollection)
        {
            StylesheetHelper.StylesheetCollectionFileName = RegistryHandler.ReadFromRegistry("StylesheetCollectionFileName");

            if (StylesheetHelper.StylesheetCollectionFileName == "")
            {
                StylesheetHelper.StylesheetCollectionFileName = null;
            }
            else
            {
                StylesheetCollection temporaryStylesheetCollection = StylesheetHelper.XmlToStylesheetCollection(XmlHelper.ReadXmlFromFile(StylesheetHelper.StylesheetCollectionFileName));

                if (StylesheetHelper.StylesheetCollection == null)
                {
                    StylesheetHelper.StylesheetCollectionFileName = null;
                }
                else
                {
                    StylesheetHelper.StylesheetCollection = temporaryStylesheetCollection;
                }
            }
        }
    }
Exemple #4
0
    private bool Import(string xml)
    {
        StylesheetCollection temporaryStylesheetCollection = StylesheetHelper.XmlToStylesheetCollection(xml);

        if (temporaryStylesheetCollection != null)
        {
            StylesheetHelper.StylesheetCollection = temporaryStylesheetCollection;
            FillList();
            SelectFirstItem();

            descriptionTextBox.Text = StylesheetHelper.StylesheetCollection.Description;
            SetChangesMade(false);
            return(true);
        }

        return(false);
    }
Exemple #5
0
    public static string StylesheetCollectionToXml(StylesheetCollection stylesheetCollection)
    {
        if (stylesheetCollection.Stylesheets == null)
        {
            return("");
        }

        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
        stringBuilder.Append(string.Format("<stylesheets description=\"{0}\">", System.Security.SecurityElement.Escape(stylesheetCollection.Description)));

        foreach (Stylesheet stylesheet in stylesheetCollection.Stylesheets)
        {
            stringBuilder.Append(string.Format("<stylesheet name=\"{0}\" description=\"{1}\" xsl=\"{2}\" enabled=\"{3}\" outputFormat=\"{4}\" />", System.Security.SecurityElement.Escape(stylesheet.Name), System.Security.SecurityElement.Escape(stylesheet.Description), System.Security.SecurityElement.Escape(stylesheet.Xslt), stylesheet.Enabled, stylesheet.OutputFormat));
        }

        stringBuilder.Append("</stylesheets>");
        return(stringBuilder.ToString());
    }