Esempio n. 1
0
        private void callBack <T>(Task <T> ar)
        {
            log.Debug("finished: " + ar.GetType());

            if (ar is Task)
            {
                TaskCompleted tc = (ar.Result as TaskCompleted);
                if (tc != null)
                {
                    try
                    {
                        log.Debug("try get task");
                        ITask task = runningTasks[tc.TaskId];
                        log.Debug("finished: " + task.Name + "-" + task.Uid);

                        TaskData td = GetTaskDataByName(task.Name);
                        td.IncNextRun();
                        if (td.ExtraRun)
                        {
                            log.Info("Extrarun: " + tc.Message);
                        }
                        //if we are not running anymore we remove the tasks in the storeTasks function
                        //if (Running)
                        //{
                        //runningTasks.Remove(tc.TaskId);
                        ITask removed;
                        runningTasks.TryRemove(tc.TaskId, out removed);
                        td.ExtraRun = false;
                        //}

                                                #if DBUS
                        // rc.TaskFinished(tc.Message);  //TODO Taskfinished Evenet for DBus
                                                #endif

                        lock (finishedTasks)
                        {
                            log.Debug("add finished task:" + removed.Name + "-" + removed.Uid);
                            finishedTasks.Add(removed.Uid, removed);
                        }

                        switch (tc.State)
                        {
                        case TaskCompletedState.None:
                        case TaskCompletedState.Error:
                            log.Error(tc.Message);
                            break;

                        case TaskCompletedState.Success:
                            log.Debug(tc.Message);
                            break;

                        default:
                            throw new Exception("undefined state");
                        }
                    } catch (Exception ex)
                    {
                        log.Error("callBack:: " + ex.ToString());                         //TODO logging
                        throw;
                    }
                }
                else
                {
                    throw new Exception("method should return an TaskCompleted object");
                }
            }
            else
            {
                throw new Exception("this should not happen");
            }

            log.Debug("end finished");
        }