当前位置: 首页>>代码示例>>C#>>正文


C# Message.Write方法代码示例

本文整理汇总了C#中Message.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Message.Write方法的具体用法?C# Message.Write怎么用?C# Message.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Message的用法示例。


在下文中一共展示了Message.Write方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleMessage

        //, List<InputOutputThreadObjectHandler<PSTMsgParser>> outputobjects, InputOutputMessageQueue<PSTMsgParser> inqueue, InputOutputMessageQueue<PSTMsgParser> outqueue)
        private void HandleMessage(Message rdomail, string exportdir)
        {
            if (this.ProcessedMsgs.Contains(rdomail.Node))
                return;

            this.ProcessedMsgs.Add(rdomail.Node);

            string entryid = rdomail.Node.ToString();
            string msgdir = exportdir; // [email protected]"\" + entryid;
            if (!Directory.Exists(msgdir))
                Directory.CreateDirectory(msgdir);
            if (Directory.Exists(msgdir))
            {
                string attachmentsdir = msgdir + @"\Children";
                if (this.SaveAttachments && rdomail.AttachmentCount > 0)
                    Directory.CreateDirectory(attachmentsdir);

                if ((this.SaveAsTypes & SaveAsType.Eml) == SaveAsType.Eml)
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Eml, true));
                if ((this.SaveAsTypes & SaveAsType.Msg) == SaveAsType.Msg)
                    this.OutputFiles.Add(rdomail.Write(msgdir + @"MSG\", Message.SaveAsMessageType.Msg, true));
                if ((this.SaveAsTypes & SaveAsType.Html) == SaveAsType.Html)
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Html, true));
                if (rdomail.HasBody && ((this.SaveAsTypes & SaveAsType.Text) == SaveAsType.Text))
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Text, true));
                if (rdomail.HasRtfBody && ((this.SaveAsTypes & SaveAsType.Rtf) == SaveAsType.Rtf))
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Rtf, true));
                if ((this.SaveAsTypes & SaveAsType.Xml) == SaveAsType.Xml)
                    this.OutputFiles.Add(rdomail.Write(msgdir + @"XML\", Message.SaveAsMessageType.Xml, true));
                foreach (pstsdk.definition.pst.message.IAttachment rdoattachment in rdomail.Attachments)
                {
            //					if (rdoattachment.IsMessage)
            //						HandleMessage((Message)rdoattachment.OpenAsMessage(), this.ExportDirectory + @"\" + entryid); //, outputobjects, inqueue, outqueue);
            //					else
            //					{
                        if (this.SaveAttachments)
                        {
                            string filename = attachmentsdir + @"\" + rdoattachment.Filename;
                            using (var bw = new BinaryWriter(File.OpenWrite(filename)))
                            {
                                bw.Write(rdoattachment.Bytes);
                                this.OutputFiles.Add(filename);
                            }
                        }
            //					}
                    rdoattachment.Dispose();
                }
            }
        }
开发者ID:kmrgithub,项目名称:KRSrcWorkflow,代码行数:50,代码来源:PSTMsgParser_PstSdk.cs

