Example #1
0
 private static void GetExceptionInfo(System.Exception ex, ref StringBuilder message, ref StringBuilder stackTrace)
 {
     if (ex == null)
     {
         return;
     }
     if (message == null)
     {
         message = new StringBuilder();
     }
     if (stackTrace == null)
     {
         stackTrace = new StringBuilder();
     }
     if (!string.IsNullOrWhiteSpace(ex.Message))
     {
         message.AppendLine(ex.Message);
     }
     if (!string.IsNullOrWhiteSpace(ex.StackTrace))
     {
         stackTrace.AppendLine(ex.StackTrace);
     }
     if (ex is Managers.ManagerException)
     {
         Managers.ManagerException mgrEx = ex as Managers.ManagerException;
         if (mgrEx != null && mgrEx.Errors != null)
         {
             foreach (System.Exception errEx in mgrEx.Errors)
             {
                 GetExceptionInfo(errEx, ref message, ref stackTrace);
             }
         }
     }
 }
Example #2
0
        public static void LogManagerError(Managers.ManagerException exception)
        {
            System.Windows.Forms.MessageBox.Show(exception.Message, "Error",
                                                 System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

            // log to file
            StringBuilder message    = new StringBuilder();
            StringBuilder stackTrace = new StringBuilder();

            GetExceptionInfo(exception, ref message, ref stackTrace);
            Log("LogManagerError_Message", message.ToString());
            Log("LogManagerError_Stack", stackTrace.ToString());
        }
Example #3
0
            public static bool SendEmail(Word.Document wDoc, RenderSettings renderSetting, ref List <string> tempFiles)
            {
                try
                {
                    #region 1. get email info
                    EmailInfo emailInfo = renderSetting.ChannelSpecificInfo as EmailInfo;
                    if (emailInfo == null)
                    {
                        return(false);
                    }
                    #endregion

                    #region 2. initialize outlook object
                    Outlook.Application oApp      = new Outlook.Application();
                    Outlook.MailItem    oMailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem);
                    #endregion

                    #region 3. set email address and subject
                    string addresses = GetEmailListString(emailInfo.To);
                    if (!string.IsNullOrEmpty(addresses))
                    {
                        oMailItem.To = addresses;
                    }

                    addresses = GetEmailListString(emailInfo.Cc);
                    if (!string.IsNullOrEmpty(addresses))
                    {
                        oMailItem.CC = addresses;
                    }

                    addresses = GetEmailListString(emailInfo.Bcc);
                    if (!string.IsNullOrEmpty(addresses))
                    {
                        oMailItem.BCC = addresses;
                    }

                    oMailItem.Subject = emailInfo.Subject;
                    #endregion

                    #region 4. set email body and attachment
                    switch (renderSetting.Channel)
                    {
                    case RenderSettings.ChannelType.Email:
                        AddDocumentContent(ref oMailItem, wDoc, emailInfo.Body1, emailInfo.Body2);
                        switch (emailInfo.FormatOption)
                        {
                        case BodyFormat.HTML:
                            oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
                            break;

                        case BodyFormat.PlainText:
                            oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
                            break;

                        case BodyFormat.RichText:
                            oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
                            break;

                        default:
                            break;
                        }
                        break;

                    case RenderSettings.ChannelType.Attachment:
                        oMailItem.Body = string.Format("{0}\r\n{1}", emailInfo.Body1, emailInfo.Body2);
                        AddAttachment(ref oMailItem, wDoc, renderSetting.Media, emailInfo.ValidAttachmentName, ref tempFiles);
                        break;

                    default:
                        break;
                    }
                    #endregion

                    #region 5. send email
                    ((Outlook._MailItem)oMailItem).Display();
                    if (emailInfo.PressSend == SendMode.Auto)
                    {
                        ((Outlook._MailItem)oMailItem).Send();
                    }
                    #endregion

                    #region 6. release email object
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oMailItem);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp);
                    #endregion

                    return(true);
                }
                catch (System.Exception ex)
                {
                    Managers.ManagerException mgrExp = new Managers.ManagerException(ErrorCode.ipe_SendOutlookMailError,
                                                                                     MessageUtils.Expand(Properties.Resources.ipe_SendOutlookMailError, ex.Message), ex.StackTrace);
                    throw mgrExp;
                }
            }
Example #4
0
        internal static void SendEmail(Word.Document wDoc, RenderSettings renderSetting, ref List <string> tempFiles)
        {
            MailType mailType = GetDefaultEmailClientProgram();

            switch (mailType)
            {
            case MailType.OutLook:
                bool isSuccess = false;
                try
                {
                    isSuccess = OutLookMail.SendEmail(wDoc, renderSetting, ref tempFiles);
                }
                catch (BaseException baseExp)
                {
                    Managers.ManagerException mgrExp = new Managers.ManagerException(ErrorCode.ipe_SendMailError);
                    baseExp.Errors.Add(baseExp);

                    throw mgrExp;
                }
                catch (System.Exception ex)
                {
                    Managers.ManagerException mgrExp = new Managers.ManagerException(ErrorCode.ipe_SendMailError,
                                                                                     MessageUtils.Expand(Properties.Resources.ipe_SendMailError, ex.Message), ex.StackTrace);

                    throw mgrExp;
                }

                if (!isSuccess)
                {
                    try
                    {
                        WordMail.SendEmail(wDoc, renderSetting);
                    }
                    catch (System.Exception ex)
                    {
                        Managers.ManagerException mgrExp = new Managers.ManagerException(ErrorCode.ipe_SendMailError,
                                                                                         MessageUtils.Expand(Properties.Resources.ipe_SendMailError, ex.Message), ex.StackTrace);

                        throw mgrExp;
                    }
                }
                break;

            case MailType.Unknow:
                try
                {
                    WordMail.SendEmail(wDoc, renderSetting);
                }
                catch (System.Exception ex)
                {
                    Managers.ManagerException mgrExp = new Managers.ManagerException(ErrorCode.ipe_SendMailError,
                                                                                     MessageUtils.Expand(Properties.Resources.ipe_SendMailError, ex.Message), ex.StackTrace);

                    throw mgrExp;
                }
                break;

            default:
                break;
            }
        }