Exemplo n.º 1
0
        /// <summary>
        /// Serialize session state.
        /// </summary>
        public static void Serialize(AppJson appJson, out string jsonClient)
        {
            appJson.RequestJson = null;

            UtilStopwatch.TimeStart("Serialize");
            UtilJson.Serialize(appJson, out string jsonSession, out jsonClient);
            UtilStopwatch.TimeStop("Serialize");
            UtilServer.Session.SetString("AppInternal", jsonSession);

            UtilStopwatch.Log(string.Format("JsonSession.Length={0:n0}; JsonClient.Length={1:n0};", jsonSession.Length, jsonClient.Length));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserialize session state.
        /// </summary>
        public static AppJson Deserialize()
        {
            AppJson result = null;
            string  json   = UtilServer.Session.GetString("AppInternal");

            if (!string.IsNullOrEmpty(json)) // Not session expired.
            {
                UtilStopwatch.TimeStart("Deserialize");
                result = (AppJson)UtilJson.Deserialize(json);
                UtilStopwatch.TimeStop("Deserialize");
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Every client request goes through here.
        /// </summary>
        public async Task RunAsync(HttpContext context)
        {
            // await Task.Delay(500); // Simulate slow network.

            UtilStopwatch.RequestBind();
            try
            {
                UtilStopwatch.TimeStart(name: "Request");

                UtilServer.Cors();

                // Request path
                string path = context.Request.Path;

                // Get current website request from "ConfigServer.json"
                AppSelector appSelector = new AppSelector();

                // POST app.json
                if (!await Post(context, path, appSelector))
                {
                    // GET index.html from "Application.Server/Framework/Application.Website/" (With server side rendering or serve index.html directly)
                    if (!await WebsiteServerSideRenderingAsync(context, path, appSelector, null))
                    {
                        // GET file from "Application.Server/Framework/Application.Website/"
                        if (!await WebsiteFileAsync(context, path, appSelector))
                        {
                            // GET Angular file from "Application.Server/Framework/Framework.Angular/browser"
                            if (!await AngularBrowserFileAsync(context, path))
                            {
                                // GET file from database or navigate to subpage.
                                if (!await FileDownloadAsync(context, path, appSelector))
                                {
                                    context.Response.StatusCode = StatusCodes.Status404NotFound;
                                }
                            }
                        }
                    }
                }

                // Total time for one request.
                UtilStopwatch.TimeStop(name: "Request");
                // One log entry for one request.
                UtilStopwatch.TimeLog();
            }
            finally
            {
                UtilStopwatch.RequestRelease();
            }
        }