void FirstOperation(Task task, int operationIndex) { FirstOperationCalled = true; FirstOperationIndex = operationIndex; if (FirstOperationCallback != null) FirstOperationCallback(); }
void SecondOperation(Task task, int operationIndex) { SecondOperationCalled = true; SecondOperationIndex = operationIndex; if (SecondOperationCallback != null) SecondOperationCallback(); }
static dynamic ToDynamic(Task task) { dynamic dynamicTask = new ExpandoObject(); dynamicTask.Type = task.GetType().Name; dynamicTask.Id = task.Id.Value; dynamicTask.CurrentOperation = task.CurrentOperation; PopulateStateFromProperties(dynamicTask, task); return dynamicTask; }
static void PopulateStateFromProperties(ExpandoObject target, Task source) { var sourceType = source.GetType(); var taskType = typeof(Task); var taskProperties = taskType.GetProperties(); var declaringTypeProperties = sourceType.GetProperties().Where(p => p.DeclaringType == sourceType); var sourceProperties = declaringTypeProperties.Where(p => !taskProperties.Any(pp => pp.Name == p.Name)); var dictionary = sourceProperties.ToDictionary(p => p.Name, p => p.GetValue(source, null).ToString()); foreach (var key in dictionary.Keys) ((IDictionary<string, object>)target)[key] = dictionary[key]; }
public void Delete(Task task) { lock (_entityContext) { var existing = _entityContext.GetById(task.Id.Value); if (existing != null) { _entityContext.Delete(existing); _entityContext.Commit(); } } }
public void Save(Task task) { lock (_entityContext) { var existing = _entityContext.GetById(task.Id.Value); if (existing != null) _entityContext.Update(ToTaskEntity(task, existing)); else _entityContext.Insert(ToTaskEntity(task)); _entityContext.Commit(); } }
void Perform(Task task, int operationIndex) { IEnumerable<IEvent> events; do { events = _eventStore.GetBatch(PageNumber, 10); if (events.Count() <= 0) break; var actualEvents = events.Where(e => !e.GetType().Namespace.Contains("Mimir")); _eventSubscriptionManager.Process(actualEvents); PageNumber++; Progress(); } while (events.Count() > 0 && events != null); }
#pragma warning disable 1591 // Xml Comments public void Start(Task task, Action<Task> taskDone=null) { if (task.IsDone) { taskDone(task); return; } if (!_tasks.Contains(task)) _tasks.Add(task); if (task.CanRunOperationsAsynchronously) ScheduleOperations(task, taskDone); else ExecuteOperations(task, taskDone); }
#pragma warning restore 1591 // Xml Comments void ScheduleOperations(Task task, Action<Task> taskDone) { _taskOperationIds[task] = new Guid[task.Operations.Length]; var operationsDone = new bool[task.Operations.Length]; for (var operationIndex = 0; operationIndex < task.CurrentOperation; operationIndex++) operationsDone[operationIndex] = true; for (var operationIndex = task.CurrentOperation; operationIndex < task.Operations.Length; operationIndex++) ScheduleOperation(task, operationsDone, operationIndex, taskDone); if (!_tasks.Contains(task)) StopOperationsForTask(task); if (!operationsDone.Any(b => b == false)) _taskOperationIds.Remove(task); }
void PopulateStateFromProperties(TaskEntity target, Task source) { var sourceType = source.GetType(); var taskType = typeof(Task); #if(NETFX_CORE) var taskProperties = taskType.GetTypeInfo().DeclaredProperties; var declaringTypeProperties = sourceType.GetTypeInfo().DeclaredProperties.Where(p => p.DeclaringType == sourceType); #else var taskProperties = taskType.GetProperties(); var declaringTypeProperties = sourceType.GetProperties().Where(p => p.DeclaringType == sourceType); #endif var sourceProperties = declaringTypeProperties.Where(p=>!taskProperties.Any(pp=>pp.Name == p.Name)); var sourcePropertiesDictionary = sourceProperties.ToDictionary(p => p.Name, p => p.GetValue(source, null).ToString()); sourcePropertiesDictionary.ForEach(target.State.Add); }
TaskEntity ToTaskEntity(Task task, TaskEntity taskEntity = null) { if( taskEntity == null ) taskEntity = new TaskEntity(); taskEntity.Id = task.Id; taskEntity.CurrentOperation = task.CurrentOperation; taskEntity.Type = task.GetType(); PopulateStateFromProperties(taskEntity, task); return taskEntity; }
void PopulatePropertiesFromState(Task target, TaskEntity source) { var targetType = target.GetType(); foreach (var key in source.State.Keys) { #if(NETFX_CORE) var property = targetType.GetTypeInfo().GetDeclaredProperty(key); #else var property = targetType.GetProperty(key); #endif if (property != null) { var value = Convert.ChangeType(source.State[key], property.PropertyType, null); property.SetValue(target, value, null); } } }
public void SecondOperation(Task task, int operationIndex) { SecondOperationCalled = true; }
public void FirstOperation(Task task, int operationIndex) { FirstOperationCalled = true; }
public void Paused(Task task) { }
public void Resumed(Task task) { }
public static void StateChanged(Task task) { GlobalHost.ConnectionManager.GetHubContext<TaskHub>().Clients.All.StateChanged(ToDynamic(task)); }
void ScheduleOperation(Task task, bool[] operationsDone, int operationIndex, Action<Task> taskDone) { var currentOperationIndex = operationIndex; _taskOperationIds[task][currentOperationIndex] = _scheduler.Start<Task>(t => t.Operations[currentOperationIndex](t, currentOperationIndex), task, t => { task.CurrentOperation = currentOperationIndex + 1; operationsDone[currentOperationIndex] = true; if( taskDone != null ) if (!operationsDone.Any(b => b == false)) taskDone(task); }); }
public void Stopped(Task task) { TaskHub.Stopped(task); }
public void StateChanged(Task task) { TaskHub.StateChanged(task); }
void StopOperationsForTask(Task task) { if (_taskOperationIds.ContainsKey(task)) foreach (var operationId in _taskOperationIds[task]) if (operationId != Guid.Empty) _scheduler.Stop(operationId); }
void ExecuteOperations(Task task, Action<Task> taskDone) { _scheduler.Start<Task>(t => { for (var operationIndex = task.CurrentOperation; operationIndex < task.Operations.Length; operationIndex++) { task.Operations[operationIndex](task, operationIndex); task.CurrentOperation++; if (!_tasks.Contains(task)) break; } _tasks.Remove(task); if( taskDone != null ) taskDone(task); }, task); }
void PopulatePropertiesFromState(Task target, TaskEntity source) { var targetType = target.GetType(); foreach (var key in source.State.Keys) { var property = targetType.GetProperty(key); if (property != null) { var value = Convert.ChangeType(source.State[key], property.PropertyType, null); property.SetValue(target, value, null); } } }
public void Stop(Task task) { _tasks.Remove(task); StopOperationsForTask(task); }
public void Started(Task task) { TaskHub.Started(task); }