Beispiel #1
0
        public static List<ExportTemplate> GetExportTemplates(string type = "")
        {
            var tempInfo = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Templates"), "template.xml", SearchOption.AllDirectories);
            var templates = new List<ExportTemplate>();

            foreach (var file in tempInfo)
            {
                XmlDocument xmlReader = XRead.OpenPath(file);
                if (xmlReader == null)
                {
                    XtraMessageBox.Show(
                        string.Format(
                            "The template configuration file '{0}' is invalid!",
                            Path.GetFileName(file)
                        ), 
                        "Invalid Export Template"
                    );
                }
                var templateName = XRead.GetString(xmlReader, "name", 1);

                try
                {
                    var author = new ExportTemplate.Author();

                    var xmlAuthor = xmlReader.GetElementsByTagName("author")[0].InnerXml;
                    XmlDocument temp = XRead.OpenXml("<x>" + xmlAuthor + "</x>");
                    if (type != "")
                    {
                        if (XRead.GetString(xmlReader, "type") != type)
                            continue;
                    }

                    templates.Add(new ExportTemplate
                    {
                        name = templateName,
                        date = XRead.GetString(xmlReader, "date"),
                        file = Path.Combine(Path.GetDirectoryName(file), XRead.GetString(xmlReader, "templatefile")),
                        description = XRead.GetString(xmlReader, "description"),
                        outputformat = XRead.GetString(xmlReader, "outputformat"),
                        type = XRead.GetString(xmlReader, "type"),
                        author = new ExportTemplate.Author
                        {
                            name = XRead.GetString(temp, "name"),
                            website = XRead.GetString(temp, "website"),
                            email = XRead.GetString(temp, "email")
                        }
                    });
                }
                catch (Exception e)
                {
                    if (e is XmlException || e is InvalidOperationException)
                    {
                        XtraMessageBox.Show(
                            string.Format(
                                "The template '{0}' is invalid!", 
                                templateName
                            ), 
                            "Invalid Export Template"
                        );
                    }
                    else
                    {
                        throw e;
                    }
                }

            }

            return templates;
        }
Beispiel #2
0
        public static List <ExportTemplate> GetExportTemplates(string type = "")
        {
            var tempInfo  = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Templates"), "template.xml", SearchOption.AllDirectories);
            var templates = new List <ExportTemplate>();

            foreach (var file in tempInfo)
            {
                XmlDocument xmlReader = XRead.OpenPath(file);
                if (xmlReader == null)
                {
                    XtraMessageBox.Show(
                        string.Format(
                            "The template configuration file '{0}' is invalid!",
                            Path.GetFileName(file)
                            ),
                        "Invalid Export Template"
                        );
                }
                var templateName = XRead.GetString(xmlReader, "name", 1);

                try
                {
                    var author = new ExportTemplate.Author();

                    var         xmlAuthor = xmlReader.GetElementsByTagName("author")[0].InnerXml;
                    XmlDocument temp      = XRead.OpenXml("<x>" + xmlAuthor + "</x>");
                    if (type != "")
                    {
                        if (XRead.GetString(xmlReader, "type") != type)
                        {
                            continue;
                        }
                    }

                    templates.Add(new ExportTemplate
                    {
                        name         = templateName,
                        date         = XRead.GetString(xmlReader, "date"),
                        file         = Path.Combine(Path.GetDirectoryName(file), XRead.GetString(xmlReader, "templatefile")),
                        description  = XRead.GetString(xmlReader, "description"),
                        outputformat = XRead.GetString(xmlReader, "outputformat"),
                        type         = XRead.GetString(xmlReader, "type"),
                        author       = new ExportTemplate.Author
                        {
                            name    = XRead.GetString(temp, "name"),
                            website = XRead.GetString(temp, "website"),
                            email   = XRead.GetString(temp, "email")
                        }
                    });
                }
                catch (Exception e)
                {
                    if (e is XmlException || e is InvalidOperationException)
                    {
                        XtraMessageBox.Show(
                            string.Format(
                                "The template '{0}' is invalid!",
                                templateName
                                ),
                            "Invalid Export Template"
                            );
                    }
                    else
                    {
                        throw e;
                    }
                }
            }

            return(templates);
        }