/// <summary> /// Accepts the edited connection by assigning all changes /// from the EditItem to the DataItem and persisting the changes. /// </summary> public void Accept() { if (ConnectionNames != null && ConnectionNames.Any(x => x == EditItem.Name) && !Runtime.ShowConfirm( "A connection with the same name already exists. Would you like to overwrite the existing connection?", MessageBoxButton.YesNo)) { return; } // Reset saved SSL protocol EditItem.SecurityProtocol = 0; // Get selected SSL protocols SecurityProtocols .Where(x => x.IsEnabled && x.IsSelected) .ForEach(x => EditItem.SecurityProtocol |= x.Protocol); TestConnection() .ContinueWith(x => { if (x.Result || Runtime.Invoke(() => Runtime.ShowConfirm("Connection failed.\n\nDo you wish to save the connection settings anyway?", MessageBoxButton.YesNo))) { AcceptConnectionChanges(); } }); }
protected virtual int Run(string[] args) { try { SecurityProtocols.EnableAllSecurityProtocols(); var options = CommonOptions.Parse(args); Log.Verbose($"Calamari Version: {GetType().Assembly.GetInformationalVersion()}"); if (options.Command.Equals("version", StringComparison.OrdinalIgnoreCase)) { return(0); } var envInfo = string.Join($"{Environment.NewLine} ", EnvironmentHelper.SafelyGetEnvironmentInformation()); Log.Verbose($"Environment Information: {Environment.NewLine} {envInfo}"); EnvironmentHelper.SetEnvironmentVariable("OctopusCalamariWorkingDirectory", Environment.CurrentDirectory); ProxyInitializer.InitializeDefaultProxy(); var builder = new ContainerBuilder(); ConfigureContainer(builder, options); using var container = builder.Build(); container.Resolve <VariableLogger>().LogVariables(); #if DEBUG var waitForDebugger = container.Resolve <IVariables>().Get(KnownVariables.Calamari.WaitForDebugger); if (string.Equals(waitForDebugger, "true", StringComparison.CurrentCultureIgnoreCase)) { using var proc = Process.GetCurrentProcess(); Log.Info($"Waiting for debugger to attach... (PID: {proc.Id})"); while (!Debugger.IsAttached) { Thread.Sleep(1000); } } #endif return(ResolveAndExecuteCommand(container, options)); } catch (Exception ex) { return(ConsoleFormatter.PrintError(ConsoleLog.Instance, ex)); } }
public static int Main(string[] args) { try { SecurityProtocols.EnableAllSecurityProtocols(); var options = CommonOptions.Parse(args); return(new Program(ConsoleLog.Instance).Run(options)); } catch (Exception ex) { return(ConsoleFormatter.PrintError(ConsoleLog.Instance, ex)); } }
/// <summary> /// Initializes the EditItem property. /// 1) Clones the incoming DataItem, if provided, to the EditItem to use as a working copy. /// 2) If a DataItem was not provided the EditItem is set using the persisted connection /// data for the current connection type. /// 3) If there is no persisted connection data then the EditItem is set to a blank connection. /// </summary> internal void InitializeEditItem() { if (!string.IsNullOrWhiteSpace(DataItem?.Uri)) { EditItem = Mapper.Map(DataItem, new Connection()); } else { EditItem = OpenConnectionFile() ?? new Connection(); } EditItem.PropertyChanged += EditItem_PropertyChanged; // Set selected SSL protocols SecurityProtocols .Where(x => x.IsEnabled) .ForEach(x => x.IsSelected = EditItem.SecurityProtocol.HasFlag(x.Protocol)); }
/// <summary> /// Executes a connection test and reports the result to the user. /// </summary> public Task <bool> TestConnection() { ResetTestStatus(); EditItem.Password = RevealablePasswordBox.Password; EditItem.ProxyPassword = RevealableProxyPasswordBox.Password; // Reset saved SSL protocol EditItem.SecurityProtocol = 0; // Get selected SSL protocols SecurityProtocols .Where(x => x.IsEnabled && x.IsSelected) .ForEach(x => EditItem.SecurityProtocol |= x.Protocol); _log.DebugFormat("Testing a {0} connection", ConnectionType); // Resolve a connection test specific to the current ConnectionType var connectionTest = Runtime.Container.Resolve <IConnectionTest>(ConnectionType.ToString()); if (connectionTest != null) { Runtime.ShowBusy(); CanTestConnection = false; return(Task.Run(async() => { var result = await connectionTest.CanConnect(EditItem); await Runtime.InvokeAsync(() => ShowTestResult(result)); return result; }) .ContinueWith(x => { Runtime.ShowBusy(false); return x.Result; })); } return(Task.FromResult(IsTestSuccess)); }
protected async Task <int> Run(string[] args) { try { SecurityProtocols.EnableAllSecurityProtocols(); var options = CommonOptions.Parse(args); log.Verbose($"Calamari Version: {GetType().Assembly.GetInformationalVersion()}"); if (options.Command.Equals("version", StringComparison.OrdinalIgnoreCase)) { return(0); } var envInfo = string.Join($"{Environment.NewLine} ", EnvironmentHelper.SafelyGetEnvironmentInformation()); log.Verbose($"Environment Information: {Environment.NewLine} {envInfo}"); EnvironmentHelper.SetEnvironmentVariable("OctopusCalamariWorkingDirectory", Environment.CurrentDirectory); ProxyInitializer.InitializeDefaultProxy(); var builder = new ContainerBuilder(); ConfigureContainer(builder, options); using (var container = builder.Build()) { container.Resolve <VariableLogger>().LogVariables(); await ResolveAndExecuteCommand(container, options); return(0); } } catch (Exception ex) { return(ConsoleFormatter.PrintError(ConsoleLog.Instance, ex)); } }
public void EnableAllSecurityProtocols() { // Enabling of TLS1.2 happens on Calamari.exe startup in main, // however this will ensure it is applied during Unit Tests which will bypass the main entrypoint SecurityProtocols.EnableAllSecurityProtocols(); }