Esempio n. 1
0
        /// <see cref="ITaskManager.StartTask"/>
        public ITask StartTask(TaskMethod taskMethod, string name, object parameter)
        {
            IUIBackgroundTask adaptedTask =
                UITaskManager.StartParallelTask(delegate(object param) { taskMethod(parameter); }, name);

            return(new TaskAdapter(adaptedTask));
        }
Esempio n. 2
0
        public void InvokesTaskMethodWithBooleanParameter()
        {
            var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Test"), Resolver);
            task.Invoke(new TaskParameters(new Dictionary<string, string> { { "fast", @"true" } }));

            Assert.That(Output.ToString().Trim(), Is.EqualTo(@"testing fast"));
        }
Esempio n. 3
0
        public void InvokesTaskMethodWithNoParameters()
        {
            var task = new TaskMethod(typeof (FakeTaskClass).GetMethod("Compile"), Resolver);
            task.Invoke(new TaskParameters(new Dictionary<string, string>()));

            Assert.That(Output.ToString().Trim(), Is.EqualTo("compiling"));
        }
Esempio n. 4
0
        public void InvokesTaskMethodWithOptionalStringParameterNotGiven()
        {
            var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Optional"), Resolver);
            task.Invoke(new TaskParameters(new Dictionary<string, string>()));

            Assert.That(Output.ToString().Trim(), Is.EqualTo(@"optional fileName: stuff.txt"));
        }
Esempio n. 5
0
        public void InvokesTaskMethodWithStringParameter()
        {
            var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Deploy"), Resolver);
            task.Invoke(new TaskParameters(new Dictionary<string, string> { { "dir", @"c:\sites" } }));

            Assert.That(Output.ToString().Trim(), Is.EqualTo(@"deploying c:\sites"));
        }
Esempio n. 6
0
        public void InvokesTaskMethodWithOptionalStringParameterGiven()
        {
            var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Optional"), Resolver);
            task.Invoke(new Arguments(new Dictionary<string, string>{{"fileName", "thefile.txt"}}));

            Assert.That(Output.ToString().Trim(), Is.EqualTo(@"optional fileName: thefile.txt"));
        }
Esempio n. 7
0
        public void InvokesTaskMethodWithNullableIntParameterGiven()
        {
            var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Nullable"), Resolver);
            task.Invoke(new TaskParameters(new Dictionary<string, string>{{"port", "80"}}));

            Assert.That(Output.ToString().Trim(), Is.EqualTo(@"port: 80"));
        }
Esempio n. 8
0
 public Task(ProgressChain chain, float weight, TaskMethod method)
 {
     Weight               = weight;
     Chain                = chain;
     Progress             = new ProgressHandler();
     Progress.OnChange   += (s, e) => { chain.ProgressChanged(); };
     Progress.OnComplete += (s, e) => { chain.Next(); };
     Method               = method;
 }
Esempio n. 9
0
        public Hook(TaskMethod method)
        {
            ArgumentNullException.ThrowIfNull(method);

            methodType = MethodType.Task;
            taskMethod = method;
            Unsafe.SkipInit(out voidMethod);
            Unsafe.SkipInit(out valueTaskMethod);
        }
Esempio n. 10
0
        public void EnumeratesTaskNamesForMethodInfo()
        {
            var taskNames = new TaskMethod(typeof(TasksForTaskNames).GetMethod("DoStuff"), Resolver).AllNames.ToArray();

            Assert.That(taskNames, Has.Member("DoStuff"));
            Assert.That(taskNames, Has.Member("TasksForTaskNames.DoStuff"));
            Assert.That(taskNames, Has.Member("Tests.TasksForTaskNames.DoStuff"));
            Assert.That(taskNames, Has.Member("Framework.Tests.TasksForTaskNames.DoStuff"));
            Assert.That(taskNames, Has.Member("Bounce.Framework.Tests.TasksForTaskNames.DoStuff"));
        }
Esempio n. 11
0
        public void InvokesTaskMethodWithOptionalStringParameterGiven()
        {
            var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Optional"), Resolver);

            task.Invoke(new Arguments(new Dictionary <string, string> {
                { "fileName", "thefile.txt" }
            }));

            Assert.That(Output.ToString().Trim(), Is.EqualTo(@"optional fileName: thefile.txt"));
        }
