Esempio n. 1
0
        public async Task ProcessAttachment(long incidentId, string fileName)
        {
            String            fileAsBase64 = Convert.ToBase64String(File.ReadAllBytes(fileName));
            AttachmentWrapper payload      = new AttachmentWrapper();

            payload.Attachment = IncidentAttachment.CreateIncidentAttachment(Path.GetFileName(fileName), fileAsBase64);

            string createAttachementUri = "https://icm.ad.msft.net/api/cert/incidents(" + incidentId
                                          + ")/CreateAttachment";

            Logger.DebugFormat("CreateAttachementUri {0}", createAttachementUri);

            try
            {
                using (WebRequestHandler handler = new WebRequestHandler())
                {
                    handler.ClientCertificates.Add(certificate);

                    using (HttpClient client = new HttpClient(handler))
                    {
                        client.BaseAddress = new Uri(createAttachementUri);
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                        var response = await client.PostAsJsonAsync(createAttachementUri, payload);

                        Logger.InfoFormat(response.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex.ToString());
            }
        }
Esempio n. 2
0
 public static IncidentAttachment CreateIncidentAttachment(string filename, string contentsBase64)
 {
     IncidentAttachment incidentAttachment = new IncidentAttachment();
     incidentAttachment.Filename = filename;
     incidentAttachment.ContentsBase64 = contentsBase64;
     return incidentAttachment;
 }