예제 #1
0
        //private void openInTabblesContextMenu_Click(CommandBarButton ctrl, ref bool cancelDefault)
        //{
        //    if (IsAnyEmailSelected(false))
        //    {
        //        OpenEmailInTabbles(this.selectedMails[0]);
        //    }
        //}

        public void OpenEmailInTabbles_safe(MailItem m)
        {
            try
            {
                var atSubj            = new XAttribute("subject", m.Subject ?? "");
                var atCmdLine         = new XAttribute("command_line", outlookPrefix + ThisAddIn.getEntryIdDebug(m, "nh,klhtuy748"));
                var ats               = new[] { atSubj, atCmdLine };
                var xelRoot           = new XElement("locate_email", ats);
                var xdoc              = new XDocument(xelRoot);
                var tabblesWasRunning = sendXmlToTabbles(xdoc);
                if (!tabblesWasRunning)
                {
                    showMessageTabblesIsNotRunning();
                }
            }
            catch (Exception ec)
            {
                try
                {
                    var crashId    = "outlook-addin: error open email in tabbles";
                    var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(ec);
                    var str        = crashId + stackTrace;
                    Log.log(str);
                }
                catch
                {
                }
            }
        }
예제 #2
0
        /// <summary>
        ///  attenzione, cambiare nome, se no si confonde con l'altro menu e non mostra i titoli sotto i 3 pulsanti nella ribbon
        /// </summary>
        /// <param name="ribbonID"></param>
        /// <returns></returns>
        //public string GetLabel(Office.IRibbonControl control, int index)
        //{
        //    return Files.ToList()[index].Value.Item1;

        //    //try
        //    //{
        //    //    if (index < Files.Length)
        //    //    {
        //    //        var filename = Files[index];
        //    //        var fi = new FileInfo(filename);
        //    //        if (fi.FullName.ToLower().EndsWith("lnk"))
        //    //        {
        //    //            IWshShell shell = new WshShell();
        //    //            var lnk = shell.CreateShortcut(fi.FullName) as IWshShortcut;
        //    //            if (lnk != null)
        //    //            {
        //    //                return Path.GetFileName(lnk.TargetPath);
        //    //            }
        //    //            else
        //    //            {
        //    //                return Path.GetFileName(filename);
        //    //            }
        //    //        }
        //    //        else
        //    //        {
        //    //            return Path.GetFileName(filename);
        //    //        }
        //    //    }
        //    //}
        //    //catch
        //    //{
        //    //}

        //    //return null;
        //}



        public string GetCustomUI(string ribbonID)
        {
            try
            {
                if (ribbonID == "Microsoft.Outlook.Explorer")
                {
                    return(GetResourceText("Tabbles.OutlookAddIn.RibbonExplorer.xml"));
                }
                else if (ribbonID == "Microsoft.Outlook.Mail.Compose" ||
                         ribbonID == "Microsoft.Outlook.Mail.Read")
                {
                    return(GetResourceText("Tabbles.OutlookAddIn.RibbonInspector.xml"));
                }

                return(null);
            }
            catch (System.Exception e)
            {
                var crashId    = "outlook-addin: error get custom ui ";
                var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(e);
                var str        = crashId + stackTrace;
                Log.log(str);



                return(null);
            }
        }
예제 #3
0
        //private void openInTabblesMenuButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
        //{
        //    OpenSelectedEmailInTabbles();
        //}

        public void OpenTheOpenEmailInTabbles_safe()
        {
            try
            {
                var item     = outlookApp.ActiveInspector().CurrentItem;
                var mailItem = item as MailItem;
                if (mailItem != null)
                {
                    OpenEmailInTabbles_safe(mailItem);
                }
                else
                {
                    MessageBox.Show(Res.notAnEmail);
                }
            }
            catch (Exception e)
            {
                try
                {
                    var crashId    = "outlook-addin: error in open the open email";
                    var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(e);
                    var str        = crashId + stackTrace;
                    Log.log(str);
                }
                catch
                {
                }
            }
        }
