Exemplo n.º 1
0
 void FirstOperation(Task task, int operationIndex)
 {
     FirstOperationCalled = true;
     FirstOperationIndex = operationIndex;
     if (FirstOperationCallback != null)
         FirstOperationCallback();
 }
Exemplo n.º 2
0
 void SecondOperation(Task task, int operationIndex)
 {
     SecondOperationCalled = true;
     SecondOperationIndex = operationIndex;
     if (SecondOperationCallback != null)
         SecondOperationCallback();
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
        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];
        }
Exemplo n.º 5
0
 public void Delete(Task task)
 {
     lock (_entityContext)
     {
         var existing = _entityContext.GetById(task.Id.Value);
         if (existing != null)
         {
             _entityContext.Delete(existing);
             _entityContext.Commit();
         }
     }
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 8
0
#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);
        }
Exemplo n.º 9
0
#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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 12
0
        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);
                }
            }
        }
Exemplo n.º 13
0
 public void SecondOperation(Task task, int operationIndex)
 {
     SecondOperationCalled = true;
 }
Exemplo n.º 14
0
 public void FirstOperation(Task task, int operationIndex)
 {
     FirstOperationCalled = true;
 }
Exemplo n.º 15
0
 public void Paused(Task task)
 {
     
 }
Exemplo n.º 16
0
 public void Resumed(Task task)
 {
     
 }
Exemplo n.º 17
0
 public static void StateChanged(Task task)
 {
     GlobalHost.ConnectionManager.GetHubContext<TaskHub>().Clients.All.StateChanged(ToDynamic(task));
 }
Exemplo n.º 18
0
        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);
            });
        }
Exemplo n.º 19
0
 public void Stopped(Task task)
 {
     TaskHub.Stopped(task);
 }
Exemplo n.º 20
0
 public void StateChanged(Task task)
 {
     TaskHub.StateChanged(task);
 }
Exemplo n.º 21
0
 void StopOperationsForTask(Task task)
 {
     if (_taskOperationIds.ContainsKey(task))
         foreach (var operationId in _taskOperationIds[task])
             if (operationId != Guid.Empty)
                 _scheduler.Stop(operationId);
 }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
 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);
         }
     }
 }
Exemplo n.º 24
0
        public void Stop(Task task)
        {
            _tasks.Remove(task);
            StopOperationsForTask(task);

        }
Exemplo n.º 25
0
 public void Started(Task task)
 {
     TaskHub.Started(task);
 }