public static void CreateDir(SelgorsCopyModel model) { Console.Write($"Create directory "); switch (model.Country) { case "PL": model.DirInfo = Directory.CreateDirectory(Path.Combine(model.PolandDestinationPath, $"poland_{DateTime.Now:dd_MMMM_yyyy_HH_mm_ss}")); break; case "RO": model.DirInfo = Directory.CreateDirectory(Path.Combine(model.RomaniaDestinationPath, $"romania_{DateTime.Now:dd_MMMM_yyyy_HH_mm_ss}")); break; case "RU": model.DirInfo = Directory.CreateDirectory(Path.Combine(model.RussiaDestinationPath, $"russia_{DateTime.Now:dd_MMMM_yyyy_HH_mm_ss}")); break; default: throw new Exception($"{model.Country} is not valid country"); } foreach (var item in Directory.GetFiles(model.DirInfo.FullName)) { File.Delete(item); } Console.Write($"{model.DirInfo.FullName}"); }
public static void CopyApp(SelgorsCopyModel model) { Console.Write($"Copy"); File.Copy(model.File.FullName, Path.Combine(model.DirInfo.FullName, model.File.Name), true); Console.Write($" {model.File.Name}"); }
public static void GetArtifacts(SelgorsCopyModel model) { Console.Write($"Get artifacts file"); model.File = new DirectoryInfo(Path.Combine(model.ArtifactsZipPath)) .GetFiles("Selgros_PG_SPG_*_artifacts.zip") .OrderBy(s => s.CreationTime) .Last(); Console.Write($" {model.File.Name}"); }
public static void CreateSchema2(SelgorsCopyModel model) { Console.Write($"CreateSchema"); var schema2 = File.ReadAllLines(model.SchemaFilePath); model.LineEnd = schema2.Length.ToString(); var lines = schema2.Skip(int.Parse(model.LinesCut)); File.WriteAllLines(Path.Combine(model.DirInfo.FullName, "SelgrosPG_Schema3.sql"), lines); }
private static void MakeStep(Action <SelgorsCopyModel> action, SelgorsCopyModel model) { try { action(model); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("...successful"); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("...FAILD"); //Console.WriteLine(e); throw; } finally { Console.ResetColor(); } }
private static void MakeStepWithQuestion(Action <SelgorsCopyModel> action, SelgorsCopyModel model) { try { var q = $"Do you want to continue with {action.Method.Name } step [Y/n]?"; Console.Write(q); ConsoleKey key = ConsoleKey.Escape; while ((key = Console.ReadKey(true).Key) != ConsoleKey.Escape) { if (key == ConsoleKey.Y) { action(model); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("...successful"); break; } else if (key == ConsoleKey.N) { Console.WriteLine("...skip"); break; } } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("...FAILD"); //Console.WriteLine(e); throw; } finally { Console.ResetColor(); } }
public PageCreator(SelgorsCopyModel selgorsCopyModel) { this.selgorsCopyModel = selgorsCopyModel; switch (selgorsCopyModel.Country) { case "PL": id = PAGE_UPDATE_POLAND_ID; break; case "RO": id = PAGE_UPDATE_ROMANIA_ID; break; case "RU": id = PAGE_UPDATE_RUSIA_ID; break; default: throw new Exception($"{selgorsCopyModel.Country} is not valid country"); } }
public static void CreateUpdateScriptTestEnv(SelgorsCopyModel model) { Console.Write($"Create update script for test environment"); switch (model.Country) { case "PL": model.UpdateScript = new UpdateScriptBuilderPL().BuildTest(model.File.Name, model.Version); break; case "RO": model.UpdateScript = new UpdateScriptBuilderRO().BuildTest(model.File.Name, model.Version); break; case "RU": model.UpdateScript = new UpdateScriptBuilderRU().BuildTest(model.File.Name, model.Version); break; default: throw new Exception($"{model.Country} is not valid country"); } File.WriteAllText(Path.Combine(model.DirInfo.FullName, "update-test-environment.bat"), model.UpdateScript); }
static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName) .AddJsonFile("appsettings.json"); var configuration = builder.Build(); SelgorsCopyModel model = null; var result = Parser.Default.ParseArguments <CommandLineOptions>(args) .WithParsed <CommandLineOptions>(o => { model = o; model.Configuration = new ConfigurationBuilder() .AddUserSecrets <UserSecret>() .Build(); }) .WithNotParsed(errorList => { Environment.Exit(100); }); model.SchemaFilePath = configuration[nameof(model.SchemaFilePath)]; model.PolandDestinationPath = configuration[nameof(model.PolandDestinationPath)]; model.RomaniaDestinationPath = configuration[nameof(model.RomaniaDestinationPath)]; model.RussiaDestinationPath = configuration[nameof(model.RussiaDestinationPath)]; model.TranslationsFilePath = configuration[nameof(model.TranslationsFilePath)]; model.ArtifactsZipPath = configuration[nameof(model.ArtifactsZipPath)]; var exePath = Path.GetDirectoryName(System.Reflection .Assembly.GetExecutingAssembly().CodeBase); Regex appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+bin)"); var appRoot = appPathMatcher.Match(exePath).Value; Console.WriteLine(@" ______ ______ .______ ____ ____ "); Console.WriteLine(@" / | / __ \ | _ \ \ \ / / "); Console.WriteLine(@" | ,----'| | | | | |_) | \ \/ / "); Console.WriteLine(@" | | | | | | | ___/ \_ _/ "); Console.WriteLine(@" | `----.| `--' | | | | | "); Console.WriteLine(@" \______ | \______/ | _| |__| "); Console.WriteLine(@" _______. _______ __ _______ .______ ______ _______."); Console.WriteLine(@" / || ____|| | / _____|| _ \ / __ \ / |"); Console.WriteLine(@" | (----`| |__ | | | | __ | |_) | | | | | | (----`"); Console.WriteLine(@" \ \ | __| | | | | |_ | | / | | | | \ \ "); Console.WriteLine(@".----) | | |____ | `----.| |__| | | |\ \----.| `--' | .----) | "); Console.WriteLine($@"|_______/ |_______||_______| \______| | _| `._____| \______/ |_______/ {Assembly.GetEntryAssembly().GetName().Version}"); Console.WriteLine(); MakeStep(Steps.GetArtifacts, model); MakeStep(Steps.CreateDir, model); MakeStep(Steps.CreateSchema2, model); MakeStep(Steps.CreateTranslations, model); MakeStep(Steps.CopyApp, model); MakeStep(Steps.CreateUpdateScript, model); MakeStep(Steps.CreateUpdateScriptTestEnv, model); MakeStep(Steps.CreateAppsettings, model); MakeStepWithQuestion(Steps.CreatePage, model); MakeStep(Steps.Stop, model); }
public static void CreateTranslations(SelgorsCopyModel model) { Console.Write($"Copy translations"); File.Copy(model.TranslationsFilePath, Path.Combine(model.DirInfo.FullName, "SelgrosPG_Translations.sql"), true); }
public static void CreatePage(SelgorsCopyModel model) { var pageCreator = new PageCreator(model); pageCreator.Create(); }
public static void Stop(SelgorsCopyModel model) { Console.Write($"Update package create on {model.DirInfo.FullName}"); }
public static void CreateAppsettings(SelgorsCopyModel model) { Console.Write($"Create appsettings.json"); File.WriteAllText(Path.Combine(model.DirInfo.FullName, "appsettings.json"), "{\"CheckVersionProcess.ExcludeDirectories\": [\"App_Data\",\"UploadImages\",\"logs\" ],\"Web.Config.AppSettings.Version.KeyName\": \"AppVersion\"}"); }