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


C# Message.Dispose方法代码示例

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


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

示例1: DisposingOwnedStreamTest

        public void DisposingOwnedStreamTest()
        {
            // ownStream = true
            var ms = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!"));
            var msg = new Message(ms, true);
            msg.Dispose();

            TestAssert.Throws<ObjectDisposedException>(() => ms.Write(Encoding.UTF8.GetBytes("howdy"), 0, 5));

            // ownStream = false
            ms = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!"));
            msg = new Message(ms, false);
            msg.Dispose();

            ms.Write(Encoding.UTF8.GetBytes("howdy"), 0, 5);
        }
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:16,代码来源:MessageTests.cs

示例2: AsyncProcessRequest

        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msgReq, ITransportHeaders headers, Stream stream)
        {
            // scope state
            string strQueuePath = null;
            string strObjectUri = null;
            Message outMsg = null;
            MessageQueueTransaction mqtx = new MessageQueueTransaction();

            try
            {
                #region pre-processor (mapping url address)
                // split into the queuepath and endpoint
                strObjectUri = ParseLogicalUrl(m_LogicalUri, out strQueuePath);

                // update Uri property
                msgReq.Properties[MSMQChannelProperties.ObjectUri] = strObjectUri;

                // pass TransportHeaders to the receiver
                if(m_Sender.AllowHeaders == true)
                {
                    headers["__RequestUri"] = strObjectUri;
                    msgReq.Properties["__RequestHeaders"] = headers;
                }
                #endregion

                #region send a remoting message
                // set the destination queue
                m_OutQueue.Path = strQueuePath;

                // create a message
                outMsg = new Message(msgReq, new BinaryMessageFormatter());

                // option: timeout to pick-up a message (receive message)
                int intTimeToBeReceived = m_Sender.TimeToBeReceived;
                if(intTimeToBeReceived > 0)
                    outMsg.TimeToBeReceived = TimeSpan.FromSeconds(intTimeToBeReceived);

                // option: timeout to reach destination queue (send message)
                int intTimeToReachQueue = m_Sender.TimeToReachQueue;
                if(intTimeToReachQueue > 0)
                    outMsg.TimeToReachQueue = TimeSpan.FromSeconds(intTimeToReachQueue);

                // option: notify a negative receive on the client/server side
                if(m_Sender.AdminQueuePath != MSMQChannelDefaults.EmptyStr)
                {
                    // acknowledge type (mandatory)
                    outMsg.AcknowledgeType = AcknowledgeTypes.NegativeReceive | AcknowledgeTypes.NotAcknowledgeReachQueue;

                    // admin queue for a time-expired messages
                    outMsg.AdministrationQueue = m_Sender.AdminQueue;
                }

                // message label
                string label = string.Format("{0}/{1}, url={2}", Convert.ToString(msgReq.Properties["__TypeName"]).Split(',')[0],
                    Convert.ToString(msgReq.Properties["__MethodName"]), strObjectUri);

                //// Send message based on the transaction context
                //if(ContextUtil.IsInTransaction == true)
                //{
                //    // we are already in the transaction - automatic (DTC) transactional message
                //    m_OutQueue.Send(outMsg, label, MessageQueueTransactionType.Automatic);
                //}
                //else
                //{
                    // this is a single transactional message
                    mqtx.Begin();
                    m_OutQueue.Send(outMsg, label, mqtx);
                    mqtx.Commit();
                //}
                #endregion
            }
            catch(Exception ex)
            {
                string strError = string.Format("[{0}]MSMQClientTransportSink.AsyncProcessRequest error = {1}, queuepath={2},",
                    m_Sender.ChannelName, ex.Message, strQueuePath);

                m_Sender.WriteLogMsg(strError, EventLogEntryType.Error);
                throw new Exception(strError);
            }
            finally
            {
                #region clean-up
                if(mqtx.Status == MessageQueueTransactionStatus.Pending)
                {
                    mqtx.Abort();
                    Trace.WriteLine(string.Format("[{0}]MSMQClientTransportSink.AsyncProcessRequest Aborted, msgId = {1}", m_Sender.ChannelName, outMsg.Id));
                }

                if(outMsg != null)
                    outMsg.Dispose();
                #endregion
            }
        }
开发者ID:yallie,项目名称:zyan,代码行数:93,代码来源:SenderMessageSink.cs