示例2: DownloadRequest

            private Message DownloadRequest(Message req)
            {
                Check.Assert<InvalidDataException>(HasState(req.TransferId, "start-time")
                    && HasState(req.TransferId, "nonce")
                    && HasState(req.TransferId, "server-key")
                    && !HasState(req.TransferId, "session-key"));

                byte[] nonceExpected = Convert.FromBase64String(ReadState(req.TransferId, "nonce"));
                DeleteState(req.TransferId, "nonce");

                byte[] serverKeyBits = Convert.FromBase64String(ReadState(req.TransferId, "server-key"));
                DeleteState(req.TransferId, "server-key");

                byte[] hnonce = req.ReadBytes(32);
                string name = req.ReadString(1024);
                byte[] clientKeyBits = req.ReadBytes(32);
                req.VerifySignature(_clientKey);

                Check.Assert<InvalidDataException>(
                    Hash.SHA256(nonceExpected).Equals(Hash.FromBytes(hnonce))
                );

                Salt sessionKey = SessionSecret(clientKeyBits, serverKeyBits);
                long length;
                OnDownloadBytes(req.TransferId, name, out length, 0, 0, Stream.Null);

                Message response = new Message(TransferState.DownloadResponse, req.TransferId, _clientKey, s => sessionKey);
                response.Write(MaxOutboundFileChunk);
                response.Write(length);
                if(length <= MaxOutboundFileChunk)
                {
                    Delete(req.TransferId);
                    using (MemoryStream ms = new MemoryStream())
                    {
                        OnDownloadBytes(req.TransferId, name, out length, 0, (int)length, ms);
                        Check.Assert<InvalidDataException>(ms.Position == length);
                        response.Write(ms.ToArray());
                    }
                }
                else
                {
                    WriteState(req.TransferId, "total-length", length.ToString());
                    WriteState(req.TransferId, "location", name ?? String.Empty);
                    WriteState(req.TransferId, "session-key", sessionKey.ToString());
                    response.Write(new byte[0]);
                }

                return response;
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:49,代码来源:SecureTransferServer.cs

示例3: DownloadBytesRequest

            private Message DownloadBytesRequest(Message req)
            {
                string location = req.ReadString(1024);
                long position = req.ReadInt64();
                int count = req.ReadInt32();
                req.VerifySignature(_clientKey);

                Check.Assert<InvalidDataException>(location == ReadState(req.TransferId, "location"));
                long totalSize = long.Parse(ReadState(req.TransferId, "total-length"));
                Check.InRange(position, 0, totalSize);
                Check.InRange(position + count, 0, totalSize);

                Message response = new Message(TransferState.DownloadBytesResponse, req.TransferId, _clientKey, SessionKey);

                using (MemoryStream ms = new MemoryStream())
                {
                    long length;
                    OnDownloadBytes(req.TransferId, location, out length, position, count, ms);
                    Check.Assert<InvalidDataException>(length == totalSize);
                    Check.Assert<InvalidDataException>(ms.Position == count);
                    response.Write(ms.ToArray());
                }
                return response;
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:24,代码来源:SecureTransferServer.cs

示例4: TransferRequest

            private Message TransferRequest(Message req)
            {
                Check.Assert<InvalidDataException>(HasState(req.TransferId, "start-time")
                    && HasState(req.TransferId, "nonce")
                    && HasState(req.TransferId, "server-key")
                    && !HasState(req.TransferId, "session-key"));

                byte[] nonceExpected = Convert.FromBase64String(ReadState(req.TransferId, "nonce"));
                DeleteState(req.TransferId, "nonce");

                byte[] serverKeyBits = Convert.FromBase64String(ReadState(req.TransferId, "server-key"));
                DeleteState(req.TransferId, "server-key");

                byte[] hnonce = req.ReadBytes(32);
                long length = req.ReadInt64();
                string name = req.ReadString(1024);
                byte[] clientKeyBits = req.ReadBytes(32);
                req.VerifySignature(_clientKey);

                Check.Assert<InvalidDataException>(
                    Hash.SHA256(nonceExpected).Equals(Hash.FromBytes(hnonce))
                );

                OnBeginTransfer(req.TransferId, name, length);

                WriteState(req.TransferId, "total-length", length.ToString());
                WriteState(req.TransferId, "location", name ?? String.Empty);
                WriteState(req.TransferId, "session-key", SessionSecret(clientKeyBits, serverKeyBits).ToString());

                Message response = new Message(TransferState.UploadResponse, req.TransferId, _clientKey, SessionKey);
                response.Write(MaxInboundFileChunk);
                return response;
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:33,代码来源:SecureTransferServer.cs

示例5: SendBytesRequest

            private Message SendBytesRequest(Message req)
            {
                long position = req.ReadInt64();
                byte[] bytes = req.ReadBytes(MaxInboundFileChunk);
                req.VerifySignature(_clientKey);

                string location = ReadState(req.TransferId, "location");
                long totalSize = long.Parse(ReadState(req.TransferId, "total-length"));
                Check.InRange(position, 0, totalSize - bytes.Length);

                OnBytesReceived(req.TransferId, location, totalSize, position, bytes);

                Message response = new Message(TransferState.SendBytesResponse, req.TransferId, _clientKey, SessionKey);
                response.Write(position);
                return response;
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:16,代码来源:SecureTransferServer.cs

示例6: CompleteUpload

            private void CompleteUpload(Guid transferId, Salt sessionKey, string location, Hash fullHash)
            {
                // STEP 4: Finalize the transfer
                using (Message req = new Message(TransferState.UploadCompleteRequest, transferId, _publicKey, s => sessionKey))
                {
                    req.Write(location);
                    req.Write(fullHash.ToArray());

                    Stream response = SendPayload(req, location, req.ToStream(_privateKey));
                    using (Message rsp = new Message(response, _privateKey, s => sessionKey))
                    {
                        Check.Assert<InvalidOperationException>(rsp.State == TransferState.UploadCompleteResponse);
                        rsp.VerifySignature(_publicKey);
                    }
                }
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:16,代码来源:SecureTransferClient.cs

示例7: NonceRequest

            private Message NonceRequest(Message req)
            {
                req.VerifySignature(_clientKey);

                Check.Assert<InvalidDataException>(HasState(req.TransferId, "start-time") == false);
                WriteState(req.TransferId, "start-time", DateTime.UtcNow.Ticks.ToString());

                byte[] nonce = new byte[NonceSize];
                new Random().NextBytes(nonce);
                WriteState(req.TransferId, "nonce", Convert.ToBase64String(nonce));

                byte[] keydata = new byte[KeyBytes];
                new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(keydata);
                WriteState(req.TransferId, "server-key", Convert.ToBase64String(keydata));

                Message response = new Message(TransferState.NonceResponse, req.TransferId, _clientKey, NoSession);
                response.Write(nonce);
                response.Write(keydata);
                return response;
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:20,代码来源:SecureTransferServer.cs

示例8: ReadByteRange

            private void ReadByteRange(Guid transferId, Salt sessionKey, string location, StreamCache streams, long offset, int count)
            {
                using (Message req = new Message(TransferState.DownloadBytesRequest, transferId, _publicKey, s=>sessionKey))
                {
                    req.Write(location);
                    req.Write(offset);
                    req.Write(count);

                    Stream response = SendPayload(req, location, req.ToStream(_privateKey));
                    using (Message rsp = new Message(response, _privateKey, s=>sessionKey))
                    {
                        Check.Assert<InvalidOperationException>(rsp.State == TransferState.DownloadBytesResponse);
                        byte[] bytes = rsp.ReadBytes(100 * 1000 * 1024);
                        Check.Assert<InvalidOperationException>(bytes.Length == count);
                        
                        rsp.VerifySignature(_publicKey);

                        using(Stream io = streams.Open(FileAccess.Write))
                        {
                            io.Seek(offset, SeekOrigin.Begin);
                            io.Write(bytes, 0, count);
                        }
                    }
                }
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:25,代码来源:SecureTransferClient.cs

示例9: TransferBytes

            private void TransferBytes(Guid transferId, Salt sessionKey, string location, long offset, byte[] bytes)
            {
                // STEP 3...n: Send a block of bytes
                using (Message req = new Message(TransferState.SendBytesRequest, transferId, _publicKey, s => sessionKey))
                {
                    req.Write(offset);
                    req.Write(bytes);

                    Stream response = SendPayload(req, location, req.ToStream(_privateKey));
                    using (Message rsp = new Message(response, _privateKey, s => sessionKey))
                    {
                        Check.Assert<InvalidOperationException>(rsp.State == TransferState.SendBytesResponse);
                        Check.Assert<InvalidOperationException>(rsp.ReadInt64() == offset);
                        rsp.VerifySignature(_publicKey);
                    }
                }
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:17,代码来源:SecureTransferClient.cs

示例10: BeginUpload

            private Salt BeginUpload(Guid transferId, string location, long length, out int maxMessageLength)
            {
                byte[] serverKeyBits;
                byte[] nonce = GetNonce(transferId, location, out serverKeyBits);
                Hash hnonce = Hash.SHA256(nonce);
                
                //STEP 2: Create and send session key
                Salt clientKeyBits = new Salt(Salt.Size.b256);
                Salt sessionSecret = SessionSecret(clientKeyBits, serverKeyBits);

                using (Message req = new Message(TransferState.UploadRequest, transferId, _publicKey, NoSession))
                {
                    req.Write(hnonce.ToArray());
                    req.Write(length);
                    req.Write(location);
                    req.Write(clientKeyBits.ToArray());

                    Stream response = SendPayload(req, location, req.ToStream(_privateKey));
                    using (Message rsp = new Message(response, _privateKey, s=>sessionSecret))
                    {
                        Check.Assert<InvalidOperationException>(rsp.State == TransferState.UploadResponse);
                        maxMessageLength = Check.InRange(rsp.ReadInt32(), 0, int.MaxValue);
                        rsp.VerifySignature(_publicKey);
                    }
                }
                return sessionSecret;
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:27,代码来源:SecureTransferClient.cs

示例11: Download

            private bool Download(string location, StreamCache output)
            {
                int maxMessageLength;
                long fileLength, bytesReceived = 0;
                Guid transferId = Guid.NewGuid();
                byte[] serverKeyBits;
                byte[] nonce = GetNonce(transferId, location, out serverKeyBits);
                Hash hnonce = Hash.SHA256(nonce);

                //STEP 2: Create and send session key
                Salt clientKeyBits = new Salt(Salt.Size.b256);
                Salt sessionKey = SessionSecret(clientKeyBits, serverKeyBits);

                using (Message req = new Message(TransferState.DownloadRequest, transferId, _publicKey, NoSession))
                {
                    req.Write(hnonce.ToArray());
                    req.Write(location);
                    req.Write(clientKeyBits.ToArray());

                    Stream response = SendPayload(req, location, req.ToStream(_privateKey));
                    using (Message rsp = new Message(response, _privateKey, s=>sessionKey))
                    {
                        Check.Assert<InvalidOperationException>(rsp.State == TransferState.DownloadResponse);
                        maxMessageLength = Check.InRange(rsp.ReadInt32(), 0, int.MaxValue);
                        fileLength = Check.InRange(rsp.ReadInt64(), 0, 0x00FFFFFFFFFFFFFFL);
                        byte[] bytes = rsp.ReadBytes(100 * 1000 * 1024);
                        rsp.VerifySignature(_publicKey);

                        using(Stream io = output.Open(FileAccess.Write))
                        {
                            io.SetLength(fileLength);
                            if (bytes.Length > 0)
                            {
                                io.Seek(0, SeekOrigin.Begin);
                                io.Write(bytes, 0, bytes.Length);
                                bytesReceived += bytes.Length;
                            }
                        }
                    }
                }
                //STEP 3...n: Continue downloading other chunks of the file
                if (bytesReceived < fileLength)
                {
                    bool[] failed = new bool[1];
                    using (WorkQueue queue = new WorkQueue(LimitThreads))
                    {
                        queue.OnError += (o, e) => { failed[0] = true; };
                        while (bytesReceived < fileLength && !failed[0] && !_abort.WaitOne(0, false))
                        {
                            int len = (int) Math.Min(fileLength - bytesReceived, maxMessageLength);
                            BytesToRead task = new BytesToRead(
                                this, LimitThreads, transferId, sessionKey, location, output, bytesReceived, len);
                            queue.Enqueue(task.Send);
                            OnProgressChanged(location, bytesReceived, fileLength);
                            bytesReceived += len;
                        }

                        queue.Complete(true, failed[0] ? 5000 : 7200000);
                    }

                    if (_abort.WaitOne(0, false))
                        return false;
                    Check.Assert<InvalidDataException>(failed[0] == false);

                    // STEP 4: Complete the transfer
                    using (Message req = new Message(TransferState.DownloadCompleteRequest, transferId, _publicKey, s => sessionKey))
                    {
                        SendPayload(req, location, req.ToStream(_privateKey)).Dispose();
                    }
                }
                OnProgressChanged(location, fileLength, fileLength);
                return true;
            }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:73,代码来源:SecureTransferClient.cs

示例12: HandleMessage

        private void HandleMessage(Message rdomail, string exportdir)
        {
            if (this.ProcessedMsgs.Contains(rdomail.Node))
                return;

            this.ProcessedMsgs.Add(rdomail.Node);

            string msgdir = exportdir;
            if (this.SaveAsTypes != SaveAsType.None || this.SaveAttachments == true)
                msgdir = msgdir + @"\" + rdomail.Node.ToString();

            if (!Directory.Exists(msgdir))
                Directory.CreateDirectory(msgdir);
            if (Directory.Exists(msgdir))
            {
                if ((this.SaveAsTypes & SaveAsType.Xml) == SaveAsType.Xml)
                    this.OutputFiles.Add(rdomail.Write(this.Pst2MsgCompatible ? exportdir + @"\XML" : msgdir, Message.SaveAsMessageType.Xml, true), "Xml");
                if ((this.SaveAsTypes & SaveAsType.Eml) == SaveAsType.Eml)
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Eml, true));
                if ((this.SaveAsTypes & SaveAsType.Msg) == SaveAsType.Msg)
                    this.OutputFiles.Add(rdomail.Write(this.Pst2MsgCompatible ? exportdir + @"\MSG" : msgdir, Message.SaveAsMessageType.Msg, true), "Msg");
                if ((this.SaveAsTypes & SaveAsType.Html) == SaveAsType.Html)
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Html, true), "Html");
                if (rdomail.HasBody && ((this.SaveAsTypes & SaveAsType.Text) == SaveAsType.Text))
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Text, true), "Text");
                if (rdomail.HasRtfBody && ((this.SaveAsTypes & SaveAsType.Rtf) == SaveAsType.Rtf))
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Rtf, true));
                foreach (pstsdk.definition.pst.message.IAttachment rdoattachment in rdomail.Attachments)
                {
                    if (rdoattachment.IsMessage)
                    {
                        Message attachmsg = null;
                        try
                        {
                            attachmsg = (Message)rdoattachment.OpenAsMessage();
                            attachmsg.Pst = rdomail.Pst;
                        }
                        catch (Exception ex)
                        {
                            WFLogger.NLogger.ErrorException(string.Format("PSTFile={0}  NodeID={1}", this.PSTFile, this.FileToProcess), ex);
                        }
                        finally
                        {
                            if (attachmsg != null)
                            {
                                if (this.SaveEmbeddedMsgs == true && attachmsg.Node == Convert.ToUInt32(this.FileToProcess))
                                {
                                    SaveAsType origsaveastype = this.SaveAsTypes;
                                    this.SaveAsTypes = SaveAsType.Msg | SaveAsType.Xml | SaveAsType.Html;
                                    HandleMessage(attachmsg, exportdir);
                                    this.SaveAsTypes = origsaveastype;
                                }
                                else
                                    this.OutputFiles.Add(attachmsg.Node.Value.ToString(), "EmbeddedMsg");
                            }
                        }
                    }
                    else if (this.SaveAttachments)
                    {
                        string filedir = string.Format("{0}\\{1}", msgdir, WFUtilities.GetNextDirectoryNumber(msgdir));
                        if (!Directory.Exists(filedir))
                            Directory.CreateDirectory(filedir);
                        if (Directory.Exists(filedir))
                        {
                            string filename = filedir + @"\" + rdoattachment.Filename;
                            using (var bw = new BinaryWriter(File.OpenWrite(filename)))
                            {
                                bw.Write(rdoattachment.Bytes);
                                this.OutputFiles.Add(filename, "Attachment");
                            }
                        }
                    }
                    rdoattachment.Dispose();
                }
            }
        }
开发者ID:kmrgithub,项目名称:KRSrcWorkflow,代码行数:76,代码来源:PSTMsgParser_Orig.cs


注:本文中的Message.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。