예제 #1
0
        private static List <Insight> RunInsightQuery(String SQL)
        {
            Logger.instance.Debug("Getting insight history");
            Database       db          = new Database();
            List <string>  rows        = db.Read(SQL, 3);
            List <Insight> InsightList = new List <Insight>();

            Logger.instance.Debug("Iterating through rows of insights");
            foreach (string row in rows)
            {
                string[] cols       = row.Split(new Database().COLUMN_DELIMETER);
                long     UID        = Int64.Parse(cols[0]);
                String   Insight    = cols[1];
                DateTime DateLogged = Utils.FormatDateTime(cols[2]);

                Insight i = new Insight(UID, Insight, DateLogged);
                InsightList.Add(i);
            }

            Logger.instance.Debug("Returning insight list");
            return(InsightList);
        }
예제 #2
0
        // Method for using WUAPI to install the named update - "Windows Update" service needs turning on before calling this method
        public void installUpdate()
        {
            try
            {
                Logger.instance.Debug("Installing update");
                List <Update> updates = new List <Update>();

                IUpdateSession  uSession;
                IUpdateSearcher uSearcher;
                uSession = new UpdateSession(); //Create an Update interface in WUA

                Logger.instance.Debug("Creating searcher");
                uSearcher = uSession.CreateUpdateSearcher(); // Search for available Updates

                Logger.instance.Debug("Creating holder for updates");
                UpdateCollection updatesToDownload = new UpdateCollection();

                Logger.instance.Debug("Searching for specific update");
                ISearchResult uResult = uSearcher.Search("Type='Software' And IsAssigned = 1"); //Save the result of the search

                Logger.instance.Debug("Creating update collection");
                UpdateCollection updatesToInstall = new UpdateCollection();

                for (int i = 0; i < uResult.Updates.Count; i++)
                {
                    if (uResult.Updates[i].Title.ToString().Equals(this.Name))
                    {
                        updatesToInstall.Add(uResult.Updates[i]);   //save all the queued updates to the downloader queue
                        break;
                    }
                }

                if (updatesToInstall.Count > 0)
                {
                    Logger.instance.Debug("Creating update installer");
                    IUpdateInstaller installer = uSession.CreateUpdateInstaller(); //create an interface for installation of updates
                    installer.Updates = updatesToInstall;

                    Logger.instance.Debug("Installing update");
                    IInstallationResult installationRes = installer.Install();

                    if (installationRes.GetUpdateResult(0).HResult == 0) // 0 (zero) code means succeeded
                    {
                        this.isInstalled       = true;
                        this.DateTimeInstalled = DateTime.UtcNow;
                        save();
                    }
                    else  // For status codes other than 0 (zero)
                    {
                        String  result = "Failed to install update " + Name + ".  It returned windows update error code = " + installationRes.GetUpdateResult(0).HResult.ToString();
                        Insight ins    = new Insight();
                        ins.InsightText = result;
                        ins.Save();

                        Logger.instance.Warning(result);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.instance.Error(e);
            }
        }