コード例 #1
0
ファイル: DocGenerator.cs プロジェクト: xgalv/Cryptool2
 private static int CompareTemplateDirectories(TemplateDirectory x, TemplateDirectory y)
 {
     if (x.Order < y.Order)
     {
         return(-1);
     }
     if (x.Order > y.Order)
     {
         return(1);
     }
     return(String.Compare(x.GetName(), y.GetName()));
 }
コード例 #2
0
ファイル: DocGenerator.cs プロジェクト: xgalv/Cryptool2
        private TemplateDirectory ReadTemplates(string baseDir, string subdir, TemplateDirectory parent, Generator generator)
        {
            var directory   = new DirectoryInfo(Path.Combine(baseDir, Path.Combine(TemplateDirectory, subdir)));
            var templateDir = new TemplateDirectory(directory, parent);

            //recursively analyze subdirs:
            foreach (var childdir in directory.GetDirectories())
            {
                var subDir = ReadTemplates(baseDir, Path.Combine(subdir, childdir.Name), templateDir, generator);
                templateDir.SubDirectories.Add(subDir);
            }
            templateDir.SubDirectories.Sort(CompareTemplateDirectories);

            foreach (var file in directory.GetFiles().Where(x => (x.Extension.ToLower() == ".cwm")))
            {
                try
                {
                    var templatePage = new TemplateDocumentationPage(file.FullName, subdir, templateDir);
                    if (templatePage.RelevantPlugins != null)
                    {
                        foreach (var relevantPlugin in templatePage.RelevantPlugins)
                        {
                            if (RelevantComponentToTemplatesMap.ContainsKey(relevantPlugin))
                            {
                                RelevantComponentToTemplatesMap[relevantPlugin].Add(templatePage);
                            }
                            else
                            {
                                RelevantComponentToTemplatesMap.Add(relevantPlugin, new List <TemplateDocumentationPage>()
                                {
                                    templatePage
                                });
                            }
                        }
                    }
                    generator.AddDocumentationPage(templatePage);
                    templateDir.ContainingTemplateDocPages.Add(templatePage);
                }
                catch (Exception ex)
                {
                    GuiLogMessage(string.Format("Error while trying to read templates for Online Help generation: {0} ({1})", ex.Message, file.FullName), NotificationLevel.Warning);
                }
                templateDir.ContainingTemplateDocPages.Sort(CompareTemplateDocPages);
            }

            return(templateDir);
        }
コード例 #3
0
ファイル: TemplateDirectory.cs プロジェクト: xgalv/Cryptool2
        public TemplateDirectory(DirectoryInfo directory, TemplateDirectory parent = null)
        {
            ContainingTemplateDocPages = new List <TemplateDocumentationPage>();
            SubDirectories             = new List <TemplateDirectory>();
            LocalizedInfos             = new Dictionary <string, LocalizedTemplateInfos>();
            LocalizedInfos.Add("en", new LocalizedTemplateInfos()
            {
                Lang = "en", Name = directory.Name
            });

            Parent = parent;

            //Read metainfos:
            var metainfo = directory.GetFiles("dir.xml");

            if (metainfo.Length > 0)
            {
                XElement metaXML = XElement.Load(metainfo[0].FullName);

                foreach (var nameElements in metaXML.Elements("name"))
                {
                    var langAtt = nameElements.Attribute("lang");
                    if (langAtt != null)
                    {
                        if (LocalizedInfos.ContainsKey(langAtt.Value))
                        {
                            LocalizedInfos[langAtt.Value].Name = nameElements.Value;
                        }
                        else
                        {
                            LocalizedInfos.Add(langAtt.Value, new LocalizedTemplateInfos()
                            {
                                Lang = langAtt.Value, Name = nameElements.Value
                            });
                        }
                    }
                }

                foreach (var summaryElements in metaXML.Elements("summary"))
                {
                    var langAtt = summaryElements.Attribute("lang");
                    if (langAtt != null)
                    {
                        if (LocalizedInfos.ContainsKey(langAtt.Value))
                        {
                            LocalizedInfos[langAtt.Value].Summary = summaryElements;
                        }
                        else
                        {
                            LocalizedInfos.Add(langAtt.Value, new LocalizedTemplateInfos()
                            {
                                Lang = langAtt.Value, Summary = summaryElements
                            });
                        }
                    }
                }

                if (metaXML.Element("icon") != null && metaXML.Element("icon").Attribute("file") != null)
                {
                    var iconFile = Path.Combine(directory.FullName, metaXML.Element("icon").Attribute("file").Value);
                    if (File.Exists(iconFile))
                    {
                        DirIcon = BitmapFrame.Create(new BitmapImage(new Uri(iconFile)));
                    }
                }

                if (metaXML.Attribute("order") != null)
                {
                    try
                    {
                        Order = int.Parse(metaXML.Attribute("order").Value);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }