Exemple #1
0
        public UpdateFake(string updateID)
        {
            _identity = CommonMocks.GetUpdateIdentity(updateID);

            var behavMock = new Mock <IInstallationBehavior>();

            behavMock.Setup(b => b.CanRequestUserInput).Returns(false);
            behavMock.Setup(b => b.Impact).Returns(InstallationImpact.iiNormal);
            behavMock.Setup(b => b.RebootBehavior).Returns(InstallationRebootBehavior.irbNeverReboots);
            _installationBehavior = behavMock.Object;
        }
Exemple #2
0
        public static void UpdateHist(Server server, bool initiated)
        {
            try
            {
                Type            t              = Type.GetTypeFromProgID("Microsoft.Update.Session", server.Location); //wcswapp01.intellig.local     OH0KLT733D7S2.global.ds.honeywell.com     labengdemctl00.labmasoh.local  wcbuildapp02.intellig.local
                UpdateSession   session        = (UpdateSession)Activator.CreateInstance(t);
                IUpdateSearcher updateSearcher = session.CreateUpdateSearcher();

                int count = updateSearcher.GetTotalHistoryCount();
                IUpdateHistoryEntryCollection history = updateSearcher.QueryHistory(0, count);

                DateTime current = DateTime.Now;

                for (int i = 0; i < count; ++i)
                {
                    if (initiated == true)
                    {
                        int hecc = current.Day * (-1);
                        if (history[i].Date >= current.AddMonths(-1).AddDays(hecc))
                        {
                            Info                temp            = new Info();
                            IUpdateIdentity     ID              = history[i].UpdateIdentity;
                            OperationResultCode operationResult = history[i].ResultCode;
                            string              Result          = operationResult.ToString();

                            if (Result == "orcSucceeded")
                            {
                                temp.TestResults  = "Succeeded";
                                temp.UpdateStatus = "Succeeded";
                            }
                            else
                            {
                                temp.TestResults  = "Failed";
                                temp.UpdateStatus = "Failed";
                            }

                            temp.TestDate = history[i].Date;
                            temp.updateID = ID.UpdateID;
                            temp.Title    = history[i].Title;
                            temp.ICW      = server.ICW;
                            temp.Server   = server.ServerName;

                            temp.Active = "Yes";

                            InfoList.Add(temp);
                        }
                    }

                    else
                    {
                        Info                temp            = new Info();
                        IUpdateIdentity     ID              = history[i].UpdateIdentity;
                        OperationResultCode operationResult = history[i].ResultCode;
                        string              Result          = operationResult.ToString();

                        if (Result == "orcSucceeded")
                        {
                            temp.TestResults  = "Succeeded";
                            temp.UpdateStatus = "Succeeded";
                        }
                        else
                        {
                            temp.TestResults  = "Failed";
                            temp.UpdateStatus = "Failed";
                        }

                        temp.TestDate = history[i].Date;
                        temp.updateID = ID.UpdateID;
                        temp.Title    = history[i].Title;
                        temp.ICW      = server.ICW;
                        temp.Server   = server.ServerName;

                        temp.Active = "Yes";

                        //### Uncomment to ignore the updates older than 7 months
                        //if (temp.TestDate <= current.AddMonths(-7))
                        int      y    = current.Year;
                        DateTime year = new DateTime(y, 1, 1);
                        if (temp.TestDate <= year)
                        {
                            break;
                        }

                        InfoList.Add(temp);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void Load()
        {
            List <string> categoriesToExclude = Properties.Settings.Default.update_categories_to_exclude.Cast <string>().ToList().ConvertAll(x => x.ToLower().Trim());

            UpdateSession   session  = new UpdateSession();
            IUpdateSearcher searcher = session.CreateUpdateSearcher();

            searcher.Online = false;

            //try
            //{
            //    ISearchResult result = searcher.Search("IsInstalled=1");

            //    foreach (IUpdate u in result.Updates)
            //    {
            //        var title = u.Title;
            //        var kb = u.KBArticleIDs.Cast<string>().ToList().Aggregate( (x,y) => $"{x},{y}");
            //        var date = u.LastDeploymentChangeTime;

            //        WindowsUpdatesData.Add(new WindowsUpdatesElement()
            //        {
            //            Date = date.ToString(),
            //            Kb = kb,
            //            Title = title
            //        });
            //    }
            //}
            //catch { }


            var count = searcher.GetTotalHistoryCount();

            if (count == 0)
            {
                return;
            }

            var history = searcher.QueryHistory(0, count);

            for (int i = 0; i < count; i++)
            {
                IUpdateHistoryEntry2 e = (IUpdateHistoryEntry2)history[i];

                var category = "n/a";

                ICategoryCollection categories = e.Categories;
                foreach (ICategory oc in categories)
                {
                    category = oc.Name;
                    break;
                }

                // check for excluded catgory
                if (categoriesToExclude.Contains(category.ToLower().Trim()))
                {
                    continue;
                }

                var title = history[i].Title;

                IUpdateIdentity ident = history[i].UpdateIdentity;

                var id = ident.UpdateID;

                WindowsUpdatesData.Add(new WindowsUpdatesElement()
                {
                    Kb       = id,
                    Title    = title,
                    Date     = history[i].Date.ToString(),
                    Result   = history[i].ResultCode.ToString().Replace("orc", string.Empty),
                    Category = category
                });
            }
        }