Beispiel #1
0
        public static T DeserializeObject <T>(string _xml)
        {
            XmlSerializer ser = new XmlSerializer(typeof(T));
            MemoryStream  ms  = null;

            T output = default(T);

            try
            {
                byte[] arr = System.Text.Encoding.ASCII.GetBytes(_xml);

                ms = new MemoryStream(arr, false);

                output = (T)ser.Deserialize(ms);
            }
            catch (Exception ex)
            {
                TraceFileHelper.Exception(ex.ToString());
            }
            finally
            {
                if (ms != null)
                {
                    ms.Close();
                }
            }

            return(output);
        }
Beispiel #2
0
        public static object DeserializeObject(Type _outputType, string _xml)
        {
            XmlSerializer ser = new XmlSerializer(_outputType);
            MemoryStream  ms  = null;

            Object output = null;

            try
            {
                byte[] arr = System.Text.Encoding.ASCII.GetBytes(_xml);

                ms = new MemoryStream(arr, false);

                output = ser.Deserialize(ms);
            }
            catch (Exception ex)
            {
                TraceFileHelper.Exception(ex.ToString());
            }
            finally
            {
                if (ms != null)
                {
                    ms.Close();
                }
            }

            return(output);
        }
Beispiel #3
0
        public static void SendMessage(MailMessage _mail)
        {
            try
            {
                SmtpClient client = new SmtpClient();
                client.Host = Config.GetSettingValue("SMTP_HOST");


                string userName = Config.GetSettingValue("SMTP_USER");
                string password = Config.GetSettingValue("SMTP_PASSWORD");
                string domain   = Config.GetSettingValue("SMTP_DOMAIN");

                NetworkCredential credentials = new NetworkCredential(userName, password, domain);
                client.Credentials = credentials;
                try
                {
                    client.Send(_mail);
                    string logMessage = String.Format("Email sent to {0} with subject {1}", _mail.To[0].User,
                                                      _mail.Subject);
                    TraceFileHelper.Info(logMessage);
                }
                catch (Exception ex)
                {
                    TraceFileHelper.Exception(ex.ToString());

                    string logMessage = String.Format("Unable to send email to {0} with subject {1}", _mail.To[0].User,
                                                      _mail.Subject);
                    TraceFileHelper.Info(logMessage);
                }
            }
            catch (Exception ex)
            {
                TraceFileHelper.Exception(ex);
            }
        }
Beispiel #4
0
        public static object DeserializeObject(Type _outputType, Stream _data)
        {
            XmlSerializer ser = new XmlSerializer(_outputType);

            Object output = null;

            try
            {
                output = ser.Deserialize(_data);
            }
            catch (Exception ex)
            {
                TraceFileHelper.Exception(ex.ToString());
            }
            finally
            {
                // Don't close stream here the calling method is responsible
            }

            return(output);
        }