public async Task Run(XConsole xc) { try { xc.WriteInfo(this, "Trying to get current session log level..."); var level = Extensions.HostBuilderExtensions.GetLogLevel(); xc.WriteInfo(this, "Current session log level is ", false); xc.WriteSuccess(this, level); } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { var settings = scope.ServiceProvider.GetService <IDbSettingsReader>(); xc.WriteInfo(this, "Retriving version information.."); var versions = new Versions() { AppVersion = settings.GetAppVersion(), DataSeederFrameworkVersion = settings.GetDataSeederFrameworkVersion(), FrameWorkVersion = AppSettingsAccessor.GetFrameWorkBuildNumber(true) }; xc.WriteSuccess(this, "Done."); var table = xc.CreateTable(new string[] { "Item", "Value" }); table.AddRow("Application Version", versions.AppVersion); table.AddRow("Data Seeder Framework Version", versions.DataSeederFrameworkVersion); table.AddRow("Framework Version", versions.FrameWorkVersion); var parts = versions.NugetVersion.Split('.'); table.AddRow("Nuget Version", parts.Length <= 3 ? versions.NugetVersion : string.Join('.', parts.Take(3))); xc.WriteTable(table); } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { var settings = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); var url = settings.FindSingleWhere(x => x.SettingName == CORE_SYSTEM_SETTING_NAMES.APP_BASE_URL.ToString()); if (url != null) { if (string.IsNullOrEmpty(url.Value)) { xc.WriteWarning(this, "App base url value is not set in the settings"); } else { xc.WriteInfo(this, $"App is hosted at ", false); xc.Writer.Write($"'{url.Value}' ", ConsoleColor.Gray); xc.WriteInfo(this, "Status code - ", false); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url.Value); request.Timeout = 15000; HttpWebResponse response; try { response = (HttpWebResponse)request.GetResponse(); xc.WriteSuccess(this, response.StatusCode.ToString()); } catch (Exception ex) { xc.WriteError(this, "Unreachable."); throw ex; } } } else { xc.WriteError(this, "App base url setting not found."); } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { var config = scope.ServiceProvider.GetService <IConfiguration>(); var settingDB = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); var remoteSite = settingDB.FindSingleWhere(x => x.SettingName == CORE_SYSTEM_SETTING_NAMES.APP_BASE_URL.ToString()); if (remoteSite == null && string.IsNullOrEmpty(remoteSite.Value)) { xc.WriteError(this, "App base url is not found in the db.Cannot continue."); } else { xc.WriteInfo(this, $"Sending request to {remoteSite.Value} for remote settings list."); var data = new WebClient().DownloadString($"{remoteSite.Value}/{XConsole.SERVICE_CONSTROLLER}/listloadedsettings?{config[AdminPasswordVerification.ADMIN_PASS_KEYT]}={config[AdminPasswordVerification.ADMIN_PASS_VALUE]}"); xc.WriteSuccess(this, "Received response."); try { xc.WriteInfo(this, "Now trying to parse received data."); var dictionary = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, SystemSetting> > >(data); xc.WriteSuccess(this, "Successfull parsed response data"); var table = xc.CreateTable(new[] { "ID", "Name", "DisplayName", "Group", "Value" }); foreach (var k in dictionary.Keys) { var root = dictionary[k]; foreach (var l in root.Keys) { var s = root[l]; table.AddRow(s.Id, s.SettingName, s.DisplayName, s.GroupName, s.Value); } } xc.WriteTable(table); } catch (Exception ex) { xc.WriteError(this, "Error parsing received data." + ex.Message); } } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { var exicoCtx = scope.ServiceProvider.GetService <ExicoShopifyDbContext>(); var con = exicoCtx.Database.GetDbConnection().ConnectionString; if (!string.IsNullOrEmpty(con)) { var parts = con.Split(new char[] { ';' }); xc.WriteInfo(this, "X Console will connect using>> "); var table = xc.CreateTable(new string[] { "Con Attribute", "value" }); foreach (var part in parts) { var keyValue = part.Split(new char[] { '=' }); var key = keyValue[0]; var value = keyValue[1]; table.AddRow(key, value); } xc.WriteTable(table); xc.WriteInfo(this, "Connection status: ", false); try { exicoCtx.Database.GetDbConnection().Open(); xc.WriteSuccess(this, "OK"); exicoCtx.Database.GetDbConnection().Close(); } catch (Exception ex) { xc.WriteError(this, "ERROR"); throw ex; } } else { xc.WriteError(this, "Framework db context connection string is empty."); } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { var config = scope.ServiceProvider.GetService <IConfiguration>(); var settingDB = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); var remoteSite = settingDB.FindSingleWhere(x => x.SettingName == CORE_SYSTEM_SETTING_NAMES.APP_BASE_URL.ToString()); if (remoteSite == null && string.IsNullOrEmpty(remoteSite.Value)) { xc.WriteError(this, "App base url is not found in the db.Cannot continue."); } else { xc.WriteInfo(this, $"Sending request to {remoteSite.Value} to get log level info."); var data = new WebClient().DownloadString($"{remoteSite.Value}/{XConsole.SERVICE_CONSTROLLER}/GetCurrentLogLevel?{config[AdminPasswordVerification.ADMIN_PASS_KEYT]}={config[AdminPasswordVerification.ADMIN_PASS_VALUE]}"); xc.WriteSuccess(this, "Received response."); try { xc.WriteInfo(this, "Now trying to parse received data."); var response = JsonConvert.DeserializeObject <string>(data); xc.WriteSuccess(this, "Successfull parsed response data."); if (!string.IsNullOrEmpty(response)) { xc.WriteInfo(this, $"Server responded current log level is ", false); xc.WriteSuccess(this, response); } else { xc.WriteError(this, "Server responded log level query was unsuccessful."); } } catch (Exception ex) { xc.WriteError(this, "Error parsing received data." + ex.Message); } } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { xc.AskForInput(this, "Enter store my shopify domain (exact URL): "); var store = Console.ReadLine(); xc.AskForInput(this, "Enter plan id: "); var planId = Int32.Parse(Console.ReadLine()); AspNetUser user = null; Plan plan = null; using (var scope = xc.WebHost.Services.CreateScope()) { var userService = scope.ServiceProvider.GetService <IDbService <AspNetUser> >(); user = userService.FindSingleWhere(x => x.MyShopifyDomain == store); if (user == null) { xc.WriteError(this, "Store not found."); } else { var planService = scope.ServiceProvider.GetService <IDbService <Plan> >(); plan = planService.FindSingleWhere(x => x.Id == planId); if (plan == null) { xc.WriteError(this, "Plan not found."); } else { xc.WriteSuccess(this, $"Found the plan {plan.Name}."); var prevPlanId = user.PlanId; user.PlanId = plan.Id; xc.WriteInfo(this, "Updating plan id for the store."); var updatedUser = userService.Update(user, user.Id); if (updatedUser == null) { xc.WriteError(this, "Update failed."); } else { xc.WriteSuccess(this, "Successfully updated."); var table = xc.CreateTable(new string[] { "Column", "Value" }); table.AddRow(new[] { "Id", updatedUser.Id }); table.AddRow(new[] { "Store", updatedUser.MyShopifyDomain }); table.AddRow(new[] { "PreviousPlan", prevPlanId.Value.ToString() }); table.AddRow(new[] { "PreviousPlan", updatedUser.PlanId.ToString() }); xc.WriteTable(table); } } } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { var config = scope.ServiceProvider.GetService <IConfiguration>(); var settingDB = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); var remoteSite = settingDB.FindSingleWhere(x => x.SettingName == CORE_SYSTEM_SETTING_NAMES.APP_BASE_URL.ToString()); if (remoteSite == null && string.IsNullOrEmpty(remoteSite.Value)) { xc.WriteError(this, "App base url is not found in the db.Cannot continue."); } else { xc.WriteInfo(this, $"Sending request to {remoteSite.Value} for remote plans list."); var data = new WebClient().DownloadString($"{remoteSite.Value}/{XConsole.SERVICE_CONSTROLLER}/listloadedplans?{config[AdminPasswordVerification.ADMIN_PASS_KEYT]}={config[AdminPasswordVerification.ADMIN_PASS_VALUE]}"); xc.WriteSuccess(this, "Received response."); try { xc.WriteInfo(this, "Now trying to parse received data."); var list = JsonConvert.DeserializeObject <List <PlanAppModel> >(data); xc.WriteSuccess(this, "Successfull parsed response data"); var table = xc.CreateTable(new string[] { "Id", "Name", "TrialDays", "IsActive", "IsDev", "IsTest", "DisplayOrder", "IsPopular", "Price" }); foreach (var i in list) { table.AddRow(i.Id, i.Name, i.TrialDays, i.Active, i.IsDev, i.IsTest, i.DisplayOrder, i.IsPopular, i.Price.ToString("C")); } xc.WriteTable(table); } catch (Exception ex) { xc.WriteError(this, "Error parsing received data." + ex.Message); } } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { xc.AskForInput(this, "Enter myshopify domain(exact url): "); using (var scope = xc.WebHost.Services.CreateScope()) { string input = Console.ReadLine(); UserManager <AspNetUser> db = scope.ServiceProvider.GetService <UserManager <AspNetUser> >(); var user = db.FindByNameAsync(input).Result; if (user != null) { xc.WriteSuccess(this, "Found store."); xc.AskForInput(this, "Make this store admin ? (y or n): "); var confirm = Console.ReadLine(); if (confirm == "y" || confirm == "Y") { if (db.IsInRoleAsync(user, UserInContextHelper.ADMIN_ROLE).Result) { xc.WriteWarning(this, $"Account ({user.MyShopifyDomain}) is already an admin account."); } else { xc.WriteInfo(this, "Updating store as admin account."); var result = await db.AddToRoleAsync(user, UserInContextHelper.ADMIN_ROLE); if (result.Succeeded) { xc.WriteSuccess(this, $"Successfully updated."); } else { xc.WriteError(this, $"Update failed."); } } } else { xc.WriteWarning(this, $"Did not update the store as admin."); } } else { xc.WriteWarning(this, "Store not found."); } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { var db = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); var item = db.FindSingleWhere(x => x.SettingName == CORE_SYSTEM_SETTING_NAMES.PRIVILEGED_IPS.ToString()); if (item == null) { xc.WriteError(this, $"Could not list IPs because the setting {CORE_SYSTEM_SETTING_NAMES.PRIVILEGED_IPS} doesn't exit in the database."); } else { xc.WriteInfo(this, "Printing the list of priviledged IPs"); if (string.IsNullOrEmpty(item.Value)) { xc.WriteWarning(this, "none found."); } else { var ips = item.Value.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); xc.WriteInfo(this, $"Total {ips.Length} IPs found."); foreach (var i in ips) { xc.WriteSuccess(this, i); } } } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { xc.AskForInput(this, "Enter file name with or without path (file extension not needed): "); var fileName = Console.ReadLine(); if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrWhiteSpace(fileName)) { using (var scope = xc.WebHost.Services.CreateScope()) { var userService = scope.ServiceProvider.GetService <IDbService <AspNetUser> >(); var users = userService.FindAll(); xc.WriteInfo(this, $"Found {users.Count} records"); var csv = new StringBuilder(); csv.AppendLine("Email Address,First Name"); foreach (var u in users) { var newLine = string.Format("{0},{1}", u.Email, u.MyShopifyDomain); csv.AppendLine(newLine); } await File.WriteAllTextAsync(fileName + ".csv", csv.ToString()); xc.WriteInfo(this, $"Finished writing to {new FileInfo(fileName).FullName}.csv file."); xc.WriteSuccess(this, $"Export was successfull."); } } else { xc.WriteWarning(this, "Invalid file name."); } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { xc.AskForInput(this, "Enter setting name or id: "); var sIdName = Console.ReadLine(); var settingsService = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); var setting = settingsService.FindSingleWhere(x => x.SettingName == sIdName || x.Id.ToString() == sIdName); if (setting == null) { xc.WriteError(this, "Setting not found."); } else { xc.WriteSuccess(this, $"Found the setting '{setting.SettingName}'."); xc.AskForInput(this, "Enter setting value: "); var sVal = Console.ReadLine(); var oldValue = setting.Value; setting.Value = sVal; xc.WriteInfo(this, "Updating the setting."); setting = settingsService.Update(setting, setting.Id); if (setting == null) { xc.WriteWarning(this, "Update failed."); } else { xc.WriteSuccess(this, "Successfully updated."); var table = xc.CreateTable(new[] { "Column", "Value" }); table.AddRow("SettingId", setting.Id); table.AddRow("SettingName", setting.SettingName); table.AddRow("OldValue", oldValue); table.AddRow("UpdatedValue", setting.Value); xc.WriteTable(table); } } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { xc.AskForInput(this, "Enter myshopify domain (exact url): "); using (var scope = xc.WebHost.Services.CreateScope()) { string input = Console.ReadLine(); var db = scope.ServiceProvider.GetService <IDbService <AspNetUser> >(); var user = db.FindSingleWhere(x => x.MyShopifyDomain == input); if (user != null) { xc.AskForInput(this, "Enter shopify token: "); var token = Console.ReadLine(); var previousToken = user.ShopifyAccessToken; user.ShopifyAccessToken = token; xc.WriteInfo(this, "Updating token."); var updatedUser = db.Update(user, user.Id); if (updatedUser != null) { xc.WriteSuccess(this, "Successfully saved new token for the store."); var table = xc.CreateTable(new string[] { "Column", "Value" }); table.AddRow(new[] { "Id", updatedUser.Id }); table.AddRow(new[] { "Store", updatedUser.MyShopifyDomain }); table.AddRow(new[] { "PreviousToken", previousToken }); table.AddRow(new[] { "CurrentToken", updatedUser.ShopifyAccessToken }); xc.WriteTable(table); } else { xc.WriteError(this, "Error saving new token for the store."); } } else { xc.WriteWarning(this, "Store not found."); } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { var db = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); xc.AskForInput(this, "Enter the myshopify domain of the target shopify store: "); var storeUrl = Console.ReadLine(); if (string.IsNullOrEmpty(storeUrl)) { xc.WriteError(this, "Not a valid my shopify domain name."); } else if (!storeUrl.EndsWith(".myshopify.com")) { xc.WriteError(this, "Not a valid my shopify domain name."); } else { var apiKey = db.FindSingleWhere(x => x.SettingName == CORE_SYSTEM_SETTING_NAMES.API_KEY.ToString()); if (apiKey == null) { xc.WriteError(this, $"Setting { CORE_SYSTEM_SETTING_NAMES.API_KEY.ToString()} is missing in the settings table."); } else { if (string.IsNullOrEmpty(apiKey.Value)) { xc.WriteWarning(this, $"{CORE_SYSTEM_SETTING_NAMES.API_KEY.ToString()} setting doesn't have a value. Please update that setting first."); } else /*all good */ { xc.WriteInfo(this, "The installation URL for the app is "); xc.WriteSuccess(this, $"{storeUrl}/admin/api/auth?api_key={apiKey.Value}"); } } } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { xc.AskForInput(this, "Enter log level (case sensitive) you want to switch over: "); var toLevel = Console.ReadLine(); xc.WriteInfo(this, $"Trying to change log level to {toLevel} ..."); Serilog.Events.LogEventLevel level = (Serilog.Events.LogEventLevel)Enum.Parse(typeof(Serilog.Events.LogEventLevel), toLevel); Extensions.HostBuilderExtensions.SwitchToLogLevel(level); xc.WriteSuccess(this, "Done"); } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { xc.AskForInput(this, "Filter by (leave blank for all): ", false); var filter = Console.ReadLine(); List <string> list; if (string.IsNullOrEmpty(filter)) { list = xc.CommandList; } else { filter = filter.Replace("-", "").ToLower(); list = xc.CommandList.Where(x => x.ToLower().Contains(filter)).ToList(); } xc.WriteInfo(this, $"Total {list.Count} commands found."); if (list.Count > 0) { var table = xc.CreateTable(new string[] { "Command", "Description" }); foreach (string className in list) { try { var instance = xc.CreateCommandInstance(className); table.AddRow(new[] { instance.GetName(), instance.GetDescription() }); } catch (Exception) { throw; } } //table.Write(ConsoleTables.Format.Alternative); xc.WriteTable(table); } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { xc.AskForInput(this, "Filter by name (or part of it) or leave blank for all settings: "); using (var scope = xc.WebHost.Services.CreateScope()) { string input = Console.ReadLine(); var settingsService = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); List <SystemSetting> setting; xc.WriteInfo(this, "Searching settings."); if (string.IsNullOrEmpty(input)) { setting = settingsService.FindAll(); } else { setting = settingsService.FindManyWhere(x => x.SettingName.Contains(input)); } if (setting.Count <= 0) { xc.WriteWarning(this, "Total 0 settings found."); } else { xc.WriteSuccess(this, $"Total {setting.Count} setting(s) found."); var table = xc.CreateTable(new[] { "ID", "Name", "DisplayName", "Group", "Value" }); foreach (var s in setting) { table.AddRow(s.Id, s.SettingName, s.DisplayName, s.GroupName, s.Value); } xc.WriteTable(table); } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { xc.AskForInput(this, "Filter by name or ID (leave blank for all): ", false); var filter = Console.ReadLine(); using (var scope = xc.WebHost.Services.CreateScope()) { var db = scope.ServiceProvider.GetService <IDbService <Plan> >(); List <Plan> list; if (string.IsNullOrEmpty(filter)) { list = db.FindAll(); } else { list = db.FindManyWhere(x => x.Name.Contains(filter) || x.Id.ToString() == filter); } xc.WriteInfo(this, "Listing plans."); if (list.Count > 0) { xc.WriteSuccess(this, $"Total {list.Count} plan(s) found."); var table = xc.CreateTable(new string[] { "Id", "Name", "TrialDays", "IsActive", "IsDev", "IsTest", "DisplayOrder", "IsPopular", "Price" }); foreach (var i in list) { table.AddRow(i.Id, i.Name, i.TrialDays, i.Active, i.IsDev, i.IsTest, i.DisplayOrder, i.IsPopular, i.Price.ToString("C")); } xc.WriteTable(table); } else { xc.WriteWarning(this, "Total 0 plan(s) found."); } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { AspNetUser user = new AspNetUser(); xc.AskForInput(this, "Enter myshopify URL (without http part): "); user.MyShopifyDomain = Console.ReadLine(); xc.AskForInput(this, "Enter shop email: "); user.Email = Console.ReadLine(); xc.AskForInput(this, "Enter plan id: "); var pid = Console.ReadLine(); user.PlanId = Int32.Parse(pid); xc.AskForInput(this, "Enter shopify access token: "); user.ShopifyAccessToken = Console.ReadLine(); user.UserName = user.MyShopifyDomain; xc.AskForInput(this, "Enter Charge Id (optoinal for admin store): "); var cid = Console.ReadLine(); if (string.IsNullOrEmpty(cid)) { user.ShopifyChargeId = null; } else { user.ShopifyChargeId = long.Parse(cid); } user.BillingOn = DateTime.Now; UserManager <AspNetUser> db = scope.ServiceProvider.GetService <UserManager <AspNetUser> >(); xc.WriteInfo(this, "Installing the app for the store."); var passGen = scope.ServiceProvider.GetService <IGenerateUserPassword>(); var pass = passGen.GetPassword(new Data.Domain.AppModels.PasswordGeneratorInfo(user)); var result = await db.CreateAsync(user, pass); if (result.Succeeded) { xc.WriteSuccess(this, "Successfull installed the app."); var table = xc.CreateTable(new string[] { "Column", "Value" }); table.AddRow("Id", user.Id); table.AddRow("UserName", user.UserName); table.AddRow("MyShopifyDomain", user.MyShopifyDomain); table.AddRow("Email", user.Email); table.AddRow("ShopifyAccessToken", user.ShopifyAccessToken); table.AddRow("PlanId", user.PlanId); table.AddRow("ShopifyChargeId", user.ShopifyChargeId); table.AddRow("BilingOn", user.BillingOn); xc.WriteTable(table); } else { xc.WriteError(this, $"Installation error occurred.{Environment.NewLine}{result.ToString()}"); } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { var ipServiceUrl = "http://ipinfo.io/ip"; string externalIp = null; try { externalIp = new WebClient().DownloadString(ipServiceUrl); externalIp = Regex.Replace(externalIp, @"\r\n?|\n|\t", String.Empty); xc.WriteInfo(this, $"(FYI : your external IP is - {externalIp})"); } catch (Exception) { xc.WriteInfo(this, $"(FYI : your external IP is - ", false); xc.WriteError(this, $"failed to retrive using {ipServiceUrl}.)"); } xc.AskForInput(this, "Enter the IP you want to add to the Privilege IP list: "); string ip = Console.ReadLine(); if (!string.IsNullOrEmpty(ip)) { var db = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); var item = db.FindSingleWhere(x => x.SettingName == CORE_SYSTEM_SETTING_NAMES.PRIVILEGED_IPS.ToString()); if (item == null) { xc.WriteError(this, $"Could not add IP because the setting {CORE_SYSTEM_SETTING_NAMES.PRIVILEGED_IPS} doesn't exit in the database."); } else { var alreadyExists = false; if (item.Value != null) { if (item.Value.Contains(ip)) { xc.WriteInfo(this, $"IP {ip} is already in the privileged IP list."); alreadyExists = true; } } if (!alreadyExists) { ip = ip.Trim(); item.Value = string.IsNullOrEmpty(item.Value) ? ip : $"{item.Value},{ip}"; xc.WriteInfo(this, "Updating IP list."); var itemUpdated = db.Update(item, item.Id); if (itemUpdated == null) { xc.WriteError(this, text: $"Adding {externalIp} to the privileged IP list failed."); } else { xc.WriteSuccess(this, $"{externalIp} has been added to the privileged IP list."); } } } } else { xc.WriteWarning(this, $"Nothing has been added to the privileged IP list."); } } } catch (Exception ex) { xc.WriteException(this, ex); } }
public async Task Run(XConsole xc) { try { using (var scope = xc.WebHost.Services.CreateScope()) { xc.AskForInput(this, "Enter the IP you want to remove from the privilege IP list: "); string ip = Console.ReadLine(); if (!string.IsNullOrEmpty(ip)) { var db = scope.ServiceProvider.GetService <IDbService <SystemSetting> >(); var item = db.FindSingleWhere(x => x.SettingName == CORE_SYSTEM_SETTING_NAMES.PRIVILEGED_IPS.ToString()); if (item == null) { xc.WriteError(this, $"Could not add IP because the setting {CORE_SYSTEM_SETTING_NAMES.PRIVILEGED_IPS} doesn't exit in the database."); } else { if (item.Value != null) { if (item.Value.Contains(ip)) { xc.WriteInfo(this, $"IP {ip} is found in the privileged IP list."); List <string> _ips = new List <string>(); xc.WriteInfo(this, $"Updating privileged IP table."); foreach (var i in item.Value.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)) { if (!i.Trim().Equals(ip.Trim())) { _ips.Add(i); } } item.Value = string.Join(',', _ips); var itemUpdated = db.Update(item, item.Id); if (itemUpdated == null) { xc.WriteError(this, text: $"Removing {ip} to the privileged IP list failed."); } else { xc.WriteSuccess(this, $"{ip} has been removed from the privileged IP list."); } } else { xc.WriteWarning(this, $"The ip {ip} doesn't even exist in the priviledged IP tables."); } } } } else { xc.WriteWarning(this, $"Nothing has been removed from the privileged IP list."); } } } catch (Exception ex) { xc.WriteException(this, ex); } }