public OperationResult SendTheFax(string faxName, string faxPath, string recipientName,
            string faxNumber,string sendID,string applicationPath)
        {
            OperationResult operationResult = new OperationResult();

            FileStream fileStream;
            StreamReader reader = null; ;
            Stream data = null;
            WebResponse response = null;
            StreamWriter streamWriter = null;

            faxName = faxName.Replace("&", "");
            recipientName = recipientName.Replace("&", "");

            try
            {
                fileName = ConfigurationValues.ProcessFaxPath;

                fileStream = File.Create(fileName);

                fileStream.Close();

                streamWriter = File.AppendText(fileName);

                streamWriter.WriteLine("<?xml version=”1.0” encoding=”UTF-8”?>");  
                streamWriter.WriteLine("<schedule_fax>");
                streamWriter.WriteLine("<cover_page>");
                streamWriter.WriteLine("<enabled>false</enabled>");
                streamWriter.WriteLine("</cover_page>");
                streamWriter.WriteLine("<sender>");
                streamWriter.WriteLine("<name>" + faxName + "</name>");
                streamWriter.WriteLine("<email_address>" + sendID + "</email_address>");
                streamWriter.WriteLine("</sender>");
                streamWriter.WriteLine("<recipient>");
                streamWriter.WriteLine("<name>" + recipientName + "</name>");
                streamWriter.WriteLine("<fax_number>" + faxNumber + "</fax_number>");
                streamWriter.WriteLine("</recipient>");
                streamWriter.WriteLine("<attachment>");
                streamWriter.WriteLine("<location>inline</location>");
                streamWriter.WriteLine("<name>test.pdf</name>");
                streamWriter.WriteLine("<receipt_attachment>never</receipt_attachment>");
                streamWriter.WriteLine("<content_type>application/pdf</content_type>");
                streamWriter.WriteLine("<content_transfer_encoding>base64</content_transfer_encoding>");
                streamWriter.WriteLine("<content>");
                streamWriter.WriteLine(EncodePDFDocument(faxPath));
                streamWriter.WriteLine("</content>");
                streamWriter.WriteLine("</attachment>");
                streamWriter.WriteLine("<max_tries>3</max_tries>");
                streamWriter.WriteLine("<priority>1</priority>");
                streamWriter.WriteLine("<try_interval>600</try_interval>");
                streamWriter.WriteLine("<receipt>never</receipt>");
                streamWriter.WriteLine("<receipt_attachment>none</receipt_attachment>");
                streamWriter.WriteLine("</schedule_fax>");

                streamWriter.Close();

                ServicePointManager.Expect100Continue = false;

                //Create a request using a URL that can receive a post. 
                WebRequest request = WebRequest.Create("http://192.168.105.92/ffws/v1/ofax");


                string authInfo = "admin:admin";
                //string authInfo = userName + ":" + userPassword;
                authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
                request.Headers["Authorization"] = "Basic " + authInfo;

                //Add authentication to request  
                //request.Credentials = new NetworkCredential("admin", "admin");

                //Set the Method property of the request to POST.
                request.Method = "POST";

                //Set the ContentType property of the WebRequest.
                request.ContentType = "application/xml";

                //Get File size
                //FileInfo fileSize = new FileInfo("C:/Users/test/Documents/Visual Studio 2008/Projects/sendFax/sendFax/schedule.xml");
                FileInfo fileSize = new FileInfo(fileName);
                int len = (int)fileSize.Length;


                //Set the ContentLength property of the WebRequest.
                request.ContentLength = len;

                //Get the request stream.
                Stream dataStream = request.GetRequestStream();

                StreamReader textIn = new StreamReader(new FileStream(fileName,
                                                            FileMode.Open, FileAccess.Read));

                string TextLines = textIn.ReadToEnd();
                byte[] byteArray = Encoding.UTF8.GetBytes(TextLines);
                //Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);

                textIn.Close();
                //Close the Stream object.
                dataStream.Close();

                //Get the response.
                response = request.GetResponse();

                //Display the status.
                Console.WriteLine(((HttpWebResponse)response).StatusDescription);

                //Get the stream containing content returned by the server.
                data = response.GetResponseStream();

                //Open the stream using a StreamReader for easy access.
                reader = new StreamReader(data);

                //Read the content.
                string responseFromServer = reader.ReadToEnd();

                //Display the content.
                Console.WriteLine(responseFromServer);

                //Clean up the streams.
                reader.Close();
                data.Close();
                response.Close();
                operationResult.Success = true;
                return operationResult;
            }
            catch(Exception er)
            {
                try
                {
                    //Clean up the streams.
                    reader.Close();
                }
                catch { }
                try
                {
                    data.Close();
                }
                catch { }
                try
                {
                    response.Close();
                }
                catch { }
                try
                {
                    streamWriter.Close();
                }
                catch { }
                operationResult.Success = false;
                operationResult.AddMessage(er.ToString());
                return operationResult;
            }
        }
        private OperationResult CreateFaxRecord(string faxName, string faxNumber, string recipientName,
            string faxPath)
        {

            OperationResult operationResult = new OperationResult();            

            try
            {
                SendFax sendAFax = new AutomatedFaxBL.Models.SendFax();
                sendAFax.AccountID = "1001";
                sendAFax.UserID = ConfigurationValues.FaxAutomationUserName;
                sendAFax.FaxName = faxName;
                sendAFax.FaxPath = faxPath;
                sendAFax.FaxNumber = faxNumber;
                sendAFax.RecipientName = recipientName;
                sendAFax.Notes = string.Empty;
                sendAFax.PageCount = Utility.GetPDFPageCount(faxPath);
                sendAFax.FaxSent = "Y";
                sendAFax.InUse = "N";
                sendAFax.ToTif = "Y";
                sendAFax.CallWait = 0;
                sendAFax.TimesCalled = 0;
                sendAFax.Status = "New Fax Entry";
                sendAFax.ShowFax = "Y";
                sendAFax.CreateTime = DateTime.Now.ToShortDateString()
                    + " " + DateTime.Now.ToShortTimeString();
                sendAFax.CompletionTime = string.Empty;
                sendAFax.DateStamp = DateTime.Now.ToShortDateString()
                    + " " + DateTime.Now.ToShortTimeString();
                operationResult = faxRepository.SendFax(sendAFax);
                return operationResult;
            }
            catch(Exception er)
            {
                Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString());
                operationResult.Success = false;
                operationResult.ErrorMessage = er.ToString();
                return operationResult;
            }
        }