Exemplo n.º 1
0
        public static NetSuitePortTypeClient GetProxy()
        {
            try
            {
                NetSuitePortTypeClient proxy = new NetSuitePortTypeClient();

                proxy.preferences = new Preferences();
                proxy.preferences.ignoreReadOnlyFields          = true;
                proxy.preferences.ignoreReadOnlyFieldsSpecified = true;

                proxy.tokenPassport = CreateTokenPassport();

                return(proxy);
            }
            catch (Exception e)
            {
                int logId = AuditLog.AddLog("NetSuiteHelper GetProxy() error").Id;

                AuditLog.AddLogDetails(logId, AuditLogType.Error, e.Message);

                if (e.InnerException != null)
                {
                    AuditLog.AddLogDetails(logId, AuditLogType.Error, e.InnerException.Message);
                }

                throw;
            }
        }
Exemplo n.º 2
0
        public static bool SendMail(MailMessage message, MailPriority priority, int auditLogId = 0)
        {
            try
            {
                SmtpClient client   = new SmtpClient();
                string     smtpHost = ConfigurationManager.AppSettings["SmtpHost"];

                if (!String.IsNullOrEmpty(smtpHost))
                {
                    client.Host = smtpHost;
                }
                else
                {
                    client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                }

                message.Priority = priority;

                if (message.From == null)
                {
                    message.From = new MailAddress(ConfigurationManager.AppSettings["FromEmailAddress"]);
                }

                if (message.From == null)
                {
                    throw new InvalidOperationException("Mail can't be without sender");
                }

                client.Send(message);
            }
            catch (Exception ex)
            {
                try
                {
                    EventLog myLog       = new EventLog();
                    string   traceSource = "logging-event-source-name";
                    if (String.IsNullOrEmpty(traceSource))
                    {
                        traceSource = "NOC";
                    }

                    myLog.Source = traceSource;
                    myLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
                }
                catch
                {
                }

                if (auditLogId <= 0)
                {
                    auditLogId = AuditLog.AddLog("SendMail exception").Id;
                }

                IObjectManager manager    = (ManagerCache.GetManager(typeof(AuditLog)));
                AuditLog       log        = (AuditLog)manager.GetObject(auditLogId);
                string         messageLog = "";
                messageLog += "Expection: " + ex.ToString();
                if (ex.InnerException != null)
                {
                    messageLog += "\r\n<br/>Inner Exception: " + ex.InnerException.ToString();
                }
                messageLog += "\r\n<br/>Mail To: " + message.To.ToString();
                messageLog += "\r\n<br/>Mail Body: " + message.Body;
                log.AddLogDetails(AuditLogType.Error, messageLog);
            }

            return(true);
        }