コード例 #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 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);
        }