コード例 #1
0
        private MAPIFolder getCalendarStore(NameSpace oNS)
        {
            MAPIFolder defaultCalendar = null;

            if (Settings.Instance.OutlookService == OutlookOgcs.Calendar.Service.AlternativeMailbox && Settings.Instance.MailboxName != "")
            {
                log.Debug("Finding Alternative Mailbox calendar folders");
                Folders          binFolders = null;
                Store            binStore   = null;
                PropertyAccessor pa         = null;
                try {
                    binFolders = oNS.Folders;
                    binStore   = binFolders[Settings.Instance.MailboxName].Store;
                    pa         = binStore.PropertyAccessor;
                    object bin = pa.GetProperty(PR_IPM_WASTEBASKET_ENTRYID);
                    string excludeDeletedFolder = pa.BinaryToString(bin); //EntryID

                    Forms.Main.Instance.lOutlookCalendar.Text      = "Getting calendars";
                    Forms.Main.Instance.lOutlookCalendar.BackColor = System.Drawing.Color.Yellow;
                    findCalendars(oNS.Folders[Settings.Instance.MailboxName].Folders, calendarFolders, excludeDeletedFolder);
                    Forms.Main.Instance.lOutlookCalendar.BackColor = System.Drawing.Color.White;
                    Forms.Main.Instance.lOutlookCalendar.Text      = "Select calendar";
                } catch (System.Exception ex) {
                    log.Error("Failed to find calendar folders in alternate mailbox '" + Settings.Instance.MailboxName + "'.");
                    log.Debug(ex.Message);
                } finally {
                    pa         = (PropertyAccessor)OutlookOgcs.Calendar.ReleaseObject(pa);
                    binStore   = (Store)OutlookOgcs.Calendar.ReleaseObject(binStore);
                    binFolders = (Folders)OutlookOgcs.Calendar.ReleaseObject(binFolders);
                }

                //Default to first calendar in drop down
                defaultCalendar = calendarFolders.FirstOrDefault().Value;
                if (defaultCalendar == null)
                {
                    log.Info("Could not find Alternative mailbox Calendar folder. Reverting to the default mailbox calendar.");
                    System.Windows.Forms.MessageBox.Show("Unable to find a Calendar folder in the alternative mailbox.\r\n" +
                                                         "Reverting to the default mailbox calendar", "Calendar not found", System.Windows.Forms.MessageBoxButtons.OK);
                    getDefaultCalendar(oNS, ref defaultCalendar);
                    Forms.Main.Instance.ddMailboxName.Text = "";
                }
            }
            else if (Settings.Instance.OutlookService == OutlookOgcs.Calendar.Service.SharedCalendar)
            {
                log.Debug("Finding shared calendar");
                if (Forms.Main.Instance.Visible)
                {
                    SelectNamesDialog snd;
                    try {
                        snd = oNS.GetSelectNamesDialog();
                        snd.NumberOfRecipientSelectors = OlRecipientSelectors.olShowNone;
                        snd.ForceResolution            = true;
                        snd.AllowMultipleSelection     = false;
                        snd.Display();
                        if (snd.Recipients.Count == 0)
                        {
                            log.Info("No shared calendar selected.");
                            getDefaultCalendar(oNS, ref defaultCalendar);
                        }
                        else
                        {
                            String     sharedURI      = snd.Recipients[1].Address;
                            MAPIFolder sharedCalendar = getSharedCalendar(oNS, sharedURI);
                            if (sharedCalendar == null)
                            {
                                getDefaultCalendar(oNS, ref defaultCalendar);
                            }
                            else
                            {
                                Settings.Instance.SharedCalendar = sharedURI;
                                return(sharedCalendar);
                            }
                        }
                    } finally {
                        snd = null;
                    }
                }
                else
                {
                    defaultCalendar = getSharedCalendar(oNS, Settings.Instance.SharedCalendar);
                    if (defaultCalendar == null)
                    {
                        getDefaultCalendar(oNS, ref defaultCalendar);
                    }
                    else
                    {
                        return(defaultCalendar);
                    }
                }
            }
            else
            {
                getDefaultCalendar(oNS, ref defaultCalendar);
            }
            log.Debug("Default Calendar folder: " + defaultCalendar.Name);
            log.Debug("Folder type: " + defaultCalendar.Store.ExchangeStoreType.ToString());
            return(defaultCalendar);
        }