예제 #4
0
 public void OpenSelectedEmailInTabbles_safe()
 {
     try
     {
         if (IsAnyEmailSelected(true))
         {
             OpenEmailInTabbles_safe(this.selectedMails[0]);
         }
         else
         {
             MessageBox.Show(Res.noEmailSelected);
         }
     }
     catch (Exception e)
     {
         try
         {
             var crashId    = "outlook-addin: error in open selected email in tabbles";
             var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(e);
             var str        = crashId + stackTrace;
             Log.log(str);
         }
         catch
         {
         }
     }
 }
예제 #5
0
 public void openQuickTagAndShowResultInOutlook_safe()
 {
     try
     {
         var xelRoot           = new XElement("quick_open_tags_in_outlook");
         var xdoc              = new XDocument(xelRoot);
         var tabblesWasRunning = sendXmlToTabbles(xdoc);
         if (!tabblesWasRunning)
         {
             showMessageTabblesIsNotRunning();
         }
     }
     catch (Exception ec)
     {
         try
         {
             var crashId    = "outlook-addin: error openQuickTagAndShowResultInOutlook ";
             var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(ec);
             var str        = crashId + stackTrace;
             Log.log(str);
         }
         catch
         {
         }
     }
 }
예제 #6
0
        public void TagEmailsWithTabbles_safe(List <MailItem> mails)
        {
            try
            {
                var emails = (from m in mails
                              let atSubj = new XAttribute("subject", m.Subject ?? "")
                                           let atCmdLine = new XAttribute("command_line", outlookPrefix + ThisAddIn.getEntryIdDebug(m, "kflbjfghwjkkfre"))
                                                           let ats = new[] { atSubj, atCmdLine }
                              select new XElement("email", ats)).ToArray();
                var xelRoot           = new XElement("i_need_to_tag_emails", emails);
                var xdoc              = new XDocument(xelRoot);
                var tabblesWasRunning = sendXmlToTabbles(xdoc);
                if (!tabblesWasRunning)
                {
                    showMessageTabblesIsNotRunning();
                }
            }
            catch (Exception ec)
            {
                try
                {
                    var crashId    = "outlook-addin: error TagEmailsWithTabbles ";
                    var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(ec);
                    var str        = crashId + stackTrace;
                    Log.log(str);
                }
                catch
                {
                }
            }

            // todo
            //if (SendMessageToTabbles == null)
            //{
            //    return;
            //}

            //var emails = (from MailItem mi in this.selectedMails
            //              select new Generic
            //              {
            //                  name = mi.Subject,
            //                  commandLine = this.outlookPrefix + mi.EntryID,
            //                  icon = new IconOther(),
            //                  showCommandLine = false
            //              }).ToList();

            //SendMessageToTabbles(new INeedToTagGenericsWithTabblesQuickTagDialog()
            //{
            //    gens = emails
            //});
        }
예제 #7
0
        public Bitmap OnLoadImage(string imageName)
        {
            try
            {
                Bitmap image = null;

                switch (imageName)
                {
                case "tag_using_tabbles":
                    image = Res.Outlook_32x32_tag;
                    break;

                case "open_in_tabbles":
                    image = Res.Outlook_32x32_open;
                    break;

                case "search":
                    image = Res.Outlook_32x32_search;
                    break;

                case "sync_with_tabbles":
                    image = Res.Outlook_32x32_sync;
                    break;

                case "tag_using_tabbles_small":
                    image = Res.Outlook_16x16_tag;
                    break;

                case "open_in_tabbles_small":
                    image = Res.Outlook_16x16_open;
                    break;

                default:
                    break;
                }

                return(image);
            }
            catch (System.Exception e)
            {
                var crashId    = "outlook-addin: error onloadimage ";
                var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(e);
                var str        = crashId + stackTrace;
                Log.log(str);



                return(null);
            }
        }
