Ejemplo n.º 1
0
        /// <summary>
        /// Populates the object from an XML representation
        /// </summary>
        /// <param name="node">The XML representation of the object</param>
        private void FromXml(XmlNode node)
        {
            XmlNode successNode = node.SelectSingleNode("success-when");

            if (successNode == null)
            {
                throw new ArgumentNullException("The async command must have a success-when node");
            }
            else
            {
                this.ExpectSuccess = new AsyncCommandSendExpect(successNode);
            }

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.Name == "send")
                {
                    this.Commands.Add(new AsyncCommandSend(child));
                }
                else if (child.Name == "send-when")
                {
                    this.Commands.Add(new AsyncCommandSendExpect(child));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes an asynchronous command
        /// </summary>
        /// <param name="csentry">The CSEntryChange to apply to this command</param>
        /// <param name="result">The result object for the current operation</param>
        /// <param name="command">The definition of the command to execute</param>
        private static void ExecuteAsyncCommand(CSEntryChange csentry, OperationResult result, AsyncCommand command)
        {
            string output = string.Empty;

            try
            {
                ShellStream shell = client.CreateShellStream("lithnet.sshma", 80, 24, 800, 600, 1024);
                output += shell.ReadLine();

                foreach (AsyncCommandSend sendCommand in command.Commands)
                {
                    if (sendCommand is AsyncCommandSendExpect)
                    {
                        AsyncCommandSendExpect expectCommand = sendCommand as AsyncCommandSendExpect;
                        string   expectText = expectCommand.Expect.ExpandDeclaration(csentry, false, false);
                        TimeSpan timeout    = new TimeSpan(0, 0, expectCommand.Timeout);

                        shell.Expect(
                            timeout,
                            new ExpectAction(
                                expectText,
                                (s) =>
                        {
                            System.Diagnostics.Debug.WriteLine(s);
                            output += s;
                            shell.Write(expectCommand.Command.ExpandDeclaration(csentry, false, false) + "\n");
                        }));
                    }
                    else
                    {
                        shell.Write(sendCommand.Command.ExpandDeclaration(csentry, false, false) + "\n");
                    }
                }

                if (command.ExpectSuccess != null)
                {
                    if (!string.IsNullOrWhiteSpace(command.ExpectSuccess.Expect.DeclarationText))
                    {
                        TimeSpan timeout = new TimeSpan(0, 0, command.ExpectSuccess.Timeout);
                        if (shell.Expect(command.ExpectSuccess.Expect.ExpandDeclaration(csentry, false, false), timeout) == null)
                        {
                            throw new ExtensibleExtensionException("The asynchronous command did not return the expected result");
                        }
                    }
                }
            }
            finally
            {
                Logger.WriteLine("Shell session log:", LogLevel.Debug);
                Logger.WriteLine(output, LogLevel.Debug);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes an asynchronous command
        /// </summary>
        /// <param name="csentry">The CSEntry to apply to this command</param>
        /// <param name="result">The result object for the current operation</param>
        /// <param name="command">The definition of the command to execute</param>
        /// <param name="oldPassword">The old password, or null if performing a password set as opposed to a password change</param>
        /// <param name="newPassword">The new password</param>
        private static void ExecuteAsyncCommand(CSEntry csentry, OperationResult result, AsyncCommand command, string oldPassword, string newPassword)
        {
            string output = string.Empty;

            try
            {
                ShellStream shell = client.CreateShellStream("lithnet.sshma", 80, 24, 800, 600, 1024);
                output += shell.ReadLine();

                foreach (AsyncCommandSend sendCommand in command.Commands)
                {
                    if (sendCommand is AsyncCommandSendExpect)
                    {
                        AsyncCommandSendExpect expectCommand = sendCommand as AsyncCommandSendExpect;
                        string   expectText      = expectCommand.Expect.ExpandDeclaration(csentry, oldPassword, newPassword, false);
                        TimeSpan timeout         = new TimeSpan(0, 0, expectCommand.Timeout);
                        bool     expectedArrived = false;

                        shell.Expect(
                            timeout,
                            new ExpectAction(
                                expectText,
                                (s) =>
                        {
                            expectedArrived = true;
                            System.Diagnostics.Debug.WriteLine(s);
                            output += s;
                            shell.Write(expectCommand.Command.ExpandDeclaration(csentry, oldPassword, newPassword, false) + "\n");
                        }));

                        if (!expectedArrived)
                        {
                            output += shell.Read();
                            throw new UnexpectedDataException("The expected value was not found in the session in the specified timeout period");
                        }
                    }
                    else
                    {
                        shell.Write(sendCommand.Command.ExpandDeclaration(csentry, oldPassword, newPassword, false) + "\n");
                    }
                }

                if (command.ExpectSuccess != null)
                {
                    if (!string.IsNullOrWhiteSpace(command.ExpectSuccess.Expect.DeclarationText))
                    {
                        TimeSpan timeout      = new TimeSpan(0, 0, command.ExpectSuccess.Timeout);
                        string   expectResult = shell.Expect(command.ExpectSuccess.Expect.ExpandDeclaration(csentry, oldPassword, newPassword, false), timeout);
                        output += expectResult ?? string.Empty;

                        if (expectResult == null)
                        {
                            output += shell.Read();
                            throw new Microsoft.MetadirectoryServices.ExtensibleExtensionException("The asynchronous command did not return the expected result");
                        }
                    }
                }

                output += shell.Read();
            }
            finally
            {
                Logger.WriteLine("Shell session log:", LogLevel.Debug);
                Logger.WriteLine(output, LogLevel.Debug);
            }
        }