public static void CheckNotificationResultsAndUpdateStatus(Task task, IConfigurationSession configurationSession, IEnumerable <ChangeNotificationData> notificationResults)
        {
            IEnumerable <ChangeNotificationData> source = from r in notificationResults
                                                          where r.ErrorCode != UnifiedPolicyErrorCode.Success
                                                          select r;

            if (!source.Any <ChangeNotificationData>())
            {
                return;
            }
            string text = configurationSession.GetOrgContainer().OrganizationId.ToExternalDirectoryOrganizationId();
            Guid   tenantId;

            if (!Guid.TryParse(text, out tenantId))
            {
                task.WriteWarning(Strings.WarningInvalidTenant(text));
                return;
            }
            List <UnifiedPolicyStatus> source2 = (from failureResult in source
                                                  select new UnifiedPolicyStatus
            {
                ErrorCode = failureResult.ErrorCode,
                ErrorMessage = Strings.PolicyNotifyErrorErrorMsg,
                AdditionalDiagnostics = failureResult.ErrorMessage,
                ObjectId = failureResult.Id,
                ObjectType = failureResult.ObjectType,
                ParentObjectId = new Guid?(failureResult.ParentId),
                TenantId = tenantId,
                Version = failureResult.Version,
                WhenProcessedUTC = DateTime.UtcNow,
                Workload = failureResult.Workload
            }).ToList <UnifiedPolicyStatus>();
            IUnifiedPolicyStatusPublisher unifiedPolicyStatusPublisher = HygieneUtils.InstantiateType <IUnifiedPolicyStatusPublisher>("Microsoft.Exchange.Hygiene.Data.Directory.UnifiedPolicy.UnifiedPolicySession");

            using (IEnumerator enumerator = Enum.GetValues(typeof(Workload)).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Workload workload = (Workload)enumerator.Current;
                    IEnumerable <UnifiedPolicyStatus> source3 = from s in source2
                                                                where s.Workload == workload
                                                                select s;
                    if (source3.Any <UnifiedPolicyStatus>())
                    {
                        try
                        {
                            unifiedPolicyStatusPublisher.PublishStatus(source3.Cast <object>(), false);
                        }
                        catch (Exception ex)
                        {
                            task.WriteWarning(Strings.WarningFailurePublishingStatus(ex.Message));
                        }
                    }
                }
            }
        }
Example #2
0
 protected override void InternalValidate()
 {
     base.InternalValidate();
     this.session = HygieneUtils.InstantiateType <ITenantThrottlingSession>("Microsoft.Exchange.Hygiene.Data.Reporting.ReportingSession");
 }