/// <summary>
 /// Opens a message store.
 /// </summary>
 /// <param name="storeName">store name</param>
 /// <returns>true, if the message store was successfully opened; otherwise, failed.</returns>
 public bool OpenMessageStore(string storeName)
 {
     bool bResult = false;
     try
     {
         if (Content != null)
         {
             Content.SeekRow(BookMark.BEGINNING, 0);
             if (Content.SetColumns(new PropTags[] { PropTags.PR_DISPLAY_NAME, PropTags.PR_ENTRYID, PropTags.PR_DEFAULT_STORE }))
             {
                 SRow[] sRows;
                  while (Content.QueryRows(1, out sRows))
                 {
                     if (sRows.Length != 1)
                         break;
                     if (string.IsNullOrEmpty(storeName))
                     {
                         if (sRows[0].propVals[2].AsBool)
                             bResult = true;
                     }
                     else if (sRows[0].propVals[0].AsString.IndexOf(storeName) > -1)
                         bResult = true;
                     if (bResult)
                         break;
                 }
                 if (bResult)
                 {
                     if (CurrentStore != null)
                     {
                         CurrentStore.Dispose();
                         CurrentStore = null;
                     }
                     SBinary entryId = SBinary.SBinaryCreate(sRows[0].propVals[1].AsBinary);
                     storeName = sRows[0].propVals[0].AsString;
                     IntPtr pStore = IntPtr.Zero;
                     if (session_.OpenMsgStore(0, entryId.cb, entryId.lpb, IntPtr.Zero, (uint)MAPIFlag.BEST_ACCESS, out pStore) == HRESULT.S_OK)
                     {
                         if (pStore != IntPtr.Zero)
                         {
                             IMsgStore msgStore = Marshal.GetObjectForIUnknown(pStore) as IMsgStore;
                             CurrentStore = new MessageStore(this, msgStore, new EntryID(entryId.AsBytes), storeName);
                         }
                     }
                     SBinary.SBinaryRelease(ref entryId);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine(ex.Message);
     }
     return bResult;
 }
Пример #2
0
 public StoreInfo(MessageStore store)
 {
     session_ = store.Session;
     Name     = store.Name;
     EntryId  = store.StoreID;
 }
 public StoreInfo(MessageStore store)
 {
     session_ = store.Session;
     Name = store.Name;
     EntryId = store.StoreID;
 }
Пример #4
0
        /// <summary>
        /// Opens a message store.
        /// </summary>
        /// <param name="storeName">store name</param>
        /// <returns>true, if the message store was successfully opened; otherwise, failed.</returns>
        public bool OpenMessageStore(string storeName)
        {
            bool bResult = false;

            try
            {
                if (Content != null)
                {
                    Content.SeekRow(BookMark.BEGINNING, 0);
                    if (Content.SetColumns(new PropTags[] { PropTags.PR_DISPLAY_NAME, PropTags.PR_ENTRYID, PropTags.PR_DEFAULT_STORE }))
                    {
                        SRow[] sRows;
                        while (Content.QueryRows(1, out sRows))
                        {
                            if (sRows.Length != 1)
                            {
                                break;
                            }
                            if (string.IsNullOrEmpty(storeName))
                            {
                                if (sRows[0].propVals[2].AsBool)
                                {
                                    bResult = true;
                                }
                            }
                            else if (sRows[0].propVals[0].AsString.IndexOf(storeName) > -1)
                            {
                                bResult = true;
                            }
                            if (bResult)
                            {
                                break;
                            }
                        }
                        if (bResult)
                        {
                            if (CurrentStore != null)
                            {
                                CurrentStore.Dispose();
                                CurrentStore = null;
                            }
                            SBinary entryId = SBinary.SBinaryCreate(sRows[0].propVals[1].AsBinary);
                            storeName = sRows[0].propVals[0].AsString;
                            IntPtr pStore = IntPtr.Zero;
                            if (session_.OpenMsgStore(0, entryId.cb, entryId.lpb, IntPtr.Zero, (uint)MAPIFlag.BEST_ACCESS, out pStore) == HRESULT.S_OK)
                            {
                                if (pStore != IntPtr.Zero)
                                {
                                    IMsgStore msgStore = Marshal.GetObjectForIUnknown(pStore) as IMsgStore;
                                    CurrentStore = new MessageStore(this, msgStore, new EntryID(entryId.AsBytes), storeName);
                                }
                            }
                            SBinary.SBinaryRelease(ref entryId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            return(bResult);
        }