示例#1
0
        private void WaitForItemSend(InspectorHook hook)
        {

            // If you can find a better way to do this please change the following code!
            // This evil is required, because if the user clicks send and we are still processing we have to stop our worker threads.
            // ItemSend is not an option , because it will may be fired after other add-ins have intercepted the event.

            // The hook needs to be created in the main thread because Outlook is an STA application.
            Task.Factory.StartNew(() =>
                                      {
                                          try
                                          {
                                              if (hook.TryAttach()) // Less evil
                                              {
                                                  Logger.LogInfo("Waiting using hook.MailMessageNotAvailable");
                                                  SpinWait.SpinUntil(hook.MailMessageNotAvailable);
                                                  hook.Dispose();
                                              }
                                              else // More evil
                                              {
                                                  Logger.LogInfo("Waiting using IsMailItemSent");
                                                  SpinWait.SpinUntil(() => IsMailItemSent(hook.Inspector));
                                                  hook.Cancel();
                                              }
                                          }
                                          catch (Exception e)
                                          {
                                              Logger.LogError(e);
                                          }
                                      });
        }
示例#2
0
        public void AddProtectTaskPanes(WsInspector inspector, bool hookSendButton = true, bool visible = false)
        {
            try
            {
                var hook = new InspectorHook(inspector);
                WaitForItemSend(hook);

                _customTaskPanes = Globals.ThisAddin.GetCustomTaskPaneCollection();

                var alertBar = AddAlertTaskPane(_customTaskPanes, inspector);

                var ctp = new ProtectTaskPane(inspector, (AlertBarControl)alertBar.Control, OnStatusUpdate)
                {
                    Dock
                        =
                        DockStyle
                        .Fill
                };

                ctp.InspectorHook = hook;

                CustomTaskPane taskPane = _customTaskPanes.Add(ctp, "Workshare Protect",
                                                                inspector.UnSafeInspector);
                taskPane.Visible = visible;
                taskPane.Width = Utils.AdjustDimensionWithDpiHook(350);
                taskPane.VisibleChanged += TaskPaneVisibleChanged;
                taskPane.DockPositionChanged += OnDockPositionChanged;
                taskPane.DockPosition = (MsoCTPDockPosition)OptionApi.GetInt("InteractiveProtectDockPosition");

                if (_protectTaskPanes.TryAdd(inspector.Id, taskPane) && hookSendButton)
                {
                    hook.ActionQueueController = ctp.Presenter.ActionQueueController;
                    ctp.InitializeMailItemWithAttachments();
                }

            }
            catch (Exception e)
            {
                Logger.LogError(e);                
                throw;
            }
        }