Example #1
0
        public static string CreateListOfAnalyzerOptions(RoslynatorMetadata metadata)
        {
            IEnumerable <string> options = metadata.GetAllAnalyzers()
                                           .SelectMany(f => f.Options)
                                           .Select(analyzerOption =>
            {
                string optionKey = analyzerOption.OptionKey;

                if (!optionKey.StartsWith("roslynator.", StringComparison.Ordinal))
                {
                    optionKey = $"roslynator.{analyzerOption.ParentId}.{optionKey}";
                }

                return(analyzerOption, value: optionKey + " = " + (analyzerOption.OptionValue ?? "true"));
            })
                                           .OrderBy(f => f.value)
                                           .Select(f => $"# {f.analyzerOption.Title}{NewLine}{f.value}");

            MDocument document = Document(
                Heading1("List of EditorConfig Options"),
                FencedCodeBlock(
                    string.Join(NewLine + NewLine, options),
                    "editorconfig"));

            document.AddFootnote();

            var format = new MarkdownFormat(tableOptions: MarkdownFormat.Default.TableOptions | TableOptions.FormatContent);

            return(document.ToString(format));
        }
Example #2
0
        public static string GenerateAssemblyReadme(string assemblyName)
        {
            Assembly assembly = Assembly.Load(new AssemblyName(assemblyName));

            var doc = new MDocument(Heading1(assemblyName + " API"));

            foreach (IGrouping <string, TypeInfo> grouping in assembly
                     .DefinedTypes
                     .Where(f => f.IsPublic)
                     .GroupBy(f => f.Namespace)
                     .OrderBy(f => f.Key))
            {
                doc.Add(Heading2("Namespace " + grouping.Key));

                AddHeadingWithTypes(doc, "Static Classes", grouping.Where(f => f.IsClass && f.IsStatic()));
                AddHeadingWithTypes(doc, "Classes", grouping.Where(f => f.IsClass && !f.IsStatic()));
                AddHeadingWithTypes(doc, "Structs", grouping.Where(f => f.IsValueType));
                AddHeadingWithTypes(doc, "Interfaces", grouping.Where(f => f.IsInterface));
            }

            doc.AddFootnote();

            return(doc.ToString());

            void AddHeadingWithTypes(MContainer parent, string name, IEnumerable <TypeInfo> types)
            {
                if (types.Any())
                {
                    parent.Add(Heading3(name), types
                               .OrderBy(f => f.Name)
                               .Select(f => BulletItem(f.Name)));
                }
            }
        }
Example #3
0
        public static SettingModel ToModel(this Setting entity, IMDocumentService documentService)
        {
            var img = new MDocument();

            if (!string.IsNullOrWhiteSpace(entity.FileId))
            {
                img = documentService.GetById(entity.FileId);
            }

            var modelVm = new SettingModel()
            {
                Id          = entity.Id,
                CODE        = entity.CODE,
                CreatedBy   = entity.CreatedBy,
                CreatedDate = entity.CreatedDate,
                FileId      = entity.FileId,
                HTMLContent = entity.HTMLContent,
                Published   = entity.Published,
                FileUrl     = img?.FileUrl,
                Show        = entity.Show,
                Type        = entity.Type
            };

            return(modelVm);
        }
