private void AddModuleToCsproj(InstallData installData) { var projectPath = Path.GetFullPath(project); try { var currentModuleDirectory = Helper.GetModuleDirectory(Directory.GetCurrentDirectory()); var packagesDirectory = Path.Combine(currentModuleDirectory, "packages"); new NuGetPackageHepler(Log).InstallPackages(installData.NuGetPackages, packagesDirectory, projectPath); } catch (Exception e) { ConsoleWriter.WriteWarning($"Installation of NuGet packages failed: {e.InnerException?.Message ?? e.Message}"); Log.Error("Installation of NuGet packages failed:", e); } var csproj = new ProjectFile(projectPath); foreach (var buildItem in installData.BuildFiles) { var refName = Path.GetFileNameWithoutExtension(buildItem); var hintPath = Helper.GetRelativePath(Path.Combine(Helper.CurrentWorkspace, buildItem), Directory.GetParent(projectPath).FullName); AddRef(csproj, refName, hintPath); CheckExistBuildFile(Path.Combine(Helper.CurrentWorkspace, buildItem)); } if (!testReplaces) { csproj.Save(); } }
private InstallResult InstallHelper(InstallData installData) { InstallResult installResult; var component = installData.Component; try { if (installData.LocalPath == null) { return(InstallResult.Failure); } installResult = InstallCore(installData.LocalPath, installData.InstallDir, component); } catch (OperationCanceledException) { Logger.Info("User canceled during install."); return(InstallResult.Cancel); } catch (UnauthorizedAccessException e) { Elevator.Instance.RequestElevation(e, CurrentComponent); return(InstallResult.Failure); } catch (Exception ex) { LogFailure(component, ComponentAction.Update, ex.Message); return(InstallResult.FailureException); } PrintReturnCode(installResult, component, ComponentAction.Update); return(installResult); }
private InstallResult UninstallHelper(InstallData uninstallData) { InstallResult result; var component = uninstallData.Component; try { if (uninstallData.Component == null && uninstallData.LocalPath == null) { result = InstallResult.Failure; } else { result = UninstallCore(uninstallData.InstallDir, component); } } catch (OperationCanceledException) { Logger.Info("User canceled during component uninstall."); return(InstallResult.Cancel); } catch (Exception e) { LogFailure(component, ComponentAction.Delete, e.ToString()); return(InstallResult.FailureException); } PrintReturnCode(result, component, ComponentAction.Delete); return(result); }
private InstallData GetInstallContent(string configuration) { var result = new InstallData(); var configQueue = new Queue <string>(); configQueue.Enqueue(configuration); result.MainConfigBuildFiles.AddRange(GetAllInstallFilesFromConfig(configuration).Where(r => !r.StartsWith("module "))); while (configQueue.Count > 0) { var currentConfig = configQueue.Dequeue(); var currentDeps = GetInstallSectionFromConfig(currentConfig, "install"); result.BuildFiles.AddRange(currentDeps.Where(r => !r.StartsWith("module ") && !r.StartsWith("nuget "))); result.Artifacts.AddRange(result.BuildFiles.Where(r => !result.Artifacts.Contains(r))); result.Artifacts.AddRange(GetInstallSectionFromConfig(currentConfig, "artifacts").Where(r => !r.StartsWith("module "))); result.Artifacts.AddRange(GetInstallSectionFromConfig(currentConfig, "artefacts").Where(r => !r.StartsWith("module "))); result.ExternalModules.AddRange(currentDeps.Where(r => r.StartsWith("module "))); result.NuGetPackages.AddRange(currentDeps.Where(r => r.StartsWith("nuget "))); if (!IsInherited(currentConfig)) { continue; } var childConfigurations = GetParentConfigurations(currentConfig); if (childConfigurations == null || childConfigurations.Count == 0) { continue; } foreach (var childConfig in childConfigurations) { configQueue.Enqueue(childConfig); } } return(result); }
private static IEnumerable <string> ConcatDistinct(InstallData a, InstallData b, Func <InstallData, IEnumerable <string> > getCollectionFunc) { var firstCollection = getCollectionFunc(a) ?? Enumerable.Empty <string>(); var secondCollection = getCollectionFunc(b) ?? Enumerable.Empty <string>(); return(firstCollection.Union(secondCollection)); }
public void Parse(InstallSection installSection, InstallData expected) { var parser = new InstallSectionParser(); var actual = parser.Parse(installSection); actual.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering()); }
private void ValidateCollectionRefs(InstallData actual, Func <InstallData, object> getCollection) { var firstCollection = getCollection(First); var secondCollection = getCollection(Second); var actualCollection = getCollection(actual); Assert.False(ReferenceEquals(firstCollection, actualCollection) || ReferenceEquals(secondCollection, actualCollection), "New instance of InstallData's collection had to be created"); }
public void Merge(InstallSection installSection, InstallData defaults, InstallData[] parentInstalls, InstallData expected) { var parser = new InstallSectionParser(); var merger = new InstallSectionMerger(); var currentConfigInstallData = parser.Parse(installSection, defaults?.CurrentConfigurationInstallFiles); var actual = merger.Merge(currentConfigInstallData, defaults, parentInstalls); actual.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering()); }
/// <summary> /// Returns new instance of InstallData with properties copied from first and second InstallData /// </summary> public static InstallData JoinWith(this InstallData first, [NotNull] InstallData second, IEnumerable <string> currentConfigurationInstallFiles) { var result = new InstallData { Artifacts = new List <string>(ConcatDistinct(first, second, item => item.Artifacts)), ExternalModules = new List <string>(ConcatDistinct(first, second, item => item.ExternalModules)), InstallFiles = new List <string>(ConcatDistinct(first, second, item => item.InstallFiles)), NuGetPackages = new List <string>(ConcatDistinct(first, second, item => item.NuGetPackages)), CurrentConfigurationInstallFiles = new List <string>(currentConfigurationInstallFiles), }; return(result); }
public static void Main(string[] args) { Translator var_translator = new Translator(); InstallData var_data = new InstallData(); if (!var_data.IsAppInstalled) { var_translator.SetLanguage(Language.English.ToString()); MessageBox.Show(var_translator.GetMsg("ServerSystem.FailRun"), "SYSTEM"); return; } var_translator.SetLanguage(var_data.language); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); { // ---------------------------- // PRODUCTION CODE // ---------------------------- try { Exchange exchange = new Exchange(); ApplicationUtil var_util = new ApplicationUtil(); exchange.GetNewDataClient(var_data.serverMachine, Convert.ToInt32(var_data.clientServerPort), Convert.ToInt32(var_data.maxPacket), var_data.language); event_MainForm ev_MainForm = new event_MainForm(var_util, exchange); ev_MainForm.doEvent(event_MainForm.event_Start, null); } catch (System.Exception se) { if (se.Message != "Exit") { MessageBox.Show(se.Message, "END SYSTEM"); } } finally {} } }
public InstallData Merge(InstallData currentInstalls, InstallData defaultInstalls = null, InstallData[] parentInstalls = null) { if (defaultInstalls == null && parentInstalls == null) { return(currentInstalls); } var accumulate = defaultInstalls ?? new InstallData(); if (parentInstalls != null) { accumulate = parentInstalls.Aggregate(accumulate, (cur, parent) => cur.JoinWith(parent, currentInstalls.CurrentConfigurationInstallFiles)); } accumulate = accumulate.JoinWith(currentInstalls, currentInstalls.CurrentConfigurationInstallFiles); return(accumulate); }
private void AddModuleToCsproj(InstallData installData) { var projectPath = Path.GetFullPath(project); var csproj = new ProjectFile(projectPath); foreach (var buildItem in installData.BuildFiles) { var refName = Path.GetFileNameWithoutExtension(buildItem); var hintPath = Helper.GetRelativePath(Path.Combine(Helper.CurrentWorkspace, buildItem), Directory.GetParent(projectPath).FullName); AddRef(csproj, refName, hintPath); CheckExistBuildFile(Path.Combine(Helper.CurrentWorkspace, buildItem)); } if (!testReplaces) { csproj.Save(); } }
public InstallData Parse(InstallSection configSection, List <string> currentConfigurationInstallFilesFromDefault = null) { var externalModules = configSection.Install .Where(line => line.StartsWith(ModulePrefix)) .Select(line => line.Substring(ModulePrefix.Length)) .ToList(); var nugets = configSection.Install .Where(line => line.StartsWith(NugetPrefix)) .Select(line => line.Substring(NugetPrefix.Length)) .ToList(); var installFiles = configSection.Install .Where(IsBuildFileName) .Distinct() .ToList(); var artifacts = installFiles .Concat(configSection.Artifacts) .Where(IsBuildFileName) .Distinct() .ToList(); // currentConfigurationInstallFiles are inherited from 'default' section ¯\_(ツ)_/¯ var currentConfigurationInstallFiles = (currentConfigurationInstallFilesFromDefault ?? Enumerable.Empty <string>()) .Concat(artifacts) .ToList(); var installData = new InstallData { InstallFiles = installFiles, CurrentConfigurationInstallFiles = currentConfigurationInstallFiles, Artifacts = artifacts, ExternalModules = externalModules, NuGetPackages = nugets }; return(installData); }
private void AddModuleToCsproj(InstallData installData) { var projectPath = Path.GetFullPath(project); var csproj = new ProjectFile(projectPath); try { csproj.InstallNuGetPackages(installData.NuGetPackages); } catch (Exception e) { ConsoleWriter.Shared.WriteWarning($"Installation of NuGet packages failed: {e.InnerException?.Message ?? e.Message}"); Log.LogError("Installation of NuGet packages failed:", e); } foreach (var buildItem in installData.InstallFiles) { var buildItemPath = Platform.IsUnix() ? Helper.WindowsPathSlashesToUnix(buildItem) : buildItem; var refName = Path.GetFileNameWithoutExtension(buildItemPath); var hintPath = Helper.GetRelativePath( Path.Combine(Helper.CurrentWorkspace, buildItemPath), Directory.GetParent(projectPath).FullName); if (Platform.IsUnix()) { hintPath = Helper.UnixPathSlashesToWindows(hintPath); } AddRef(csproj, refName, hintPath); CheckExistBuildFile(Path.Combine(Helper.CurrentWorkspace, buildItemPath)); } if (!testReplaces) { csproj.Save(); } }
public override bool doEvent(int event_number, object arg) { switch (event_number) { #region - event_Start - case event_Start: { //InitEventCode event_Start #if ROBOT #else doEvent(event_Translate, null); doEvent(event_FormIsOpening, null); #endif //EndEventCode return(true); } #endregion #region - event_Translate - case event_Translate: { //InitEventCode event_Translate //EndEventCode return(true); } #endregion #region - event_FormIsOpening - case event_FormIsOpening: { //InitEventCode event_FormIsOpening string st_csv_files = ""; string st_new_version = ""; StreamReader sr = new StreamReader("app.txt"); string app = sr.ReadLine(); sr.Close(); i_Form.LblCmd.Text = "Buscando lista de arquivos..."; i_Form.Show(); Application.DoEvents(); Thread.Sleep(500); #if LINUX_DIST var_exchange.infra_fetchIncomingVersion(app, Context.FALSE, ref st_csv_files, ref st_new_version); #else var_exchange.infra_fetchIncomingVersion(app, ref st_csv_files, ref st_new_version); #endif // pares de "nome_arquivo,indice" int tot = var_util.indexCSV(st_csv_files); int num = 1; for (int t = 0, dot = 0; t < tot; ++t) { string fileName = var_util.getCSV(t); // busca nome string next_part = var_util.getCSV(++t); // busca indice // mostrador no diálogo string basicTag = "Buscando arquivo [" + num.ToString() + " de " + (tot / 2).ToString() + "] "; ++num; StringBuilder archive = new StringBuilder(); while (next_part != "") { string current_tag = basicTag, tmp_content = ""; // pequena animação indicando download... if (++dot == 15) { dot = 1; } for (int g = 0; g < dot; ++g) { current_tag += "."; } Application.DoEvents(); i_Form.LblCmd.Text = current_tag; Application.DoEvents(); var_exchange.infra_fetchFile(next_part, ref next_part, ref tmp_content); archive.Append(tmp_content); } if (File.Exists(fileName)) { File.Delete(fileName); } FileStream fs = new FileStream(fileName, FileMode.CreateNew); BinaryWriter bw = new BinaryWriter(fs); bw.Write(HexEncoding.GetBytes(archive.ToString())); bw.Close(); fs.Close(); } InstallData ins = new InstallData(); i_Form.LblCmd.Text = "Alterando versão do software..."; Application.DoEvents(); Thread.Sleep(250); ins.st_version = st_new_version; ins.ins_registration(); string ver_path = System.Environment.GetEnvironmentVariable("COMMONPROGRAMFILES") + "\\" + InfraSoftwareClient.nameClient + " " + app + "\\version.txt"; if (File.Exists(ver_path)) { File.Delete(ver_path); } StreamWriter sw = new StreamWriter(ver_path); sw.WriteLine(st_new_version); sw.Close(); File.Delete("app.txt"); var_exchange.m_Client.ExitSession(); Process p = new Process(); #if LINUX_DIST p.StartInfo.FileName = "Linux" + app + ".exe"; #else p.StartInfo.FileName = app + ".exe"; #endif p.StartInfo.Arguments = ""; p.StartInfo.CreateNoWindow = false; p.Start(); i_Form.Close(); Application.ExitThread(); //EndEventCode return(true); } #endregion #region - event_FormIsClosing - case event_FormIsClosing: { //InitEventCode event_FormIsClosing //EndEventCode return(true); } #endregion #region - robot_ShowDialog - case robot_ShowDialog: { //InitEventCode robot_ShowDialog if (i_Form.IsDisposed) { i_Form = new MainForm(this); } i_Form.Show(); //EndEventCode return(true); } #endregion #region - robot_CloseDialog - case robot_CloseDialog: { //InitEventCode robot_CloseDialog i_Form.Close(); //EndEventCode return(true); } #endregion default: break; } return(false); }
public override bool doEvent(int event_number, object arg) { switch (event_number) { #region - event_Load - case event_Load: { //InitEventCode event_Load #if ROBOT var_util.execDefinedRobot(this, var_alias); #else doEvent(event_Translate, null); doEvent(event_FormIsOpening, null); #endif //EndEventCode return(true); } #endregion #region - event_Translate - case event_Translate: { //InitEventCode event_Translate //EndEventCode return(true); } #endregion #region - event_FormIsOpening - case event_FormIsOpening: { //InitEventCode event_FormIsOpening InstallData inst_data = new InstallData(); i_Form.LblVersion.Text = inst_data.st_version; ctrl_TxtNome.AcquireTextBox(i_Form.TxtNome, this, event_val_TxtNome, 20, alphaTextController.ENABLE_NUMBERS); ctrl_TxtEmpresa.AcquireTextBox(i_Form.TxtEmpresa, this, event_val_TxtEmpresa, 8, alphaTextController.ENABLE_NUMBERS); ctrl_TxtSenha.AcquireTextBox(i_Form.TxtSenha, this, event_val_TxtSenha, 16, alphaTextController.ENABLE_NUMBERS, alphaTextController.ENABLE_SYMBOLS); ctrl_TxtNome.SetupErrorProvider(ErrorIconAlignment.MiddleRight, false); ctrl_TxtEmpresa.SetupErrorProvider(ErrorIconAlignment.MiddleRight, false); ctrl_TxtSenha.SetupErrorProvider(ErrorIconAlignment.MiddleRight, false); //EndEventCode return(true); } #endregion #region - robot_ShowDialog - case robot_ShowDialog: { //InitEventCode robot_ShowDialog if (i_Form.IsDisposed) { i_Form = new dlgLogin(this); } i_Form.Show(); //EndEventCode return(true); } #endregion #region - robot_CloseDialog - case robot_CloseDialog: { //InitEventCode robot_CloseDialog i_Form.Close(); //EndEventCode return(true); } #endregion #region - event_Confirmar - case event_Confirmar: { //InitEventCode event_Confirmar bool IsDone = true; if (!ctrl_TxtNome.IsUserValidated) { ctrl_TxtNome.SetErrorMessage("Nome incompleto"); IsDone = false; } if (!ctrl_TxtSenha.IsUserValidated) { ctrl_TxtSenha.SetErrorMessage("Senha incompleta"); IsDone = false; } if (!IsDone) { return(false); } string tg_trocaSenha = ""; string var_st_empresa = ctrl_TxtEmpresa.getTextBoxValue(); string st_senha_atual = var_util.getMd5Hash(ctrl_TxtSenha.getTextBoxValue()); if (var_exchange.exec_login(ctrl_TxtNome.getTextBoxValue(), var_st_empresa, st_senha_atual, ref tg_trocaSenha, ref header)) { if (tg_trocaSenha == Context.TRUE) { var_IsChangePass = true; } var_IsCanceled = false; var_st_nome = ctrl_TxtNome.getTextBoxValue(); i_Form.Close(); } else { if (!ctrl_TxtEmpresa.IsUserValidated) { ctrl_TxtEmpresa.SetErrorMessage("Código de empresa incompleto"); } } //EndEventCode return(true); } #endregion #region - event_val_TxtNome - case event_val_TxtNome: { //InitEventCode event_val_TxtNome switch (arg as string) { case alphaTextController.ALPHA_COMPLETE: case alphaTextController.ALPHA_INCOMPLETE: { if (ctrl_TxtNome.getTextBoxValue().Length > 3) { i_Form.TxtNome.BackColor = Color.White; ctrl_TxtNome.IsUserValidated = true; ctrl_TxtNome.CleanError(); } else { i_Form.TxtNome.BackColor = colorInvalid; ctrl_TxtNome.IsUserValidated = false; } break; } default: break; } //EndEventCode return(true); } #endregion #region - event_val_TxtEmpresa - case event_val_TxtEmpresa: { //InitEventCode event_val_TxtEmpresa switch (arg as string) { case alphaTextController.ALPHA_COMPLETE: case alphaTextController.ALPHA_INCOMPLETE: { if (ctrl_TxtEmpresa.getTextBoxValue().Length > 0) { i_Form.TxtEmpresa.BackColor = Color.White; ctrl_TxtEmpresa.IsUserValidated = true; ctrl_TxtEmpresa.CleanError(); } else { i_Form.TxtEmpresa.BackColor = colorInvalid; ctrl_TxtEmpresa.IsUserValidated = false; } if (ctrl_TxtEmpresa.GetEnterPressed()) { doEvent(event_Confirmar, null); } break; } default: break; } //EndEventCode return(true); } #endregion #region - event_val_TxtSenha - case event_val_TxtSenha: { //InitEventCode event_val_TxtSenha switch (arg as string) { case alphaTextController.ALPHA_COMPLETE: case alphaTextController.ALPHA_INCOMPLETE: { if (ctrl_TxtSenha.getTextBoxValue().Length > 3) { i_Form.TxtSenha.BackColor = Color.White; ctrl_TxtSenha.IsUserValidated = true; ctrl_TxtSenha.CleanError(); } else { i_Form.TxtSenha.BackColor = colorInvalid; ctrl_TxtSenha.IsUserValidated = false; } if (ctrl_TxtSenha.GetEnterPressed()) { doEvent(event_Confirmar, null); } break; } default: break; } //EndEventCode return(true); } #endregion #region - event_BtnConfirmarClick - case event_BtnConfirmarClick: { //InitEventCode event_BtnConfirmarClick //EndEventCode return(true); } #endregion default: break; } return(false); }
public static void Main(string[] args) { InstallData var_data = new InstallData(); bool isFirstInstance; using (Mutex mtx = new Mutex(true, "ConveyNET" + InstallData.app, out isFirstInstance)) { if (!isFirstInstance) { Application.Exit(); return; } Translator var_translator = new Translator(); if (!var_data.IsAppInstalled) { var_translator.SetLanguage(Language.English.ToString()); MessageBox.Show(var_translator.GetMsg("ServerSystem.FailRun"), "SYSTEM"); return; } var_translator.SetLanguage(var_data.language); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Exchange exchange = new Exchange(); ApplicationUtil var_util = new ApplicationUtil(); try { exchange.GetNewDataClient(var_data.serverMachine, ref var_data.serverStandby, ref var_data.serverStandByPort, Convert.ToInt32(var_data.clientServerPort), Convert.ToInt32(var_data.maxPacket), var_data.language); var_data.ins_registration(); } catch (System.Exception sez) { if (var_data.serverStandby != "" && var_data.serverStandByPort != "") { try { exchange.GetNewDataClient(var_data.serverStandby, Convert.ToInt32(var_data.serverStandByPort), Convert.ToInt32(var_data.maxPacket), var_data.language); } catch (System.Exception se) { if (se.Message == "Exit") { MessageBox.Show(var_translator.GetMsg("ServerSystem.Unavailable"), "SYSTEM"); Application.ExitThread(); return; } } } else if (sez.Message == "Exit") { MessageBox.Show(var_translator.GetMsg("ServerSystem.Unavailable"), "SYSTEM"); Application.ExitThread(); return; } } string st_versionOutdated = ""; exchange.fetch_softwareVersion(var_data.st_version, ref st_versionOutdated); if (st_versionOutdated == Context.TRUE) { #region - fetch latest version - string target_path = "app.txt"; if (File.Exists(target_path)) { File.Delete(target_path); } StreamWriter sw = new StreamWriter(target_path); sw.WriteLine(InstallData.app); sw.Close(); event_dlgUpdate ev_call = new event_dlgUpdate(var_util, exchange); ev_call.i_Form.ShowDialog(); #endregion } else { // ############################ // ## Start main program! // ############################ event_MainForm ev_MainForm = new event_MainForm(var_util, exchange); ev_MainForm.doEvent(event_MainForm.event_Start, null); } } catch (System.Exception se) { if (se.Message != "Exit") { MessageBox.Show(se.Message, "SYSTEM OUT"); } } finally {} } }