Пример #1
0
        private void CreateRequestFile(FaxRequest request, string path)
        {
            string       requestFile = path + "Request.xml";
            string       xmlData     = GetRequestXML(request);
            StreamWriter writer      = new StreamWriter(requestFile);

            writer.Write(xmlData);
            writer.Close();
        }
Пример #2
0
        public void SendToFaxGateway(string smtpServer, string fromAddr,string faxGatewayEmailAddr, FaxRequest request, string requestFilePath)
        {

            ValidateRequest(request);
            CreateRequestFile(request, requestFilePath);
            SmtpClient smtpClient = new SmtpClient(smtpServer);
            smtpClient.Host = smtpServer;
          
            MailMessage message  = new MailMessage(fromAddr,faxGatewayEmailAddr);
            GetAttachments(message,request, requestFilePath);
            message.Subject = "Fax Request";
            smtpClient.Send(message);
            message.Dispose();
            
        }
Пример #3
0
        private void GetAttachments(MailMessage message, FaxRequest request, string requestFilePath)
        {
            Attachment attachment = new Attachment(requestFilePath + "request.xml");

            message.Attachments.Add(attachment);
            foreach (var doc in request.Documents)
            {
                if (doc != null)
                {
                    var stream = new MemoryStream(doc.DocumentContents);

                    var documentFileName = doc.DocumentFileName;
                    if (!".TIF".Equals(Path.GetExtension(documentFileName), StringComparison.InvariantCultureIgnoreCase))
                    {
                        documentFileName = Path.ChangeExtension(documentFileName, ".tif");
                    }
                    Attachment att = new Attachment(stream, documentFileName, "image/tiff");
                    message.Attachments.Add(att);
                }
            }
        }
Пример #4
0
        private void GetAttachments(MailMessage message, FaxRequest request, string requestFilePath)
        {
            
            Attachment attachment = new Attachment(requestFilePath + "request.xml");
            message.Attachments.Add(attachment);            
            foreach (var doc in request.Documents)
            {                
                if (doc != null)
                {
                    var stream = new MemoryStream(doc.DocumentContents);

                    var documentFileName = doc.DocumentFileName;
                    if (!".TIF".Equals(Path.GetExtension(documentFileName), StringComparison.InvariantCultureIgnoreCase))
                    {
                        documentFileName = Path.ChangeExtension(documentFileName, ".tif");
                    }
                    Attachment att = new Attachment(stream, documentFileName, "image/tiff");
                    message.Attachments.Add(att);                                        
                }
            }

        }
Пример #5
0
        private string GetActionString(FaxRequest request)
        {
            using (var sw = new StringWriter())
            {
                using (var writer = new XmlTextWriter(sw))
                {
                    if (request.Action != null)
                    {
                        writer.WriteStartElement("actions");
                        writer.WriteStartElement("action");

                        WriteCallbackAction(request.Action.SuccessAction, writer, "onsuccess");
                        WriteCallbackAction(request.Action.FailureAction, writer, "onfail");

                        writer.WriteEndElement();
                        writer.WriteEndElement();
                        return(sw.ToString());
                    }
                }
            }
            return(null);
        }
Пример #6
0
        private string GetActionString(FaxRequest request)
        {
            using (var sw = new StringWriter())
            {

                using (var writer = new XmlTextWriter(sw))
                {                    
                    if (request.Action != null)
                    {
                        writer.WriteStartElement("actions");
                        writer.WriteStartElement("action");

                        WriteCallbackAction(request.Action.SuccessAction, writer, "onsuccess");
                        WriteCallbackAction(request.Action.FailureAction, writer, "onfail");

                        writer.WriteEndElement();
                        writer.WriteEndElement();
                        return sw.ToString();
                    }
                }
            }
            return null;
        }
