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 { xc.AskForInput(this, "Enter command name: "); using (var scope = xc.WebHost.Services.CreateScope()) { string command = Console.ReadLine(); var commandClass = xc.FindCommand(command); if (commandClass != null) { try { var commandInstance = xc.CreateCommandInstance(commandClass); xc.WriteHelp(commandInstance); } catch (Exception) { xc.WriteError(this, $"Unable to display help for {command}"); } } else { xc.WriteWarning(this, "Command not found."); } } } 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 name = settings.FindSingleWhere(x => x.SettingName == CORE_SYSTEM_SETTING_NAMES.APP_NAME.ToString()); if (name != null) { Console.Title = $"X-Console - {name.Value}"; xc.SetPromptString($"{name.Value}:>> "); } else { xc.WriteError(this, "App name is not set in the db."); } } } 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 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} 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 { 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 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()) { 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()) { xc.AskForInput(this, "Enter TO email address: "); var to = Console.ReadLine(); if (IsValidEmail(to)) { xc.AskForInput(this, "Enter FROM email address: "); var from = Console.ReadLine(); if (IsValidEmail(from)) { xc.AskForInput(this, "Enter subject: "); var subject = Console.ReadLine(); xc.AskForInput(this, "Enter message: "); var message = Console.ReadLine(); var emailer = scope.ServiceProvider.GetService <IEmailer>(); emailer.AddTo(to); emailer.SetFromAddress(from); emailer.SetSubject(subject); emailer.SetMessage(message, true); var result = await emailer.Send(true); if (result) { xc.WriteSuccess(this, $"Successfully sent the email to {to}."); } else { xc.WriteError(this, $"Could not send the email to {to}."); } } else { xc.WriteWarning(this, "FROM email address is not valid."); } } else { xc.WriteWarning(this, "TO email address is not valid."); } } } 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> >(); 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 { 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); } }