Ejemplo n.º 1
0
        /// <summary>
        /// The is update marked for uninstall.
        /// </summary>
        /// <param name="update">
        /// The update.
        /// </param>
        /// <param name="targetGroup">
        /// The target group.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private static bool IsUpdateMarkedForUninstall(IUpdate update, IComputerTargetGroup targetGroup)
        {
            UpdateApprovalCollection approvals = update.GetUpdateApprovals(targetGroup);

            foreach (IUpdateApproval approval in approvals)
            {
                if (approval.Action == UpdateApprovalAction.Uninstall)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Approves a superseded update
        ///     Using previous approval settings
        /// </summary>
        /// <param name="newUpdate">
        /// The new update
        /// </param>
        /// <param name="previousUpdate">
        /// The previously approved update
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="recentlyApproved">
        /// List of recently approved updates
        /// </param>
        /// <param name="shouldApproveUninstalledSupersededUpdate">
        /// Whether an update that has been uninstalled should be approved if superseded.
        /// </param>
        private static void ApproveSupersededUpdate(
            IUpdate newUpdate,
            IUpdate previousUpdate,
            bool isTest,
            List <Guid> recentlyApproved,
            bool shouldApproveUninstalledSupersededUpdate)
        {
            if (isTest)
            {
                Console.Out.Write("(TEST) ");
            }

            Console.Out.WriteLine(newUpdate.Title);
            recentlyApproved.Add(newUpdate.Id.UpdateId);

            if (isTest)
            {
                return;
            }

            UpdateApprovalCollection approvals = previousUpdate.GetUpdateApprovals();

            foreach (IUpdateApproval approval in approvals)
            {
                IComputerTargetGroup ctg = approval.GetComputerTargetGroup();

                if (approval.Action == UpdateApprovalAction.Uninstall && !shouldApproveUninstalledSupersededUpdate)
                {
                    // this update has been marked for removal
                    Console.WriteLine(
                        " WARNING: Superseded update is marked for uninstall and settings don't allow it to be automatically approved. Target group: "
                        + ctg.Name);

                    continue;
                }

                newUpdate.Approve(UpdateApprovalAction.Install, ctg);

                Console.Out.WriteLine(" " + ctg.Name);
            }
        }
Ejemplo n.º 3
0
        private void FillDataGridView(UpdateCollection updatesToApprove, List <MetaGroup> metaGroups, ComputerGroup computersGroup)
        {
            Logger.EnteringMethod();
            bool uninstallAllowed = IsUninstallationAllowed(updatesToApprove);

            object[] approvalsObj;

            if (uninstallAllowed)
            {
                lblUninstallationAllowed.Text = resMan.GetString("UninstallationAllowed");
                approvalsObj = new object[]
                { resMan.GetString(ApprovalObject.Approvals.Unchanged.ToString()),
                  resMan.GetString(ApprovalObject.Approvals.ApproveForInstallation.ToString()),
                  resMan.GetString(ApprovalObject.Approvals.ApproveForOptionalInstallation.ToString()),
                  resMan.GetString(ApprovalObject.Approvals.ApproveForUninstallation.ToString()),
                  resMan.GetString(ApprovalObject.Approvals.NotApproved.ToString()) };
            }
            else
            {
                lblUninstallationAllowed.Text = resMan.GetString("UninstallationDisallowed");
                approvalsObj = new object[]
                { resMan.GetString(ApprovalObject.Approvals.Unchanged.ToString()),
                  resMan.GetString(ApprovalObject.Approvals.ApproveForInstallation.ToString()),
                  resMan.GetString(ApprovalObject.Approvals.ApproveForOptionalInstallation.ToString()),
                  resMan.GetString(ApprovalObject.Approvals.NotApproved.ToString()) };
            }
            DateTime noDeadLineSet = DateTime.MaxValue;

            dgvTargetGroup.SuspendLayout();
            DataGridViewComboBoxColumn approvalColumn = (DataGridViewComboBoxColumn)dgvTargetGroup.Columns["Approval"];

            approvalColumn.Items.AddRange(approvalsObj);
            cmbBxApproval.Items.AddRange(approvalsObj);
            cmbBxApproval.SelectedIndex = 0;

            FillMetaGroup(metaGroups);
            FillComputerGroup(computersGroup);

            foreach (DataGridViewRow row in dgvTargetGroup.Rows)
            {
                if ((row.Cells["Group"].Value as ComputerGroup).ComputerGroupId == _allComputerGroup.Id)
                {
                    (row.Cells["Approval"] as DataGridViewComboBoxCell).Items.Remove(resMan.GetString(ApprovalObject.Approvals.NotApproved.ToString()));
                }
                if (updatesToApprove.Count == 1)
                {
                    UpdateApprovalCollection approvals = _wsus.GetUpdateApprovalStatus((row.Cells["Group"].Value as ComputerGroup).ComputerGroupId, updatesToApprove[0]);
                    if (approvals.Count != 0)
                    {
                        switch (approvals[0].Action)
                        {
                        case UpdateApprovalAction.All:
                            row.Cells["Approval"].Value = resMan.GetString(ApprovalObject.Approvals.Unchanged.ToString());
                            break;

                        case UpdateApprovalAction.Install:
                            if (approvals[0].IsOptional)
                            {
                                row.Cells["Approval"].Value = resMan.GetString(ApprovalObject.Approvals.ApproveForOptionalInstallation.ToString());
                            }
                            else
                            {
                                row.Cells["Approval"].Value = resMan.GetString(ApprovalObject.Approvals.ApproveForInstallation.ToString());
                            }
                            if (approvals[0].Deadline != noDeadLineSet)
                            {
                                row.Cells["DeadLine"].Value = approvals[0].Deadline.ToLocalTime();
                            }
                            break;

                        case UpdateApprovalAction.NotApproved:
                            row.Cells["Approval"].Value = resMan.GetString(ApprovalObject.Approvals.NotApproved.ToString());
                            break;

                        case UpdateApprovalAction.Uninstall:
                            row.Cells["Approval"].Value = resMan.GetString(ApprovalObject.Approvals.ApproveForUninstallation.ToString());
                            if (approvals[0].Deadline != noDeadLineSet)
                            {
                                row.Cells["DeadLine"].Value = approvals[0].Deadline.ToLocalTime();
                            }
                            break;

                        default:
                            row.Cells["Approval"].Value = resMan.GetString(ApprovalObject.Approvals.Unchanged.ToString());
                            break;
                        }
                    }
                    else
                    {
                        row.Cells["Approval"].Value = resMan.GetString(ApprovalObject.Approvals.Unchanged.ToString());
                    }
                }
                else
                {
                    row.Cells["Approval"].Value = resMan.GetString(ApprovalObject.Approvals.Unchanged.ToString());
                }
            }
            dgvTargetGroup.ResumeLayout();
        }