public async Task get_list_data_backup(AppJson configs) { string api_backup_list = System.Configuration.ConfigurationSettings.AppSettings["api_backup_list"]; var BYTESAVE_API_PBL = System.Configuration.ConfigurationSettings.AppSettings["BYTESAVE_API_PBL"]; try { HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(BYTESAVE_API_PBL + api_backup_list + Get_Serial_number() + "/" + configs.email_loggin); WebReq.Method = "GET"; WebReq.Timeout = 10000; HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse(); string jsonString; using (Stream stream = WebResp.GetResponseStream()) //modified from your code since the using statement disposes the stream automatically when done { StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8); jsonString = reader.ReadToEnd(); dynamic d = JsonConvert.DeserializeObject(jsonString); json_backup_bytesave json_backup_bytesaves = d.ToObject <json_backup_bytesave>(); //var msg = json["msg"].ToString(); if (json_backup_bytesaves.status == "true") { List <backup_bytesave> lst_backup = new List <backup_bytesave>(); if (json_backup_bytesaves.countdata > 0) { foreach (var item in json_backup_bytesaves.data) { lst_backup.Add(new backup_bytesave { id = item.id, id_agent = item.id_agent, id_connect_bytesave = item.id_connect_bytesave, name = item.name, local_path = item.local_path, container_name = item.container_name, time = item.time, time_delete = item.time_delete, connect_bytesave_name = item.connect_bytesave_name, time_delete_file_in_LastVersion = item.time_delete_file_in_LastVersion, connect_bytesave_username_account = item.connect_bytesave_username_account, email = item.email, is_folder = item.is_folder, time_create_at = item.time_create_at, time_update_at = item.time_update_at, }); } } configs.Settings.backup_bytesaves = lst_backup; File.WriteAllText(filePath, System.Text.Json.JsonSerializer.Serialize(configs)); } } } catch (Exception ex) { NLogManager.LogError("[check_is_logged] -> " + BYTESAVE_API_PBL + api_backup_list + Get_Serial_number() + "/" + configs.email_loggin); NLogManager.LogError("[check_is_logged] -> " + ex); new MainUtility().save_log_agent(ex.ToString(), "get_list_data_backup", 0, 0, configs.email_loggin); configs.Settings.backup_bytesaves = new List <backup_bytesave>(); File.WriteAllText(filePath, System.Text.Json.JsonSerializer.Serialize(configs)); } }
/// <summary> /// Returns JsonClient. Create AppJson and process request. /// </summary> internal async Task <string> ProcessAsync(HttpContext context, AppJson appJson) { if (appJson == null) { // Create AppJson with session data. appJson = await CreateAppJsonSession(context); } // Process try { await appJson.ProcessInternalAsync(appJson); } catch (Exception exception) { appJson.BootstrapAlert(UtilFramework.ExceptionToString(exception), BootstrapAlertEnum.Error); appJson.IsReload = true; } // Version tag RenderVersion(appJson); // RequestCount appJson.RequestCount = appJson.RequestJson.RequestCount; // ResponseCount appJson.ResponseCount += 1; // SerializeSession, SerializeClient UtilSession.Serialize(appJson, out string jsonClientResponse); return(jsonClientResponse); }
/// <summary> /// Remove shadow covering application behind modal window. /// </summary> internal static void DivModalBackdropRemove(AppJson owner) { foreach (var item in owner.List.Where(item => item.CssClass == "modal-backdrop show").ToList()) { item.ComponentRemove(); } }
internal static void ProcessAsync(AppJson appJson) { if (UtilSession.Request(appJson, CommandEnum.BulmaNavbarItemIsClick, out CommandJson commandJson, out BulmaNavbar navbar)) { var navbarItem = navbar.ItemListAll().Single(item => item.Id == commandJson.BulmaNavbarItemId); Grid grid = navbarItem.Grid; // User clicked navbar button if (navbarItem.ItemEnum == BulmaNavbarItemEnum.Text) { appJson.RequestJson.CommandAdd(new CommandJson { CommandEnum = CommandEnum.GridIsClickRow, ComponentId = grid.Id, RowStateId = navbarItem.RowStateId }); } // User changed navbar filter text if (navbarItem.ItemEnum == BulmaNavbarItemEnum.Filter) { string filterText = commandJson.BulmaFilterText; int rowStateId = navbarItem.RowStateId; var column = grid.ColumnList.Single(item => item.FieldNameCSharp == navbarItem.FilterFieldNameCSharp); var cell = grid.CellList.Single(item => item.RowStateId == rowStateId && item.ColumnId == column.Id && item.CellEnum == GridCellEnum.Filter); appJson.RequestJson.CommandAdd(new CommandJson { CommandEnum = CommandEnum.GridCellIsModify, ComponentId = grid.Id, RowStateId = navbarItem.RowStateId, GridCellId = cell.Id, GridCellText = filterText }); } } }
public void get_list_data_connect(AppJson configs) { string api_connect_list = System.Configuration.ConfigurationSettings.AppSettings["api_connect_list"]; var BYTESAVE_API_PBL = System.Configuration.ConfigurationSettings.AppSettings["BYTESAVE_API_PBL"]; try { HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(BYTESAVE_API_PBL + api_connect_list + Get_Serial_number() + "/" + configs.email_loggin); WebReq.Method = "GET"; WebReq.Timeout = 10000; HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse(); string jsonString; using (Stream stream = WebResp.GetResponseStream()) //modified from your code since the using statement disposes the stream automatically when done { StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8); jsonString = reader.ReadToEnd(); dynamic d = JsonConvert.DeserializeObject(jsonString); json_connect_bytesave json_connect_bytesaves = d.ToObject <json_connect_bytesave>(); //var msg = json["msg"].ToString(); if (json_connect_bytesaves.status == "true") { List <connect_bytesave> lst = new List <connect_bytesave>(); if (json_connect_bytesaves.countdata > 0) { foreach (var item in json_connect_bytesaves.data) { lst.Add(new connect_bytesave { id = item.id, id_agent = item.id_agent, id_metric_service = item.id_metric_service, metric_service_max_storage = item.metric_service_max_storage, metric_service_information_connect = item.metric_service_information_connect, metric_service_username_account = item.metric_service_username_account, time_check_at = item.time_check_at, name = item.name, type_text = item.type_text, type = item.type, time_create_at = item.time_create_at, time_update_at = item.time_update_at, }); } } configs.Settings.connect_bytesaves = lst; File.WriteAllText(filePath, System.Text.Json.JsonSerializer.Serialize(configs)); //return json_connect_bytesaves; } } } catch (Exception ex) { NLogManager.LogError("[check_is_logged] -> " + BYTESAVE_API_PBL + api_connect_list + Get_Serial_number() + "/" + configs.email_loggin); NLogManager.LogError("[check_is_logged] -> " + ex); new MainUtility().save_log_agent(ex.ToString(), "get_list_data_connect", 0, 0, configs.email_loggin); configs.Settings.connect_bytesaves = new List <connect_bytesave>(); File.WriteAllText(filePath, System.Text.Json.JsonSerializer.Serialize(configs)); } //return null; }
public async Task <JsonResult> CCC([FromForm] AppJson ss) { if (ss.a == null || ss.b == null) { return(new JsonResult(new { code = 0, result = "aaaaaaaa" })); } return(new JsonResult(new { code = 200, result = ss.a + "|" + ss.b })); }
/// <summary> /// User clicked home button for example on navbar. /// </summary> public static Task ProcessHomeIsClickAsync(AppJson appJson) { if (UtilSession.Request(appJson, CommandEnum.HomeIsClick, out _, out ComponentJson _)) { // User clicked home button } return(Task.FromResult(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)); }
public static void BootstrapNavbarRender(AppJson appJson) { int buttonId = 0; // BootstrapNavbarButton.Id foreach (BootstrapNavbar bootstrapNavbar in appJson.ComponentListAll().OfType <BootstrapNavbar>()) { bootstrapNavbar.ButtonList = new List <BootstrapNavbarButton>(); // Clear foreach (var item in bootstrapNavbar.GridList) { if (item.Grid?.TypeRow != null) { var propertyInfoList = UtilDalType.TypeRowToPropertyInfoList(item.Grid.TypeRow); PropertyInfo propertyInfoId = propertyInfoList.Where(item => item.Name == "Id" && item.PropertyType == typeof(int)).SingleOrDefault(); PropertyInfo propertyInfoParentId = propertyInfoList.Where(item => item.Name == "ParentId" && item.PropertyType == typeof(int?)).SingleOrDefault(); PropertyInfo propertyInfoTextHtml = propertyInfoList.Where(item => item.Name == "TextHtml" && item.PropertyType == typeof(string)).SingleOrDefault(); if (propertyInfoParentId != null) { UtilFramework.Assert(propertyInfoId != null, "Row needs a column 'Id'!"); } UtilFramework.Assert(propertyInfoTextHtml != null, string.Format("Row needs a column 'TextHtml' ({0})!", UtilDalType.TypeRowToTableNameCSharp(item.Grid.TypeRow))); // Add for example language switch if (item.IsSelectMode) { if (item.Grid.RowSelect != null) { string textHtml = (string)propertyInfoTextHtml.GetValue(item.Grid.RowSelect); var args = new BootstrapNavbarButtonArgs { BootstrapNavbar = bootstrapNavbar, Grid = item.Grid, Row = item.Grid.RowSelect }; var result = new BootstrapNavbarButtonResult { TextHtml = textHtml }; bootstrapNavbar.ButtonTextHtml(args, result); buttonId += 1; var button = new BootstrapNavbarButton { Id = buttonId, Grid = item.Grid, RowStateId = item.Grid.RowSelectRowStateId.Value, TextHtml = result.TextHtml }; bootstrapNavbar.ButtonList.Add(button); BootstrapNavbarRender(bootstrapNavbar, item, button, ref button.ButtonList, findParentId: null, propertyInfoId, propertyInfoParentId, propertyInfoTextHtml, ref buttonId); } } else { BootstrapNavbarRender(bootstrapNavbar, item, null, ref bootstrapNavbar.ButtonList, findParentId: null, propertyInfoId, propertyInfoParentId, propertyInfoTextHtml, ref buttonId); } } } } }
/// <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); }
/// <summary> /// Returns true, if expected command has been sent by client. /// </summary> public static bool Request <T>(AppJson appJson, CommandEnum command, out CommandJson commandJson, out T componentJson) where T : ComponentJson { bool result = false; commandJson = appJson.RequestJson.CommandGet(); componentJson = (T)null; if (command == commandJson.CommandEnum) { result = true; componentJson = (T)appJson.Root.RootComponentJsonList[commandJson.ComponentId]; } return(result); }
/// <summary> /// Create AppJson without session data. /// </summary> public AppJson CreateAppJson() { Type type = UtilFramework.TypeFromName(AppTypeName); if (type == null) { throw new Exception(string.Format("AppTypeName does not exist! See also file: ConfigServer.json ({0})", AppTypeName)); } AppJson result = (AppJson)Activator.CreateInstance(type); return(result); }
/// <summary> /// User clicked internal link or clicked backward, forward navigation history. Instead of GET and download Angular again a POST command is sent. /// </summary> public static async Task ProcessNavigateLinkAsync(AppJson appJson) { // User clicked internal link. if (UtilSession.Request(appJson, RequestCommand.NavigateLink, out CommandJson commandJson, out ComponentJson _)) { await appJson.NavigateSessionInternalAsync(commandJson.NavigateLinkPath, commandJson.NavigateLinkPathIsAddHistory); } // User clicked backward, forward navigation button. if (UtilSession.Request(appJson, RequestCommand.NavigateLinkBackwardForward, out commandJson, out ComponentJson _)) { await appJson.NavigateSessionInternalAsync(commandJson.NavigateLinkPath, commandJson.NavigateLinkPathIsAddHistory); } }
/// <summary> /// User clicked internal link or user clicked backward or forward button in browser. Instead of GET and download Angular again a POST command is sent. /// </summary> public static async Task ProcessNavigatePostAsync(AppJson appJson) { // User clicked internal link. if (UtilSession.Request(appJson, CommandEnum.NavigatePost, out CommandJson commandJson, out ComponentJson _)) { await appJson.NavigateSessionInternalAsync(commandJson.NavigatePath, commandJson.NavigatePathIsAddHistory); } // User clicked backward or forward button in browser. if (UtilSession.Request(appJson, CommandEnum.NavigateBackwardForward, out commandJson, out ComponentJson _)) { await appJson.NavigateSessionInternalAsync(commandJson.NavigatePath, commandJson.NavigatePathIsAddHistory); } }
/// <summary> /// Process bootstrap modal dialog window. /// </summary> public static void ProcessBootstrapModal(AppJson appJson) { appJson.IsBootstrapModal = false; BootstrapModal.DivModalBackdropRemove(appJson); bool isExist = false; foreach (var item in appJson.ComponentListAll().OfType <BootstrapModal>()) { item.ButtonClose?.ComponentMoveLast(); isExist = true; } if (isExist) { appJson.IsBootstrapModal = true; BootstrapModal.DivModalBackdropCreate(appJson); } }
/// <summary> /// Remove non Div components from DivContainer. /// </summary> public static void DivContainerRender(AppJson appJson) { foreach (var divContainer in appJson.ComponentListAll().OfType <DivContainer>()) { List <ComponentJson> listRemove = new List <ComponentJson>(); // Collect items to remove. foreach (var item in divContainer.List) { if (!(item is Div)) // ComponentJson.Type is not evalueted on DivComponent children! { listRemove.Add(item); } } foreach (var item in listRemove) { item.ComponentRemove(); } } }
public void get_info_to_server(AppJson configs) { string api_info = System.Configuration.ConfigurationSettings.AppSettings["api_info"]; //string id_service = System.Configuration.ConfigurationSettings.AppSettings["id_service"]; var BYTESAVE_API_PBL = System.Configuration.ConfigurationSettings.AppSettings["BYTESAVE_API_PBL"]; try { HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(BYTESAVE_API_PBL + api_info + Get_Serial_number() + "/" + configs.email_loggin); WebReq.Method = "GET"; WebReq.Timeout = 10000; HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse(); string jsonString; using (Stream stream = WebResp.GetResponseStream()) //modified from your code since the using statement disposes the stream automatically when done { StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8); jsonString = reader.ReadToEnd(); dynamic d = JsonConvert.DeserializeObject(jsonString); json_info_bytesave json_info_bytesaves = d.ToObject <json_info_bytesave>(); //var msg = json["msg"].ToString(); if (json_info_bytesaves.status == "true") { var info = new Info(); if (json_info_bytesaves.countdata > 0) { var item = json_info_bytesaves.data[0]; info.name_version = item.name_version; info.bytesave_expiration_date = item.bytesave_expiration_date; } configs.Settings.bytesave_info.information = info; File.WriteAllText(filePath, System.Text.Json.JsonSerializer.Serialize(configs)); } } } catch (Exception ex) { NLogManager.LogError("[get_info_to_server] -> " + BYTESAVE_API_PBL + api_info + Get_Serial_number() + "/" + configs.email_loggin); NLogManager.LogError("[get_info_to_server] -> " + ex); new MainUtility().save_log_agent(ex.ToString(), "get_info_to_server", 0, 0, configs.email_loggin); configs.Settings.bytesave_info.information = new Info(); File.WriteAllText(filePath, System.Text.Json.JsonSerializer.Serialize(configs)); } }
/// <summary> /// Process navbar button click. /// </summary> public static async Task ProcessBootstrapNavbarAsync(AppJson appJson) { if (UtilSession.Request(appJson, CommandEnum.BootstrapNavbarButtonIsClick, out CommandJson commandJson, out BootstrapNavbar navbar)) { if (navbar.ButtonList != null) { var buttonList = new List <BootstrapNavbarButton>(); ProcessBootstrapNavbarButtonListAll(navbar.ButtonList, buttonList); foreach (BootstrapNavbarButton button in buttonList) { if (commandJson.BootstrapNavbarButtonId == button.Id) { GridRowState rowState = button.Grid.RowStateList[button.RowStateId - 1]; await UtilGrid.RowSelectAsync(button.Grid, rowState, isRender : true); } } } } }
private void RenderVersion(AppJson appJson) { // Version appJson.Version = UtilFramework.Version; appJson.VersionBuild = UtilFramework.VersionBuild; // Session appJson.Session = UtilServer.Session.Id; if (string.IsNullOrEmpty(appJson.SessionApp)) { appJson.SessionApp = UtilServer.Session.Id; } // IsReload if (UtilServer.Session.Id != appJson.SessionApp) // Session expired! { appJson.IsReload = true; } }
internal static void Render(AppJson appJson) { int navbarItemId = 0; foreach (BulmaNavbar navbar in appJson.ComponentListAll().OfType <BulmaNavbar>()) { // ItemList clear navbar.ItemStartList.Clear(); navbar.ItemEndList.Clear(); // Add level 0 and level 1 to navbar foreach (var navbarGrid in navbar.GridList) { Render(navbar, navbarGrid, ref navbarItemId); } // Add data grid filter (input text) to navbar if (navbar.Filter != null) { var filter = navbar.Filter; var grid = filter.Grid; // Get filter text from value store. new GridFilter(grid).FilterValueList().TryGetValue(filter.FieldNameCSharp, out var gridFilterValue); string filterText = gridFilterValue?.Text; int rowSateId = grid.RowStateList.Single(item => item.RowEnum == GridRowEnum.Filter).Id; // Filter input text box var navbarItem = new BulmaNavbarItem { Id = navbarItemId += 1, ItemEnum = BulmaNavbarItemEnum.Filter, Grid = grid, FilterFieldNameCSharp = filter.FieldNameCSharp, RowStateId = rowSateId, FilterText = filterText, FilterPlaceholder = "Search" }; if (filter.IsNavbarEnd == false) { navbar.ItemStartList.Add(navbarItem); } else { navbar.ItemEndList.Add(navbarItem); } } } }
public void WriteConfig_Loggin() { var configs = new AppJson(); try { filePath = Path.GetFullPath("appsettings.json"); var str = File.ReadAllText(filePath); configs = System.Text.Json.JsonSerializer.Deserialize <AppJson>(str); get_info_to_server(configs); get_list_data_backup(configs); //var ex_lst_backup = list_backup.data.Except(configs.Settings.backup_bytesaves).ToList(); get_setting_to_server(configs); get_list_data_connect(configs); } catch (Exception ex) { new MainUtility().save_log_agent(ex.ToString(), "MainWindowModel", 0, 0, configs.email_loggin); } }
/// <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); }
/// <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); }
/// <summary> /// Add shadow covering application behind modal window. /// </summary> internal static void DivModalBackdropCreate(AppJson appJson) { Div result = new Div(appJson); result.CssClass = "modal-backdrop show"; }