Пример #1
0
            /// <summary>
            /// Method is called when a new message arrives from the Publisher
            /// </summary>
            /// <param name="status">get data avaliable</param>
            public override void OnDataAvailable(DataAvailableStatus <ChatMessage> status)
            {
                DataReader <ChatMessage>     dr;
                SampleIterator <ChatMessage> It;
                ChatMessage dt;

                // Obtain the source of DataReader
                dr = status.GetSource();
                // Obtain the stack of messages published
                It = dr.Take();



                // Iterator of the list of messages, to present it in console
                foreach (Sample <ChatMessage> smp in It)
                {
                    // SampleInfo stuff is built into Sample:
                    // InstanceHandle inst = smp.GetInstanceHandle();
                    // Data accessible from Sample; null if invalid:
                    cache = cache + 1;
                    dt    = smp.GetData();


                    if (backgroundWorker1.IsBusy || backgroundWorker4.IsBusy)
                    {
                        BackgroundLoop(dt, cache);
                    }
                    else
                    {
                        cache = cache - 1;
                        this.backgroundWorker1.RunWorkerAsync(dt);
                        this.backgroundWorker4.RunWorkerAsync(cache);
                    }
                }
            }
Пример #2
0
            //private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

            public override void OnDataAvailable(DataAvailableStatus <Greeting> status)
            {
                DataReader <Greeting>     dr = status.GetSource();
                SampleIterator <Greeting> it = dr.Take();

                foreach (Sample <Greeting> smp in it)
                {
                    // SampleInfo stuff is built into Sample:
                    // InstanceHandle inst = smp.GetInstanceHandle();
                    // Data accessible from Sample; null if invalid:
                    Greeting dt = smp.GetData();
                    Console.WriteLine("Received data:\"{0}\"", dt.Value);
                }
            }