コード例 #1
0
ファイル: StreamlineFax.cs プロジェクト: JaganPaineedi/SvnGit
        private async Task SendToRightFaxAsync(string pharmacyName, string faxNumber, string scriptFilePath, string subject)
        {
            HttpClient client = new HttpClient();
            //Set configuration
            string rightfaxAPIURL = System.Configuration.ConfigurationSettings.AppSettings["rightfaxAPIURL"];
            string rightfaxuser   = System.Configuration.ConfigurationSettings.AppSettings["rightfaxuser"];
            string rightfaxpasswd = System.Configuration.ConfigurationSettings.AppSettings["rightfaxpasswd"];
            string temppath       = System.Configuration.ConfigurationSettings.AppSettings["TempPath"];

            client.BaseAddress = new Uri(rightfaxAPIURL);
            var byteArray = Encoding.ASCII.GetBytes(rightfaxuser + ":" + rightfaxpasswd);

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

            try
            {
                //Upload attachment and get the generated URL location for the attachment
                Uri resultAttachmentURI = await UploadAttachment(client, new System.IO.FileInfo(scriptFilePath));

                RFAttachmentUrl oRFAttachmentURL = new RFAttachmentUrl
                {
                    AttachmentUrl = resultAttachmentURI.ToString()
                };


                // Create a new recipient
                RFRecipient oRecipient = new RFRecipient
                {
                    Name        = pharmacyName,
                    Destination = faxNumber
                };

                // Create a new fax
                SendJobRequest oSendJobRequest = new SendJobRequest
                {
                    UserID               = rightfaxuser,
                    HoldForPreview       = "true",
                    Priority             = "High",
                    Resolution           = "Fine",
                    CoversheetTemplateId = "1",
                    SendAfter            = DateTime.Now.ToString(), //UTC time
                    Recipients           = new List <RFRecipient> {
                        oRecipient
                    },
                    Attachments = new List <RFAttachmentUrl> {
                        oRFAttachmentURL
                    }
                };

                var url = await SubmitJobAsync(oSendJobRequest);
            }
            catch (Exception e)
            {
                throw new Exception("Failed to submit fax. " + e.Message);
            }
        }
コード例 #2
0
ファイル: StreamlineFax.cs プロジェクト: JaganPaineedi/SvnGit
        static async Task <Uri> SubmitJobAsync(SendJobRequest oSendJobRequest)
        {
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.PostAsJsonAsync("SendJobs", oSendJobRequest);

            response.EnsureSuccessStatusCode();
            //System.Windows.Forms.MessageBox.Show(response.ToString());
            return(response.Headers.Location);
        }