コード例 #1
0
        /// <summary>
        /// Called to perform a 'Deploy Agent' Operation on the specified PC
        /// </summary>
        /// <param name="operationThread"></param>
        protected bool DeployAgent(OperationThreadData operationThread, Asset.AGENTSTATUS assetStatus)
        {
            // This is the status of the operation
            bool success = true;

            // This is the text which we shall display for the operation
            string message = "Success";

            // Get the operation to be performed
            Operation operation = operationThread.ActiveOperation;

            try
            {
                // Get the Agent Service Controller passing it the name of the computer
                AuditAgentServiceController agentServiceController = new AuditAgentServiceController(operation.AssetName);

                // Use it to get the current status of the asset

                // If already started, flag this
                if (assetStatus == Asset.AGENTSTATUS.Running)
                {
                    message = "The AuditWizard Agent Service is already running";
                }

                else
                {
                    // If the agent has not been deployed to this computer previously then do so now
                    if (assetStatus == Asset.AGENTSTATUS.notdeployed)
                    {
                        // Install the Agent Service (throws an exception on error)
                        agentServiceController.Install();
                        assetStatus = Asset.AGENTSTATUS.deployed;
                        AssetDAO lwDataAccess = new AssetDAO();
                        lwDataAccess.AssetUpdateAssetStatus(operation.AssetID, assetStatus);
                    }

                    // If the status is now deployed then we can start the Agent
                    if (assetStatus == Asset.AGENTSTATUS.deployed)
                    {
                        // Start the agent (throws an exception on error)
                        agentServiceController.Start();
                    }
                }
            }

            catch (Exception e)
            {
                success = false;
                message = "Error: An Exception occurred while Deploying the AuditAgent, the error text was " + e.Message;
            }

            // Update the Operation object with the overall status and completion message
            operation.Status    = (success) ? Operation.STATUS.complete_success : Operation.STATUS.complete_error;
            operation.ErrorText = message;

            // Return now
            return(success);
        }
コード例 #2
0
        /// <summary>
        /// Called to perform a 'Remove Agent' Operation on the specified PC
        /// </summary>
        /// <param name="operationThread"></param>
        protected bool RemoveAgent(OperationThreadData operationThread, Asset.AGENTSTATUS assetStatus)
        {
            // This is the status of the operation
            bool success = true;

            // This is the text which we shall display for the operation
            string message = "Success";

            // Get the operation to be performed
            Operation operation = operationThread.ActiveOperation;

            // If the AuditAgent is not deployed then just log this - it isn't an error as such but there is
            // no point removing the agent if it is not deployed
            if (assetStatus == Asset.AGENTSTATUS.notdeployed)
            {
                message = "The AuditAgent was not deployed";
            }

            else
            {
                try
                {
                    // Get the Agent Service Controller passing it the name of the computer
                    AuditAgentServiceController agentServiceController = new AuditAgentServiceController(operation.AssetName);

                    // If the AuditAgent is RUNNING then we need to stop it before we can remove it
                    if (assetStatus == Asset.AGENTSTATUS.Running)
                    {
                        success = StopAgent(operationThread, assetStatus);
                        Thread.Sleep(2000);
                    }

                    // Now remove the AudutAgent
                    if (success)
                    {
                        // Use it to get the current status of the asset
                        success = agentServiceController.Remove();
                        message = (success) ? "Success" : "An error occurred while removing the AuditAgent Service";
                    }
                }
                catch (Exception e)
                {
                    success = false;
                    message = "Error: An Exception occurred while removing the AuditAgent Service, the error text was " + e.Message;
                }
            }

            // Update the Operation object with the overall status and completion message
            operation.Status    = (success) ? Operation.STATUS.complete_success : Operation.STATUS.complete_error;
            operation.ErrorText = message;

            // Return now
            return(success);
        }
コード例 #3
0
        /// <summary>
        /// Called to perform a 'Stop Agent' Operation on the specified PC
        /// </summary>
        /// <param name="operationThread"></param>
        protected bool StopAgent(OperationThreadData operationThread, Asset.AGENTSTATUS assetStatus)
        {
            // This is the status of the operation
            bool success = true;

            // This is the text which we shall display for the operation
            string message = "Success";

            // Get the operation to be performed
            Operation operation = operationThread.ActiveOperation;

            // To STOP the agent it must be deployed, if not then this is an error.
            if (assetStatus == Asset.AGENTSTATUS.notdeployed)
            {
                success = false;
                message = "The AuditAgent has not been deployed";
            }

            // Already STOPPED is not an error but don't try and start it again
            else if (assetStatus == Asset.AGENTSTATUS.deployed)
            {
                message = "The AuditAgent was already stopped";
            }

            else
            {
                try
                {
                    // Get the Agent Service Controller passing it the name of the computer
                    AuditAgentServiceController agentServiceController = new AuditAgentServiceController(operation.AssetName);

                    // Use it to get the current status of the asset
                    agentServiceController.Stop();
                }
                catch (Exception e)
                {
                    success = false;
                    message = "Error: An Exception occurred while stopping the AuditAgent, the error text was " + e.Message;
                }
            }

            // Update the Operation object with the overall status and completion message
            operation.Status    = (success) ? Operation.STATUS.complete_success : Operation.STATUS.complete_error;
            operation.ErrorText = message;

            // Return now
            return(success);
        }
