static IEnumerable <SourceCodePage> CreateSourceCodePages(DemoPageModel demo) { List <SourceCodePage> result = new List <SourceCodePage>(); if (IsMvc) { foreach (string fileName in demo.SourceFiles) { if (fileName.StartsWith("~/Models/")) { AddSourceCodePage(result, string.Format("Model ({0})", Path.GetFileNameWithoutExtension(fileName)), fileName, false); } } string controllerUrl = string.Format("~/Controllers/{0}/{0}Controller.{1}.cs", demo.Group.Key, demo.Key); AddSourceCodePage(result, "Controller", controllerUrl, true, false); string commonControllerUrl = string.Format("~/Controllers/{0}Controller.cs", demo.Group.Key); AddSourceCodePage(result, "Controller (common)", commonControllerUrl, false); string viewUrl = string.Format("~/Views/{0}/{1}.cshtml", demo.Group.Key, demo.Key); AddSourceCodePage(result, "View", viewUrl, true, false); foreach (string fileName in demo.SourceFiles) { if (fileName.StartsWith("~/Views/")) { AddSourceCodePage(result, string.Format("View ({0})", Path.GetFileNameWithoutExtension(fileName)), fileName, true); } else if (fileName.StartsWith("~/Code/")) { AddSourceCodePage(result, string.Format("{0}", Path.GetFileName(fileName)), fileName, true); } else if (!fileName.StartsWith("~/Models/")) { AddSourceCodePage(result, Path.GetFileName(fileName), fileName, false); } } } else { string baseUrl = GenerateDemoUrl(demo); string[] highlightedTagNames = new string[0]; if (!IsOverview) { highlightedTagNames = demo.Group.GetHighlightedTagNames(). Concat(demo.GetHighlightedTagNames()). Concat(demo.Product.GetHighlightedTagNames()).ToArray(); } AddSourceCodePage(result, "ASPX", baseUrl, true, true, highlightedTagNames); if (HasCodeFile(baseUrl)) { AddSourceCodePage(result, "C#", baseUrl + ".cs", CodeLanguage == "C#", true); AddSourceCodePage(result, "VB", baseUrl + ".vb", CodeLanguage == "VB"); } foreach (string fileName in demo.SourceFiles) { AddSourceCodePage(result, Path.GetFileName(fileName), fileName, false, true, highlightedTagNames); } } return(result); }
static DemoPageModel CreateErrorPageDemoModel() { DemoPageModel result = new DemoPageModel { IsErrorPage = true, Product = DemosModel.Current, Group = new DemoGroupModel() }; return(result); }
public static IEnumerable <SourceCodePage> GetSourceCodePages(DemoPageModel demo) { lock (sourceCodeCacheLock) { if (!sourceCodeCache.ContainsKey(demo)) { sourceCodeCache[demo] = CreateSourceCodePages(demo); } return(sourceCodeCache[demo]); } }
public List <DemoPageModel> GetAllDemos() { List <DemoPageModel> result = new List <DemoPageModel>(); if (Overview != null) { DemoPageModel overviewDemo = Overview as DemoPageModel; overviewDemo.Key = Overview.Key; result.Add(overviewDemo); } result.AddRange(Demos); return(result); }
static DemoPageModel CreateBogusDemoModel() { DemoGroupModel group = new DemoGroupModel(); group.Title = "ASP.NET"; DemoPageModel result = new DemoPageModel(); result.Group = group; result.HideSourceCode = true; result.Title = BogusDemoTitle; return(result); }
static IEnumerable <SearchResult> GetRes(List <string[]> requests, DemoPageModel demo, string text, string productText) { var results = new List <SearchResult>(); var rank = CalculateRank(requests, demo); if (rank > -1) { var sr = new SearchResult(demo, rank); sr.Text = text; sr.ProductText = productText; results.Add(sr); } return(results); }
static int CalculateRank(List <string[]> requests, DemoPageModel demo) { int resultRank = 0; int keywordRank = 0; foreach (var request in requests) { int requestRank = -1; if (CalculateRank(request, demo.KeywordsRankList, out keywordRank)) { requestRank += keywordRank; } if (demo.Group != null && CalculateRank(request, demo.Group.KeywordsRankList, out keywordRank)) { requestRank += keywordRank; } if (CalculateRank(request, demo.Product.KeywordsRankList, out keywordRank)) { requestRank += keywordRank; } if (requestRank == -1 && WordsExclusions.Any(re => re.Equals(request[0], StringComparison.InvariantCultureIgnoreCase))) { requestRank = 0; } if (requestRank > -1) { resultRank += requestRank; } else { return(-1); } } return(resultRank); }