public IActionResult Index()
        {
            var game = new Game
            {
                Guid        = Guid.NewGuid().ToString(),
                CreatedDate = DateTime.Now,
                IsActive    = true,
                IsCompleted = false
            };

            game.Patterns.Add(new GamePattern
            {
                Level    = 0,
                CodePeg1 = SiteExtensions.RandomEnum <CodePeg>(),
                CodePeg2 = SiteExtensions.RandomEnum <CodePeg>(),
                CodePeg3 = SiteExtensions.RandomEnum <CodePeg>(),
                CodePeg4 = SiteExtensions.RandomEnum <CodePeg>(),
                KeyPeg1  = KeyPeg.None,
                KeyPeg2  = KeyPeg.None,
                KeyPeg3  = KeyPeg.None,
                KeyPeg4  = KeyPeg.None,
                Game     = game
            });
            _context.Games.Add(game);
            _context.GamePatterns.Add(game.Patterns.First());
            _context.SaveChanges();
            return(View(game));
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        // Note: Configures Services
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider sp)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();
            app.UseCors(builder =>
                        builder.WithOrigins("http://www.jobyjobs.com", "http://joby.ori-pc.com")
                        .AllowAnyOrigin()   //Todo. find a better solution.
                        .AllowAnyHeader()
                        .AllowAnyMethod()); //Note: allow CORS;

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            //user code here:
            //Initializes cache.
            SiteExtensions.Initialize(Configuration);
            sp.GetService <ICacheManager>().Initialize(sp.GetService <IBLCacheSource>());
        }
        public override void Process(HttpRequestArgs args)
        {
            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                return;
            }

            string requestUrl = context.Request.Url.ToString();

            if (string.IsNullOrEmpty(requestUrl) || !requestUrl.ToLower().EndsWith("robots.txt"))
            {
                return;
            }

            string robotsContent = string.Empty;

            if (Sitecore.Context.Site != null && Sitecore.Context.Database != null)
            {
                Item siteTenantItem = SiteExtensions.GetTenantItem(Sitecore.Context.Site);
                if (siteTenantItem != null)
                {
                    robotsContent = siteTenantItem.Fields[Constants.RobotsTextField].Value;
                }
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write(robotsContent);
            context.Response.End();
        }
Beispiel #4
0
        public static List <Item> GetBreadcrumbTrail(this Item item)
        {
            List <Item> items = new List <Item>();
            var         sc    = SiteExtensions.GetContextSite();

            if (sc != null)
            {
                var startItem = Sitecore.Context.Database.GetItem(sc.StartPath);
                if (startItem != null)
                {
                    Item currentItem = item;
                    items.Add(currentItem);
                    while (!currentItem.ID.Equals(startItem.ID))
                    {
                        currentItem = currentItem.Parent;
                        if (currentItem == null)
                        {
                            return(new List <Item>());
                        }

                        items.Insert(0, currentItem);
                    }
                }
            }

            return(items);
        }
Beispiel #5
0
        public static IHtmlString GetCDNFooterScripts(this HtmlHelper helper)
        {
            //Get CDN Helper Prefix from Sitecore Setting.
            var site   = SiteExtensions.GetContextSite();
            var cdnURL = GetFormattedCdnHostName(site.Properties["cdnHostName"]);

            return(helper.GetFooterScripts(cdnURL));
        }
Beispiel #6
0
            public void WhenSourceDoesNotExist_ShouldThrow_Fact()
            {
                // Arrange, Act, Assert
                var exception = Assert.Throws <Exception>(() =>
                                                          SiteExtensions.GetVirtualPath(Helper.ServerManager.Sites[0], "unknown", ""));

                Xunit.Assert.Equal("Binding for protocol 'unknown' is not defined for the website 'WebSite1'.", exception.Message);
            }
            public void WhenHostProvided_IfPortProvided_ShouldReturnHostAndPort()
            {
                // Arrange
                var mock = new WebServerMockGenerator();

                // Act
                var path = SiteExtensions.GetVirtualPath(mock.ServerManager.Sites[0], "http", "myhost");

                // Assert
                Assert.Equal("http://myhost:8080", path);
            }
            public void WhenHostNotProvided_IfPortNotProvided_ShouldReturnHostFromBindingAndPort80()
            {
                // Arrange
                var mock = new WebServerMockGenerator();

                // Act
                var path = SiteExtensions.GetVirtualPath(mock.ServerManager.Sites[0], "https", "");

                // Assert
                Assert.Equal("https://mylocalhost", path);
            }
            public void WhenNoBindings_ShouldThrow()
            {
                // Arrange
                var mock = new WebServerMockGenerator();

                mock.ServerManager.Sites[0].Bindings.Clear();

                // Act
                var exception = Assert.Throws <Exception>(() => SiteExtensions.GetVirtualPath(mock.ServerManager.Sites[0], "http", "myhost"));

                // Assert
                Assert.Equal(string.Format("Binding for protocol 'http' is not defined for the website '{0}'.", mock.ServerManager.Sites[0].Name), exception.Message);
            }
