Exemplo n.º 1
0
        private async Task <ITaskState> DoTask(ITaskState taskState, ScheduleMode mode, CancellationToken cancellationToken)
        {
            var currentTime = DateTime.Now;

            if (options.PollingSchedules != null)
            {
                foreach (var item in options.PollingSchedules)
                {
                    var pw = EnsureWrapped(item);
                    if (IsDue(currentTime, pw))
                    {
                        pw.LastRunTime = pw.NextRunTime;
                        pw.NextRunTime = pw.Schedule.GetNextOccurrence(pw.NextRunTime);
                        var r = await Poll(item);

                        if (r)
                        {
                            log.LogInformation($"Poll {item.Url} succeeded");
                        }
                    }
                }
            }
            else
            {
                log.LogInformation("no urls provided");
            }
            return(null);
        }
Exemplo n.º 2
0
        private async Task <ITaskState> DoTask(ITaskState taskState, ScheduleMode mode, CancellationToken cancellationToken)
        {
            var configuredOn = DateTimeOffset.Now;

            using (db = dbf.GetWebDbContext <ServiceDb>())
            {
                await db.Database.EnsureCreatedAsync();

                //var sm = new ServerManager();
                //foreach (var site in sm.Sites)
                //{
                //    await AddSiteFolder(configuredOn, site);
                //}
                foreach (var fs in options.FolderSources)
                {
                    await AddFolderSource(configuredOn, fs);
                }
                var staleList = await db.SourceFolders
                                .Include(x => x.Backups)
                                .Where(x => x.ConfiguredOn < configuredOn).ToArrayAsync();

                foreach (var sf in staleList)
                {
                    var backups = sf.Backups.ToArray();
                    db.Backups.RemoveRange(backups);
                    db.SourceFolders.Remove(sf);
                    log.LogInformation($"{sf.DisplayName} {sf.FullPath} (with {backups.Count()} backups) removed");
                }
                await db.SaveChangesAsync();

                var count = db.SourceFolders.Count();
                log.LogInformation($"found {count} source folders in database");
                return(null);// Task.FromResult<ITaskState>(null);
            }
        }
Exemplo n.º 3
0
        protected override void InternalCopyFromModified(IProperty srcProperty)
        {
            Task       task      = (Task)base.XsoItem;
            ITaskState taskState = (ITaskState)srcProperty;

            if (taskState.Complete)
            {
                if (taskState.DateCompleted != null)
                {
                    if (task.IsRecurring)
                    {
                        task.SuppressCreateOneOff = false;
                    }
                    task.SetCompleteTimesForUtcSession(taskState.DateCompleted.Value, taskState.DateCompleted);
                    return;
                }
                throw new ConversionException("DateCompleted must be specified if Complete = 1");
            }
            else
            {
                if (taskState.DateCompleted != null)
                {
                    throw new ConversionException("DateCompleted must not be specified if Complete = 0");
                }
                task.SetStatusNotStarted();
                return;
            }
        }
Exemplo n.º 4
0
        /**
         * Restore from the ITaskState the number of times that the child task of
         * this decorator has been run so far. It is read from the variable whose
         * name is {@link #STATE_VARIABLE_NAME}.
         *
         * @see jbt.execution.core.ExecutionTask#restoreState(ITaskState)
         */

        protected override void RestoreState(ITaskState state)
        {
            try
            {
                _numRunsSoFar = (int)state.GetStateVariable(StateVariableName);
            }
            catch
            {
            }
        }
Exemplo n.º 5
0
        private void btnStateCreate_Click(object sender, RoutedEventArgs e)
        {
            ITaskState state = NinjectFactory.Instance.Get <ITaskState>();

            state.Name     = "New task state";
            state.Priority = 1.5M;
            ViewModel.TaskStates.Add(state);
            ViewModel.CheckableTaskStates.Add(Checkable.Create(state, true));
            ViewModel.SelectedTaskState = state;
            Repository.Save(state);
        }
