public void ExecuteAttach(AttachKind objType, IMailItem mItem)
        {
            try
            {
                AttachWorkerBase worker;
                switch (objType)
                {
                case AttachKind.Contact:
                    worker = new AttachWorkerContact();
                    break;

                case AttachKind.Organization:
                    worker = new AttachWorkerOrganization();
                    break;

                default:
                    throw new NotImplementedException(objType.ToString());
                }
                worker.Init(_application, mItem);
                var result = worker.ExecuteAttach();

                switch (result.Code)
                {
                case AttachmentResultCode.NotFound:
                    if (worker.CreateNewObject(result.Message))
                    {
                        worker.OnAfterSuccessfulAttach();
                        result = worker.ExecuteAttach();
                    }
                    break;

                case AttachmentResultCode.Error:

                    MessageBox.Show(string.IsNullOrWhiteSpace(result.Message) ? "Error" : result.Message, "PPOL", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                default:
                    if (!string.IsNullOrWhiteSpace(result.Message))
                    {
                        MessageBox.Show(result.Message, "PPOL", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                ClassFactory.Instance.ConnectionProblem(ex);
            }
        }
Esempio n. 2
0
        void ExecuteAttach(AttachKind kind, IRibbonControl control, AttachBehavior behavior)
        {
            try
            {
                var inspector = control.Context as Outlook._Inspector;
                if (inspector != null)
                {
                    inspector = OutlookApp.ActiveInspector();
                }
                if (inspector != null)
                {
                    using (var mi = app.GetItemByInspector(inspector))
                    {
                        Marshal.ReleaseComObject(inspector);
                        if (mi != null)
                        {
                            switch (behavior)
                            {
                            case AttachBehavior.Send:
                                executeAttachOnSend[mi] = new AttachOnSendParameters {
                                    AttachKind = kind
                                };
                                try
                                {
                                    mi.Send();
                                }
                                finally
                                {
                                    executeAttachOnSend.Remove(mi);
                                }
                                break;

                            case AttachBehavior.SyncAttach:
                                ClassFactory.Instance.EmailAttachProcessor.ExecuteAttach(kind, mi);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ShowEx(ex);
            }
        }