예제 #8
0
        public void OnAction(Office.IRibbonControl control)
        {
            try
            {
                switch (control.Id)
                {
                case "tagUsingTabblesButton":
                case "tagUsingTabblesMenuSingle":
                case "tagUsingTabblesMenuMultiple":
                    mMenuManager.TagSelectedEmailsWithTabbles();
                    break;

                case "tagUsingTabblesButtonSingleMail":
                    mMenuManager.TagOpenEmailWithTabbles();
                    break;

                case "openInTabblesButton":
                case "openInTabblesMenu":
                    mMenuManager.OpenSelectedEmailInTabbles_safe();
                    break;

                case "openInTabblesButtonSingleMail":
                    mMenuManager.OpenTheOpenEmailInTabbles_safe();
                    break;

                case "tabblesSearchButton":
                    mMenuManager.openQuickTagAndShowResultInOutlook_safe();
                    break;

                case "syncWithTabblesButton":
                    mAddin.importOutlookTaggingIntoTabbles();
                    //if (SyncWithTabbles != null)
                    //{
                    //    SyncWithTabbles(control, EventArgs.Empty);
                    //}
                    break;

                default:
                    break;
                }
            }
            catch (System.Exception e)
            {
                var crashId    = "outlook-addin: error on-action";
                var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(e);
                var str        = crashId + stackTrace;
                Log.log(str);
            }
        }
예제 #9
0
        /*
         * let execInThread f =
         * if Threading.Thread.CurrentThread.IsBackground then // modo rapido per capire se siamo già in un thread
         *      f ()
         * else
         *      let body () =
         *              try
         *                      f()
         *              with
         | ecc  ->
         |                   showCrashDialog ecc None "execInThread - "
         |      (  // faccio partire il thread
         |      let th = new System.Threading.Thread(body)
         |      th.CurrentUICulture <-  new Globalization.CultureInfo(g_lang)
         |      th.Priority <- Threading.ThreadPriority.Normal
         |      th.IsBackground <- true
         |      th.Start ()
         |      )
         |
         *
         * */


        /// <summary>
        /// Execute a given piece of code in background, in a thread, in order to return quickly.
        /// </summary>
        /// <param name="dobj"></param>
        /// <param name="a"></param>
        //public static void execInThread(Action a)
        //{
        //    if (System.Threading.Thread.CurrentThread.IsBackground)
        //    {
        //        // we are already in a thread, no need to start another.

        //        a.Invoke();
        //    }
        //    else
        //    {

        //        var th = new Task((() =>
        //        {
        //            try
        //            {
        //                a.Invoke();
        //            }
        //            catch (Exception e)
        //            {
        //                Log.log(">>> execInThread: exception:" + Utils.stringOfException(e));
        //            }

        //        }));

        //        th.Start();
        //    }

        //}

        //public static void execInThreadForceNewThread(Action a)
        //{

        //    var th = new Task((() =>
        //    {
        //        try
        //        {
        //            a.Invoke();
        //        }
        //        catch (Exception e)
        //        {
        //            Log.log(">>> execInThreadForceNewThread: exception:" + Utils.stringOfException(e));
        //        }

        //    }));

        //    // th.CurrentUICulture = ...
        //    //th.Priority = ThreadPriority.Normal;
        //    //th.IsBackground = true;
        //    th.Start();

        //}
        public static void gui(System.Windows.Threading.DispatcherObject dobj, Action a)
        {
            var aWrapped = new Action(() =>
            {
                try
                {
                    a();
                }
                catch (Exception e)
                {
                    var crashId    = "outlook-addin: crash in gui fun";
                    var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(e);
                    var str        = crashId + stackTrace;
                    Log.log(str);
                }
            });

            dobj.Dispatcher.Invoke(aWrapped, null);
        }
예제 #10
0
 private void OnNewExplorer(Explorer explorer)
 {
     try
     {
         AddExplorerListeners(explorer);
     }
     catch (Exception e)
     {
         try
         {
             var crashId    = "outlook-addin: error onNewExplorer ";
             var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(e);
             var str        = crashId + stackTrace;
             Log.log(str);
         }
         catch
         {
         }
     }
 }
