public static CompliancePolicySyncNotificationClient Create(IConfigurationSession configurationSession, WriteVerboseDelegate writeVerboseDelegate)
        {
            ArgumentValidator.ThrowIfNull("configurationSession", configurationSession);
            OrganizationId organizationId = configurationSession.GetOrgContainer().OrganizationId;

            return(ProvisioningCache.Instance.TryAddAndGetOrganizationDictionaryValue <CompliancePolicySyncNotificationClient, Workload>(CannedProvisioningCacheKeys.OrganizationUnifiedPolicyNotificationClients, organizationId, Workload.SharePoint, delegate()
            {
                if (writeVerboseDelegate != null)
                {
                    writeVerboseDelegate(Strings.VerboseCreateNotificationClient(Workload.SharePoint.ToString()));
                }
                Uri syncSvrUrlFromCache = CompliancePolicySyncNotificationClient.GetSyncSvrUrlFromCache(SyncSvcEndPointType.RestOAuth);
                ICredentials credentials = UnifiedPolicyConfiguration.GetInstance().GetCredentials(configurationSession, null);
                Uri uri = null;
                Uri uri2 = null;
                UnifiedPolicyConfiguration.GetInstance().GetTenantSharePointUrls(configurationSession, out uri, out uri2);
                if (uri == null || uri2 == null || syncSvrUrlFromCache == null)
                {
                    throw new CompliancePolicySyncNotificationClientException(Strings.ErrorCannotInitializeNotificationClientToSharePoint(uri, uri2, syncSvrUrlFromCache));
                }
                SpCompliancePolicySyncNotificationClient result = new SpCompliancePolicySyncNotificationClient(uri, uri2, credentials, syncSvrUrlFromCache);
                if (writeVerboseDelegate != null)
                {
                    writeVerboseDelegate(Strings.VerboseSpNotificationClientInfo(uri, syncSvrUrlFromCache, credentials.GetType().Name));
                }
                return result;
            }));
        }