Пример #7
0
        private string GetRequestXML(FaxRequest request)
        {
            StringWriter stringWriter = new StringWriter();
            XmlWriter writer = new XmlTextWriter(stringWriter);
            writer.WriteStartElement("Transmission");
            writer.WriteElementString("app_code",GetXmlStringValue(request.AppCode));
            stringWriter.Write('\n');
            writer.WriteElementString("app_ref",GetXmlStringValue(request.AppReference));
            stringWriter.Write('\n');
            writer.WriteElementString("app_sender", GetXmlStringValue(request.AppSender));
            stringWriter.Write('\n');
            WriteCallbackAction(request.ReceiptAction, writer, "receipt");
            
            writer.WriteStartElement("documents");
            
            IList<AttachDocument> documents = request.Documents;
            foreach (var doc in documents)
            {                
                if (doc != null)
                {
                    writer.WriteStartElement("document");
                    writer.WriteAttributeString("location", doc.Location);
                    writer.WriteAttributeString("total_pages", doc.TotalPages.ToString());
                    writer.WriteValue(GetFileName(doc.DocumentFileName));
                    writer.WriteEndElement();
                    stringWriter.Write('\n');
                }
            }
            writer.WriteEndElement();
            stringWriter.Write('\n');
            writer.WriteStartElement("transmit_instructions");
            writer.WriteStartElement("sendto");
            writer.WriteAttributeString("cover_required", "N");
            writer.WriteElementString("method", request.SendMethod);
            stringWriter.Write('\n');
            writer.WriteElementString("country_code", GetXmlStringValue(request.CountryCode));
            stringWriter.Write('\n');
            writer.WriteElementString("area_code", GetXmlStringValue(request.AreaCode));
            stringWriter.Write('\n');
            writer.WriteElementString("local_number", GetXmlStringValue(request.FaxNumber));
            stringWriter.Write('\n');
            writer.WriteElementString("email", GetXmlStringValue(request.EmailAddress));
            stringWriter.Write('\n');
            writer.WriteElementString("recipient", GetXmlStringValue(request.Recipient));
            stringWriter.Write('\n');
            string actionString = GetActionString(request);
            if (actionString != null) 
            {
                writer.WriteRaw(actionString);
                stringWriter.Write('\n');
            }            
            stringWriter.Write('\n');
            writer.WriteEndElement();
            stringWriter.Write('\n');
            writer.WriteEndElement();
            stringWriter.Write('\n');
            
            if (request.Vault.Name != null && !"".Equals(request.Vault.Name))
            {
                writer.WriteStartElement("vault_instructions");
                writer.WriteElementString("vault_name", GetXmlStringValue(request.Vault.Name));
                stringWriter.Write('\n');
                writer.WriteStartElement("vauld_doc_data");
                writer.WriteElementString("onbehalfofuser", GetXmlStringValue(request.Vault.OnBehalfofUser));
                stringWriter.Write('\n');
                writer.WriteElementString("title", GetXmlStringValue(request.Vault.Title));
                stringWriter.Write('\n');
                writer.WriteElementString("author", GetXmlStringValue(request.Vault.Author));
                stringWriter.Write('\n');
                writer.WriteElementString("desc", GetXmlStringValue(request.Vault.Description));
                stringWriter.Write('\n');
                Hashtable docProps = request.Vault.VaultIndex;

                if (docProps.Count > 0)
                {
                    writer.WriteStartElement("vault_index");
                    IDictionaryEnumerator enumerator = docProps.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        string key = (string) enumerator.Key;
                        string val = (string)enumerator.Value;

                        writer.WriteStartElement("index");
                        writer.WriteAttributeString("id", GetXmlStringValue(key));
                        writer.WriteValue(GetXmlStringValue(val));
                        writer.WriteEndElement();
                        stringWriter.Write('\n');
                    }
                    writer.WriteEndElement();
                    stringWriter.Write('\n');
                 
                }
            }

            writer.WriteEndElement();
            stringWriter.Write('\n');  
            stringWriter.Flush();
            String returnString = stringWriter.ToString();
            writer.Close();
            stringWriter.Close();
            return returnString;
        }
Пример #8
0
        private void CreateRequestFile(FaxRequest request, string path)
        {
            string requestFile = path + "Request.xml";
            string xmlData = GetRequestXML(request);
            StreamWriter writer = new StreamWriter(requestFile);
            writer.Write(xmlData);
            writer.Close();

        }