예제 #11
0
        //void explorer_BeforeItemCut(ref bool Cancel)
        //{
        //    var y = 5;
        //}

        //void explorer_BeforeItemCopy(ref bool Cancel)
        //{
        //    var y = 5;
        //}

        //// era chiamata in explorer_BeforeItemPaste
        //private void TrackEmailMove(ref object clipboardContent, MAPIFolder target, ref bool cancel)
        //{
        //    if (!this.trackItemMove) //prevent infinite loop
        //    {
        //        return;
        //    }

        //    if (clipboardContent is Selection)
        //    {
        //        List<MailItem> mails = new List<MailItem>();

        //        Selection selection = (Selection)clipboardContent;
        //        foreach (object itemObj in selection)
        //        {
        //            if (itemObj is MailItem)
        //            {
        //                mails.Add((MailItem)itemObj);
        //            }
        //        }

        //        if (mails.Count == 0)
        //        {
        //            return;
        //        }

        //        bool movedFromStore = false;
        //        try
        //        {
        //            foreach (MailItem mail in mails)
        //            {
        //                if (string.IsNullOrEmpty(mail.Categories))
        //                {
        //                    continue;
        //                }

        //                if (mail.Parent is Folder)
        //                {
        //                    Folder parent = (Folder)mail.Parent;
        //                    if (parent.StoreID != target.StoreID)
        //                    {
        //                        movedFromStore = true;
        //                        break;
        //                    }
        //                }
        //            }

        //            if (!movedFromStore)
        //            {
        //                return;
        //            }

        //            // todo maurizio
        //            //if (!CheckTabblesRunning())
        //            //{
        //            //    cancel = true;
        //            //    WinForms.MessageBox.Show(Res.MsgTabblesIsNotRunning, Res.MsgCaptionTabblesAddIn);
        //            //    return;
        //            //}

        //            cancel = true;
        //            this.trackItemMove = false;

        //            foreach (MailItem mail in mails)
        //            {
        //                MailItem mailAfterMove = (MailItem)mail.Move(target);
        //                Utils.ReleaseComObject(mailAfterMove);
        //                //WinForms.MessageBox.Show(mail.EntryID + "\n\n" + mailAfterMove.EntryID);
        //                //TODO Maurizio: call Tabbles API at this point
        //            }
        //            this.trackItemMove = true;

        //        }
        //        finally
        //        {
        //            foreach (MailItem mail in mails)
        //            {
        //                Utils.ReleaseComObject(mail);
        //            }
        //        }
        //    }
        //}

        private void UpdateSelectedEmails_safe()
        {
            try
            {
                var selection = this.outlookApp.ActiveExplorer().Selection;
                FillSelectedMails(selection);
            }
            catch (Exception ec)
            {
                try
                {
                    var crashId    = "outlook-addin: error in update-selected-emails";
                    var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(ec);
                    var str        = crashId + stackTrace;
                    Log.log(str);
                }
                catch
                {
                }
            }
        }
예제 #12
0
        public string GetLabel(Office.IRibbonControl control)
        {
            try
            {
                switch (control.Id)
                {
                case "tagUsingTabblesButton":
                case "tagUsingTabblesButtonSingleMail":
                case "tagUsingTabblesMenuSingle":
                case "tagUsingTabblesMenuMultiple":
                    return(Res.MenuTagUsingTabbles2);

                case "openInTabblesButton":
                case "openInTabblesButtonSingleMail":
                case "openInTabblesMenu":
                    return(Res.MenuOpenInTabbles2);

                case "tabblesSearchButton":
                    return(Res.MenuTabblesSearch3);

                case "syncWithTabblesButton":
                    return(Res.MenuSyncWithTabbles3);

                default:
                    return(string.Empty);
                }
            }
            catch (System.Exception e)
            {
                var crashId    = "outlook-addin: error get label ";
                var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(e);
                var str        = crashId + stackTrace;
                Log.log(str);



                return(string.Empty);
            }
        }