Example #4
0
        /// <summary>
        /// 根据搜索好的路线绘制分支线
        /// </summary>
        /// <param name="listBranch"></param>
        /// <param name="mp"></param>
        /// <param name="md"></param>
        private MDocument WriteBranchWithMD(List <string> listBranch)
        {
            //当前行
            int lineIndex = 0;
            //先绘制出一条线
            List <string>   branchList = listBranch[0].Split(',').ToList();
            var             molList    = branchList[0].Split(';').ToList();
            MoleCulePostion mp         = new MoleCulePostion(molList[0]);
            MDocument       md         = new MDocument(mp.Mol);
            //写mol层次号
            string txt = molList[1];

            _ListTextPosition.Add(txt + "," + mp.Center_x + "," + (mp.Bottom_y - TxtspaceWithMolInY));
            WriteSimpleBranch(mp, branchList, 1, mp.Mol, md, true);
            lineIndex += branchList.Count / BranchOneLineNum + (branchList.Count % BranchOneLineNum > 0 ? 1 : 0);

            //再绘制出其他的线
            for (int i = 1; i < listBranch.Count; i++)
            {
                List <string>   branchList1 = listBranch[i].Split(',').ToList();
                var             molList1    = branchList1[0].Split(';').ToList();
                MoleCulePostion mp1         = new MoleCulePostion(molList1[0]);
                SetMolPosition(mp1, 0, mp.Center_y - SpanceY * BranchSPFWithY * lineIndex);
                //写mol层次号
                txt = molList1[1];
                _ListTextPosition.Add(txt + "," + mp1.Center_x + "," + (mp1.Bottom_y - TxtspaceWithMolInY));
                lineIndex += branchList1.Count / BranchOneLineNum + (branchList1.Count % BranchOneLineNum > 0 ? 1 : 0);
                //划分支
                WriteSimpleBranch(mp1, branchList1, 1, mp.Mol, md, false);
                //合并分支显示
                mp.Mol.fuse(mp1.Mol);
            }
            //返回绘图
            return(md);
        }
Example #5
0
        public static string CreateAnalyzersByCategoryMarkdown(IEnumerable <AnalyzerDescriptor> analyzers, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Roslynator Analyzers by Category"),
                Table(
                    TableRow("Category", "Title", "Id", TableColumn(HorizontalAlignment.Center, "Enabled by Default")),
                    GetRows()));

            document.AddFootnote();

            return(document.ToString());

            IEnumerable <MTableRow> GetRows()
            {
                foreach (IGrouping <string, AnalyzerDescriptor> grouping in analyzers
                         .GroupBy(f => MarkdownEscaper.Escape(f.Category))
                         .OrderBy(f => f.Key, comparer))
                {
                    foreach (AnalyzerDescriptor analyzer in grouping.OrderBy(f => f.Title, comparer))
                    {
                        yield return(TableRow(
                                         grouping.Key,
                                         Link(analyzer.Title.TrimEnd('.'), $"../../docs/analyzers/{analyzer.Id}.md"),
                                         analyzer.Id,
                                         CheckboxOrHyphen(analyzer.IsEnabledByDefault)));
                    }
                }
            }
        }
Example #6
0
        public static string CreateRefactoringsMarkdown(IEnumerable <RefactoringDescriptor> refactorings, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Roslynator Refactorings"),
                GetRefactorings());

            document.AddFootnote();

            return(document.ToString());

            IEnumerable <object> GetRefactorings()
            {
                foreach (RefactoringDescriptor refactoring in refactorings.OrderBy(f => f.Title, comparer))
                {
                    yield return(Heading4($"{refactoring.Title} ({refactoring.Id})"));

                    yield return(BulletItem(Bold("Syntax"), ": ", string.Join(", ", refactoring.Syntaxes.Select(f => f.Name))));

                    if (!string.IsNullOrEmpty(refactoring.Span))
                    {
                        yield return(BulletItem(Bold("Span"), ": ", refactoring.Span));
                    }

                    foreach (object item in GetRefactoringSamples(refactoring))
                    {
                        yield return(item);
                    }
                }
            }
        }
Example #7
0
        public static PricingModel ToViewModel(this Pricing entity, IPricingService pricingService, IMDocumentService documentService)
        {
            var img = new MDocument();

            if (!string.IsNullOrWhiteSpace(entity.ImageId))
            {
                img = documentService.GetById(entity.ImageId);
            }

            var modelVm = new PricingModel()
            {
                Id               = entity.Id,
                CreatedBy        = entity.CreatedBy,
                CreatedDate      = entity.CreatedDate,
                Description      = entity.Description,
                ViewCount        = entity.ViewCount,
                ImageId          = entity.ImageId,
                Name             = entity.Name,
                Published        = entity.Published,
                ShortDescription = entity.ShortDescription,
                ImageUrl         = img?.FileUrl
            };

            return(modelVm);
        }
