Ejemplo n.º 1
0
        /// <summary>
        /// Ends a connection to the server. It is called after processing is completed with the server to release resources
        /// </summary>
        void IMAExtensible2Password.ClosePasswordConnection()
        {
            OperationBase operation = MAConfig.GlobalOperations.FirstOrDefault(t => t is PasswordEndOperation);

            if (operation != null)
            {
                try
                {
                    SshConnection.ExecuteOperation(operation);
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("Could not perform password end operation");
                    Logger.WriteException(ex);
                    throw new ExtensibleExtensionException("Password end operation failed", ex);
                }
            }

            try
            {
                SshConnection.CloseSshConnection();
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Could not close SSH connection");
                Logger.WriteException(ex);
            }

            Logger.WriteLine("Ending password operation");
            Logger.WriteSeparatorLine('*');
        }
Ejemplo n.º 2
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)
        {
            XmlAttribute classAttribute = node.Attributes["object-class"];

            if (classAttribute == null)
            {
                throw new ArgumentNullException("The object class must be specified");
            }

            if (MASchema.Objects.Contains(classAttribute.Value))
            {
                this.ObjectClass = classAttribute.Value;
            }
            else
            {
                throw new NoSuchObjectTypeException(classAttribute.Value);
            }

            foreach (XmlNode operationNode in node.ChildNodes)
            {
                if (operationNode.Name == "global-operation" || operationNode.Name == "object-operation")
                {
                    this.ObjectOperations.Add(OperationBase.CreateObjectOperationFromXmlNode(operationNode));
                }
            }

            if (MAConfig.Capabilities.DeltaImport)
            {
                if (!this.ObjectOperations.Any(t => t is ImportDeltaOperation))
                {
                    throw new ArgumentException("A delta import operation must be defined for all objects if the delta capabilities is enabled in the configuration file");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Ends an export session
        /// </summary>
        /// <param name="exportRunStep">The results of the export session close</param>
        void IMAExtensible2CallExport.CloseExportConnection(CloseExportConnectionRunStep exportRunStep)
        {
            OperationBase operation = MAConfig.GlobalOperations.FirstOrDefault(t => t is ExportEndOperation);

            if (operation != null)
            {
                try
                {
                    SshConnection.ExecuteOperation(operation);
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("Could not perform export end operation");
                    Logger.WriteException(ex);
                    throw new ExtensibleExtensionException("Export end operation failed", ex);
                }
            }

            try
            {
                SshConnection.CloseSshConnection();
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Could not close SSH connection");
                Logger.WriteException(ex);
            }

            Logger.WriteLine("Export Complete");
            Logger.WriteSeparatorLine('*');
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes the specified operation against the SSH client
        /// </summary>
        /// <param name="operation">The operation to execute</param>
        /// <param name="csentry">The object to run the operation against</param>
        /// <param name="oldPassword">The old password for the specified object</param>
        /// <param name="newPassword">The new password for the specified object</param>
        /// <returns>An OperationResult object containing the results of the execution</returns>
        private static OperationResult ExecuteOperation(OperationBase operation, CSEntry csentry, string oldPassword, string newPassword)
        {
            OperationResult result = new OperationResult();

            if (operation == null)
            {
                return(null);
            }

            result.ExecutedOperation = operation;

            foreach (CommandBase command in operation.Commands)
            {
                if (command is SyncCommand)
                {
                    ExecuteSyncCommand(csentry, result, command as SyncCommand, oldPassword, newPassword);
                }
                else if (command is AsyncCommand)
                {
                    ExecuteAsyncCommand(csentry, result, command as AsyncCommand, oldPassword, newPassword);
                }
                else
                {
                    throw new ArgumentException("Unknown command type");
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Reads the global-operations xmlNode from the Xml file
        /// </summary>
        /// <param name="rootNode">The root xmlNode of the Xml file</param>
        private static void ReadGlobalOperationsNode(XmlNode rootNode)
        {
            GlobalOperations.Clear();

            foreach (XmlNode globalOperation in rootNode.SelectNodes("global-operations/global-operation"))
            {
                GlobalOperations.Add(OperationBase.CreateObjectOperationFromXmlNode(globalOperation));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deletes an object from the target system
        /// </summary>
        /// <param name="csentry">The CSEntryChange containing the new object and its attributes</param>
        private static void PerformCSEntryExportDelete(CSEntryChange csentry)
        {
            ObjectOperationGroup group = MAConfig.OperationGroups[csentry.ObjectType];

            if (group == null)
            {
                throw new InvalidOperationException("The object class does not have a delete operation");
            }

            OperationBase   operation = group.ObjectOperations.FirstOrDefault(t => t is ExportDeleteOperation);
            OperationResult result    = SshConnection.ExecuteOperation(operation, csentry);

            if (result != null)
            {
                Logger.WriteLine("ExportDelete on object '{0}' returned: {1}", csentry.DN, result.ExecutedCommands.Last().Result);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Begins a password connection to the server
        /// </summary>
        /// <param name="configParameters">The collection of configuration parameters</param>
        /// <param name="partition">The partition details on which the password operation should occur</param>
        void IMAExtensible2Password.OpenPasswordConnection(KeyedCollection <string, ConfigParameter> configParameters, Partition partition)
        {
            try
            {
                ManagementAgent.MAParameters = new MAParameters(configParameters);
                Logger.LogPath = ManagementAgent.MAParameters.LogPath;
                Logger.WriteSeparatorLine('*');
                Logger.WriteLine("Starting password operation");

                MAConfig.Load(ManagementAgent.MAParameters.MAConfigurationFilePath);

                SshConnection.OpenSshConnection(ManagementAgent.MAParameters);

                OperationBase operation = MAConfig.GlobalOperations.FirstOrDefault(t => t is PasswordStartOperation);

                if (operation != null)
                {
                    try
                    {
                        SshConnection.ExecuteOperation(operation);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteLine("Could not perform password start operation");
                        Logger.WriteException(ex);
                        throw new ExtensibleExtensionException("Password start operation failed", ex);
                    }
                }
            }
            catch (ExtensibleExtensionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.WriteLine("A exception occured during the open password connection operartion");
                Logger.WriteException(ex);
                throw new ExtensibleExtensionException("An exception occured during the open password connection operation", ex);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Begins an export session
        /// </summary>
        /// <param name="configParameters">The configuration parameters supplied to this management agent</param>
        /// <param name="types">The schema types that apply to this export run</param>
        /// <param name="exportRunStep">The definition of the current run step</param>
        void IMAExtensible2CallExport.OpenExportConnection(KeyedCollection <string, ConfigParameter> configParameters, Schema types, OpenExportConnectionRunStep exportRunStep)
        {
            try
            {
                ManagementAgent.MAParameters = new MAParameters(configParameters);
                Logger.LogPath = ManagementAgent.MAParameters.LogPath;
                Logger.WriteSeparatorLine('*');
                Logger.WriteLine("Starting Export");

                MAConfig.Load(ManagementAgent.MAParameters.MAConfigurationFilePath);

                SshConnection.OpenSshConnection(ManagementAgent.MAParameters);

                OperationBase operation = MAConfig.GlobalOperations.FirstOrDefault(t => t is ExportStartOperation);

                if (operation != null)
                {
                    try
                    {
                        SshConnection.ExecuteOperation(operation);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteLine("Could not perform export start operation");
                        Logger.WriteException(ex);
                        throw new ExtensibleExtensionException("Export start operation failed", ex);
                    }
                }
            }
            catch (ExtensibleExtensionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.WriteLine("A exception occured during the open export connection operartion");
                Logger.WriteException(ex);
                throw new ExtensibleExtensionException("An exception occured during the open export connection operation", ex);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Executes the specified operation against the SSH client
        /// </summary>
        /// <param name="operation">The operation to execute</param>
        /// <param name="csentry">The object to run the operation against</param>
        /// <returns>An OperationResult object containing the results of the execution</returns>
        public static OperationResult ExecuteOperation(OperationBase operation, CSEntryChange csentry)
        {
            OperationResult result = new OperationResult();

            result.ExecutedOperation = operation;

            foreach (CommandBase command in operation.Commands.Where(t => t.ShouldExecute(csentry)))
            {
                if (command is SyncCommand)
                {
                    ExecuteSyncCommand(csentry, result, command as SyncCommand);
                }
                else if (command is AsyncCommand)
                {
                    ExecuteAsyncCommand(csentry, result, command as AsyncCommand);
                }
                else
                {
                    throw new ArgumentException("Unknown command type");
                }
            }

            return(result);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Executes the specified operation against the SSH client
 /// </summary>
 /// <param name="operation">The operation to execute</param>
 /// <returns>An OperationResult object containing the results of the execution</returns>
 public static OperationResult ExecuteOperation(OperationBase operation)
 {
     return(ExecuteOperation(operation, null));
 }