public SettingsManager(Outlook.Application app)
 {
     Application = app;
     this.profile = Application.Session.CurrentProfileName;
     Outlook.Folder oInbox = (Outlook.Folder)Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
     this.storage = oInbox.GetStorage("calcifyStore", Outlook.OlStorageIdentifierType.olIdentifyBySubject);
 }
Beispiel #2
0
        public static Options LoadFromConfigItem()
        {
            // grab the FAI message that houses user config
            Outlook.MAPIFolder  inboxFolder = Globals.ThisAddIn.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            Outlook.StorageItem configItem  = inboxFolder.GetStorage(Options.CONFIG_MESSAGE_SUBJECT, Outlook.OlStorageIdentifierType.olIdentifyBySubject);

            XmlSerializer x = new XmlSerializer(typeof(Options));

            using (StringWriter writer = new StringWriter())
            {
                // we found existing user config so deserialize the stored XML into an Options object for add-in to use
                if (configItem.EntryID != null && configItem.EntryID != "")
                {
                    Log.WriteEntry("User options were loaded from Exchange.");
                    // if we fail to deserialize, just return an empty one
                    Options opts;
                    try
                    {
                        opts = (Options)x.Deserialize(new StringReader(configItem.Body));
                    } catch
                    {
                        MessageBox.Show("There was an error reading your WFM for Outlook settings from Exchange so it has been reset. Please update your settings again accordingly.");
                        opts = new Options();
                    }

                    return(opts);
                }
            }

            return(null);
        }
        public static void RemoveFormFromPersonalFormsLibrary(string name)
        {
            bool formFound = false;

            Outlook.Table olTable;
            Outlook.Row   olRow;
            string        searchFilter;

            if (null == m_Application)
            {
                Initialise();
            }
            try
            {
                Outlook.MAPIFolder olFolder = GetCommonViewsFolder();
                if (null != olFolder)
                {
                    searchFilter = "[MessageClass] = \"IPM.Microsoft.FolderDesign.FormsDescription\"";
                    olTable      = olFolder.GetTable(searchFilter, Outlook.OlTableContents.olHiddenItems);
                    olTable.Columns.Add(PR_DISPLAY_NAME);
                    olTable.Columns.Add(SEARCH_FORM_MESSAGECLASS);
                    olTable.Columns.Add(PR_LONG_TERM_ENTRYID_FROM_TABLE);
                    olTable.Restrict(searchFilter);
                    while (!olTable.EndOfTable)
                    {
                        olRow = olTable.GetNextRow();
                        if (name.ToLower() == olRow[PR_DISPLAY_NAME].ToString().ToLower())
                        {
                            formFound = true;
                            byte[] entryId = olRow[PR_LONG_TERM_ENTRYID_FROM_TABLE];
                            string temp    = "";
                            for (int i = 0; i < entryId.Length; i++)
                            {
                                temp += entryId[i].ToString("X2");
                            }
                            object item = m_NameSpace.GetItemFromID(temp, olFolder.StoreID);
                            if (item is Outlook.StorageItem)
                            {
                                Outlook.StorageItem storageItem = item as Outlook.StorageItem;
                                storageItem.Delete();
                                Console.WriteLine("Form succesfully deleted. You might need to restart Outlook.");
                            }
                        }
                    }
                    if (!formFound)
                    {
                        Console.WriteLine("The form couldn't be found in the Personal Forms Library.");
                    }
                }
                ClearLocalFormCache();
            }
            catch (Exception exception)
            {
                Console.WriteLine("Unable to remove form. Error: " + exception.ToString());
            }
            finally
            {
            }
        }
Beispiel #4
0
 public IStorageItem GetStorageItem(string name)
 {
     NSOutlook.StorageItem item = _item.GetStorage(name, NSOutlook.OlStorageIdentifierType.olIdentifyBySubject);
     if (item == null)
     {
         return(null);
     }
     return(new StorageItemWrapper(item));
 }
Beispiel #5
0
        /// <summary>
        /// Persist this object to Exchange as a StorageItem.
        /// </summary>
        public void Save()
        {
            Outlook.MAPIFolder  inboxFolder = Globals.ThisAddIn.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            Outlook.StorageItem configItem  = inboxFolder.GetStorage(Options.CONFIG_MESSAGE_SUBJECT, Outlook.OlStorageIdentifierType.olIdentifyBySubject);
            configItem.Subject = Options.CONFIG_MESSAGE_SUBJECT;

            XmlSerializer x = new XmlSerializer(typeof(Options));

            using (StringWriter writer = new StringWriter())
            {
                // serialize this object into XML and store into the config item's body property
                x.Serialize(writer, this);
                configItem.Body = writer.ToString();

                // persist the item to Exchange
                configItem.Save();

                Log.WriteEntry("User options were saved to Exchange.");
            }
        }
 private SettingsManager()
 {
     this.storage = null;
 }