Example #8
0
        public static string GenerateProjectReadme(
            IEnumerable <SnippetGeneratorResult> results,
            ProjectReadmeSettings settings)
        {
            MDocument document = Document();

            return(GenerateProjectReadme(results, document, settings));
        }
Example #9
0
        public static string GenerateDirectoryReadme(
            IEnumerable <Snippet> snippets,
            DirectoryReadmeSettings settings)
        {
            MDocument document = Document();

            return(GenerateDirectoryReadme(snippets, document, settings));
        }
Example #10
0
        public static void Main()
        {
            MDocument document = Document();

            Console.WriteLine(document.ToString());

            Console.ReadKey();
        }
Example #11
0
        private static string GetString(this MDocument document, bool addFootnote = true)
        {
            if (addFootnote)
            {
                document.Add(NewLine, Italic("(Generated with ", Link("DotMarkdown", "http://github.com/JosefPihrt/DotMarkdown"), ")"));
            }

            return(document.ToString(MarkdownFormat.Default.WithTableOptions(TableOptions.FormatHeader)));
        }
Example #12
0
        /// <summary>
        /// 绘图
        /// </summary>
        /// <param name="rootTree"></param>
        /// <returns></returns>
        private MDocument WriteBrachTree(TreeNodes rootTree)
        {
            //获取所有分支
            List <string> listBranch = GetAllBranch(rootTree);

            //开始遍历子节点
            _ListTextPosition = new List <string>();
            MDocument md = WriteBranchWithMD(listBranch);

            return(md);
        }
Example #13
0
        private static void Main(string[] args)
        {
            _shortcuts = Pihrtsoft.Records.Document.ReadRecords(@"..\..\Data\Shortcuts.xml")
                         .Where(f => !f.HasTag(KnownTags.Disabled))
                         .Select(Mapper.MapShortcutInfo)
                         .ToArray();

            SnippetDirectory[] directories = LoadDirectories(@"..\..\Data\Directories.xml");

            ShortcutInfo.SerializeToXml(Path.Combine(VisualStudioExtensionProjectPath, "Shortcuts.xml"), _shortcuts);

            LoadLanguages();

            SaveChangedSnippets(directories);

            var visualStudio = new VisualStudioEnvironment();

            (List <SnippetGeneratorResult> visualStudioResults, List <Snippet> visualStudioSnippets) = GenerateSnippets(
                visualStudio,
                directories,
                VisualStudioExtensionProjectPath);

            var visualStudioCode = new VisualStudioCodeEnvironment();

            (List <SnippetGeneratorResult> visualStudioCodeResults, List <Snippet> visualStudioCodeSnippets) = GenerateSnippets(
                visualStudioCode,
                directories,
                VisualStudioCodeExtensionProjectPath);

            CheckDuplicateShortcuts(visualStudioSnippets, visualStudio);
            CheckDuplicateShortcuts(visualStudioCodeSnippets, visualStudioCode);

            IEnumerable <Language> languages = visualStudioResults
                                               .Concat(visualStudioCodeResults)
                                               .Select(f => f.Language)
                                               .Distinct();

            var document = new MDocument(
                Heading1(ProductName),
                BulletList(
                    CodeGenerationUtility.GetProjectSubtitle(languages),
                    BulletItem(Link("Release Notes", $"{MasterGitHubUrl}/{ChangeLogFileName}"), ".")));

#if !DEBUG
            MarkdownGenerator.GenerateProjectReadme(visualStudioResults, document, visualStudio.CreateProjectReadmeSettings(), addFootnote: false);

            MarkdownGenerator.GenerateProjectReadme(visualStudioCodeResults, document, visualStudioCode.CreateProjectReadmeSettings());

            IOUtility.WriteAllText(Path.Combine(SolutionDirectoryPath, ReadMeFileName), document.ToString(MarkdownFormat.Default.WithTableOptions(TableOptions.FormatHeader)), IOUtility.UTF8NoBom);
#endif

            Console.WriteLine("*** END ***");
            Console.ReadKey();
        }