Beispiel #10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        // Note: Configures Services
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider sp)
        {
            m_logger.Error("Test: Startup.Configure() : Start");
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement = true
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            if (env.IsDevelopment())
            {
                //test: read raw request.
                //app.Use(next => context => { context.Request.EnableRewind(); return next(context); });
            }
            app.UseAuthentication();
            app.UseCors(builder =>
                        builder.WithOrigins("http://www.jobyjobs.com", "http://joby.ori-pc.com")
                        .AllowAnyOrigin()   //Todo. find a better solution.
                        .AllowAnyHeader()
                        .AllowAnyMethod()); //Note: allow CORS;
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });
            app.UseSignalR(routes =>
            {
                routes.MapHub <ChatHub>("chat");
                routes.MapHub <NotificationsHub>("notifications");
            });

            //user code here:
            //Initializes cache.
            SiteExtensions.Initialize(Configuration);
            sp.GetService <ICacheManager>().Initialize(sp.GetService <IBLCacheSource>());
            m_logger.Error("Test: Startup.Configure() : End");
        }
Beispiel #11
0
        public override void Process(HttpRequestArgs args)
        {
            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                return;
            }

            string requestUrl = context.Request.Url.ToString();

            if (string.IsNullOrEmpty(requestUrl) || !requestUrl.ToLower().EndsWith("sitemap.xml"))
            {
                return;
            }

            string siteMapContent = string.Empty;

            if (Sitecore.Context.Site != null && Sitecore.Context.Database != null)
            {
                Item siteTenantItem = SiteExtensions.GetTenantItem(Sitecore.Context.Site);
                Item homeItem       = SiteExtensions.GetStartItem(Sitecore.Context.Site);
                if (siteTenantItem != null && homeItem != null)
                {
                    var logService         = ServiceLocator.ServiceProvider.GetService <ILogService>();
                    var glassMapperService = ServiceLocator.ServiceProvider.GetService <IGlassMapperService>();


                    //grab the base domain to use in each page item
                    var siteMapBaseDomain = siteTenantItem.Fields[Constants.SitemapBaseDomainField].Value;
                    var homeSiteMapItem   = glassMapperService.GetItem <ISiteMapItem>(homeItem.Paths.Path);

                    //Cached "per site"
                    string siteCacheKey = string.Format("{0}_{1}", Sitecore.Context.Site.Name, Constants.SitemapContentCacheKey);
                    if (CacheManagerService.GetObject(siteCacheKey) == null)
                    {
                        List <ISiteMapItem> allPageItemsFlattened = new List <ISiteMapItem>();

                        if (homeSiteMapItem.IncludeInSitemap)
                        {
                            allPageItemsFlattened.Add(homeSiteMapItem);
                        }

                        var flattenedSiteMapItems = GetRecursiveFlattenedSiteMapItems(homeSiteMapItem, allPageItemsFlattened);
                        if (flattenedSiteMapItems != null)
                        {
                            siteMapContent = GenerateSiteMapXML(flattenedSiteMapItems, siteMapBaseDomain, logService, glassMapperService);
                            CacheManagerService.SetObject(siteCacheKey, siteMapContent);
                        }
                    }
                    else
                    {
                        siteMapContent = CacheManagerService.GetObject(siteCacheKey).ToString();
                    }
                }
            }

            context.Response.ContentType = "text/xml";
            context.Response.Write(siteMapContent);
            context.Response.End();
        }