Exemplo n.º 1
0
        /// <summary>
        /// Enqueues a unit of work
        /// </summary>
        /// <param name="work">The work to be performed</param>
        /// <param name="worker">The handler that will be invoked to perform the work</param>
        /// <param name="observers">A listener for which appropriate actions will be invoked during
        /// execution</param>
        /// <returns></returns>
        public WorkPartition Submit(IPartitionedWork work, Action <IPartitionedWork> worker, IReadOnlyList <IWorkAgentObserver> observers)
        {
            var clrTaskId = WorkPartition.AssignIdentity();

            Action <IPartitionedWork> adapter = w =>
            {
                iter(observers, observer => observer.RaiseWorkDispatched(work));

                try
                {
                    worker(work);
                }
                finally
                {
                    HandleTaskCompletion(clrTaskId).OnNone(()
                                                           => Notify(AppMessage.Warn("There was no task to complete")));
                }

                iter(observers, observer => observer.RaiseWorkCompleted(work));
            };

            var workTask = EnqueueWork(WorkPartition.Create(clrTaskId, work, adapter));

            iter(observers, observer => observer.RaiseWorkSubmitted(work));
            return(workTask);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Defines a correlated warning
 /// </summary>
 /// <param name="CT">The correlation value</param>
 /// <param name="text">The message text</param>
 /// <param name="callerFile">The file from which the call was made</param>
 /// <param name="callerName">The name of the invoking member</param>
 /// <returns></returns>
 public static IAppMessage warn(CorrelationToken CT, string text,
                                [CallerFilePath] string callerFile   = null,
                                [CallerMemberName] string callerName = null)
 => AppMessage.Warn(text, callerFile, callerName);
Exemplo n.º 3
0
 /// <summary>
 /// Defines a correlated warning with typed content
 /// </summary>
 /// <typeparam name="C">The content type</typeparam>
 /// <param name="CT">The correlation value</param>
 /// <param name="template">A content-bound template string</param>
 /// <param name="content">The typed content</param>
 /// <param name="callerFile">The file from which the call was made</param>
 /// <param name="callerName">The name of the invoking member</param>
 /// <returns></returns>
 public static IAppMessage warn <C>(CorrelationToken CT, string template, C content,
                                    [CallerFilePath] string callerFile   = null,
                                    [CallerMemberName] string callerName = null)
 => AppMessage.Warn(CT, template, content, callerFile, callerName);
Exemplo n.º 4
0
 static IAppMessage EmptyWorker() => AppMessage.Warn("I do nothing");
Exemplo n.º 5
0
 public static IAppMessage AlreadyRunning()
 => AppMessage.Warn("The agent is already running");
Exemplo n.º 6
0
 public static IAppMessage TasksUnfinished(int Count, int Timeout)
 => AppMessage.Warn("There were @Count currentingly executing tasks when a wait timeout of @Timeout ms expired", new
 {
     Count,
     Timeout
 });
Exemplo n.º 7
0
 public static IAppMessage EnqueuedNewCommands(CommandSpecDescriptor d, int Count)
 => AppMessage.Warn("Enqueued @Count new @CommandName commands", new
 {
     d.CommandName,
     Count
 });
Exemplo n.º 8
0
 public static IAppMessage OrchestratedTasksStillExecuting(CommandSpecDescriptor d)
 => AppMessage.Warn("@CommandName commands are still executing", new
 {
     d.CommandName
 });