Example #14
0
        private MemoryStream writeq()
        {
            //树绘图
            MDocument md    = new MDocument(MolImporter.importMol("O"));
            MPoint    p1    = new MPoint(1, 1);
            MPoint    p2    = new MPoint(1, 2);
            MPolyline arrow = new MRectangle(p1, p2);

            md.addObject(arrow);
            MemoryStream stream = new MemoryStream(MolExporter.exportToBinFormat(md, "mrv"));

            return(stream);
        }
Example #15
0
        public static string CreateReadMe(IEnumerable <AnalyzerDescriptor> analyzers, IEnumerable <RefactoringDescriptor> refactorings, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading3("List of Analyzers"),
                analyzers
                .OrderBy(f => f.Id, comparer)
                .Select(analyzer => BulletItem(analyzer.Id, " - ", Link(analyzer.Title.TrimEnd('.'), $"docs/analyzers/{analyzer.Id}.md"))),
                Heading3("List of Refactorings"),
                refactorings
                .OrderBy(f => f.Title, comparer)
                .Select(refactoring => BulletItem(Link(refactoring.Title.TrimEnd('.'), $"docs/refactorings/{refactoring.Id}.md"))));

            return(File.ReadAllText(@"..\text\ReadMe.txt", Encoding.UTF8)
                   + Environment.NewLine
                   + document);
        }
Example #16
0
        public static string CreateRefactoringsReadMe(IEnumerable <RefactoringDescriptor> refactorings, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Roslynator Refactorings"),
                Table(
                    TableRow("Id", "Title", TableColumn(HorizontalAlignment.Center, "Enabled by Default")),
                    refactorings.OrderBy(f => f.Title, comparer).Select(f =>
            {
                return(TableRow(
                           f.Id,
                           Link(f.Title.TrimEnd('.'), $"../../docs/refactorings/{f.Id}.md"),
                           CheckboxOrHyphen(f.IsEnabledByDefault)));
            })));

            return(document.ToString());
        }
Example #17
0
        /// <summary>
        /// 绘图
        /// </summary>
        /// <param name="rootTree"></param>
        /// <returns></returns>
        private MDocument WriteTree(TreeNodes rootTree)
        {
            MoleCulePostion mp = new MoleCulePostion(rootTree.Smiles);
            MDocument       md = new MDocument(mp.Mol);

            //初始化树的叶子节点数量
            InitTreeLeapNum(rootTree);

            //开始遍历子节点
            _DicListTextPosition = new Dictionary <int, List <string> >();
            _DicListTextPosition.Add(0, new List <string>()); //上
            _DicListTextPosition.Add(1, new List <string>()); //中
            _DicListTextPosition.Add(2, new List <string>()); //下
            SearchChildNode(rootTree, md, mp, mp.Mol, 1);
            return(md);
        }
Example #18
0
        public static string CreateCompilerDiagnosticMarkdown(CompilerDiagnosticDescriptor diagnostic, IEnumerable <CodeFixDescriptor> codeFixes, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading1(diagnostic.Id),
                Table(
                    TableRow("Property", "Value"),
                    TableRow("Id", diagnostic.Id),
                    TableRow("Title", diagnostic.Title),
                    TableRow("Severity", diagnostic.Severity),
                    (!string.IsNullOrEmpty(diagnostic.HelpUrl)) ? TableRow("Official Documentation", Link("link", diagnostic.HelpUrl)) : null),
                Heading2("Code Fixes"),
                BulletList(codeFixes
                           .Where(f => f.FixableDiagnosticIds.Any(diagnosticId => diagnosticId == diagnostic.Id))
                           .Select(f => f.Title)
                           .OrderBy(f => f, comparer)));

            return(document.ToString(MarkdownFormat.Default.WithTableOptions(MarkdownFormat.Default.TableOptions | TableOptions.FormatContent)));
        }