Exemplo n.º 6
0
        private void btnCompleteTask_Click(object sender, RoutedEventArgs e)
        {
            ITask      task  = (sender as Button).Tag as ITask;
            ITaskState state = Repository.TaskStates.FirstOrDefault(s => s.Flag == TaskStateFlag.Completed);

            if (task != null && state != null && task.State != state)
            {
                task.State = state;
                Repository.Save(task);
                ViewModelHelper.UpdateTasks(Repository, ViewModel);
            }
        }
 private BroadcastSenderReduceReceiverUpdateFunctionFT(
     [Parameter(typeof(BroadcastReduceConfiguration.NumberOfIterations))] int maxIters,
     [Parameter(typeof(BroadcastReduceConfiguration.Dimensions))] int dim,
     [Parameter(typeof(BroadcastReduceConfiguration.NumWorkers))] int numWorkers,
     ITaskState taskState)
 {
     _maxIters   = maxIters;
     _iterations = 0;
     _dim        = dim;
     _intArr     = new int[_dim];
     _workers    = numWorkers;
     _taskState  = (UpdateTaskState <int[], int[]>)taskState;
 }
Exemplo n.º 8
0
 public void Save(ITaskState state)
 {
     if (state.ID == 0)
     {
         if (states.Count > 0)
         {
             state.ID = TaskStates.Max(s => s.ID) + 1;
         }
         else
         {
             state.ID = 1;
         }
         states.Add(state);
     }
 }
Exemplo n.º 9
0
        /**
         *
         * @see jbt.execution.core.IBTExecutor#getBehaviourTree()
         */

        /**
         * Sets the permanent state of a given task. The task is identified by the position it occupies
         * in the execution behaviour tree, which unambiguously identifies it.
         *
         * @param taskPosition
         *            the position of the task whose state must be stored.
         * @param state
         *            the state of the task, or null if it should be cleared.
         * @return true if there was a previous state for this task in the BTExecutor, or false
         *         otherwise.
         */

        public bool SetTaskState(Position taskPosition, ITaskState state)
        {
            if (state == null)
            {
                return(_tasksStates.Remove(taskPosition));
            }

            if (_tasksStates.ContainsKey(taskPosition))
            {
                _tasksStates.Add(taskPosition, state);
                return(false);
            }
            _tasksStates[taskPosition] = state;
            return(true);
        }
Exemplo n.º 10
0
        /**
         * Terminates the execution of this task and all the tasks below it.
         * <p>
         * When this method is called, the task is marked as terminated. From then
         * on, ticking the task will have no effect, and its status will be
         * {@link Status#TERMINATED}. Also, when terminating the task, it requests
         * to be removed from both the list of tickable and open nodes of the
         * BTExecutor. It also stores the task state after being terminated, by
         * calling {@link #storeTerminationState()}.
         * <p>
         * Finally, this method calls the abstract method
         * {@link #internalTerminate()}. <code>internalTerminate()</code> is the
         * method that actually terminates the execution of the task and all the
         * tasks below it, usually by calling <code>terminate()</code> on the active
         * children and by stopping any process associated to the task. <b>
         * <code>internalTerminate()</code> must be defined for each subclass, since
         * their termination processes differ from one another</b>.
         * <p>
         * This method cannot be called if the task has not been spawned yet (an
         * exception is thrown in that case). However, it is valid terminating a
         * task that has already been terminated, in which case nothing happens.
         */

        public void Terminate()
        {
            if (!_tickable)
            {
                throw new Exception("Cannot terminate a task that has not been spawned yet.");
            }
            if (!_terminated)
            {
                _terminated = true;
                _status     = Status.Terminated;
                _executor.RequestRemovalFromList(BTExecutor.BTExecutorList.Tickable, this);
                _executor.RequestRemovalFromList(BTExecutor.BTExecutorList.Open, this);
                ITaskState taskState = StoreTerminationState();
                _executor.SetTaskState(Position, taskState);
                InternalTerminate();
            }
        }
Exemplo n.º 11
0
        public void Delete(ITaskState state)
        {
            ITaskState newState = TaskStates.FirstOrDefault(s => s.Flag == TaskStateFlag.Initial);

            foreach (ITask task in Tasks.Where(t => t.State == state).ToArray())
            {
                if (newState != null)
                {
                    task.State = newState;
                }
                else
                {
                    tasks.Remove(task);
                }
            }

            states.Remove(state);
        }
