Exemplo n.º 1
0
        static IEnumerable <SourceCodePage> CreateSourceCodePages(DemoPageModel demo)
        {
            List <SourceCodePage> result = new List <SourceCodePage>();

            if (IsMvc)
            {
                FillMvcModelPages(demo, result);
                FillMvcControllerPages(demo, result);
                FillMvcViewPages(demo, result);
                FillMvcOtherPages(demo, result);
            }
            else
            {
                var baseUrl             = GenerateDemoUrl(demo);
                var highlightedTagNames = GetHighlightedTagNames(demo);
                AddSourceCodePage(result, "ASPX", baseUrl, true, true, highlightedTagNames);
                if (HasCodeFile(baseUrl))
                {
                    AddSourceCodePage(result, "C#", baseUrl + ".cs", CodeLanguage == "C#");
                    AddSourceCodePage(result, "VB", baseUrl + ".vb", CodeLanguage == "VB");
                }
                foreach (string fileName in demo.SourceFiles)
                {
                    AddSourceCodePage(result, Path.GetFileName(fileName), fileName, false, true, highlightedTagNames);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        static int CalculateRank(List <string[]> requests, DemoPageModel demo)
        {
            int resultRank  = 0;
            int keywordRank = 0;

            foreach (var request in requests)
            {
                int requestRank = -1;
                if (SearchAgregator.CalculateRank(request, demo.KeywordsRankList, out keywordRank))
                {
                    requestRank += keywordRank;
                }
                if (demo.Group != null && SearchAgregator.CalculateRank(request, demo.Group.KeywordsRankList, out keywordRank))
                {
                    requestRank += keywordRank;
                }
                if (SearchAgregator.CalculateRank(request, demo.Product.KeywordsRankList, out keywordRank))
                {
                    requestRank += keywordRank;
                }
                if (requestRank == -1 && Search.WordsExclusions.Any(re => re.Equals(request[0], SearchAgregator.DefaultStringComparison)))
                {
                    requestRank = 0;
                }
                if (requestRank > -1)
                {
                    resultRank += requestRank;
                }
                else
                {
                    return(-1);
                }
            }
            return(resultRank);
        }
Exemplo n.º 3
0
        static void AddDemoToCache(DemoPageModel demo)
        {
            var productKey = demo.Product.Key;
            var groupKey   = Utils.GetDemoGroupKey(demo);
            var fullKey    = (productKey + groupKey + demo.Key).ToLower();

            AvailableDemos[fullKey] = demo;
        }
Exemplo n.º 4
0
        static void FillMvcControllerPages(DemoPageModel demo, List <SourceCodePage> result)
        {
            string controllerUrl = string.Format("~/Controllers/{0}/{0}Controller.{1}.cs", GetDemoGroupKey(demo), demo.Key);

            AddSourceCodePageIfExists(result, "Controller", controllerUrl, true);
            string commonControllerUrl = string.Format("~/Controllers/{0}Controller.cs", GetDemoGroupKey(demo));

            AddSourceCodePageIfExists(result, "Controller (common)", commonControllerUrl, false);
        }
Exemplo n.º 5
0
        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);
                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);
        }
Exemplo n.º 6
0
        static DemoPageModel CreateErrorPageDemoModel()
        {
            DemoPageModel result = new DemoPageModel {
                IsErrorPage = true,
                Product     = DemosModel.Current,
                Group       = new DemoGroupModel()
            };

            return(result);
        }
Exemplo n.º 7
0
 public static IEnumerable <SourceCodePage> GetSourceCodePages(DemoPageModel demo)
 {
     lock (sourceCodeCacheLock) {
         if (!sourceCodeCache.ContainsKey(demo))
         {
             sourceCodeCache[demo] = CreateSourceCodePages(demo);
         }
         return(sourceCodeCache[demo]);
     }
 }
