Example #1
0
        public void AddTest()
        {
            var result = _manager.Add(new ToDoTask
            {
                Title    = "Contact Paul",
                Done     = false,
                Category = new Category
                {
                    CategoryId = 1,
                    Name       = "General"
                }
            }).Result;

            Assert.True(result);
        }
        public void OnAdd_Test()
        {
            TestHelper.ClearDatabase(options);
            TaskManager manager = new TaskManager(options);
            var         task    = new TaskNote {
                Name = "1t", PlanedExecutionTime = new TimeSpan(0, 0, 10).Ticks
            };

            Assert.True(task.CreationDate == default(DateTime));
            Assert.True(task.CalculatedPlanedExecutionTime == default(TimeSpan).Ticks);

            manager.Add(task);
            task = manager.Find(task.Id);

            Assert.Equal(DateTime.Now.Date, task.CreationDate.Date);
            Assert.Equal(task.PlanedExecutionTime, task.CalculatedPlanedExecutionTime);
        }
Example #3
0
        /// <summary>
        /// Adds the task.
        /// </summary>
        /// <param name="task">The task.</param>
        /// <param name="userId">The user id.</param>
        public TaskViewModel AddTask(TaskViewModel task, int studentId)
        {
            TaskViewModel taskViewModel = null;

            try
            {
                Task studentTask = ObjectMapper.Map <TaskViewModel, Model.Entities.Task>(task);
                studentTask.UserId = studentId;
                Task taskModel = TaskManager.Add(studentTask);
                taskViewModel = ObjectMapper.Map <Model.Entities.Task, TaskViewModel>(taskModel);
                return(taskViewModel);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex, PolicyNameType.ExceptionReplacing);
                return(taskViewModel);
            }
        }