예제 #13
0
        void explorer_BeforeItemPaste_safe(ref object clipboardContent, MAPIFolder Target, ref bool Cancel)
        {
            try
            {
                if (!this.trackItemMove) //prevent infinite loop
                {
                    return;
                }

                if (clipboardContent is Selection)
                {
                    var mailsToMove = new List <MailItem>();

                    var selection = (Selection)clipboardContent;
                    foreach (object itemObj in selection)
                    {
                        var obj = itemObj as MailItem;
                        if (obj != null)
                        {
                            mailsToMove.Add(obj);
                        }
                    }

                    if (mailsToMove.Count == 0)
                    {
                        return;
                    }


                    try
                    {
                        bool mailMovedToDifferentStore = u.c(() =>
                        {
                            foreach (MailItem mail in mailsToMove)
                            {
                                if (string.IsNullOrEmpty(mail.Categories))
                                {
                                    continue;
                                }

                                if (mail.Parent is Folder)
                                {
                                    var parent = (Folder)mail.Parent;
                                    if (parent.StoreID != Target.StoreID)
                                    {
                                        return(true);
                                    }
                                }
                            }
                            return(false);
                        });

                        if (!mailMovedToDifferentStore)
                        {
                            return;
                        }


                        Cancel             = true; // because I am doing the move myself with mail.Move()
                        this.trackItemMove = false;

                        var pairs = new List <EntryIdChange>();
                        foreach (MailItem mail in mailsToMove)
                        {
                            var mailAfterMove = (MailItem)mail.Move(Target);
                            Log.log("moved mail. old id = " + ThisAddIn.getEntryIdDebug(mail, "bljbkghjrhje") + " ---- new id = " + mailAfterMove.EntryID);
                            pairs.Add(new EntryIdChange {
                                OldId = ThisAddIn.getEntryIdDebug(mail, "gflibfkhjdsbnmdbfjdhjg"), NewId = mailAfterMove.EntryID, Subject = mail.Subject ?? ""
                            });
                            Utils.ReleaseComObject(mailAfterMove);
                        }
                        this.trackItemMove = true;



                        CrashReportFsharp.execInThreadForceNewThreadDur(false, logError, FuncConvert.ToFSharpFunc <Unit>(aa =>
                        {
                            try
                            {
                                var emails = (from m in pairs
                                              let atSubj = new XAttribute("subject", m.Subject ?? "")
                                                           let atOldId = new XAttribute("old_cmd_line", outlookPrefix + m.OldId)
                                                                         let atNewId = new XAttribute("new_cmd_line", outlookPrefix + m.NewId)
                                                                                       let ats = new[] { atSubj, atOldId, atNewId }
                                              select new XElement("id_change", ats)).ToArray();
                                var xelRoot           = new XElement("update_email_ids", emails);
                                var xdoc              = new XDocument(xelRoot);
                                var tabblesWasRunning = sendXmlToTabbles(xdoc);
                                if (!tabblesWasRunning)
                                {
                                    Utils.appendToXml(xelRoot);
                                }
                            }
                            catch (Exception ecc)
                            {
                                try
                                {
                                    var crashId    = "outlook-addin: error in explorer before item paste subthread";
                                    var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(ecc);
                                    var str        = crashId + stackTrace;
                                    Log.log(str);
                                }
                                catch
                                {
                                }
                            }
                        }));
                    }
                    finally
                    {
                        foreach (MailItem mail in mailsToMove)
                        {
                            Utils.ReleaseComObject(mail);
                        }
                    }
                }
            }
            catch (Exception eOuter)
            {
                try
                {
                    var crashId    = "outlook-addin: error before item paste ";
                    var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(eOuter);
                    var str        = crashId + stackTrace;
                    Log.log(str);
                }
                catch
                {
                }
            }
        }