Пример #2
0
        private static string CreateJsonNotificationBody(Guid tenantId, bool useFullSync, bool syncNow, IEnumerable <SyncChangeInfo> syncChangeInfos)
        {
            Uri syncSvrUrlFromCache = CompliancePolicySyncNotificationClient.GetSyncSvrUrlFromCache(SyncSvcEndPointType.SoapOAuth);

            IntuneCompliancePolicySyncNotificationClient.ODMSBody odmsbody = new IntuneCompliancePolicySyncNotificationClient.ODMSBody
            {
                Key               = tenantId.ToString(),
                TenantId          = tenantId.ToString(),
                SyncSvcUrl        = syncSvrUrlFromCache.AbsoluteUri,
                FullSyncForTenant = useFullSync.ToString(),
                SyncNow           = syncNow.ToString(),
                ChangeInfoList    = new List <IntuneCompliancePolicySyncNotificationClient.ChangeInfo>()
            };
            foreach (SyncChangeInfo syncChangeInfo in syncChangeInfos)
            {
                odmsbody.ChangeInfoList.Add(new IntuneCompliancePolicySyncNotificationClient.ChangeInfo
                {
                    ChangeType = syncChangeInfo.ChangeType.ToString("d"),
                    ObjectId   = syncChangeInfo.ObjectId.ToString(),
                    ObjectType = syncChangeInfo.ObjectType.ToString("d"),
                    Version    = syncChangeInfo.Version.InternalStorage.ToString()
                });
            }
            string result;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(IntuneCompliancePolicySyncNotificationClient.ODMSBody));
                dataContractJsonSerializer.WriteObject(memoryStream, odmsbody);
                memoryStream.Seek(0L, SeekOrigin.Begin);
                byte[] array = new byte[memoryStream.Length];
                result = ((memoryStream.Read(array, 0, (int)memoryStream.Length) > 0) ? Encoding.UTF8.GetString(array) : string.Empty);
            }
            return(result);
        }
        protected override string InternalNotifyPolicyConfigChanges(IEnumerable <SyncChangeInfo> syncChangeInfos, bool fullSync, bool syncNow)
        {
            NewCompliancePolicySyncNotificationCmdlet newCompliancePolicySyncNotificationCmdlet = new NewCompliancePolicySyncNotificationCmdlet();

            newCompliancePolicySyncNotificationCmdlet.HostServerName = this.pswsHostUrl.Host;
            newCompliancePolicySyncNotificationCmdlet.Port           = this.pswsHostUrl.Port;
            newCompliancePolicySyncNotificationCmdlet.Authenticator  = Authenticator.Create(this.credentials);
            newCompliancePolicySyncNotificationCmdlet.Identity       = CompliancePolicySyncNotificationClient.GetClientInfoIdentifier(syncChangeInfos);
            newCompliancePolicySyncNotificationCmdlet.SyncSvcUrl     = this.syncSvcUrl.AbsoluteUri;
            newCompliancePolicySyncNotificationCmdlet.FullSync       = fullSync;
            newCompliancePolicySyncNotificationCmdlet.SyncNow        = syncNow;
            newCompliancePolicySyncNotificationCmdlet.RequestTimeout = new int?(150000);
            if (syncChangeInfos != null)
            {
                newCompliancePolicySyncNotificationCmdlet.SyncChangeInfos = (from syncChangeInfo in syncChangeInfos
                                                                             select syncChangeInfo.ToString()).ToArray <string>();
            }
            CompliancePolicySyncNotification compliancePolicySyncNotification = newCompliancePolicySyncNotificationCmdlet.Run();

            if (compliancePolicySyncNotification == null || string.IsNullOrEmpty(compliancePolicySyncNotification.Identity))
            {
                throw new CompliancePolicySyncNotificationClientException(Strings.ErrorCompliancePolicySyncNotificationClient(Workload.Exchange.ToString(), (newCompliancePolicySyncNotificationCmdlet.Exception != null) ? newCompliancePolicySyncNotificationCmdlet.Exception.Message : string.Empty), newCompliancePolicySyncNotificationCmdlet.Exception);
            }
            return(compliancePolicySyncNotification.Identity);
        }
        protected override string InternalNotifyPolicyConfigChanges(IEnumerable <SyncChangeInfo> syncChangeInfos, bool fullSync, bool syncNow)
        {
            string clientInfoIdentifier = CompliancePolicySyncNotificationClient.GetClientInfoIdentifier(syncChangeInfos);

            this.spPolicyCenterSite.NotifyUnifiedPolicySync(clientInfoIdentifier, this.syncSvcUrl.AbsoluteUri, (from syncChangeInfo in syncChangeInfos
                                                                                                                select syncChangeInfo.ToString()).ToArray <string>(), syncNow, fullSync);
            return(clientInfoIdentifier);
        }
        internal static string NotifyChangesByWorkload(Task task, IConfigurationSession configurationSession, Workload workload, IEnumerable <SyncChangeInfo> syncChangeInfos, bool fullSync, bool syncNow, ExecutionLog logger, Type client, out string notificationIdentifier)
        {
            Exception exception = null;

            notificationIdentifier = string.Empty;
            string text = string.Empty;

            try
            {
                CompliancePolicySyncNotificationClient compliancePolicySyncNotificationClient = AggregatedNotificationClients.workloadToNotificationClientsGetter[workload](configurationSession, new WriteVerboseDelegate(task.WriteVerbose));
                if (compliancePolicySyncNotificationClient != null)
                {
                    task.WriteVerbose(Strings.VerboseNotifyWorkloadWithChanges(workload.ToString(), string.Concat(from syncChangeInfo in syncChangeInfos
                                                                                                                  select syncChangeInfo.ToString())));
                    notificationIdentifier = compliancePolicySyncNotificationClient.NotifyPolicyConfigChanges(syncChangeInfos, fullSync, syncNow);
                    task.WriteVerbose(Strings.VerboseNotifyWorkloadWithChangesSuccess(workload.ToString(), notificationIdentifier));
                }
                else
                {
                    text = Strings.WarningNotificationClientIsMissing(workload.ToString());
                }
            }
            catch (CompliancePolicySyncNotificationClientException ex)
            {
                text      = Strings.ErrorMessageForNotificationFailure(workload.ToString(), ex.Message);
                exception = ex;
            }
            if (!string.IsNullOrEmpty(text))
            {
                logger.LogOneEntry(client.Name, string.Empty, ExecutionLog.EventType.Warning, string.Format("We failed to notify workload '{0}' with error message '{1}'", workload, text), exception);
                MonitoringItemErrorPublisher.Instance.PublishEvent("UnifiedPolicySync.SendNotificationError", UnifiedPolicyConfiguration.GetInstance().GetOrganizationIdKey(configurationSession), string.Format("Workload={0};Timestamp={1}", workload, DateTime.UtcNow), exception);
            }
            else
            {
                ExecutionLog.EventType eventType = ExecutionLog.EventType.Verbose;
                string   name          = client.Name;
                string   correlationId = notificationIdentifier;
                string   format        = "Notification '{0}' was sent to workload '{1}' with sync change info: '{2}'";
                object[] array         = new object[3];
                array[0] = notificationIdentifier;
                array[1] = workload;
                array[2] = string.Join(",", from x in syncChangeInfos
                                       select x.ToString());
                logger.LogOneEntry(eventType, name, correlationId, format, array);
            }
            return(text);
        }