Example #4
0
        public void Append(string outputFileName, int partitionReadThreadNumber, List <PartitionFileInfo> fileNameInfo)
        {
            using (var resultFile = new StreamWriter(outputFileName, false, Encoding.UTF8, 65536))
            {
                var writeTask = Task.Factory.StartNew(() =>
                {
                    foreach (var data in _dataCollection.GetConsumingEnumerable())
                    {
                        var sw = new Stopwatch();
                        Console.WriteLine($"started append {data.Partition} :: {data.FileName}");
                        sw.Start();

                        WriteToFile(data.Data, resultFile);

                        sw.Stop();
                        Console.WriteLine($"stop append {data.Partition} :: {data.FileName} :: {(sw.ElapsedMilliseconds / 1000.0).ToString()}");
                    }
                });

                foreach (var fileNameInfoItem in fileNameInfo.OrderBy(i => i.PartitionKey))
                {
                    var previousTask = _manager.GetAll().LastOrDefault();
                    var item         = CreatePartitionReadTask(previousTask, fileNameInfoItem);
                    _manager.Add(item);
                    previousTask = item;
                }

                var readTasks = _manager.GetAll();

                for (var i = 0; i < partitionReadThreadNumber; i++)
                {
                    _manager.RunNext();
                }

                Task.WaitAll(readTasks);
                _dataCollection.CompleteAdding();
                Task.WaitAll(writeTask);
            }
        }
        public void Update_RecomputeExecutionTImeTest()
        {
            TestHelper.ClearDatabase(options);
            TaskManager manager = new TaskManager(options);

            TaskNote[] tasks = new TaskNote[6];
            for (int i = 0; i < tasks.Length; i++)
            {
                tasks[i] = new TaskNote();
            }

            manager.Add(tasks[0]);
            manager.Add(tasks[1], tasks[0]);
            manager.Add(tasks[2], tasks[0]);
            manager.Add(tasks[3], tasks[1]);
            manager.Add(tasks[4], tasks[1]);
            manager.Add(tasks[5], tasks[0]);

            TestHelper.SetStatus(manager, tasks, Statuses.InProgress);
            Thread.Sleep(1000);

            tasks[3].Status = Statuses.Done;
            manager.Update(tasks[3]);

            /*
             * task0 progress
             *   task1 progress
             *     task3 done
             *   task2 progress
             */

            tasks[0]        = manager.Find(tasks[0].Id);
            tasks[0].Status = Statuses.Done;
            manager.Update(tasks[0]);

            TestHelper.Refresh(manager, tasks);

            Assert.Equal(tasks[3].CalculatedExecutionTime, tasks[3].ExecutionTime);
            Assert.Equal(tasks[4].CalculatedExecutionTime, tasks[4].ExecutionTime);
            Assert.Equal(tasks[5].CalculatedExecutionTime, tasks[5].ExecutionTime);
            Assert.Equal(tasks[2].CalculatedExecutionTime, tasks[2].ExecutionTime);

            Assert.Equal(tasks[1].CalculatedExecutionTime, tasks[1].ExecutionTime + tasks[3].CalculatedExecutionTime + tasks[4].CalculatedExecutionTime);
            Assert.Equal(tasks[0].CalculatedExecutionTime, tasks[5].CalculatedExecutionTime + tasks[1].CalculatedExecutionTime + tasks[2].CalculatedExecutionTime + tasks[0].ExecutionTime);
        }
        public void Add_ShouldLogSuccessfulMessage_WhenPassedValidTask()
        {
            // Arrange
            //var loggerMock = new Mock<ILogger>();
            //var idProviderStub = new Mock<IIdProvider>();
            //var taskStub = new Mock<ITask>();

            var loggerMock     = Mock.Create <ILogger>();
            var idProviderStub = Mock.Create <IIdProvider>();
            var taskStub       = Mock.Create <ITask>();

            var manager = new TaskManager(idProviderStub, loggerMock);
            var list    = new List();

            Mock.Arrange(() => idProviderStub.NextId()).Returns(0);
            idProviderStub.Setup(x => x.NextId()).Return(0);

            // Act
            manager.Add(taskStub);

            // Assert
            //loggerMock.Verify(x => x.Log(It.IsAny<string>()), Times.Exactly(1));
            Mock.Assert(() => loggerMock.Log(Arg.AnyString), Occurs.Once());
        }
        internal WurmCharacterLogFiles([NotNull] CharacterName characterName, [NotNull] string fullDirPathToCharacterLogsDir, [NotNull] IWurmApiLogger logger, [NotNull] LogFileInfoFactory logFileInfoFactory, [NotNull] IInternalEventInvoker internalEventInvoker,
                                       [NotNull] TaskManager taskManager)
        {
            if (characterName == null)
            {
                throw new ArgumentNullException(nameof(characterName));
            }
            if (fullDirPathToCharacterLogsDir == null)
            {
                throw new ArgumentNullException(nameof(fullDirPathToCharacterLogsDir));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (logFileInfoFactory == null)
            {
                throw new ArgumentNullException(nameof(logFileInfoFactory));
            }
            if (internalEventInvoker == null)
            {
                throw new ArgumentNullException(nameof(internalEventInvoker));
            }
            if (taskManager == null)
            {
                throw new ArgumentNullException(nameof(taskManager));
            }
            this.logger                   = logger;
            this.logFileInfoFactory       = logFileInfoFactory;
            this.taskManager              = taskManager;
            CharacterName                 = characterName;
            FullDirPathToCharacterLogsDir = fullDirPathToCharacterLogsDir;

            onFilesAddedOrRemoved = internalEventInvoker.Create(() => new CharacterLogFilesAddedOrRemoved(CharacterName));

            try
            {
                Refresh();
            }
            catch (Exception exception)
            {
                logger.Log(LogLevel.Error, "Error at initial WurmCharacterLogFiles refresh: " + CharacterName, this, exception);
            }

            directoryWatcher = new FileSystemWatcher(fullDirPathToCharacterLogsDir)
            {
                Filter       = "*.txt",
                NotifyFilter = NotifyFilters.FileName
            };
            directoryWatcher.Created += DirectoryWatcherOnChanged;
            directoryWatcher.Deleted += DirectoryWatcherOnChanged;
            directoryWatcher.Renamed += DirectoryWatcherOnChanged;
            directoryWatcher.Changed += DirectoryWatcherOnChanged;

            directoryWatcher.EnableRaisingEvents = true;

            taskHandle = new TaskHandle(Refresh, "WurmCharacterLogFiles refresh: " + CharacterName);
            taskManager.Add(taskHandle);

            taskHandle.Trigger();
        }
Example #8
0
 private void AddTasks()
 {
     _taskManager.Add(new ClearCursorTask());
     _taskManager.Add(new AssignMoveSkillTask());
     _taskManager.Add(new LeaveAreaTask());
     _taskManager.Add(new HandleBlockingChestsTask());
     _taskManager.Add(new HandleBlockingObjectTask());
     _taskManager.Add(new CombatTask(50));
     _taskManager.Add(new PostCombatHookTask());
     _taskManager.Add(new LootItemTask());
     _taskManager.Add(new SpecialObjectTask());
     _taskManager.Add(new OpenChestTask());
     _taskManager.Add(new CombatTask(-1));
     _taskManager.Add(new EnterTrialTask());
     _taskManager.Add(new IdTask());
     _taskManager.Add(new SellTask());
     _taskManager.Add(new StashTask());
     _taskManager.Add(new CurrencyRestockTask());
     _taskManager.Add(new SortInventoryTask());
     _taskManager.Add(new VendorTask());
     _taskManager.Add(new TravelToHideoutTask());
     _taskManager.Add(new SextantTask());
     _taskManager.Add(new SellMapTask());
     _taskManager.Add(new TakeMapTask());
     _taskManager.Add(new TravelToLabTask());
     _taskManager.Add(new CastAuraTask());
     _taskManager.Add(new OpenMapTask());
     _taskManager.Add(new DeviceAreaTask());
     _taskManager.Add(new ProximityTriggerTask());
     _taskManager.Add(new KillBossTask());
     _taskManager.Add(new TrackMobTask());
     _taskManager.Add(new TransitionTriggerTask());
     _taskManager.Add(new MapExplorationTask());
     _taskManager.Add(new FinishMapTask());
     _taskManager.Add(new FallbackTask());
 }