Example #1
0
        protected override void Execute(NativeActivityContext context)
        {
            if (!string.IsNullOrEmpty(ProxyHost.Get(context)))         // Proxy defined
            {
                if (!string.IsNullOrEmpty(ProxyUsername.Get(context))) // Proxy authentication
                {
                    connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), Encoding.UTF8.GetBytes(Password.Get(context)), ProxyTypes.Http, ProxyHost.Get(context), ProxyPort.Get(context), ProxyUsername.Get(context), ProxyPassword.Get(context));
                }
                else // No proxy authentication
                {
                    connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), Password.Get(context), ProxyTypes.Http, ProxyHost.Get(context), ProxyPort.Get(context));
                }
            }
            else // No Proxy defined
            {
                connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), Password.Get(context));
            }

            sshClient = new SshClient(connectionInfo);
            sshClient.Connect();

            if (Body != null)
            {
                //scheduling the execution of the child activities
                // and passing the value of the delegate argument
                context.ScheduleAction(Body, sshClient, OnCompleted, OnFaulted);
            }
        }
        private async Task ExecuteWithTimeout(NativeActivityContext context, CancellationToken cancellationToken = default)
        {
            var sshPassword   = new NetworkCredential("", Password.Get(context)).Password;
            var proxyPassword = new NetworkCredential("", ProxyPassword.Get(context)).Password;
            var sshTimeout    = TimeSpan.FromMilliseconds(SSHTimeoutMS.Get(context));

            ConnectionInfo connectionInfo;

            if (!string.IsNullOrEmpty(ProxyHost.Get(context)))         // Proxy defined
            {
                if (!string.IsNullOrEmpty(ProxyUsername.Get(context))) // Proxy authentication
                {
                    connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), Encoding.UTF8.GetBytes(sshPassword), ProxyTypes.Http, ProxyHost.Get(context), ProxyPort.Get(context), ProxyUsername.Get(context), proxyPassword);
                }
                else // No proxy authentication
                {
                    connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), sshPassword, ProxyTypes.Http, ProxyHost.Get(context), ProxyPort.Get(context));
                }
            }
            else // No Proxy defined
            {
                connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), sshPassword);
            }

            connectionInfo.Timeout = sshTimeout;

            sshClient = new SshClient(connectionInfo);
            sshClient.Connect();

            if (ShellExpectedPrompt.Expression != null)
            {
                var terminalMode = new Dictionary <TerminalModes, uint>
                {
                    { TerminalModes.ECHO, 53 }
                };

                expectedPromptRegex = new Regex(ShellExpectedPrompt.Get(context), RegexOptions.Compiled);
                currentShellStream  = sshClient.CreateShellStream("UiPathTeam.SSHConnector.Shell", 0, 0, 0, 0, 4096, terminalMode);
                var welcomeMessage = SSHHelpers.Expect(currentShellStream, expectedPromptRegex, string.Empty, sshTimeout);
                ShellWelcomeMessage.Set(context, welcomeMessage);
            }
        }
Example #3
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = RequestTimeout.GetHashCode();
         hashCode = (hashCode * 397) ^ PingTimeout.GetHashCode();
         hashCode = (hashCode * 397) ^ KeepAliveTime;
         hashCode = (hashCode * 397) ^ KeepAliveInterval;
         hashCode = (hashCode * 397) ^ Pipelined.GetHashCode();
         hashCode = (hashCode * 397) ^ HttpCompression.GetHashCode();
         hashCode = (hashCode * 397) ^ (Headers?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (ProxyAddress?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (ProxyUsername?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (ProxyPassword?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ DisableAutomaticProxyDetection.GetHashCode();
         hashCode = (hashCode * 397) ^ (BasicAuthorizationCredentials?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (ConnectionSettings?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (MemoryStreamFactory?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
        protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var activityTimeout     = TimeoutMS.Get(context);
            var host                = Host.Get(context);
            var port                = Port.Get(context);
            var username            = Username.Get(context);
            var password            = Password.Get(context);
            var shellExpectedPrompt = ShellExpectedPrompt.Get(context);
            var proxyHost           = ProxyHost.Get(context);
            var proxyPort           = ProxyPort.Get(context);
            var proxyUsername       = ProxyUsername.Get(context);
            var proxyPassword       = ProxyPassword.Get(context);

            // Set a timeout on the execution
            var task = ExecuteWithTimeout(context, cancellationToken);

            if (await Task.WhenAny(task, Task.Delay(activityTimeout, cancellationToken)) != task)
            {
                throw new TimeoutException(Resources.Timeout_Error);
            }

            if (task.Exception != null)
            {
                throw task.Exception;
            }

            _objectContainer.Add(sshClient);
            _objectContainer.Add(currentShellStream);
            _objectContainer.Add(expectedPromptRegex);

            return((ctx) => {
                // Schedule child activities
                if (Body != null)
                {
                    ctx.ScheduleAction <IObjectContainer>(Body, _objectContainer, OnCompleted, OnFaulted);
                }
            });
        }
Example #5
0
        void ReleaseDesignerOutlets()
        {
            if (CancelButton != null)
            {
                CancelButton.Dispose();
                CancelButton = null;
            }

            if (HelpButton != null)
            {
                HelpButton.Dispose();
                HelpButton = null;
            }

            if (ManualProxyButton != null)
            {
                ManualProxyButton.Dispose();
                ManualProxyButton = null;
            }

            if (NoProxyButton != null)
            {
                NoProxyButton.Dispose();
                NoProxyButton = null;
            }

            if (ProxyPassword != null)
            {
                ProxyPassword.Dispose();
                ProxyPassword = null;
            }

            if (ProxyPasswordLabel != null)
            {
                ProxyPasswordLabel.Dispose();
                ProxyPasswordLabel = null;
            }

            if (ProxyServer != null)
            {
                ProxyServer.Dispose();
                ProxyServer = null;
            }

            if (ProxyServerLabel != null)
            {
                ProxyServerLabel.Dispose();
                ProxyServerLabel = null;
            }

            if (ProxyServerHelp != null)
            {
                ProxyServerHelp.Dispose();
                ProxyServerHelp = null;
            }

            if (ProxyTab != null)
            {
                ProxyTab.Dispose();
                ProxyTab = null;
            }

            if (ProxyUsername != null)
            {
                ProxyUsername.Dispose();
                ProxyUsername = null;
            }

            if (ProxyUsernameLabel != null)
            {
                ProxyUsernameLabel.Dispose();
                ProxyUsernameLabel = null;
            }

            if (RequiresAuthorizationCheckBox != null)
            {
                RequiresAuthorizationCheckBox.Dispose();
                RequiresAuthorizationCheckBox = null;
            }

            if (SaveButton != null)
            {
                SaveButton.Dispose();
                SaveButton = null;
            }

            if (SystemDefaultProxyButton != null)
            {
                SystemDefaultProxyButton.Dispose();
                SystemDefaultProxyButton = null;
            }

            if (TabView != null)
            {
                TabView.Dispose();
                TabView = null;
            }
        }