示例3: MessageHandlerPos

        private int MessageHandlerPos(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    SchemeFortsPos.position p = new SchemeFortsPos.position(msg.Data);
                    for (int i = 0; i < Account.Positions.Count; i++)
                    {
                        if (Account.Positions[i].Instr.ID == p.isin_id)
                        {
                            if (p.pos == 0)
                            {
                                Account.Positions.RemoveAt(i);
                                return 0;
                            }
                            Account.Positions[i].Pos = p.pos;
                            Account.Positions[i].Price = p.waprice;
                            return 0;
                        }
                    }
                    if (p.pos != 0)
                    {
                        Account.Positions.Add(new AccountInfo.Position());
                        Account.Positions[Account.Positions.Count - 1].Pos = p.pos;
                        Account.Positions[Account.Positions.Count - 1].Price = p.waprice;
                        foreach (Instrument instr in Instruments)
                        {
                            if (instr.ID == p.isin_id)
                                Account.Positions[Account.Positions.Count - 1].Instr = instr;
                            return 0;
                        }
                        Account.Positions[Account.Positions.Count - 1].Instr = new Instrument();
                        Account.Positions[Account.Positions.Count - 1].Instr.ID = p.isin_id;
                    }
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {

                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)    // REPLONLINE
                {
                    mtx.WaitOne();
                    FutPosOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutVMOnline && CurrInfoOnline && SpotInfoOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisFutPosReplState = ((P2ReplStateMessage)msg).ReplState;
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
开发者ID:Groxan,项目名称:RepVol,代码行数:66,代码来源:MInfo.cs

示例4: MessageHandlerVM

        private int MessageHandlerVM(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    SchemeFortsVM.fut_vm p = new SchemeFortsVM.fut_vm(msg.Data);
                    for (int i = 0; i < Account.Positions.Count; i++)
                    {
                        if (Account.Positions[i].Instr.ID == p.isin_id)
                        {
                            Account.Positions[i].Profit = p.vm_real;
                        }
                    }
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {

                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)    // REPLONLINE
                {
                    mtx.WaitOne();
                    FutVMOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutVMOnline && CurrInfoOnline && SpotInfoOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisFutVMReplState = ((P2ReplStateMessage)msg).ReplState;
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
开发者ID:Groxan,项目名称:RepVol,代码行数:45,代码来源:MInfo.cs

示例5: MessageHandlerPart

        private int MessageHandlerPart(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    SchemeFortsPart.part p = new SchemeFortsPart.part(msg.Data);

                    Account.ClientCode = p.client_code;
                    Account.BlockedMoney = p.money_blocked;
                    Account.FreeMoney = p.money_free;
                    Account.TotalMoney = p.money_amount;
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {

                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)    // REPLONLINE
                {
                    mtx.WaitOne();
                    FutPartOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutVMOnline && CurrInfoOnline && SpotInfoOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisFutPartReplState = ((P2ReplStateMessage)msg).ReplState;
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
开发者ID:Groxan,项目名称:RepVol,代码行数:43,代码来源:MInfo.cs

示例6: MessageHandlerInfoSpot

        private int MessageHandlerInfoSpot(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    if ((msg as ru.micexrts.cgate.message.StreamDataMessage).MsgIndex == 0) // session
                    {
                        SchemeFortsInfo.session sess = new SchemeFortsInfo.session(msg.Data);
                        if (Session.ID == sess.sess_id)
                        {
                            Session.State = sess.state;
                            Session.ClearingState = sess.inter_cl_state;
                        }
                        else if (Session.ID < sess.sess_id)
                        {
                            Session.ID = sess.sess_id;
                            Session.State = sess.state;
                            Session.ClearingState = sess.inter_cl_state;
                        }
                    }
                    else if ((msg as ru.micexrts.cgate.message.StreamDataMessage).MsgIndex == 1) // fut_sess_contents
                    {
                        SchemeFortsInfo.fut_sess_contents instr = new SchemeFortsInfo.fut_sess_contents(msg.Data);
                        for (int i = 0; i < Instruments.Count; i++)
                        {
                            if (instr.isin_id == Instruments[i].ID)
                            {
                                Instruments[i].SessionID = instr.sess_id;
                                Instruments[i].State = instr.state;
                                Instruments[i].FullName = instr.name;
                                Instruments[i].Name = instr.isin;
                                Instruments[i].ShortName = instr.short_isin;
                                Instruments[i].Start = instr.d_start;
                                Instruments[i].Expitation = instr.d_exp;
                                Instruments[i].LotVolume = instr.lot_volume;
                                Instruments[i].Points = instr.roundto;

                                return 0;
                            }
                        }

                        Instruments.Add(new Instrument());
                        Instruments[Instruments.Count - 1].ID = instr.isin_id;
                        Instruments[Instruments.Count - 1].SessionID = instr.sess_id;
                        Instruments[Instruments.Count - 1].State = instr.state;
                        Instruments[Instruments.Count - 1].FullName = instr.name;
                        Instruments[Instruments.Count - 1].Name = instr.isin;
                        Instruments[Instruments.Count - 1].ShortName = instr.short_isin;
                        Instruments[Instruments.Count - 1].Start = instr.d_start;
                        Instruments[Instruments.Count - 1].Expitation = instr.d_exp;
                        Instruments[Instruments.Count - 1].LotVolume = instr.lot_volume;
                        Instruments[Instruments.Count - 1].Points = instr.roundto;
                    }
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {

                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)    // REPLONLINE
                {
                    mtx.WaitOne();
                    SpotInfoOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutVMOnline && CurrInfoOnline && SpotInfoOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisSpotInfoReplState = ((P2ReplStateMessage)msg).ReplState;
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
开发者ID:Groxan,项目名称:RepVol,代码行数:85,代码来源:MInfo.cs

示例7: MessageHandlerTrade

        private int MessageHandlerTrade(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgData)              // DATA
                {
                    if ((msg as DataMessage).MsgName == "FORTS_MSG101")
                    {
                        SchemeFortsMsg.FORTS_MSG101 repl = new SchemeFortsMsg.FORTS_MSG101(msg.Data);
                        if (repl.code == 0)
                            Ticket = repl.order_id;
                        else
                        {
                            errMessage = repl.message;
                            Ticket = -repl.code;
                        }
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG102")
                    {
                        SchemeFortsMsg.FORTS_MSG102 repl = new SchemeFortsMsg.FORTS_MSG102(msg.Data);
                        if (repl.code == 0)
                            Ticket = repl.amount;
                        else
                        {
                            errMessage = repl.message;
                            Ticket = -repl.code;
                        }
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG103")
                    {
                        SchemeFortsMsg.FORTS_MSG103 repl = new SchemeFortsMsg.FORTS_MSG103(msg.Data);
                        if (repl.code == 0)
                            Ticket = repl.num_orders;
                        else
                        {
                            errMessage = repl.message;
                            Ticket = -repl.code;
                        }
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG105")
                    {
                        SchemeFortsMsg.FORTS_MSG105 repl = new SchemeFortsMsg.FORTS_MSG105(msg.Data);
                        if (repl.code == 0)
                            Ticket = repl.order_id1;
                        else
                        {
                            errMessage = repl.message;
                            Ticket = -repl.code;
                        }
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG99")
                    {
                        SchemeFortsMsg.FORTS_MSG99 repl = new SchemeFortsMsg.FORTS_MSG99(msg.Data);
                        errMessage = repl.message;
                        OnError(new ErrorEvent("FORTS_MSG99: " + repl.message));
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG100")
                    {
                        SchemeFortsMsg.FORTS_MSG100 repl = new SchemeFortsMsg.FORTS_MSG100(msg.Data);
                        errMessage = repl.message;
                        OnError(new ErrorEvent("FORTS_MSG100: " + repl.message));
                        Execution = false;
                    }
                }
                else if (msg.Type == MessageType.MsgP2MQTimeout)
                {
                    errMessage = "Таймаут";
                    Ticket = -1488;
                    Execution = false;
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {
                    mtx.WaitOne();
                    FutTradeOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutTradeOnline && FutVMOnline && FutCommonOnline && FutDealsOnline && FutDrinksOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisPubReplState = ((P2ReplStateMessage)msg).ReplState.TrimEnd((char)0);
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
//.........这里部分代码省略.........
开发者ID:Groxan,项目名称:RepVol,代码行数:101,代码来源:MPDLL.cs

示例8: MessageHandlerDrinks

        private int MessageHandlerDrinks(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    SchemeFortsDrink.orders_aggr aggr = new SchemeFortsDrink.orders_aggr(msg.Data);
                    for (int i = 0; i < Drinks.Count; i++)
                    {
                        if (aggr.isin_id == Drinks[i].InstrId)
                        {
                            if (aggr.volume != 0)
                                Drinks[i].AddQuote(new Drink.Quote(aggr.replID, aggr.price, aggr.volume, aggr.dir));
                            else
                                Drinks[i].RemoveQuote(aggr.replID);

                            if (FutDrinksOnline)
                                OnDrink(Drinks[i]);

                            break;
                        }
                    }
                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)               // OPEN
                {
                    mtx.WaitOne();
                    FutDrinksOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutTradeOnline && FutVMOnline && FutCommonOnline && FutDealsOnline && FutDrinksOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
开发者ID:Groxan,项目名称:RepVol,代码行数:45,代码来源:MPDLL.cs

示例9: MessageHandlerDeals

        private int MessageHandlerDeals(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    if ((msg as ru.micexrts.cgate.message.StreamDataMessage).MsgIndex == 1)
                        OnDeal(new DealInfo(msg.Data));
                    else
                        OnOrder(new OrderInfo(msg.Data));
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {
                    mtx.WaitOne();
                    FutDealsOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutTradeOnline && FutVMOnline && FutCommonOnline && FutDealsOnline && FutDrinksOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisFutDealsReplState = ((P2ReplStateMessage)msg).ReplState.TrimEnd((char)0);
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
开发者ID:Groxan,项目名称:RepVol,代码行数:37,代码来源:MPDLL.cs


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