Esempio n. 12
0
        public void EnumeratesTaskNamesForMethodInfo()
        {
            var taskNames = new TaskMethod(typeof(TasksForTaskNames).GetMethod("DoStuff"), Resolver).AllNames.ToArray();

            Assert.That(taskNames, Has.Member("DoStuff"));
            Assert.That(taskNames, Has.Member("TasksForTaskNames.DoStuff"));
            Assert.That(taskNames, Has.Member("Tests.TasksForTaskNames.DoStuff"));
            Assert.That(taskNames, Has.Member("Framework.Tests.TasksForTaskNames.DoStuff"));
            Assert.That(taskNames, Has.Member("Bounce.Framework.Tests.TasksForTaskNames.DoStuff"));
        }
Esempio n. 13
0
            public Hook(TaskMethod method)
            {
                if (method is null)
                {
                    throw new ArgumentNullException(nameof(method));
                }

                methodType = MethodType.Task;
                taskMethod = method;
                Unsafe.SkipInit(out voidMethod);
                Unsafe.SkipInit(out valueTaskMethod);
            }
Esempio n. 14
0
 public static void CreateTask(string taskName, TimeSpan interval, TaskMethod method)
 {
     lock (TaskLock) {
         if (ScheduledTasks.ContainsKey(taskName))
             ScheduledTasks[taskName] = new Task {
                 LastRun = ServerCore.UnixEpoch,
                 Method = method,
                 RunInterval = interval
             };
         else
             ScheduledTasks.Add(taskName,
                 new Task { LastRun = ServerCore.UnixEpoch, Method = method, RunInterval = interval });
     }
 }
Esempio n. 15
0
        public void HandleTask(TaskType taskType, TaskMethod taskMethod, string[] args)
        {
            switch (taskType)
            {
            case TaskType.File:
                if (taskMethod == TaskMethod.Delete)
                {
                    if (args.Length <= 0)
                    {
                        throw new ArgumentException("args must be longer then 0!");
                    }
                    var fileTask = new FileTask();
                    Console.WriteLine(fileTask.ClearFile(ReplacementHelper.SanatizePathname(args[0])));
                }
                break;

            case TaskType.Directory:
                if (taskMethod == TaskMethod.Delete)
                {
                    if (args.Length == 0)
                    {
                        throw new ArgumentException("args must be longer then 0!");
                    }
                    var dirTask = new DirectoryTask();
                    Console.WriteLine(dirTask.DeleteDirectory(ReplacementHelper.SanatizePathname(args[0])));
                }
                else if (taskMethod == TaskMethod.Clean)
                {
                    if (args.Length == 0)
                    {
                        throw new ArgumentException("args must be longer then 0!");
                    }

                    var dirTask = new DirectoryTask();
                    dirTask.CleanDirectory(ReplacementHelper.SanatizePathname(args[0])).ForEach((dir) => { Console.WriteLine(dir); });
                }
                break;

            case TaskType.Recycling:
                var recyclingTask = new RecyclingTask();
                recyclingTask.ClearRecycling();
                break;
            }
        }
Esempio n. 16
0
 public void AddTask(TaskMethod task, float weight)
 {
     Tasks.Add(new Task(this, weight, task));
     OverallWeight += weight;
 }
Esempio n. 17
0
 public void AddTask(TaskMethod task, float weight)
 {
     Tasks.Add(new Task(this, weight, task));
     overallWeight += weight;
 }
 public NLPTask(T model, TaskMethod tm)
 {
     taskMethod = tm;
     this.model = model;
 }
Esempio n. 19
0
 public void ThrowsExceptionWhenCustomTypeCannotBeParsed()
 {
     var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Bad"), Resolver);
     Assert.That(() => task.Invoke(new TaskParameters(new Dictionary<string, string> { { "x", @"something" } })), Throws.InstanceOf<TaskParameterException>());
 }
Esempio n. 20
0
 public void TaskExceptionIsThrownWhenTaskThrows()
 {
     var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Throws"), Resolver);
     Assert.That(() => task.Invoke(new TaskParameters(new Dictionary<string, string>())), Throws.InstanceOf<TaskException>());
 }
Esempio n. 21
0
 public void NullableParameterIsNotRequired()
 {
     var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Nullable"), Resolver);
     Assert.That(task.Parameters.ElementAt(0).IsRequired, Is.False);
 }
Esempio n. 22
0
 public void ThrowsExceptionWhenTaskRequiredParameterNotProvided()
 {
     var task = new TaskMethod(typeof(FakeTaskClass).GetMethod("Test"), Resolver);
     Assert.That(() => task.Invoke(new TaskParameters(new Dictionary<string, string>())), Throws.InstanceOf<TaskRequiredParameterException>());
 }