コード例 #1
0
        public void SelectedIDChanged(object sender, EventArgs e)
        {
            //capture selected changed event so we can pass the id to the other page and force link
            AppSelector appSelector = (AppSelector)sender;

            if (isBlackEnabled && appSelector.SelectedID == 1)
            {
                // change headline and lead style if the black option is chosen
                this.PageHeader.HeadlineStyle = TextStyles.PageHeadline;
                this.PageHeader.LedeStyle     = TextStyles.PageLede;
                this.PageHeader.SetOpacity(1d);

                // show the radiating button if the black option is chosen
                this.rBtnLeft.Visibility = Visibility.Visible;
                this.rBtnLeft.StartEntranceAnimation();
                this.rBtnLeft.StartRadiateAnimation();
            }
            else
            {
                this.PageHeader.HeadlineStyle = TextStyles.PageHeadlineDark;
                this.PageHeader.LedeStyle     = TextStyles.PageLedeDark;
                this.PageHeader.SetOpacity(1d);

                // show the radiating button if the black option is chosen
                this.rBtnLeft.Visibility = Visibility.Collapsed;
                this.rBtnLeft.ResetEntranceAnimation();
                this.rBtnLeft.ResetRadiateAnimation();
            }
        }
コード例 #2
0
        public void SelectedIDChanged(object sender, EventArgs e)
        {
            //capture selected changed event so we can pass the id to the other page and force link
            AppSelector appSelector = (AppSelector)sender;

            AccessoriesPenPage.Current?.SetID(appSelector.SelectedID);
        }
コード例 #3
0
ファイル: Request.cs プロジェクト: bluemagicindia/Framework
        /// <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();
            }
        }
コード例 #4
0
ファイル: Request.cs プロジェクト: bluemagicindia/Framework
        /// <summary>
        /// Handle client web POST /app.json
        /// </summary>
        private static async Task <bool> Post(HttpContext context, string path, AppSelector appSelector)
        {
            bool result = false;

            if (path == "/app.json")
            {
                string jsonClient = await appSelector.ProcessAsync(context, null); // Process (Client http post)

                context.Response.ContentType = UtilServer.ContentType(path);

                await context.Response.WriteAsync(jsonClient);

                result = true;
            }

            return(result);
        }
コード例 #5
0
ファイル: Request.cs プロジェクト: bluemagicindia/Framework
        /// <summary>
        /// Returns true, if file found in folder "Application.Server/Framework/Application.Website/"
        /// </summary>
        private async Task <bool> WebsiteFileAsync(HttpContext context, string path, AppSelector appSelector)
        {
            bool result = false;

            if (UtilServer.NavigatePathIsFileName(path))
            {
                // Serve fileName
                string fileName = UtilServer.FolderNameContentRoot() + UtilFramework.FolderNameParse(appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/"), path);
                if (File.Exists(fileName))
                {
                    context.Response.ContentType = UtilServer.ContentType(fileName);
                    await context.Response.SendFileAsync(fileName);

                    return(true);
                }
            }
            return(result);
        }
コード例 #6
0
ファイル: Request.cs プロジェクト: bluemagicindia/Framework
        /// <summary>
        /// Divert request to "Application.Server/Framework/Application.Website/"
        /// </summary>
        private static async Task <bool> WebsiteServerSideRenderingAsync(HttpContext context, string navigatePath, AppSelector appSelector, AppJson appJson)
        {
            bool result = false;

            // FolderNameServer
            string folderNameServer = appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/");

            // FolderName
            string folderName = UtilServer.FolderNameContentRoot() + folderNameServer;

            if (!Directory.Exists(folderName))
            {
                throw new Exception(string.Format("Folder does not exis! Make sure cli build command did run. ({0})", folderName));
            }

            // Index.html
            string pathIndexHtml = navigatePath;

            if (!UtilServer.NavigatePathIsFileName(navigatePath))
            {
                pathIndexHtml += "index.html";
            }

            // FileName
            string fileName = UtilFramework.FolderNameParse(folderName, pathIndexHtml);

            if (File.Exists(fileName))
            {
                if (fileName.EndsWith(".html") && UtilFramework.StringNull(appSelector.AppTypeName) != null)
                {
                    context.Response.ContentType = UtilServer.ContentType(fileName);
                    string htmlIndex = await WebsiteServerSideRenderingAsync(context, appSelector, appJson);

                    await context.Response.WriteAsync(htmlIndex);

                    result = true;
                }
            }
            return(result);
        }
コード例 #7
0
ファイル: Request.cs プロジェクト: bluemagicindia/Framework
        /// <summary>
        /// Render first html GET request.
        /// </summary>
        private static async Task <string> WebsiteServerSideRenderingAsync(HttpContext context, AppSelector appSelector, AppJson appJson)
        {
            string url;

            if (UtilServer.IsIssServer)
            {
                // Running on IIS Server.
                url  = context.Request.IsHttps ? "https://" : "http://";
                url += context.Request.Host.ToUriComponent() + "/Framework/Framework.Angular/server/main.js"; // Url of server side rendering when running on IIS Server
            }
            else
            {
                // Running in Visual Studio.
                url = "http://localhost:4000/"; // Url of server side rendering when running in Visual Studio
            }

            // Process AppJson
            string jsonClient = await appSelector.ProcessAsync(context, appJson); // Process (For first server side rendering)

            // Server side rendering POST.
            string folderNameServer = appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/Framework/");

            string serverSideRenderView = UtilFramework.FolderNameParse(folderNameServer, "/index.html");

            serverSideRenderView = HttpUtility.UrlEncode(serverSideRenderView);
            url += "?view=" + serverSideRenderView;

            bool   isServerSideRendering = ConfigServer.Load().IsServerSideRendering;
            string indexHtml;

            if (isServerSideRendering)
            {
                // index.html server side rendering
                indexHtml = await UtilServer.WebPost(url, jsonClient); // Server side rendering POST. http://localhost:50919/Framework/Framework.Angular/server.js?view=Application.Website%2fDefault%2findex.html
            }
            else
            {
                // index.html serve directly
                string fileName = UtilServer.FolderNameContentRoot() + UtilFramework.FolderNameParse(appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/"), "/index.html");
                indexHtml = UtilFramework.FileLoad(fileName);
            }

            // Set jsonBrowser in index.html.
            string scriptFind    = "</app-root>"; //" <script>var jsonBrowser={}</script>"; // For example Html5Boilerplate build process renames var jsonBrowser to a.
            string scriptReplace = "</app-root><script>var jsonBrowser = " + jsonClient + "</script>";

            if (isServerSideRendering)
            {
                indexHtml = UtilFramework.Replace(indexHtml, scriptFind, scriptReplace);
            }

            // Add Angular scripts
            scriptFind    = "</body></html>";
            scriptReplace = "<script src=\"runtime.js\" defer></script><script src=\"polyfills.js\" defer></script><script src=\"main.js\" defer></script>" +
                            "</body></html>";
            indexHtml = UtilFramework.Replace(indexHtml, scriptFind, scriptReplace);

            return(indexHtml);
        }
コード例 #8
0
ファイル: Request.cs プロジェクト: bluemagicindia/Framework
        /// <summary>
        /// Browser request to download file or navigate to subpage.
        /// </summary>
        private static async Task <bool> FileDownloadAsync(HttpContext context, string navigatePath, AppSelector appSelector)
        {
            bool result;
            var  appJson        = appSelector.CreateAppJson(); // Without deserialize session.
            var  navigateResult = await appJson.NavigateInternalAsync(navigatePath);

            if (navigateResult.IsSession)
            {
                var appJsonSession = await appSelector.CreateAppJsonSession(context); // With deserialize session.

                var navigateSessionResult = await appJsonSession.NavigateSessionInternalAsync(navigatePath, isAddHistory : false);

                if (navigateSessionResult.IsPage)
                {
                    // Send page together with HTTP 404 not found code
                    if (navigateSessionResult.IsPageNotFound)
                    {
                        context.Response.StatusCode = StatusCodes.Status404NotFound;
                    }

                    result = await WebsiteServerSideRenderingAsync(context, "/", appSelector, appJsonSession);
                }
                else
                {
                    // File download with session
                    result = await FileDownloadAsync(context, navigatePath, navigateSessionResult.Data);
                }
            }
            else
            {
                // File download without session
                result = await FileDownloadAsync(context, navigatePath, navigateResult.Data);
            }
            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Browser request to download file or navigate to subpage.
        /// </summary>
        private static async Task <bool> FileDownloadAsync(HttpContext context, string path, AppSelector appSelector)
        {
            bool result;
            var  appJson        = appSelector.CreateAppJson(); // Without deserialize session.
            var  navigateResult = await appJson.NavigateInternalAsync(path);

            if (navigateResult.IsSession)
            {
                var appJsonSession = await appSelector.CreateAppJsonSession(context); // With deserialize session.

                var navigateSessionResult = await appJsonSession.NavigateSessionInternalAsync(path, false);

                if (navigateSessionResult.IsPage)
                {
                    result = await WebsiteServerSideRenderingAsync(context, "/", appSelector, appJsonSession);
                }
                else
                {
                    // File download with session
                    result = await FileDownloadAsync(context, path, navigateSessionResult.Data);
                }
            }
            else
            {
                // File download without session
                result = await FileDownloadAsync(context, path, navigateResult.Data);
            }
            return(result);
        }