Example #1
0
 /// <summary>
 /// Method to log messages to INTERFACE_LOG table and INTERFACE_XML_DATA
 /// </summary>
 /// <param name="messageLogger">Instance of SendReceiveMessageLogger</param>
 public void LogErrorMessages(SendReceiveMessageLogger messageLogger, string interfacePoint)
 {
     try
     {
         if (messageLogger != null)
         {
             messageLogger.dataContext    = DataContext;
             messageLogger.Interactive    = Equals(Mode, 'I');
             messageLogger.Correlation_Id = GetCorrelationId();
             messageLogger.Interface_Name = interfacePoint;
             messageLogger.Component_Name = "GTech Client";
             messageLogger.logEntry();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #2
0
        /// <summary>
        /// Sends an request to the EdgeFrontier Email system
        /// </summary>
        /// <returns>Returns 'true' if successfull and 'false' if it fails.</returns>
        public bool sendEmail()
        {
            XmlSerializer   sendEmailSerializer = new XmlSerializer(typeof(eMailRequest));
            string          tmpXML  = string.Empty;
            StringWriter    StrWrtr = new StringWriter();
            XmlWriter       XmlWrtr = XmlWriter.Create(StrWrtr);
            HttpWebRequest  request;
            IGTApplication  tmpApp = null;
            HttpWebResponse webresponse;
            StreamReader    tmpReader;
            StringBuilder   strBldr = new StringBuilder();
            XmlDocument     tmpXDoc = new XmlDocument();

            System.IO.Stream         requestStream;
            byte[]                   XMLBytes;
            string                   tmpException = string.Empty;
            SendReceiveMessageLogger msgLogger;
            bool logger = true;

            try
            {
                if (GTDataContext == null)
                {
                    tmpApp        = GTClassFactory.Create <IGTApplication>();
                    GTDataContext = tmpApp.DataContext;
                }
                if (EFUrl == string.Empty)
                {
                    queryForURL();
                }
                if (EmailRequest.Attachments == string.Empty)
                {
                    EmailRequest.Attachments = " ";
                }
                correlationId = getCorrelationId();

                // serialize the Email request
                sendEmailSerializer.Serialize(XmlWrtr, EmailRequest);
                tmpXML = StrWrtr.ToString();
                tmpXML = tmpXML.Replace("</eMailRequest>", "<Correlation_Id>" + correlationId + "</Correlation_Id></eMailRequest>"); // code for Testing

                // create and send the web request.
                XMLBytes = System.Text.Encoding.ASCII.GetBytes(tmpXML);

                // log the message to be sent.
                msgLogger                = new SendReceiveMessageLogger();
                msgLogger.Interactive    = GTInteractive;
                msgLogger.Interface_Name = "Send Email";
                msgLogger.Component_Name = "GTech Client";
                msgLogger.Correlation_Id = correlationId;
                msgLogger.xmlMessage     = tmpXML;
                logger = msgLogger.logEntry();  // add a log entry

                // send the request
                request               = HttpWebRequest.Create(EFUrl) as HttpWebRequest;
                request.Method        = "POST";
                request.ContentLength = XMLBytes.Length;
                request.ContentType   = "text/xml; encoding='utf-8'";
                requestStream         = request.GetRequestStream();
                requestStream.Write(XMLBytes, 0, XMLBytes.Length);
                requestStream.Close();
                webresponse = request.GetResponse() as HttpWebResponse;

                //Get the Response.

                tmpReader = new StreamReader(webresponse.GetResponseStream());
                strBldr.Append(tmpReader.ReadToEnd());

                // Log the responce
                // get the status from the
                tmpXDoc.LoadXml(strBldr.ToString());
                XmlNode     root       = tmpXDoc.FirstChild;
                XmlNodeList tmpNodeLst = root.SelectNodes("//Status");
                tmpNodeLst[0].ToString();
                // If the status is failure.
                if (tmpNodeLst[0].InnerText == "FAILURE")
                {
                    tmpNodeLst = root.SelectNodes("//ErrorMsg");
                    string errStr = tmpNodeLst[0].InnerText;
                    errStr               = errStr.Replace("'", "''");
                    tmpException         = "Email Failure " + errStr;
                    msgLogger.Log_Detail = "SendEmail.sendEmail Error: " + tmpException;
                    msgLogger.xmlMessage = tmpXDoc.OuterXml;
                    //logToDB("SendEmail.sendEmail Error:" + tmpException);
                    logger = msgLogger.logEntry();
                    if (GTInteractive == true)
                    {
                        MessageBox.Show("SendEmail: " + tmpException, "sendEmail Error", MessageBoxButtons.OK);
                    }
                    logger = false;
                }
                else
                {
                    msgLogger.xmlMessage = tmpXDoc.OuterXml;
                    msgLogger.Log_Detail = "Success";
                    logger = msgLogger.logEntry();
                }
            }
            catch (Exception e)
            {
                if (GTInteractive == true)
                {
                    MessageBox.Show("SendEmail: " + e.Message, "sendEmail Error", MessageBoxButtons.OK);
                    logger = false;
                }
                else
                {
                    logToDB("SendEmail.sendEmail Error: " + e.Message);
                }
            }
            return(logger);
        }