Example #1
0
 public IEnumerable <IDataflowMessage <TOut> > Pull()
 {
     m_LogAgent.LogInfo(DataflowNetworkConstituent.Source, m_DecoratedSource.Title, "Pulling started.");
     foreach (var dfMsg in m_DecoratedSource.Pull())
     {
         Interlocked.Increment(ref m_NumMessagesProcessed);
         m_LogAgent.LogTrace(DataflowNetworkConstituent.Source, m_DecoratedSource.Title, "Pulled source: {0}", dfMsg.Title);
         yield return(dfMsg);
     }
     m_LogAgent.LogInfo(DataflowNetworkConstituent.Source, m_DecoratedSource.Title, "Pulling finished.");
 }
        public void LogStatistics()
        {
            string dfnConstituentType = m_Constituent.ToString("G");
            string stats = StatisticsHelper.FormatLogMessage(m_Title, dfnConstituentType, Interlocked.Read(ref NumProcessedMessages), Interlocked.Read(ref NumBrokenMessages));

            m_LogAgent.LogInfo(m_Constituent, m_Title, stats);
        }
Example #3
0
        /// <summary>
        /// Activates the flow of messages inside the dataflow-network.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <exception cref="DataflowNetworkFailedException">Thrown when the dataflow-network has encountered an exception during its lifetime.</exception>
        public void Start <T>(ISourceAgent <T> source)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(null, "DataflowNetwork already disposed.");
            }

            if (m_SourceAgent == null || m_SourceAgent != source)
            {
                throw new ArgumentException("SourceAgent not linked with this network.", "source");
            }

            // Attach sinks.
            foreach (var nullLink in m_NullLinks)
            {
                nullLink();
            }

            try
            {
                // Tell the producer to start producing items.
                var mainTask = source.StartAsync();
                m_ConstituentTasks.Add(mainTask);

                // Block and wait for all the dataflow-network constituents to complete their work.
                Task.WaitAll(m_ConstituentTasks.ToArray(), m_Cts.Token);
                m_LogAgent.LogInfo(DataflowNetworkConstituent.Network, m_Name, "Network finished successfully.");
                DumpStats();
                m_LogAgent.Complete();
            }
            catch (AggregateException ex)
            {
                m_LogAgent.LogError(DataflowNetworkConstituent.Network, m_Name, ex.Flatten(), "The network encountered an unhandled exception.");
                throw new DataflowNetworkFailedException("The datanetwork " + m_Name + " failed. See the inner exception for more details", ex);
            }
            catch (OperationCanceledException)
            {
                var exceptions = m_ConstituentTasks.Where(task => task.IsFaulted).Select(task => task.Exception);
                foreach (var ex in exceptions)
                {
                    m_LogAgent.LogError(DataflowNetworkConstituent.Network, m_Name, ex.Flatten(),
                                        "The network encountered an unhandled exception.");
                }
            }
            catch (Exception ex)
            {
                m_LogAgent.LogError(DataflowNetworkConstituent.Network, m_Name, ex, "The network encountered an unhandled exception.");
                throw new DataflowNetworkFailedException("The datanetwork " + m_Name + " failed. See the inner exception for more details", ex);
            }
            finally
            {
                m_ConstituentTasks.Clear();
                m_Cts.Cancel();
                GC.Collect();
                Dispose();
            }
        }