Example #19
0
        /// <summary>
        /// 返回整个路线列表
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public string WriteToMrvWithAllRouteWithStr(string result)
        {
            //取根路线
            List <TreeNodes> treeNodes = JsonConvert.DeserializeObject <List <TreeNodes> >(result);
            TreeNodes        rootTree  = new TreeNodes();

            foreach (var item in treeNodes)
            {
                if (item.PID == 0)
                {
                    rootTree = item;
                }
            }
            //树绘图
            MDocument md = WriteTree(rootTree);

            return(MolExporter.exportToFormat(md, "mrv"));
        }
Example #20
0
        public static string CreateRefactoringMarkdown(RefactoringDescriptor refactoring)
        {
            var format = new MarkdownFormat(tableOptions: MarkdownFormat.Default.TableOptions | TableOptions.FormatContent);

            MDocument document = Document(
                Heading2(refactoring.Title),
                Table(TableRow("Property", "Value"),
                      TableRow("Id", refactoring.Id),
                      TableRow("Title", refactoring.Title),
                      TableRow("Syntax", string.Join(", ", refactoring.Syntaxes.Select(f => f.Name))),
                      (!string.IsNullOrEmpty(refactoring.Span)) ? TableRow("Span", refactoring.Span) : null,
                      TableRow("Enabled by Default", CheckboxOrHyphen(refactoring.IsEnabledByDefault))),
                Heading3("Usage"),
                GetRefactoringSamples(refactoring),
                Link("full list of refactorings", "Refactorings.md"));

            return(document.ToString(format));
        }
Example #21
0
        public static string CreateAnalyzersReadMe(IEnumerable <AnalyzerDescriptor> analyzers, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Roslynator Analyzers"),
                Link("Search Analyzers", "http://pihrt.net/Roslynator/Analyzers"),
                Table(
                    TableRow("Id", "Title", "Category", TableColumn(HorizontalAlignment.Center, "Enabled by Default")),
                    analyzers.OrderBy(f => f.Id, comparer).Select(f =>
            {
                return(TableRow(
                           f.Id,
                           Link(f.Title.TrimEnd('.'), $"../../docs/analyzers/{f.Id}.md"),
                           f.Category,
                           CheckboxOrHyphen(f.IsEnabledByDefault)));
            })));

            return(document.ToString());
        }
Example #22
0
        public static string CreateAnalyzerMarkdown(AnalyzerDescriptor analyzer)
        {
            var format = new MarkdownFormat(tableOptions: MarkdownFormat.Default.TableOptions | TableOptions.FormatContent);

            MDocument document = Document(
                Heading1($"{((analyzer.IsObsolete) ? "[deprecated] " : "")}{analyzer.Id}: {analyzer.Title.TrimEnd('.')}"),
                Table(
                    TableRow("Property", "Value"),
                    TableRow("Id", analyzer.Id),
                    TableRow("Category", analyzer.Category),
                    TableRow("Default Severity", analyzer.DefaultSeverity),
                    TableRow("Enabled by Default", CheckboxOrHyphen(analyzer.IsEnabledByDefault)),
                    TableRow("Supports Fade-Out", CheckboxOrHyphen(analyzer.SupportsFadeOut)),
                    TableRow("Supports Fade-Out Analyzer", CheckboxOrHyphen(analyzer.SupportsFadeOutAnalyzer))),
                (!string.IsNullOrEmpty(analyzer.Summary)) ? Raw(analyzer.Summary) : null,
                Samples(),
                GetLinks(analyzer.Links),
                Heading2("How to Suppress"),
                Heading3("SuppressMessageAttribute"),
                FencedCodeBlock($"[assembly: SuppressMessage(\"{analyzer.Category}\", \"{analyzer.Id}:{analyzer.Title}\", Justification = \"<Pending>\")]", LanguageIdentifiers.CSharp),
                Heading3("#pragma"),
                FencedCodeBlock($"#pragma warning disable {analyzer.Id} // {analyzer.Title}\r\n#pragma warning restore {analyzer.Id} // {analyzer.Title}", LanguageIdentifiers.CSharp),
                Heading3("Ruleset"),
                BulletItem(Link("How to configure rule set", "../HowToConfigureAnalyzers.md")));

            document.AddFootnote();

            return(document.ToString(format));

            IEnumerable <MElement> Samples()
            {
                IReadOnlyList <SampleDescriptor> samples = analyzer.Samples;

                if (samples.Count > 0)
                {
                    yield return(Heading2((samples.Count == 1) ? "Example" : "Examples"));

                    foreach (MElement item in GetSamples(samples, Heading3("Code with Diagnostic"), Heading3("Code with Fix")))
                    {
                        yield return(item);
                    }
                }
            }
        }
