Exemplo n.º 1
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 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);
        }