コード例 #1
0
        public List <T> ReadObjectChunks(ReadObjectFlags flags)
        {
            if ((flags & ReadObjectFlags.Refresh) != ReadObjectFlags.None)
            {
                this.message.Dispose();
                this.message = null;
            }
            if (this.message == null && !this.OpenMessage())
            {
                return(null);
            }
            List <T> list = new List <T>();
            T        t;

            if ((flags & ReadObjectFlags.LastChunkOnly) == ReadObjectFlags.None)
            {
                using (MapiTable attachmentTable = this.message.GetAttachmentTable())
                {
                    if (attachmentTable != null)
                    {
                        PropValue[][] array = attachmentTable.QueryAllRows(null, MoveObjectInfo <T> .AttachmentTagsToLoad);
                        foreach (PropValue[] array3 in array)
                        {
                            int @int = array3[0].GetInt();
                            using (MapiAttach mapiAttach = this.message.OpenAttach(@int))
                            {
                                using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.BestAccess))
                                {
                                    t = MoveObjectInfo <T> .DeserializeFromStream(mapiStream, (flags & ReadObjectFlags.DontThrowOnCorruptData) == ReadObjectFlags.None);
                                }
                                if (t != null)
                                {
                                    list.Add(t);
                                }
                            }
                        }
                    }
                }
            }
            t = MoveObjectInfo <T> .ReadObjectFromMessage(this.message, (flags & ReadObjectFlags.DontThrowOnCorruptData) == ReadObjectFlags.None);

            if (t != null)
            {
                list.Add(t);
            }
            if (list.Count <= 0)
            {
                return(null);
            }
            return(list);
        }
コード例 #2
0
        private uint CreateMsgWithAttachement(out byte[] entryId)
        {
            ASCIIEncoding asciiencoding = new ASCIIEncoding();
            uint          @int;

            using (MapiMessage mapiMessage = this.testFolder.CreateMessage())
            {
                PropValue[] props = new PropValue[]
                {
                    new PropValue(PropTag.Subject, string.Format("CITestSearch: {0}.", this.searchString)),
                    new PropValue(PropTag.Body, string.Format("The unique search string in the body is: {0}.", this.searchString)),
                    new PropValue(PropTag.MessageDeliveryTime, (DateTime)ExDateTime.Now)
                };
                this.threadExit.CheckStop();
                mapiMessage.SetProps(props);
                int num;
                using (MapiAttach mapiAttach = mapiMessage.CreateAttach(out num))
                {
                    string s     = string.Format("This is a test msg created by test-search task (MSExchangeSearch {0}).It will be deleted soon...", this.searchString);
                    byte[] bytes = asciiencoding.GetBytes(s);
                    using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.Create))
                    {
                        mapiStream.Write(bytes, 0, bytes.Length);
                        mapiStream.Flush();
                        this.threadExit.CheckStop();
                    }
                    props = new PropValue[]
                    {
                        new PropValue(PropTag.AttachFileName, "CITestSearch.txt"),
                        new PropValue(PropTag.AttachMethod, AttachMethods.ByValue)
                    };
                    mapiAttach.SetProps(props);
                    mapiAttach.SaveChanges();
                }
                this.threadExit.CheckStop();
                mapiMessage.SaveChanges();
                entryId = mapiMessage.GetProp(PropTag.EntryId).GetBytes();
                @int    = (uint)mapiMessage.GetProp(PropTag.DocumentId).GetInt();
            }
            return(@int);
        }
コード例 #3
0
        public void SaveObjectChunks(List <T> chunks, int maxChunks, MoveObjectInfo <T> .GetAdditionalProperties getAdditionalPropertiesCallback)
        {
            if (chunks.Count > maxChunks)
            {
                MrsTracer.Common.Warning("Too many chunks supplied, truncating", new object[0]);
                chunks.RemoveRange(0, chunks.Count - maxChunks);
            }
            bool flag = false;

            if (this.message == null)
            {
                using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(this.store, this.folderName, true))
                {
                    this.FolderId = mapiFolder.GetProp(PropTag.EntryId).GetBytes();
                    this.message  = mapiFolder.CreateMessage();
                }
                this.message.SetProps(new PropValue[]
                {
                    new PropValue(PropTag.MessageClass, this.messageClass),
                    new PropValue(PropTag.Subject, this.subject),
                    new PropValue(PropTag.ReplyTemplateID, this.searchKey)
                });
                flag = true;
            }
            if (chunks.Count > 1)
            {
                using (MapiTable attachmentTable = this.message.GetAttachmentTable())
                {
                    if (attachmentTable != null)
                    {
                        int num = attachmentTable.GetRowCount() - (maxChunks - chunks.Count);
                        if (num > 0)
                        {
                            attachmentTable.SetColumns(MoveObjectInfo <T> .AttachmentTagsToLoad);
                            PropValue[][] array = attachmentTable.QueryRows(num);
                            for (int i = 0; i < num; i++)
                            {
                                this.message.DeleteAttach(array[i][0].GetInt());
                            }
                        }
                    }
                }
                for (int j = 0; j < chunks.Count - 1; j++)
                {
                    int num2;
                    using (MapiAttach mapiAttach = this.message.CreateAttach(out num2))
                    {
                        using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.Create))
                        {
                            MoveObjectInfo <T> .SerializeToStream(chunks[j], mapiStream);
                        }
                        mapiAttach.SetProps(new PropValue[]
                        {
                            new PropValue(PropTag.AttachFileName, string.Format("MOI_Chunk_{0:yyyymmdd_HHmmssfff}", DateTime.UtcNow)),
                            new PropValue(PropTag.AttachMethod, AttachMethods.ByValue)
                        });
                        mapiAttach.SaveChanges();
                    }
                }
            }
            T obj = chunks[chunks.Count - 1];

            if (getAdditionalPropertiesCallback != null)
            {
                this.message.SetProps(getAdditionalPropertiesCallback(this.store));
            }
            using (MapiStream mapiStream2 = this.message.OpenStream(PropTag.Body, OpenPropertyFlags.Create))
            {
                MoveObjectInfo <T> .SerializeToStream(obj, mapiStream2);
            }
            this.message.SaveChanges();
            if (flag)
            {
                this.MessageId = this.message.GetProp(PropTag.EntryId).GetBytes();
            }
        }