Пример #9
0
        private void ValidateRequest(FaxRequest request)
        {
            if (request == null)
            {
                throw new Exception("Request is empty." + Environment.NewLine +
                    "Error CNF-376 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }
            if  (request.AppCode == null || "".Equals(request.AppCode) )
            {
                throw new Exception("App Code is empty." + Environment.NewLine +
                    "Error CNF-377 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }
            if (request.AppSender == null || "".Equals(request.AppSender))
            {
                throw new Exception("App Sender is empty." + Environment.NewLine +
                    "Error CNF-378 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }
            if (request.AppReference == null || "".Equals(request.AppReference))
            {
                throw new Exception("App Reference is empty." + Environment.NewLine +
                    "Error CNF-379 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }
            if (request.Documents.Count <= 0)
            {
                throw new Exception("No document is found to attach." + Environment.NewLine +
                    "Error CNF-380 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }

            IList<AttachDocument> documents = request.Documents;
            foreach (AttachDocument doc in documents)
            {                
                if (doc == null)
                {
                    throw new Exception("Invalid attached document" + Environment.NewLine +
                    "Error CNF-381 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
                if (doc.TotalPages <= 0)
                {
                    throw new Exception("Invalid value for Total pages for the attached document." + Environment.NewLine +
                    "Error CNF-382 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
                if (string.IsNullOrEmpty(doc.DocumentFileName))
                {
                    throw new Exception("The attached document can not be null" + Environment.NewLine +
                    "Error CNF-383 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }

                if (doc.DocumentContents == null)
                {
                    throw new Exception("The attachement file " + doc.DocumentFileName + " does not exist." + Environment.NewLine +
                    "Error CNF-384 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
            }

            if (request.FaxNumber == null || "".Equals(request.FaxNumber))
            {
                if (request.SendMethod.Equals("FAX"))
                {
                    throw new Exception("Fax Number is empty" + Environment.NewLine +
                    "Error CNF-385 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
            }

            if (request.EmailAddress == null || "".Equals(request.EmailAddress))
            {
                if (request.SendMethod.Equals("EMAIL"))
                {
                    throw new Exception("Email Address is empty" + Environment.NewLine +
                    "Error CNF-386 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
            }

            if ( request.Recipient == null || "".Equals(request.Recipient))
            {
                throw new Exception("The recipient is empty." + Environment.NewLine +
                    "Error CNF-387 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }

        }
Пример #10
0
        public void SendToFaxGateway(string smtpServer, string fromAddr, string faxGatewayEmailAddr, FaxRequest request, string requestFilePath)
        {
            ValidateRequest(request);
            CreateRequestFile(request, requestFilePath);
            SmtpClient smtpClient = new SmtpClient(smtpServer);

            smtpClient.Host = smtpServer;

            MailMessage message = new MailMessage(fromAddr, faxGatewayEmailAddr);

            GetAttachments(message, request, requestFilePath);
            message.Subject = "Fax Request";
            smtpClient.Send(message);
            message.Dispose();
        }
Пример #11
0
        private string GetRequestXML(FaxRequest request)
        {
            StringWriter stringWriter = new StringWriter();
            XmlWriter    writer       = new XmlTextWriter(stringWriter);

            writer.WriteStartElement("Transmission");
            writer.WriteElementString("app_code", GetXmlStringValue(request.AppCode));
            stringWriter.Write('\n');
            writer.WriteElementString("app_ref", GetXmlStringValue(request.AppReference));
            stringWriter.Write('\n');
            writer.WriteElementString("app_sender", GetXmlStringValue(request.AppSender));
            stringWriter.Write('\n');
            WriteCallbackAction(request.ReceiptAction, writer, "receipt");

            writer.WriteStartElement("documents");

            IList <AttachDocument> documents = request.Documents;

            foreach (var doc in documents)
            {
                if (doc != null)
                {
                    writer.WriteStartElement("document");
                    writer.WriteAttributeString("location", doc.Location);
                    writer.WriteAttributeString("total_pages", doc.TotalPages.ToString());
                    writer.WriteValue(GetFileName(doc.DocumentFileName));
                    writer.WriteEndElement();
                    stringWriter.Write('\n');
                }
            }
            writer.WriteEndElement();
            stringWriter.Write('\n');
            writer.WriteStartElement("transmit_instructions");
            writer.WriteStartElement("sendto");
            writer.WriteAttributeString("cover_required", "N");
            writer.WriteElementString("method", request.SendMethod);
            stringWriter.Write('\n');
            writer.WriteElementString("country_code", GetXmlStringValue(request.CountryCode));
            stringWriter.Write('\n');
            writer.WriteElementString("area_code", GetXmlStringValue(request.AreaCode));
            stringWriter.Write('\n');
            writer.WriteElementString("local_number", GetXmlStringValue(request.FaxNumber));
            stringWriter.Write('\n');
            writer.WriteElementString("email", GetXmlStringValue(request.EmailAddress));
            stringWriter.Write('\n');
            writer.WriteElementString("recipient", GetXmlStringValue(request.Recipient));
            stringWriter.Write('\n');
            string actionString = GetActionString(request);

            if (actionString != null)
            {
                writer.WriteRaw(actionString);
                stringWriter.Write('\n');
            }
            stringWriter.Write('\n');
            writer.WriteEndElement();
            stringWriter.Write('\n');
            writer.WriteEndElement();
            stringWriter.Write('\n');

            if (request.Vault.Name != null && !"".Equals(request.Vault.Name))
            {
                writer.WriteStartElement("vault_instructions");
                writer.WriteElementString("vault_name", GetXmlStringValue(request.Vault.Name));
                stringWriter.Write('\n');
                writer.WriteStartElement("vauld_doc_data");
                writer.WriteElementString("onbehalfofuser", GetXmlStringValue(request.Vault.OnBehalfofUser));
                stringWriter.Write('\n');
                writer.WriteElementString("title", GetXmlStringValue(request.Vault.Title));
                stringWriter.Write('\n');
                writer.WriteElementString("author", GetXmlStringValue(request.Vault.Author));
                stringWriter.Write('\n');
                writer.WriteElementString("desc", GetXmlStringValue(request.Vault.Description));
                stringWriter.Write('\n');
                Hashtable docProps = request.Vault.VaultIndex;

                if (docProps.Count > 0)
                {
                    writer.WriteStartElement("vault_index");
                    IDictionaryEnumerator enumerator = docProps.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        string key = (string)enumerator.Key;
                        string val = (string)enumerator.Value;

                        writer.WriteStartElement("index");
                        writer.WriteAttributeString("id", GetXmlStringValue(key));
                        writer.WriteValue(GetXmlStringValue(val));
                        writer.WriteEndElement();
                        stringWriter.Write('\n');
                    }
                    writer.WriteEndElement();
                    stringWriter.Write('\n');
                }
            }

            writer.WriteEndElement();
            stringWriter.Write('\n');
            stringWriter.Flush();
            String returnString = stringWriter.ToString();

            writer.Close();
            stringWriter.Close();
            return(returnString);
        }
Пример #12
0
        private void ValidateRequest(FaxRequest request)
        {
            if (request == null)
            {
                throw new Exception("Request is empty." + Environment.NewLine +
                                    "Error CNF-376 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }
            if (request.AppCode == null || "".Equals(request.AppCode))
            {
                throw new Exception("App Code is empty." + Environment.NewLine +
                                    "Error CNF-377 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }
            if (request.AppSender == null || "".Equals(request.AppSender))
            {
                throw new Exception("App Sender is empty." + Environment.NewLine +
                                    "Error CNF-378 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }
            if (request.AppReference == null || "".Equals(request.AppReference))
            {
                throw new Exception("App Reference is empty." + Environment.NewLine +
                                    "Error CNF-379 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }
            if (request.Documents.Count <= 0)
            {
                throw new Exception("No document is found to attach." + Environment.NewLine +
                                    "Error CNF-380 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }

            IList <AttachDocument> documents = request.Documents;

            foreach (AttachDocument doc in documents)
            {
                if (doc == null)
                {
                    throw new Exception("Invalid attached document" + Environment.NewLine +
                                        "Error CNF-381 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
                if (doc.TotalPages <= 0)
                {
                    throw new Exception("Invalid value for Total pages for the attached document." + Environment.NewLine +
                                        "Error CNF-382 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
                if (string.IsNullOrEmpty(doc.DocumentFileName))
                {
                    throw new Exception("The attached document can not be null" + Environment.NewLine +
                                        "Error CNF-383 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }

                if (doc.DocumentContents == null)
                {
                    throw new Exception("The attachement file " + doc.DocumentFileName + " does not exist." + Environment.NewLine +
                                        "Error CNF-384 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
            }

            if (request.FaxNumber == null || "".Equals(request.FaxNumber))
            {
                if (request.SendMethod.Equals("FAX"))
                {
                    throw new Exception("Fax Number is empty" + Environment.NewLine +
                                        "Error CNF-385 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
            }

            if (request.EmailAddress == null || "".Equals(request.EmailAddress))
            {
                if (request.SendMethod.Equals("EMAIL"))
                {
                    throw new Exception("Email Address is empty" + Environment.NewLine +
                                        "Error CNF-386 in " + PROJ_FILE_NAME + ".ValidateRequest().");
                }
            }

            if (request.Recipient == null || "".Equals(request.Recipient))
            {
                throw new Exception("The recipient is empty." + Environment.NewLine +
                                    "Error CNF-387 in " + PROJ_FILE_NAME + ".ValidateRequest().");
            }
        }
Пример #13
0
        private FaxRequest GetRequest()
        {
            FaxRequest request = new FaxRequest();

            request.AppCode = "CNF";
            request.AppReference = "293023";
            request.AppSender = "srajaman";
            request.ReceiptMethodType = "email";
            request.ReceiptMethodValue = "*****@*****.**";
            request.Recipient = "Samy Raj";
            request.AddDocument(@"c:\temp\test\test3.Tif", 1);
            request.FaxNumber = "3555330";
            request.Action.SucessMethodType = "email";
            request.Action.SucessMethodValue = "*****@*****.**";
            request.Action.FailMethodType = "email";
            request.Action.FailMethodValue = "*****@*****.**";


            return request;
        }