Exemplo n.º 1
0
        public string CreateUpdatePolicy(string name, string bulletinGuids, List <string> targetGuids, bool enabled)
        {
            IList <Guid> suGuids = ParseGuidList(ResolveToUpdates(bulletinGuids), true);

            if (suGuids == null)
            {
                return(string.Empty);
            }
            if (suGuids.Count == 0)
            {
                return("No software updates resolved for policy.");
            }
            Guid platformPolicy = PatchManagementVendorPolicy.GetPlatformPolicy(suGuids[0]);

            if (platformPolicy == Guid.Empty)
            {
                return(string.Format("Unable to resolve vendor from {0}", suGuids[0]));
            }
            PatchManagementVendorPolicy item = Item.GetItem(platformPolicy) as PatchManagementVendorPolicy;

            if (item == null)
            {
                return(string.Format("Unable to load vendor policy {0}", platformPolicy));
            }
            GuidCollection gc = new GuidCollection();

            foreach (Guid g in suGuids)
            {
                gc.Add(g);
            }
            SoftwareUpdateAdvertismentSet newAdvertismentSet = item.GetNewAdvertismentSet();

            newAdvertismentSet.Initialise(gc);
            SoftwareUpdateDistributionTask task = Item.GetItem(Tasks.Singletons70.SoftwareUpdateDistrbutionTask, ItemLoadFlags.WriteableIgnoreAll) as SoftwareUpdateDistributionTask;

            if (task == null)
            {
                return("Cannot initialise of SoftwareUpdateDistrbutionTask. Item is missing from the database");
            }
            newAdvertismentSet.Name    = name;
            newAdvertismentSet.Enabled = enabled;

            if (targetGuids.Count > 0)
            {
                GuidCollection targetGuidColl = new GuidCollection();
                foreach (string target in targetGuids)
                {
                    targetGuidColl.Add(new Guid(target));
                }

                newAdvertismentSet.BaseResourceTargetGuids = targetGuidColl;
            }
            ITaskExecutionInstance instance = task.CreateInstance(newAdvertismentSet, Guid.Empty, DistributionType.PolicyForWin);

            if (instance == null)
            {
                return(string.Empty);
            }
            return(instance.TaskInstanceGuid.Guid.ToString());
        }
Exemplo n.º 2
0
        public int EnsureStaged(string bulletinGuids, bool sync)
        {
            int num;
            ITaskExecutionInstance inst  = null;
            GuidCollection         guids = EnsureUpdatesStaged((IList <Guid>)ParseGuidList(ResolveToUpdates(bulletinGuids), true), sync, out inst);

            return(num = (guids != null) ? guids.Count : -1);
        }
Exemplo n.º 3
0
        public static GuidCollection EnsureUpdatesStaged(IList <Guid> guids, bool sync, out ITaskExecutionInstance inst)
        {
            inst = null;
            GuidCollection nonstagedUpdates = GetNonstagedUpdates(guids);

            if (nonstagedUpdates.Count <= 0)
            {
                return(nonstagedUpdates);
            }
            EventLog.ReportVerbose(string.Format("Staging {0} updates...", nonstagedUpdates.Count), "Stage & Distribute");
            try {
                for (int i = 0; i < 5; i++)
                {
                    inst = Item.GetItem <DownloadSWUPackageTask>(Tasks.Singletons70.DownloadSWUPackage, ItemLoadFlags.WriteableIgnoreAll).CreateInstanceForReplication(nonstagedUpdates, DownloadFilter.Auto, DownloadSWUPackageTask.EReason.DOWNLOAD_STAGE);
                    if (sync)
                    {
                        TaskHelper.WaitForTaskToComplete(inst);
                    }
                    else
                    {
                        return(nonstagedUpdates);
                    }
                    if (inst.InstanceStatus == Altiris.TaskManagement.Common.TaskInstanceStatus.Completed)
                    {
                        return(nonstagedUpdates);
                    }
                }
            }
            catch (Exception exception) {
                TraceOps.TRACE(exception);
            }
            throw new Exception(string.Format("Unable to stage '{0}' updates.", nonstagedUpdates.Count));
        }