Exemplo n.º 8
0
 public static void FillMvcModelFromResources(DemoPageModel demo, List <SourceCodePage> result)
 {
     foreach (string key in demo.ResourceKeys)
     {
         var keyParts = key.Split('_');
         if (keyParts[0].Equals("Model") || keyParts[0].Equals("DataProvider"))
         {
             AddSourceCodePage(result, string.Format("Model ({0})", keyParts[1]), key, false, true);
         }
     }
 }
Exemplo n.º 9
0
 static void FillMvcModelPages(DemoPageModel demo, List <SourceCodePage> result)
 {
     FillMvcModelFromResources(demo, result);
     foreach (string fileName in demo.SourceFiles)
     {
         if (fileName.StartsWith("~/Models/"))
         {
             AddSourceCodePage(result, string.Format("Model ({0})", Path.GetFileNameWithoutExtension(fileName)), fileName, false);
         }
     }
 }
Exemplo n.º 10
0
 public static void FillMvcOtherPagesFromResources(DemoPageModel demo, List <SourceCodePage> result)
 {
     foreach (string key in demo.ResourceKeys)
     {
         var keyParts = key.Split('_');
         if (keyParts[0].Equals("Code"))
         {
             AddSourceCodePage(result, keyParts[1], key, false, true);
         }
     }
 }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        static string[] GetHighlightedTagNames(DemoPageModel demo)
        {
            var highlightedTagNames = new string[0];

            if (!IsOverview)
            {
                highlightedTagNames = demo.Group.GetHighlightedTagNames().
                                      Concat(demo.GetHighlightedTagNames()).
                                      Concat(demo.Product.GetHighlightedTagNames()).ToArray();
            }
            return(highlightedTagNames);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        public static string GetDemoGroupKey(DemoPageModel demo)
        {
            if (!string.IsNullOrEmpty(demo.VirtualGroupKey))
            {
                return(demo.VirtualGroupKey);
            }
            var group = demo.Group;

            if (!string.IsNullOrEmpty(group.VirtualGroupKey))
            {
                return(group.VirtualGroupKey);
            }
            return(group.Key);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
 static void FillMvcOtherPages(DemoPageModel demo, List <SourceCodePage> result)
 {
     FillMvcOtherPagesFromResources(demo, result);
     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("~/Models/"))
         {
             AddSourceCodePage(result, Path.GetFileName(fileName), fileName, true);
         }
     }
 }
Exemplo n.º 17
0
        public static string GenerateDemoUrl(DemoModel demo)
        {
            if (!string.IsNullOrEmpty(demo.HighlightedLink))
            {
                return(demo.HighlightedLink);
            }
            StringBuilder str = new StringBuilder();

            if (demo.Product.IsCurrent)
            {
                str.Append("~/");
            }
            else
            {
                var url        = HttpContext.Current.Request.Url.AbsolutePath;
                var productUrl = "/" + CurrentDemo.Product.Url;
                url = url.Substring(0, url.IndexOf(productUrl, StringComparison.InvariantCultureIgnoreCase) + 1);
                str.AppendFormat("{0}{1}/", url, demo.Product.Url);
            }
            DemoPageModel demoPage = demo as DemoPageModel;
            bool          hasDemoVirtualGroupKey = demoPage != null && !string.IsNullOrEmpty(demoPage.VirtualGroupKey);
            bool          hasGroupKey            = demoPage != null && demoPage.Group != null && !string.IsNullOrEmpty(demoPage.Group.Key);

            if (hasDemoVirtualGroupKey || hasGroupKey)
            {
                str.Append(GetDemoGroupKey(demoPage));
                str.Append("/");
            }
            if (!IsMvc || !string.Equals("Index", demo.Key))
            {
                str.Append(demo.Key);
            }
            if (!IsMvc)
            {
                str.Append(".aspx");
            }
            return(str.ToString());
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        static void FillMvcViewPages(DemoPageModel demo, List <SourceCodePage> result)
        {
            string viewUrl = string.Format("~/Views/{0}/{1}.cshtml", GetDemoGroupKey(demo), demo.Key);

            AddSourceCodePage(result, "View", viewUrl, true, false);
        }