Ejemplo n.º 1
0
 public async Task Run(XConsole xc)
 {
     try
     {
         xc.AskForInput(this, "Enter myshopify domain: ");
         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.WriteSuccess(this, "Found the store.");
                 var passGen = scope.ServiceProvider.GetService <IGenerateUserPassword>();
                 var pass    = passGen.GetPassword(new Data.Domain.AppModels.PasswordGeneratorInfo(user));
                 var table   = xc.CreateTable(new[] { "UserName", "Password" });
                 table.AddRow(user.UserName, pass);
                 xc.WriteTable(table);
             }
             else
             {
                 xc.WriteWarning(this, "Store not found.");
             }
         }
     }
     catch (Exception ex)
     {
         xc.WriteException(this, ex);
     }
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
 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 store ID or my shopify domain: ");
                var        storeId = Console.ReadLine();
                AspNetUser store   = null;

                using (var scope = xc.WebHost.Services.CreateScope())
                {
                    var userService = scope.ServiceProvider.GetService <IDbService <AspNetUser> >();
                    store = userService.FindSingleWhere(x => x.Id == storeId || x.MyShopifyDomain == storeId);
                    if (store == null)
                    {
                        xc.WriteWarning(this, "Store not found.");
                    }
                    else
                    {
                        if (!store.ShopifyChargeId.HasValue)
                        {
                            xc.WriteWarning(this, "Store is not connected to shopify billing yet.");
                        }
                        else if (string.IsNullOrEmpty(store.ShopifyAccessToken))
                        {
                            xc.WriteWarning(this, "Store is not connected to shopify API yet.No access token.");
                        }
                        else
                        {
                            var shopifyApi = scope.ServiceProvider.GetService <IShopifyApi>();
                            var rObj       = await shopifyApi.GetRecurringChargeAsync(store.MyShopifyDomain, store.ShopifyAccessToken, store.ShopifyChargeId.Value);

                            xc.WriteSuccess(this, $"Found charge/billing infromation for {store.MyShopifyDomain}.");
                            var table = xc.CreateTable(new string[] { "Name", "Value" });
                            table.AddRow(new[] { "Id", rObj.Id.Value.ToString() });
                            table.AddRow(new[] { "Status", rObj.Status });
                            table.AddRow(new[] { "Name", rObj.Name });
                            table.AddRow(new[] { "Price", rObj.Price.Value.ToString("C") });
                            table.AddRow(new[] { "Is Test", rObj.Test.ToString() });
                            table.AddRow(new[] { "Trial Ends/Ended On", rObj.TrialEndsOn?.DateTime.ToString("F") });
                            table.AddRow(new[] { "Trial Days", rObj.TrialDays.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 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);
     }
 }
Ejemplo n.º 6
0
        public async Task Run(XConsole xc)
        {
            try
            {
                xc.AskForInput(this, "Enter exatct or part of my shopify url or email: ");
                using (var scope = xc.WebHost.Services.CreateScope())
                {
                    string input = Console.ReadLine();
                    if (string.IsNullOrEmpty(input))
                    {
                        xc.WriteWarning(this, "Invalid url or email.");
                    }
                    else
                    {
                        var userService = scope.ServiceProvider.GetService <IDbService <AspNetUser> >();
                        var users       = userService.FindManyWhere(x => x.MyShopifyDomain.Contains(input) || x.Email.Contains(input));
                        if (users.Count <= 0)
                        {
                            xc.WriteWarning(this, "Nothing found.");
                        }
                        else
                        {
                            xc.WriteSuccess(this, $"Found {users.Count} store(s).");
                            var table = xc.CreateTable(new[] { "Id", "MyShopifyUrl", "Email", "Plan", "ChargeId", "Token", "BillingOn", "IsAdmin" });

                            UserManager <AspNetUser> _userManager = scope.ServiceProvider.GetService <UserManager <AspNetUser> >();
                            var planService = scope.ServiceProvider.GetService <IDbService <Plan> >();
                            foreach (var u in users)
                            {
                                var isAdmin = await _userManager.IsInRoleAsync(u, UserInContextHelper.ADMIN_ROLE);

                                var    plan     = planService.FindSingleWhere(x => x.Id == u.PlanId);
                                string planInfo = plan == null ? "n/a" : plan.Name;
                                table.AddRow(u.Id, u.MyShopifyDomain, u.Email, $"{u.PlanId}({planInfo})", u.ShopifyChargeId, u.ShopifyAccessToken, u.BillingOn?.Date.ToShortDateString(), isAdmin);
                            }

                            xc.WriteTable(table);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                xc.WriteException(this, ex);
            }
        }
Ejemplo n.º 7
0
 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);
     }
 }
Ejemplo n.º 8
0
 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);
     }
 }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
 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);
     }
 }
Ejemplo n.º 12
0
 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);
     }
 }
Ejemplo n.º 13
0
 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);
     }
 }
Ejemplo n.º 14
0
        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);
            }
        }