コード例 #4
0
        /// <summary>
        /// Called to perform a 'Reaudit' Operation on the specified PC
        /// </summary>
        /// <param name="operationThread"></param>
        protected bool Reaudit(OperationThreadData operationThread, Asset.AGENTSTATUS assetStatus)
        {
            // This is the status of the operation
            bool success = true;

            // This is the text which we shall display for the operation
            string message = "Success";

            // Get the operation to be performed
            Operation operation = operationThread.ActiveOperation;

            // If the AuditAgent is not active then we fail to do a re-audit as it must be running
            if (assetStatus != Asset.AGENTSTATUS.Running)
            {
                success = false;
                message = "The AuditAgent is not currently active";
            }

            else
            {
                try
                {
                    // Get the Agent Service Controller passing it the name of the computer
                    AuditAgentServiceController agentServiceController = new AuditAgentServiceController(operation.AssetName);

                    // Use it to request a re-audit of the asset
                    success = (agentServiceController.RequestReaudit() == 0);
                    if (!success)
                    {
                        message = "An error occurred while requesting a re-audit";
                    }
                }
                catch (Exception e)
                {
                    success = false;
                    message = "Error: An Exception occurred while requesting a re-audit, the error text was " + e.Message;
                }
            }

            // Update the Operation object with the overall status and completion message
            operation.Status    = (success) ? Operation.STATUS.complete_success : Operation.STATUS.complete_error;
            operation.ErrorText = message;

            // Return now
            return(success);
        }
コード例 #5
0
        /// <summary>
        /// Called to perform a 'Check Status' Operation on the specified PC
        /// </summary>
        /// <param name="operationThread"></param>
        /// <param name="assetStatus"></param>
        protected bool CheckStatus(OperationThreadData operationThread, Asset.AGENTSTATUS assetStatus)
        {
            LogFile ourLog = LogFile.Instance;

            // This is the text which we shall display for the operation
            string message = "Success, AgentStatus is " + Asset.TranslateDeploymentStatus(assetStatus);

            // We have actually already performed the sttaus check so need not do it again!
            // Get the operation to be performed
            Operation operation = operationThread.ActiveOperation;

            operation.Status    = Operation.STATUS.complete_success;
            operation.ErrorText = message;

            // Return now
            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Called to return and update the current status of the specified (named) asset
        /// </summary>
        /// <param name="assetName"></param>
        /// <param name="assetStatus"></param>
        /// <param name="message"></param>
        protected int UpdateCurrentAgentStatus(string assetName, int assetID, out Asset.AGENTSTATUS assetStatus, out string message)
        {
            // Get the Agent Service Controller passing it the name of the computer
            AuditAgentServiceController agentServiceController = new AuditAgentServiceController(assetName);

            // Use it to get the current status of the asset
            LaytonServiceController.ServiceStatus serviceStatus = agentServiceController.CheckStatus();
            assetStatus = Asset.AGENTSTATUS.notdeployed;

            switch (serviceStatus)
            {
            case LaytonServiceController.ServiceStatus.Running:
                assetStatus = Asset.AGENTSTATUS.Running;
                break;

            case LaytonServiceController.ServiceStatus.Stopped:
                assetStatus = Asset.AGENTSTATUS.deployed;
                break;

            case LaytonServiceController.ServiceStatus.NotInstalled:
                assetStatus = Asset.AGENTSTATUS.notdeployed;
                break;

            case LaytonServiceController.ServiceStatus.UnableToConnect:
                message = "Error: Could not connect to remote computer, please check that it is turned on";
                return(-1);

            default:
                message = "Error: An Invalid or Unknown Status was returned";
                return(-1);
            }

            // Update the status of the computer in the database if we were successful
            message = Asset.TranslateDeploymentStatus(assetStatus);
            AssetDAO lwDataAccess = new AssetDAO();

            lwDataAccess.AssetUpdateAssetStatus(assetID, assetStatus);

            return(0);
        }
コード例 #7
0
        /// <summary>
        /// Called to perform a 'Clear Agent Log' Operation on the specified PC
        /// </summary>
        /// <param name="operationThread"></param>
        protected bool ClearAgentLog(OperationThreadData operationThread, Asset.AGENTSTATUS assetStatus)
        {
            // This is the status of the operation
            bool success = true;

            // This is the text which we shall display for the operation
            string message = "Success";

            // Get the operation to be performed
            Operation operation = operationThread.ActiveOperation;

            try
            {
                // Get the Agent Service Controller passing it the name of the computer
                AuditAgentServiceController agentServiceController = new AuditAgentServiceController(operation.AssetName);

                // Use it to get the current status of the asset
                success = agentServiceController.ClearLogFile();
                if (!success)
                {
                    message = "An error occurred while clearing the AuditAgent log file";
                }
            }
            catch (Exception e)
            {
                success = false;
                message = "Error: An Exception occurred while clearing the AuditAgent log file, the error text was " + e.Message;
            }

            // Update the Operation object with the overall status and completion message
            operation.Status    = (success) ? Operation.STATUS.complete_success : Operation.STATUS.complete_error;
            operation.ErrorText = message;

            // Return now
            return(success);
        }