protected virtual string OnNotifyRetryDistributionChanges(List <ChangeNotificationData> itemsToSync, Workload workload, bool isObjectLevelSync)
        {
            string text;

            return(AggregatedNotificationClients.NotifyChangesByWorkload(this, (IConfigurationSession)base.DataSession, workload, from ols in itemsToSync
                                                                         select ols.CreateSyncChangeInfo(isObjectLevelSync), false, false, this.executionLogger, base.GetType(), out text));
        }
        public static IList <ChangeNotificationData> NotifyChanges(Task task, IConfigurationSession configurationSession, UnifiedPolicyStorageBase policyStorageObject, ExecutionLog logger, Type client, IEnumerable <UnifiedPolicyStorageBase> bindingStorageObjects = null, IEnumerable <UnifiedPolicyStorageBase> ruleStorageObjects = null)
        {
            ArgumentValidator.ThrowIfNull("task", task);
            ArgumentValidator.ThrowIfNull("configurationSession", configurationSession);
            ArgumentValidator.ThrowIfNull("policyStorageObject", policyStorageObject);
            if (!ExPolicyConfigProvider.IsFFOOnline)
            {
                return(new List <ChangeNotificationData>());
            }
            List <UnifiedPolicyStorageBase> list = new List <UnifiedPolicyStorageBase>
            {
                policyStorageObject
            };

            if (bindingStorageObjects != null)
            {
                list.AddRange(bindingStorageObjects);
            }
            if (ruleStorageObjects != null)
            {
                list.AddRange(ruleStorageObjects);
            }
            Dictionary <Workload, List <ChangeNotificationData> > dictionary = AggregatedNotificationClients.NotifyChanges(task, configurationSession, list, logger, client);
            List <ChangeNotificationData> list2 = new List <ChangeNotificationData>();

            foreach (KeyValuePair <Workload, List <ChangeNotificationData> > keyValuePair in dictionary)
            {
                list2.AddRange(keyValuePair.Value);
            }
            return(list2);
        }
 private void HandleNotificationErrors(string notificationError, IEnumerable <ChangeNotificationData> syncData)
 {
     if (!string.IsNullOrEmpty(notificationError))
     {
         base.WriteWarning(notificationError);
         AggregatedNotificationClients.SetNotificationResults(syncData, notificationError);
         PolicySettingStatusHelpers.CheckNotificationResultsAndUpdateStatus(this, (IConfigurationSession)base.DataSession, syncData);
     }
 }
