示例#1
0
        /// <summary>
        /// Update the configuration for ALL deployed AuditAgents
        /// </summary>
        public void ScannerUpdate()
        {
            // Get the list of computers which currently have the AuditAgent deployed (running or not)
            AssetDAO  lwDataAccess = new AssetDAO();
            AssetList listAssets   = new AssetList(lwDataAccess.EnumerateDeployedAssets(), true);

            //if (listAssets.Count == 0)
            //{
            //    MessageBox.Show("Found no assets which already have an AuditAgent deployed.", "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}

            FormLoadScannerConfiguration form = new FormLoadScannerConfiguration(true, "Select a configuration file to update all assets.");

            if (form.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    // Use the Deserialize method to restore the object's state.
                    //auditScannerDefinition = AuditWizardSerialization.DeserializeObject(form.FileName);

                    string agentIniFileName = Path.Combine(AuditAgentStrings.AuditAgentFilesPath, AuditAgentStrings.AuditAgentIni);
                    File.Copy(form.FileName, agentIniFileName, true);
                }
                catch (System.IO.FileNotFoundException)
                {
                    MessageBox.Show("An error has occurred whilst updating the AuditAgent, please see the log file for further information.",
                                    "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // JML TODO log this exception
                    return;
                }
                catch (System.IO.IOException)
                {
                    MessageBox.Show("An error has occurred whilst updating the AuditAgent, please see the log file for further information.",
                                    "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // JML TODO log this exception
                    return;
                }
                catch
                {
                    MessageBox.Show("An error has occurred whilst updating the AuditAgent, please see the log file for further information.",
                                    "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // JML TODO log this exception
                    return;
                }
            }
            else
            {
                return;
            }

            // Ensure that we at least have a data path
            //if (auditScannerDefinition.DeployPathData == "")
            //{
            //    MessageBox.Show("The audit scanner configuration has not been configured yet", "Audit Scanner Configuration Not Defined");
            //    return;
            //}

            // Write the Agent Ini File to the Agent folder as this will combine the scanner configuration
            // with data taken from the Application Definitions File (publisher mappings etc)
            //string agentIniFileName = Path.Combine(AuditAgentStrings.AuditAgentFilesPath, AuditAgentStrings.AuditAgentIni);
            //if (auditScannerDefinition.WriteTo(agentIniFileName) != 0)
            //{
            //    MessageBox.Show("Error : Failed to write the AuditAgent configuration file", "Deploy Error");
            //    return;
            //}

            // We will pend the operation by adding it to the Operations queue in the database
            // The AuditWizard service works on this queue
            foreach (Asset asset in listAssets)
            {
                Operation newOperation = new Operation(asset.AssetID, Operation.OPERATION.updateconfiguration);
                newOperation.Add();
            }

            MessageBox.Show("The AuditAgent Update Request has been queued for " + listAssets.Count.ToString() + " PC(s) and will be actioned by the AuditWizard Service\n\nYou can check its progress by viewing the Operations Log", "Operations Queued", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }