public ActionResult Index()
        {
            int counterValue = AppStateHelper.IncrementAndGet(AppStateKeys.IndexCounter);

            Debug.WriteLine($"IndexCounter: {counterValue}");
            return(View("~/Views/CachingChildAction/Index.cshtml", (object)counterValue));
        }
Beispiel #2
0
        //Summarize information about user and environment
        private string GetBrowserInfo()
        {
            var browser          = this.Request.Browser;
            var userName         = this.User.Identity.Name;
            var totalOnlineUsers = (int)AppStateHelper.Get(AppStateKeys.ONLINE, 0);

            var result = String.Format(
                @"Browser: {0} {1},<br />EcmaScript: {2},<br />JavaScript: {3},<br />Platform: {4}," +
                "<br />Cookies: {5},<br />ActiveXControls: {6},<br />JavaApplets {7},<br />Frames: {8}," +
                "<br />IsMobile: {9},<br />Manufacture: {10},<br />Model: {11}," +
                "<br />User Name: {12}{13},<br />Online: {14},<br />Framework: {15}, <br /> OS: {16}",
                browser.Browser,
                browser.Version,
                browser.EcmaScriptVersion,
                browser["JavaScriptVersion"],
                browser.Platform,
                browser.Cookies,
                browser.ActiveXControls,
                browser.JavaApplets,
                browser.Frames,
                browser.IsMobileDevice,
                browser.MobileDeviceManufacturer,
                browser.MobileDeviceModel,
                string.Format("{0} ({1})", this.CurrentADUser.Name, this.CurrentADUser.EmailAddress),
                userName.Length == 0 ? "" : string.Format("({0})", userName.Replace(@"\", "&#92;")),
                totalOnlineUsers,
                Environment.Version.ToString(),
                Environment.OSVersion.ToString()
                );

            return(result);
        }
Beispiel #3
0
        public ActionResult Index()
        {
            int counterValue = AppStateHelper.IncrementAndGet(AppStateKeys.IndexCounter);

            Debug.WriteLine($"IndexCounter: {counterValue}");
            return(View((object)counterValue));
        }
Beispiel #4
0
        public ActionResult Index(string name, string city)
        {
            int counterValue = AppStateHelper.IncrementAndGet(AppStateKeys.IndexCounter);

            Debug.WriteLine($"IndexCounter: {counterValue}");
            return(View("~/Views/Shared/One.cshtml", (object)counterValue));
        }
Beispiel #5
0
        public ActionResult Index()
        {
            cacheSettingsHelper.DetectConfiguration(Request.RawUrl, Response.Cache);

            int counterValue = AppStateHelper.IncrementAndGet(AppStateKeys.IndexCounter);

            Debug.WriteLine($"IndexCounter: {counterValue}");
            return(View("~/Views/CachingChildAction/Index.cshtml", (object)counterValue));
        }
Beispiel #6
0
        protected override System.Data.DataTable GetData(HttpContext context, String query, int rows, Structures.Languages lang)
        {
            Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(context.Application);
            String          iso     = Format.ToIso639_1(lang);

            query = query.ToLowerInvariant();
            int natDex = 0;

            Int32.TryParse(query, out natDex);
            int limit = 0;

            if (context.Request.QueryString["limit"] != null)
            {
                limit = Convert.ToInt32(context.Request.QueryString["limit"]);
                if (natDex > limit)
                {
                    return(null);
                }
            }

            Func <KeyValuePair <int, Species>, bool> filter;

            if (natDex > 0)
            {
                filter = pair => pair.Key == natDex;
            }
            else
            {
                filter = pair => pair.Key <= limit && pair.Value.Name[iso].ToLowerInvariant().Contains(query);
            }

            IEnumerable <Species> data;

            data = pokedex.Species.Where(filter).OrderBy(pair => pair.Key).Take(rows).Select(pair => pair.Value);

            DataTable dt = new DataTable();

            dt.Columns.Add("Text", typeof(String));
            dt.Columns.Add("Value", typeof(int));
            dt.Columns.Add("html", typeof(String));

            foreach (Species s in data)
            {
                String name = s.Name[iso];
                String html = "<img src=\"" + Common.ResolveUrl(WebFormat.SpeciesImageSmall(s)) +
                              "\" alt=\"" + Common.HtmlEncode(name) +
                              "\" class=\"sprite speciesSmall\" width=\"40px\" height=\"32px\" />" +
                              String.Format("{0} (#{1})",
                                            Common.HtmlEncode(name),
                                            s.NationalDex);

                dt.Rows.Add(name, s.NationalDex, html);
            }

            return(dt);
        }
Beispiel #7
0
        protected void Session_End(object sender, EventArgs e)
        {
            // event is raised when a session is abandoned or expires
            int currentValue = (int)AppStateHelper.Get(AppStateKeys.ONLINE, 0);

            AppStateHelper.Set(AppStateKeys.ONLINE, currentValue - 1);
            AppStateHelper.SetMultiple(new Dictionary <AppStateKeys, object> {
                { AppStateKeys.LAST_REQUEST_TIME, HttpContext.Current.Timestamp },
                { AppStateKeys.LAST_REQUEST_URL, this.Request.RawUrl }
            });
        }
Beispiel #8
0
        protected void Session_Start(object sender, EventArgs e)
        {
            // event is raised each time a new session is created
            int currentValue = (int)AppStateHelper.Get(AppStateKeys.ONLINE, 0);

            AppStateHelper.Set(AppStateKeys.ONLINE, currentValue + 1);
            AppStateHelper.SetMultiple(new Dictionary <AppStateKeys, object> {
                { AppStateKeys.LAST_REQUEST_TIME, HttpContext.Current.Timestamp },
                { AppStateKeys.LAST_REQUEST_URL, this.Request.RawUrl }
            });
        }
        public ActionResult Increment()
        {
            int currentValue = (int)AppStateHelper.Get(AppStateKeys.COUNTER, 0);

            AppStateHelper.Set(AppStateKeys.COUNTER, currentValue + 1);
            AppStateHelper.SetMultiple(new Dictionary <AppStateKeys, object> {
                { AppStateKeys.LAST_REQUEST_TIME, HttpContext.Timestamp },
                { AppStateKeys.LAST_REQUEST_URL, Request.RawUrl }
            });
            return(RedirectToAction("Index"));
        }
Beispiel #10
0
        public ActionResult Index()
        {
            Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
            Response.Cache.SetCacheability(HttpCacheability.Server);
            Response.Cache.AddValidationCallback(CheckCachedItem, Request.UserAgent);

            Thread.Sleep(1000);
            int counterValue = AppStateHelper.IncrementAndGet(
                AppStateKeys.INDEX_COUNTER);

            Debug.WriteLine(string.Format("INDEX_COUNTER: {0}", counterValue));
            return(View(counterValue));
        }
        public ActionResult Index()
        {
            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("Counter", AppStateHelper.Get(AppStateKeys.COUNTER, 0));
            IDictionary <AppStateKeys, object> stateData
                = AppStateHelper.GetMultiple(AppStateKeys.LAST_REQUEST_TIME,
                                             AppStateKeys.LAST_REQUEST_URL);

            foreach (AppStateKeys key in stateData.Keys)
            {
                data.Add(Enum.GetName(typeof(AppStateKeys), key), stateData[key]);
            }
            return(View(data));
        }
Beispiel #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(Application);
            PokemonParty4   pkmn    = null;

            if (Request.QueryString.Count == 0 || Request.QueryString.Count > 2)
            {
                throw new WebException(400);
            }
            if (Request.QueryString["offer"] != null ||
                Request.QueryString["exchange"] != null)
            {
                String generation = Request.QueryString["g"];
                if (generation == null ||
                    Request.QueryString.Count != 2)
                {
                    throw new WebException(400);
                }

                int  tradeId;
                bool isExchanged;

                if (Request.QueryString["offer"] != null)
                {
                    tradeId     = Convert.ToInt32(Request.QueryString["offer"]);
                    isExchanged = false;
                }
                else if (Request.QueryString["exchange"] != null)
                {
                    tradeId     = Convert.ToInt32(Request.QueryString["exchange"]);
                    isExchanged = true;
                }
                else
                {
                    AssertHelper.Unreachable();
                    throw new WebException(400);
                }

                // todo: when userprofiles are ready, add checks that they allow viewing their GTS history
                switch (generation)
                {
                case "4":
                {
                    GtsRecord4 record = Database.Instance.GtsGetRecord4(pokedex, tradeId, isExchanged, true);
                    if (record != null)
                    {
                        pkmn = new PokemonParty4(pokedex, record.Data.ToArray());
                    }
                } break;

                case "5":
                {
                    GtsRecord5 record = Database.Instance.GtsGetRecord5(pokedex, tradeId, isExchanged, true);
                    if (record != null)
                    {
                        pkmn = new PokemonParty4(pokedex, record.Data.ToArray());
                    }
                } break;

                default:
                    throw new WebException(400);
                }
            }
            else if (Request.QueryString["check"] != null)
            {
                int checkId = Convert.ToInt32(Request.QueryString["check"]);
                throw new NotImplementedException();
            }
            else
            {
                throw new WebException(400);
            }

            if (pkmn == null)
            {
                throw new WebException(403);
            }

            Bind(pkmn);
        }
Beispiel #13
0
        /// <summary>
        /// Also we have ability set different type of configuration throughout different bootstraper class (convention => name may be different)
        /// </summary>
        protected void Application_Start()
        {
            //Config WebAPI(2)
            GlobalConfiguration.Configure(WebApiConfig.Register);
            //WebApiConfig.Register(GlobalConfiguration.Configuration);

            //Order is verty important (if i reverse areaRegistration with WebApiConfig => WebAPI 2 attributeRouting won't work
            AreaRegistration.RegisterAllAreas();

            // This method call registers all filters
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            /* Work only with razor View Engine
             * {0} represents the name of the view.
             * {1} represents the name of the controller.
             * {2} represents the name of the area.
             */
            ViewEngines.Engines.Clear();
            /*Avoid searched each view instead in .cshtml files*/
            ViewEngines.Engines.Add(new RazorViewEngine()
            {
                ViewLocationFormats            = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" },
                PartialViewLocationFormats     = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" },
                MasterLocationFormats          = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" },
                AreaViewLocationFormats        = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml" },
                AreaMasterLocationFormats      = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml" },
                AreaPartialViewLocationFormats = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml" }
            });

            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //registration custom binding providers with links to vm
            //ModelBinders.Binders.Add(typeof(SessionStorage), new StorageTableModelBinder());
            //ModelBinders.Binders.Add(typeof(InputMenuViewModel), new InputMenuModelBinder());

            //MVC4 Quick Tip #3–Removing the XML Formatter from ASP.Net Web API
            //GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

            //Configure AutoMapper
            AutoMapperBLLConfiguration.Configure();

            //https://github.com/doceandyou/Log4Net
            log4net.Config.XmlConfigurator.Configure(new FileInfo(this.Server.MapPath("~/Web.config")));

            /* Initialize simpleMembership
             * Install-Package Microsoft.AspNet.WebHelpers
             * Install-Package Microsoft.AspNet.WebPages.Data
             * (stop: required dependencies to Microsoft.AspNet.Razor > 3.0 => .Net 4.5
             * WebSecurity.InitializeDatabaseConnection("SecurityConnection", "UserProfile", "UserId", "UserName", true);
             */

            /*Custom value provider (order sense)
             * (First)
             * ValueProviderFactories.Factories.Insert(0,new CustomValueProviderFactory());
             * (End)
             * ValueProviderFactories.Factories.Add(new CustomValueProviderFactory());
             */

            /*Controller Builder
             * ControllerBuilder.Current.DefaultNamespaces.Add("DefaultNamespace");
             */

            //users online
            AppStateHelper.Set(AppStateKeys.ONLINE, 0);
        }