Ejemplo n.º 4
0
        internal static IList <ChangeNotificationData> NotifyChange(Task task, UnifiedPolicyStorageBase policyStorageObject, IEnumerable <UnifiedPolicyStorageBase> relatedStorageObjects, IConfigurationSession dataSession, ExecutionLog logger)
        {
            Exception exception = null;
            string    text      = string.Empty;
            string    empty     = string.Empty;
            ChangeNotificationData        changeNotificationData = IntuneCompliancePolicySyncNotificationClient.CreateChangeData(Workload.Intune, policyStorageObject);
            List <ChangeNotificationData> list = new List <ChangeNotificationData>
            {
                changeNotificationData
            };
            List <SyncChangeInfo> list2 = new List <SyncChangeInfo>();

            foreach (UnifiedPolicyStorageBase policyStorageObject2 in relatedStorageObjects)
            {
                list.Add(IntuneCompliancePolicySyncNotificationClient.CreateChangeData(Workload.Intune, policyStorageObject2));
            }
            foreach (ChangeNotificationData changeNotificationData2 in list)
            {
                SyncChangeInfo syncChangeInfo = changeNotificationData2.ShouldNotify ? changeNotificationData2.CreateSyncChangeInfo(true) : null;
                if (syncChangeInfo == null)
                {
                    logger.LogOneEntry(task.GetType().Name, string.Empty, ExecutionLog.EventType.Warning, string.Format("We did not notify workload '{0}' for changes to objectId {1}", Workload.Intune, changeNotificationData2.Id), exception);
                }
                list2.Add(syncChangeInfo);
            }
            try
            {
                if (list2.Any <SyncChangeInfo>())
                {
                    text = IntuneCompliancePolicySyncNotificationClient.MakeNotificationCall(task, list2, changeNotificationData.UseFullSync, changeNotificationData.ShouldNotify, dataSession, logger);
                }
            }
            catch (Exception ex)
            {
                text      = Strings.ErrorMessageForNotificationFailure(Workload.Intune.ToString(), ex.Message);
                exception = ex;
            }
            if (!string.IsNullOrEmpty(text))
            {
                task.WriteWarning(Strings.WarningNotifyWorkloadFailed(changeNotificationData.ToString()));
                logger.LogOneEntry(task.GetType().Name, string.Empty, ExecutionLog.EventType.Warning, string.Format("We failed to notify workload '{0}' with error message '{1}'", Workload.Intune, text), exception);
                MonitoringItemErrorPublisher.Instance.PublishEvent("UnifiedPolicySync.SendNotificationError", UnifiedPolicyConfiguration.GetInstance().GetOrganizationIdKey(dataSession), string.Format("Workload={0};Timestamp={1}", Workload.Intune, DateTime.UtcNow), exception);
            }
            else
            {
                logger.LogOneEntry(ExecutionLog.EventType.Verbose, task.GetType().Name, empty, "Notification '{0}' was sent to workload '{1}' with sync change info: '{2}'", new object[]
                {
                    empty,
                    Workload.Intune,
                    list2.First <SyncChangeInfo>().ToString()
                });
            }
            AggregatedNotificationClients.SetNotificationResults(list, text);
            return(list);
        }
        private Dictionary <Workload, List <ChangeNotificationData> > GenerateSyncsForFailedBindings()
        {
            Dictionary <Workload, List <ChangeNotificationData> > dictionary = new Dictionary <Workload, List <ChangeNotificationData> >();

            using (IEnumerator <BindingStorage> enumerator = this.PsPolicyPresentationObject.StorageBindings.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    BindingStorage bindingStorage = enumerator.Current;
                    IEnumerable <UnifiedPolicySettingStatus> source = PolicySettingStatusHelpers.LoadSyncStatuses(base.DataSession, Utils.GetUniversalIdentity(bindingStorage), typeof(BindingStorage).Name);
                    bool flag = false;
                    if (source.Any((UnifiedPolicySettingStatus s) => SetCompliancePolicyBase.HasDistributionFailed(bindingStorage, s)))
                    {
                        flag = true;
                        bindingStorage.PolicyVersion = CombGuidGenerator.NewGuid();
                        if (!dictionary.ContainsKey(bindingStorage.Workload))
                        {
                            dictionary[bindingStorage.Workload] = new List <ChangeNotificationData>();
                        }
                        dictionary[bindingStorage.Workload].Add(AggregatedNotificationClients.CreateChangeData(bindingStorage.Workload, bindingStorage));
                    }
                    List <ChangeNotificationData> list = this.GenerateSyncsForFailedScopes(bindingStorage.AppliedScopes);
                    list.AddRange(this.GenerateSyncsForFailedScopes(bindingStorage.RemovedScopes));
                    if (list.Any <ChangeNotificationData>())
                    {
                        if (!dictionary.ContainsKey(bindingStorage.Workload))
                        {
                            dictionary[bindingStorage.Workload] = new List <ChangeNotificationData>();
                        }
                        dictionary[bindingStorage.Workload].AddRange(list);
                        if (!flag)
                        {
                            flag = true;
                            bindingStorage.PolicyVersion = CombGuidGenerator.NewGuid();
                            base.DataSession.Save(bindingStorage);
                            dictionary[bindingStorage.Workload].Add(AggregatedNotificationClients.CreateChangeData(bindingStorage.Workload, bindingStorage));
                        }
                    }
                    if (flag)
                    {
                        base.DataSession.Save(bindingStorage);
                    }
                }
            }
            return(dictionary);
        }
        private static Dictionary <Workload, List <ChangeNotificationData> > GenerateSyncs(IEnumerable <UnifiedPolicySettingStatus> syncStatuses, IEnumerable <Workload> workloads, IConfigDataProvider dataSession, UnifiedPolicyStorageBase storageObject, ConfigurationObjectType objectType)
        {
            Dictionary <Workload, List <ChangeNotificationData> > dictionary = new Dictionary <Workload, List <ChangeNotificationData> >();

            if (syncStatuses.Any((UnifiedPolicySettingStatus s) => SetCompliancePolicyBase.HasDistributionFailed(storageObject, s)))
            {
                storageObject.PolicyVersion = CombGuidGenerator.NewGuid();
                dataSession.Save(storageObject);
                foreach (Workload workload in workloads)
                {
                    dictionary[workload] = new List <ChangeNotificationData>
                    {
                        AggregatedNotificationClients.CreateChangeData(workload, storageObject)
                    };
                }
            }
            return(dictionary);
        }
        private List <ChangeNotificationData> GenerateSyncsForFailedScopes(IEnumerable <ScopeStorage> scopeStorages)
        {
            List <ChangeNotificationData> list = new List <ChangeNotificationData>();

            foreach (ScopeStorage scopeStorage in scopeStorages)
            {
                IEnumerable <UnifiedPolicySettingStatus> enumerable = PolicySettingStatusHelpers.LoadSyncStatuses(base.DataSession, Utils.GetUniversalIdentity(scopeStorage), typeof(ScopeStorage).Name);
                foreach (UnifiedPolicySettingStatus status in enumerable)
                {
                    if (SetCompliancePolicyBase.HasDistributionFailed(scopeStorage, status))
                    {
                        scopeStorage.PolicyVersion = CombGuidGenerator.NewGuid();
                        list.Add(AggregatedNotificationClients.CreateChangeData(scopeStorage.Workload, scopeStorage));
                    }
                }
            }
            return(list);
        }
 private void SendNotification()
 {
     foreach (object obj in Enum.GetValues(typeof(Workload)))
     {
         Workload workload = (Workload)obj;
         if ((this.Workload & workload) != Workload.None)
         {
             string identity;
             string text = AggregatedNotificationClients.NotifyChangesByWorkload(this, base.DataSession as IConfigurationSession, workload, this.syncChangeInfos, this.FullSync.ToBool(), true, this.executionLogger, base.GetType(), out identity);
             if (string.IsNullOrEmpty(text))
             {
                 this.WriteResult(new PsUnifiedPolicyNotification(workload, identity, this.syncChangeInfos, this.FullSync.ToBool()));
             }
             else
             {
                 base.WriteWarning(text);
             }
         }
     }
 }
        private static Dictionary <Workload, List <ChangeNotificationData> > CreateSyncChangeDataGroupedByWorkload(IEnumerable <UnifiedPolicyStorageBase> policyStorageObjects)
        {
            Dictionary <Workload, List <ChangeNotificationData> > dictionary = new Dictionary <Workload, List <ChangeNotificationData> >();

            foreach (Workload workload in AggregatedNotificationClients.workloadToNotificationClientsGetter.Keys)
            {
                List <ChangeNotificationData> list = new List <ChangeNotificationData>();
                foreach (UnifiedPolicyStorageBase policyStorageObject in policyStorageObjects)
                {
                    ChangeNotificationData changeNotificationData = AggregatedNotificationClients.CreateChangeData(workload, policyStorageObject);
                    if (changeNotificationData != null)
                    {
                        list.Add(changeNotificationData);
                    }
                }
                if (list.Any <ChangeNotificationData>())
                {
                    dictionary.Add(workload, list);
                }
            }
            return(dictionary);
        }
        private static Dictionary <Workload, List <ChangeNotificationData> > NotifyChanges(Task task, IConfigurationSession configurationSession, IEnumerable <UnifiedPolicyStorageBase> policyStorageObjects, ExecutionLog logger, Type client)
        {
            Dictionary <Workload, List <ChangeNotificationData> > dictionary = AggregatedNotificationClients.CreateSyncChangeDataGroupedByWorkload(policyStorageObjects);

            foreach (KeyValuePair <Workload, List <ChangeNotificationData> > keyValuePair in dictionary)
            {
                IEnumerable <SyncChangeInfo> enumerable = from s in keyValuePair.Value
                                                          where s.ShouldNotify
                                                          select s into d
                                                          select d.CreateSyncChangeInfo(false);

                if (enumerable.Any <SyncChangeInfo>())
                {
                    string text2;
                    string text = AggregatedNotificationClients.NotifyChangesByWorkload(task, configurationSession, keyValuePair.Key, enumerable, false, false, logger, client, out text2);
                    if (!string.IsNullOrEmpty(text))
                    {
                        task.WriteWarning(Strings.WarningNotifyWorkloadFailed(keyValuePair.Key.ToString()));
                    }
                    AggregatedNotificationClients.SetNotificationResults(keyValuePair.Value, text);
                }
            }
            return(dictionary);
        }
Ejemplo n.º 11
0
 protected virtual IEnumerable <ChangeNotificationData> OnNotifyChanges()
 {
     return(AggregatedNotificationClients.NotifyChanges(this, base.DataSession as IConfigurationSession, base.DataObject, this.executionLogger, base.GetType(), null, null));
 }
 protected virtual IEnumerable <ChangeNotificationData> OnNotifyChanges(IEnumerable <UnifiedPolicyStorageBase> bindingStorageObjects, IEnumerable <UnifiedPolicyStorageBase> ruleStorageObjects)
 {
     return(AggregatedNotificationClients.NotifyChanges(this, (IConfigurationSession)base.DataSession, base.DataObject, this.executionLogger, base.GetType(), bindingStorageObjects, ruleStorageObjects));
 }
 protected virtual IEnumerable <ChangeNotificationData> OnNotifyChanges()
 {
     return(AggregatedNotificationClients.NotifyChanges(this, (IConfigurationSession)base.DataSession, this.DataObject, this.executionLogger, base.GetType(), this.PsPolicyPresentationObject.StorageBindings, null));
 }