Beispiel #1
0
        private static string MakeNotificationCall(Task task, List <SyncChangeInfo> syncChangeInfos, bool useFullSync, bool syncNow, IConfigurationSession dataSession, ExecutionLog logger)
        {
            string text = dataSession.GetOrgContainer().OrganizationId.ToExternalDirectoryOrganizationId();
            Guid   tenantId;

            if (!Guid.TryParse(text, out tenantId))
            {
                task.WriteWarning(Strings.WarningInvalidTenant(text));
                return("Error ExternalID not a guid");
            }
            string url    = string.Format("{0}(guid'{1}')", UnifiedPolicyConfiguration.GetInstance().GetIntuneEndpointUrl(dataSession), text);
            string body   = IntuneCompliancePolicySyncNotificationClient.CreateJsonNotificationBody(tenantId, useFullSync, syncNow, syncChangeInfos);
            string result = null;

            try
            {
                result = IntuneCompliancePolicySyncNotificationClient.Send(url, body, dataSession.GetOrgContainer().OrganizationId, dataSession, logger, task);
            }
            catch (WebException ex)
            {
                logger.LogOneEntry(task.GetType().Name, string.Empty, ExecutionLog.EventType.Warning, string.Format("We failed to notify workload '{0}'", Workload.Intune), ex);
                task.WriteVerbose(ex.ToString());
                result = ex.ToString();
            }
            return(result);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private static string Send(string url, string body, OrganizationId tenantid, IConfigurationSession dataSession, ExecutionLog logger, Task task)
        {
            HttpClientHandler handler = new HttpClientHandler
            {
                PreAuthenticate = true
            };
            string acstoken = IntuneCompliancePolicySyncNotificationClient.GetACSToken(tenantid, dataSession, logger, task);
            string result;

            using (HttpClient httpClient = new HttpClient(handler))
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", acstoken);
                httpClient.DefaultRequestHeaders.Add("api-version", "1.0");
                StringContent       content             = new StringContent(body, Encoding.UTF8, "application/json");
                HttpResponseMessage httpResponseMessage = null;
                HttpWebResponse     httpWebResponse     = null;
                try
                {
                    httpResponseMessage = httpClient.PutAsync(url, content).Result;
                }
                catch (WebException ex)
                {
                    httpWebResponse = (HttpWebResponse)ex.Response;
                    Stream   responseStream = httpWebResponse.GetResponseStream();
                    Encoding encoding       = Encoding.GetEncoding("utf-8");
                    string   text           = "Fail to notify: ";
                    if (responseStream != null)
                    {
                        StreamReader streamReader = new StreamReader(responseStream, encoding);
                        char[]       array        = new char[256];
                        for (int i = streamReader.Read(array, 0, 256); i > 0; i = streamReader.Read(array, 0, 256))
                        {
                            text += new string(array, 0, i);
                        }
                    }
                    logger.LogOneEntry(task.GetType().Name, string.Empty, ExecutionLog.EventType.Error, text, ex);
                }
                string text2;
                if (httpResponseMessage != null)
                {
                    text2 = ((httpResponseMessage.StatusCode == HttpStatusCode.OK) ? string.Empty : (httpResponseMessage.StatusCode + " " + httpResponseMessage.Content.ReadAsStringAsync().Result));
                }
                else if (httpWebResponse != null)
                {
                    text2 = httpWebResponse.StatusDescription;
                }
                else
                {
                    text2 = "Failed";
                }
                result = text2;
            }
            return(result);
        }
Beispiel #4
0
 protected override IEnumerable <ChangeNotificationData> OnNotifyChanges(IEnumerable <UnifiedPolicyStorageBase> bindingStorageObjects, IEnumerable <UnifiedPolicyStorageBase> ruleStorageObjects)
 {
     return(IntuneCompliancePolicySyncNotificationClient.NotifyChange(this, base.DataObject, ruleStorageObjects, (IConfigurationSession)base.DataSession, this.executionLogger));
 }
Beispiel #5
0
 protected override IEnumerable <ChangeNotificationData> OnNotifyChanges()
 {
     return(IntuneCompliancePolicySyncNotificationClient.NotifyChange(this, this.DataObject, new List <UnifiedPolicyStorageBase>(), (IConfigurationSession)base.DataSession, this.executionLogger));
 }