Beispiel #1
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);
        }
        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();
            }
        }