internal EmptyProductDeleterResult DeleteProduct(Guid productID)
        {
            Logger.EnteringMethod(productID.ToString());
            IUpdate                   updateToDelete  = null;
            IUpdateCategory           productToDelete = wsus.GetUpdateCategory(productID);
            IUpdateCategory           vendorToDelete  = productToDelete.GetParentUpdateCategory();
            EmptyProductDeleterResult result          = new EmptyProductDeleterResult();

            result.DeletedProduct = null;
            result.DeletedVendor  = null;
            StartWaitingForm(resMan.GetString("DeletingProduct") + productToDelete.Title);
            updateToDelete = PublishUpdate(productToDelete, vendorToDelete);

            if (updateToDelete != null && MakeLocallyPublished(productToDelete, vendorToDelete))
            {
                DeclineUpdate(updateToDelete);
                CleanUpdateRevision();
                DeleteUpdate(updateToDelete);
                System.Threading.Thread.Sleep(500);
                try
                {
                    IUpdateCategory deletedCategory = wsus.GetUpdateCategory(productToDelete.Id);
                    Logger.Write("Failed to delete : " + productToDelete.Title);
                }
                catch (Exception)
                {
                    Logger.Write("Successfuly deleted : " + productToDelete.Title);
                    result.DeletedProduct = productToDelete;
                    if (vendorToDelete.GetSubcategories().Count == 0)
                    {
                        try
                        {
                            IUpdateCategory deletedCategory = wsus.GetUpdateCategory(vendorToDelete.Id);
                            Logger.Write("Failed to delete : " + vendorToDelete.Title);
                        }
                        catch (Exception)
                        {
                            Logger.Write("Succesfully deleted : " + vendorToDelete.Title);
                            result.DeletedVendor = vendorToDelete;
                            StopWaitingForm();
                            _waitingForm.TopLevel = false;
                            return(result);
                        }
                    }
                }
            }
            else
            {
                StopWaitingForm();
                _waitingForm.TopLevel = false;
                return(result);
            }

            StopWaitingForm();
            _waitingForm.TopLevel = false;
            return(result);
        }
        private bool MakeLocallyPublished(IUpdateCategory productToDelete, IUpdateCategory vendorToDelete)
        {
            Logger.EnteringMethod("Product to Delete : " + productToDelete.Title + " and Vendor to delete : " + vendorToDelete.Title);
            try
            {
                List <Guid> Ids       = new List <Guid>();
                SqlHelper   sqlHelper = SqlHelper.GetInstance();

                sqlHelper.ServerName   = GetServerName();;
                sqlHelper.DataBaseName = "SUSDB";

                if (!sqlHelper.Connect(string.Empty, string.Empty))
                {
                    Logger.Write("Failed to connect to SQL");
                    return(false);
                }
                else
                {
                    Logger.Write("Connected to SQL");
                    Logger.Write("ProductToDelete UpdateSource = " + productToDelete.UpdateSource.ToString());
                    if (productToDelete.UpdateSource == UpdateSource.MicrosoftUpdate)
                    {
                        Ids.Add(productToDelete.Id);
                        sqlHelper.HideUpdatesInConsole(Ids);
                    }
                    Ids.Clear();
                    if (vendorToDelete.GetSubcategories().Count == 1)
                    {
                        Logger.Write("vendorToDelete UpdateSource = " + vendorToDelete.UpdateSource.ToString());
                        if (vendorToDelete.UpdateSource == UpdateSource.MicrosoftUpdate)
                        {
                            Ids.Add(vendorToDelete.Id);
                            sqlHelper.HideUpdatesInConsole(Ids);
                        }
                    }
                    sqlHelper.Disconnect();
                    Logger.Write("End of SQL session");
                }
            }
            catch (Exception ex)
            {
                Logger.Write("**** " + ex.Message);
                return(false);
            }
            Logger.Write("Successfuly made LocallyPublished");
            return(true);
        }
Example #3
0
        private void ChangeVisibiltyInWsusConsole(UpdateCollection updates, int status)
        {
            Logger.EnteringMethod();
            SqlHelper   sqlHelper       = SqlHelper.GetInstance();
            List <Guid> updateIDs       = new List <Guid>();
            string      sqlServerName   = _wsus.GetSqlServerName();
            string      sqlDataBaseName = _wsus.GetSqlDataBaseName();

            System.Version wsusVersion = _wsus.GetServerVersion();

            if (sqlServerName.Contains("MICROSOFT##SSEE") || sqlServerName.Contains("MICROSOFT##WID"))
            {
                if (wsusVersion.Major == 3)
                {
                    sqlHelper.ServerName = @"\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query";
                }
                if (wsusVersion.Major == 6)
                {
                    sqlHelper.ServerName = @"\\.\pipe\Microsoft##WID\tsql\query";
                }
                sqlHelper.DataBaseName = "SUSDB";
            }
            else
            {
                sqlHelper.ServerName   = _wsus.GetSqlServerName();
                sqlHelper.DataBaseName = _wsus.GetSqlDataBaseName();
            }

            if (sqlHelper.Connect(string.Empty, string.Empty))
            {
                foreach (IUpdate update in updates)
                {
                    updateIDs.Add(update.Id.UpdateId);
                    if (status == 0)
                    {
                        sqlHelper.ShowUpdatesInConsole(updateIDs);
                    }
                    if (status == 1)
                    {
                        sqlHelper.HideUpdatesInConsole(updateIDs);
                    }
                }

                updateIDs.Clear();
                foreach (IUpdate update in updates)
                {
                    UpdateCategoryCollection categories = update.GetUpdateCategories();
                    foreach (IUpdateCategory category in categories)
                    {
                        if (!updateIDs.Contains(category.Id) && (status == 0 || NumberOfVisibleUpdate(category.GetUpdates()) == 0))
                        {
                            updateIDs.Add(category.Id);
                            if (category.ProhibitsSubcategories && !category.ProhibitsUpdates)
                            {
                                IUpdateCategory parentCategory = category.GetParentUpdateCategory();
                                if (!updateIDs.Contains(parentCategory.Id) && (status == 0 || NumberOfVisibleCategory(parentCategory.GetSubcategories()) == 1))
                                {
                                    updateIDs.Add(parentCategory.Id);
                                }
                            }
                        }
                    }
                }

                if (status == 0)
                {
                    sqlHelper.ShowUpdatesInConsole(updateIDs);
                }
                if (status == 1)
                {
                    sqlHelper.HideUpdatesInConsole(updateIDs);
                }
                sqlHelper.Disconnect();
            }
        }