Example #23
0
        /// <summary>
        /// 返回文件流的mrv
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public MemoryStream WriteToMrvWithBranch(string result)
        {
            //取根路线
            List <TreeNodes> treeNodes = JsonConvert.DeserializeObject <List <TreeNodes> >(result);
            TreeNodes        rootTree  = new TreeNodes();

            foreach (var item in treeNodes)
            {
                if (item.PID == 0)
                {
                    rootTree = item;
                }
            }
            //树绘图
            MDocument    md     = WriteBrachTree(rootTree);
            MemoryStream stream = new MemoryStream(MolExporter.exportToBinFormat(md, "cdx"));

            return(stream);
        }
Example #24
0
        public static string CreateCodeFixesReadMe(IEnumerable <CompilerDiagnosticDescriptor> diagnostics, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Compiler Diagnostics Fixable with Roslynator"),
                Table(
                    TableRow("Id", "Title"),
                    GetRows()));

            return(document.ToString());

            IEnumerable <MTableRow> GetRows()
            {
                foreach (CompilerDiagnosticDescriptor diagnostic in diagnostics
                         .OrderBy(f => f.Id, comparer))
                {
                    yield return(TableRow(
                                     Link(diagnostic.Id, $"../../docs/cs/{diagnostic.Id}.md"),
                                     diagnostic.Title));
                }
            }
        }
Example #25
0
        private void WriteText(MDocument md, int bracnchIndex)
        {
            double max = 9999999;

            foreach (var item in _DicListTextPosition[bracnchIndex])
            {
                var    list = item.Split(',').ToList();
                double y    = Convert.ToDouble(list[2]);
                if (max > y)
                {
                    max = y;
                }
            }
            foreach (var item in _DicListTextPosition[bracnchIndex])
            {
                var    list = item.Split(',').ToList();
                double x    = Convert.ToDouble(list[1]);
                md.addObject(CreateMTextBox(list[0], new MPoint(x, max)));
            }
            _DicListTextPosition[bracnchIndex] = new List <string>();
        }
Example #26
0
        public static string GenerateProjectReadme(
            IEnumerable <SnippetGeneratorResult> results,
            MDocument document,
            ProjectReadmeSettings settings,
            bool addFootnote = true)
        {
            document.Add(
                (!string.IsNullOrEmpty(settings.Header)) ? Heading2(settings.Header) : null,
                BulletItem("Browse all available snippets with ", Link("Snippet Browser", GetSnippetBrowserUrl(settings.Environment.Kind)), "."),
                BulletItem("Download extension from ", Link("Marketplace", $"http://marketplace.visualstudio.com/search?term=publisher%3A\"Josef%20Pihrt\"%20{ProductName}&target={settings.Environment.Kind.GetIdentifier()}&sortBy=Name"), "."),
                Heading3("Snippets"),
                Table(
                    TableRow("Group", "Count", TableColumn(HorizontalAlignment.Right)),
                    results.OrderBy(f => f.DirectoryName).Select(f =>
            {
                return(TableRow(
                           Link(f.DirectoryName, $"{VisualStudioExtensionGitHubUrl}/{f.DirectoryName}/{ReadMeFileName}"),
                           f.Snippets.Count,
                           Link("Browse", GetSnippetBrowserUrl(settings.Environment.Kind, f.Language))));
            })));

            return(document.GetString(addFootnote: addFootnote));
        }
Example #27
0
        public static BlogModel ToViewModel(this Blog entity, IBlogService blogService, ICategoryService categoryService, IMDocumentService documentService)
        {
            var img = new MDocument();

            if (!string.IsNullOrWhiteSpace(entity.ImageId))
            {
                img = documentService.GetById(entity.ImageId);
            }

            var categoryId = blogService.GetCategoryId(entity.Id);
            var category   = categoryService.GetById(categoryId);

            var modelVm = new BlogModel()
            {
                Id               = entity.Id,
                CategoryId       = categoryId,
                CategoryName     = category?.Name,
                CreatedBy        = entity.CreatedBy,
                CreatedDate      = entity.CreatedDate,
                Description      = entity.Description,
                ViewCount        = entity.ViewCount,
                ImageId          = entity.ImageId,
                Name             = entity.Name,
                Published        = entity.Published,
                ShortDescription = entity.ShortDescription,
                ImageUrl         = img?.FileUrl,
                Categories       = categoryService.GetAll().Select(x => new SelectListItem()
                {
                    Selected = categoryId == x.Id, Text = x.Name, Value = x.Id
                }).ToList(),
                Alias        = entity.Alias,
                DisplayOrder = entity.DisplayOrder,
                ShowAtHome   = entity.ShowAtHome
            };

            return(modelVm);
        }
Example #28
0
        public IActionResult UploadDocument()
        {
            var file = Request.Form.Files[0];

            string wwwRootPath  = _hostingEnvironment.WebRootPath;
            string fileName     = Path.GetFileNameWithoutExtension(file.FileName);
            string extension    = Path.GetExtension(file.FileName);
            var    pathRoot     = "/Upload/Images/";
            var    id           = Guid.NewGuid().ToString();
            var    fileNameFull = id + extension;

            string path = Path.Combine(wwwRootPath + pathRoot, fileNameFull);

            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                file.CopyTo(fileStream);
            }

            var document = new MDocument()
            {
                Id              = id,
                Size            = file.Length,
                Extension       = extension,
                Type            = DocumentType.Image,
                FileName        = fileNameFull,
                FileNameDefault = fileName + extension,
                FileUrl         = pathRoot + fileNameFull,
                Published       = true,
            };

            _documentService.Add(document);



            return(Json(new { status = true, message = "upload image thành công", data = JsonConvert.SerializeObject(document) }));
        }
Example #29
0
        public static string GenerateVisualStudioMarketplaceOverview(IEnumerable <SnippetGeneratorResult> results)
        {
            MDocument document = Document(
                Heading3("Introduction"),
                BulletItem(GetProjectSubtitle(results)),
                Heading3("Links"),
                BulletList(
                    Link("Project Website", GitHubUrl),
                    Link("Release Notes", $"{MasterGitHubUrl}/{ChangeLogFileName}"),
                    BulletItem("Browse all available snippets with ", Link("Snippet Browser", GetSnippetBrowserUrl(EnvironmentKind.VisualStudio)))),
                Heading3("Snippets"),
                Table(
                    TableRow("Language", TableColumn(HorizontalAlignment.Right, "Count"), TableColumn(HorizontalAlignment.Center, "Snippet Browser")),
                    results.Select(f =>
            {
                return(TableRow(
                           Link(f.DirectoryName, VisualStudioExtensionGitHubUrl + "/" + f.DirectoryName + "/" + ReadMeFileName),
                           f.Snippets.Count,
                           Link("browse", GetSnippetBrowserUrl(EnvironmentKind.VisualStudio, f.Language))));
            })),
                NewLine);

            return(document.GetString(addFootnote: false));
        }
Example #30
0
 private static void AddFootnote(this MDocument document)
 {
     document.Add(NewLine, Italic("(Generated with ", Link("DotMarkdown", "http://github.com/JosefPihrt/DotMarkdown"), ")"));
 }