Exemplo n.º 12
0
        // Token: 0x06001038 RID: 4152 RVA: 0x0005BABC File Offset: 0x00059CBC
        protected override void InternalCopyFrom(IProperty srcProperty)
        {
            ITaskState taskState = srcProperty as ITaskState;

            if (taskState == null)
            {
                throw new UnexpectedTypeException("ITaskState", srcProperty);
            }
            if (taskState.Complete)
            {
                base.CreateAirSyncNode(this.completeTagName, "1");
                if (taskState.DateCompleted != null)
                {
                    base.CreateAirSyncNode(this.dateCompletedTag, taskState.DateCompleted.Value.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z", DateTimeFormatInfo.InvariantInfo));
                    return;
                }
            }
            else
            {
                base.CreateAirSyncNode(this.completeTagName, "0");
            }
        }
            private SenderMapFunctionFT(
                [Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId,
                [Parameter(typeof(TaskIdsToFail))] ISet <string> taskIdsToFail,
                [Parameter(typeof(FailureType))] int failureType,
                [Parameter(typeof(MaxRetryNumberInRecovery))] int maxRetryNumberInRecovery,
                [Parameter(typeof(TotalNumberOfForcedFailures))] int totalNumberOfForcedFailures,
                ITaskState taskState)
            {
                _taskId                      = taskId;
                _taskState                   = (MapTaskState <int[]>)taskState;
                _taskIdsToFail               = taskIdsToFail;
                _failureType                 = failureType;
                _maxRetryInRecovery          = maxRetryNumberInRecovery;
                _totalNumberOfForcedFailures = totalNumberOfForcedFailures;

                var taskIdSplit = taskId.Split('-');

                _retryIndex = int.Parse(taskIdSplit[taskIdSplit.Length - 1]);

                Logger.Log(Level.Info,
                           "TestSenderMapFunction: TaskId: {0}, _maxRetryInRecovery {1}, totalNumberOfForcedFailures: {2}, RetryNumber: {3}, Failure type: {4}.",
                           _taskId,
                           _maxRetryInRecovery,
                           _totalNumberOfForcedFailures,
                           _retryIndex,
                           _failureType);
                foreach (var n in _taskIdsToFail)
                {
                    Logger.Log(Level.Info, "TestSenderMapFunction: taskIdsToFail: {0}", n);
                }

                if (_failureType == FailureType.EvaluatorFailureDuringTaskInitialization ||
                    _failureType == FailureType.TaskFailureDuringTaskInitialization)
                {
                    SimulateFailure(0);
                }
            }
Exemplo n.º 14
0
        /**
         *
         * @see jbt.execution.core.IBTExecutor#getBehaviourTree()
         */
        /**
         * Sets the permanent state of a given task. The task is identified by the position it occupies
         * in the execution behaviour tree, which unambiguously identifies it.
         *
         * @param taskPosition
         *            the position of the task whose state must be stored.
         * @param state
         *            the state of the task, or null if it should be cleared.
         * @return true if there was a previous state for this task in the BTExecutor, or false
         *         otherwise.
         */
        public bool SetTaskState(Position taskPosition, ITaskState state)
        {
            if (state == null)
            {
                return _tasksStates.Remove(taskPosition);
            }

            if (_tasksStates.ContainsKey(taskPosition))
            {
                _tasksStates.Add(taskPosition, state);
                return false;
            }
            _tasksStates[taskPosition] = state;
            return true;
        }
Exemplo n.º 15
0
 /**
  * This method restores the persistent state of an ExecutionTask from an
  * {@link ITaskState} object. Some tasks need to keep some information
  * throughout the execution of the tree.
  * <p>
  * Some tasks in BTs are persistent in the sense that, after finishing, if
  * they are spawned again, they remember past information. Take for example
  * the "limit" task. A "limit" task allows to run its child node only a
  * certain number of times (for example, 5). After being spawned, it has to
  * remember how many times it has been run so far, so that, once the
  * threshold is exceeded, it fails.
  * <p>
  * The problem here is that tasks are destroyed when they leave the list of
  * tickable tasks. Thus, if the task needs to be used again, a new instance
  * for the task must be created, which, of course, will not remember past
  * information since it is a new object. This method is used for retrieving
  * from the ITaskState object past information that has previously returned
  * by either the {@link #storeState()} or the
  * {@link #storeTerminationState()} method. In particular, this method is
  * called in the {@link #spawn(IContext)} method, just before
  * {@link #internalSpawn()} gets called. By doing so, the task that is
  * created is able to restore past information needed to work. Since this
  * method is called before the task is spawned (that is, before
  * <code>internalSpawn()</code> is called), it must be assumed that the task
  * always keeps its past state.
  * <p>
  * This method reads the information that either <code>storeState()</code>
  * or <code>storeTerminationState()</code> has previously returned..
  * Therefore, it must follow the same format as that of both methods. It the
  * input ITaskState is null, it means that there is no past information to
  * retrieve, so the task should be left unchanged.
  * <p>
  * This method may be left empty if the task does not need to restore any
  * past state.
  *
  * @param state
  *            an ITaskState object containing past state information that
  *            should be retrieved, or null in case there is no past
  *            information to remember.
  */
 protected abstract void RestoreState(ITaskState state);
Exemplo n.º 16
0
 public Task()
 {
     State = new TodoState();
 }
Exemplo n.º 17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="taskState"></param>
 /// <param name="mode"></param>
 /// <param name="cancellationToken"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 protected abstract Task <ITaskState> DoTask(ITaskState taskState, ScheduleMode mode, CancellationToken cancellationToken, params object[] args);
 /**
  * Does nothing.
  *
  * @see jbt.execution.core.ExecutionTask#restoreState(ITaskState)
  */
 protected override void RestoreState(ITaskState state)
 {
 }
Exemplo n.º 19
0
 public void UpdateTask(ITaskState task, ITransaction runningTransaction, bool commit = false)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 20
0
 private TaskStateService(ITaskState state)
 {
     _state = state;
 }
Exemplo n.º 21
0
 public void UpdateTask(ITaskState task, ITransaction runningTransaction, bool commit)
 {
     Execute(() => _stateManagerImplementation.UpdateTask(task, runningTransaction, commit));
 }
Exemplo n.º 22
0
 private TaskStateService(ITaskState state)
 {
     _state = state;
 }
Exemplo n.º 23
0
        /**
         * Restore from the ITaskState the number of times that the child task of
         * this decorator has been run so far. It is read from the variable whose
         * name is {@link #STATE_VARIABLE_NAME}.
         *
         * @see jbt.execution.core.ExecutionTask#restoreState(ITaskState)
         */
        protected override void RestoreState(ITaskState state)
        {
            try
            {
                _numRunsSoFar = (int) state.GetStateVariable(StateVariableName);
            }
            catch
            {

            }
        }
        /**
         * Does nothing.
         *
         * @see jbt.execution.core.ExecutionTask#restoreState(ITaskState)
         */

        protected override void RestoreState(ITaskState state)
        {
        }
Exemplo n.º 25
0
 /**
  * This method restores the persistent state of an ExecutionTask from an
  * {@link ITaskState} object. Some tasks need to keep some information
  * throughout the execution of the tree.
  * <p>
  * Some tasks in BTs are persistent in the sense that, after finishing, if
  * they are spawned again, they remember past information. Take for example
  * the "limit" task. A "limit" task allows to run its child node only a
  * certain number of times (for example, 5). After being spawned, it has to
  * remember how many times it has been run so far, so that, once the
  * threshold is exceeded, it fails.
  * <p>
  * The problem here is that tasks are destroyed when they leave the list of
  * tickable tasks. Thus, if the task needs to be used again, a new instance
  * for the task must be created, which, of course, will not remember past
  * information since it is a new object. This method is used for retrieving
  * from the ITaskState object past information that has previously returned
  * by either the {@link #storeState()} or the
  * {@link #storeTerminationState()} method. In particular, this method is
  * called in the {@link #spawn(IContext)} method, just before
  * {@link #internalSpawn()} gets called. By doing so, the task that is
  * created is able to restore past information needed to work. Since this
  * method is called before the task is spawned (that is, before
  * <code>internalSpawn()</code> is called), it must be assumed that the task
  * always keeps its past state.
  * <p>
  * This method reads the information that either <code>storeState()</code>
  * or <code>storeTerminationState()</code> has previously returned..
  * Therefore, it must follow the same format as that of both methods. It the
  * input ITaskState is null, it means that there is no past information to
  * retrieve, so the task should be left unchanged.
  * <p>
  * This method may be left empty if the task does not need to restore any
  * past state.
  *
  * @param state
  *            an ITaskState object containing past state information that
  *            should be retrieved, or null in case there is no past
  *            information to remember.
  */
 protected abstract void RestoreState(ITaskState state);
Exemplo n.º 26
0
 public Task(ITaskState taskState)
 {
     State = taskState;
 }
 public ValuesController(ITaskState taskState)
 {
     _taskState = taskState;
 }
Exemplo n.º 28
0
        private async Task <ITaskState> DoTask(ITaskState taskState, ScheduleMode mode, CancellationToken cancellationToken)
        {
            if (options.IsBackupDestinationAvailable())
            {
                using (db = dbf.GetWebDbContext <ServiceDb>())
                {
                    var sf = await db.SourceFolders
                             .Include(x => x.Backups)
                             .SingleAsync(x => x.Id == sourceFolderId);

                    //log.LogInformation($"Backup task for source {sf.DisplayName}");
                    var destinationFolder = Path.Combine(options.GetBackupDestination(), sf.DisplayName);
                    if (!Directory.Exists(destinationFolder))
                    {
                        Directory.CreateDirectory(destinationFolder);
                        log.LogInformation($"{destinationFolder} created");
                    }
                    var isPending = await IsBackupPending(sf);

                    if (isPending.result)
                    {
                        //log.LogInformation($"Backup of {sf.GetFullname()} to {destinationFolder} is required");
                        var backup         = isPending.backup;
                        var namePart       = sf.DisplayName;
                        var datePart       = $"{(backup.ScheduledOn.ToString("yyyy.MM.dd"))}";
                        var backupFileName = $"{namePart}.{datePart}.zip";
                        backup.FullPath = Path.Combine(destinationFolder, backupFileName);
                        backup.State    = BackupState.Started;
                        var now = DateTimeOffset.Now;
                        var todaysScheduledTime = new DateTimeOffset(now.Year, now.Month, now.Day, sf.ScheduledTime, 0, 0, now.Offset);
                        log.LogInformation($"Backup of {sf.DisplayName} to {destinationFolder} started ({(todaysScheduledTime.ToString("ddMMMyyyy HH:mm:ss"))})");
                        if (sf.Type == SourceType.Website)
                        {
                            TakeSiteOffline(sf);
                        }
                        await db.SaveChangesAsync();

                        try
                        {
                            if (File.Exists(backup.FullPath))
                            {
                                File.Delete(backup.FullPath);
                                log.LogWarning($"{backup.FullPath} deleted");
                            }
                            zip(sf.FullPath, backup.FullPath);
                            backup.State      = BackupState.Finished;
                            backup.BackedUpOn = DateTimeOffset.Now;
                            await db.SaveChangesAsync();

                            log.LogInformation($"Backup of {sf.DisplayName} to {backup.FullPath} completed");
                        }
                        catch (Exception xe)
                        {
                            log.LogError(xe, $"backup failed {sf.DisplayName} to {backup.FullPath}");
                            backup.State      = BackupState.Failed;
                            backup.BackedUpOn = DateTimeOffset.Now;
                            await db.SaveChangesAsync();

                            //throw;
                        }
                        finally
                        {
                            if (sf.Type == SourceType.Website)
                            {
                                BringSiteOnline(sf);
                            }
                        }
                        await PurgeBackups(sf);
                    }
                    else
                    {
                        log.LogInformation($"Backup of {sf.DisplayName} is not pending");
                    }
                }
            }
            else
            {
                foreach (var d in DriveInfo.GetDrives())
                {
                    log.LogInformation($"Found drive {d.Name}, label {d.VolumeLabel}, ready = {d.IsReady}");
                }
                log.LogWarning($"Backup destination not available - no disk with volume label {options.BackupDriveLabel} found");
            }
            return(null);
        }