Beispiel #1
0
 private void MinerTimerTick(object source, ElapsedEventArgs e)
 {
     if (textBox_CurrentJob_Hours.InvokeRequired)
     {
         JobDelegate guiDelegate = new JobDelegate(JobDone);
         Invoke(guiDelegate, new object[] {});
     }
 }
Beispiel #2
0
    public static void Repeat(this int times, JobDelegate job)
    {
        _i = 0;
            while (++_i <= times)
                job();

            _i = 0;
    }
        internal JobPropertiesHolder(string jobName)
        {
            _jobName = jobName;
            _routine = JobExtensions.IdleJobRoutine;
            _lock    = new object();

            _logger = new ObjectLogger(this, jobName);
        }
Beispiel #4
0
        public static void Repeat(this int times, JobDelegate job)
        {
            _i = 0;
            while (++_i <= times)
            {
                job();
            }

            _i = 0;
        }
Beispiel #5
0
        public async Task Routine_ReturnsCompletedTask_LogsCompletedTask()
        {
            // Arrange
            using IJobManager jobManager = TestHelper.CreateJobManager(true);
            var job = jobManager.Create("my-job");

            var start       = "2000-01-01Z".ToUtcDateOffset();
            var timeMachine = ShiftedTimeProvider.CreateTimeMachine(start);

            TimeProvider.Override(timeMachine);


            var output = new StringWriterWithEncoding(Encoding.UTF8);

            job.Output = output;


            JobDelegate routine = (parameter, tracker, writer, token) =>
            {
                writer.WriteLine("Hi there!");
                return(Task.CompletedTask);
            };

            job.Schedule = new ConcreteSchedule(
                start.AddSeconds(1));

            job.IsEnabled = true;

            // Act
            job.Routine = routine;
            var updatedRoutine = job.Routine;

            await timeMachine.WaitUntilSecondsElapse(start, 1.5); // will fail by this time

            var outputResult = output.ToString();

            var info = job.GetInfo(null);

            // Assert
            Assert.That(updatedRoutine, Is.SameAs(routine));
            Assert.That(outputResult, Does.Contain("Hi there!"));

            Assert.That(info.CurrentRun, Is.Null);

            Assert.That(info.RunCount, Is.EqualTo(1));
            var run = info.Runs.Single();

            Assert.That(run.Status, Is.EqualTo(JobRunStatus.Completed));

            var log = _logWriter.ToString();

            Assert.That(log,
                        Does.Contain($"Job 'my-job' completed synchronously. Reason of start was 'ScheduleDueTime'."));
        }
Beispiel #6
0
 internal JobProperties(
     JobDelegate routine,
     object parameter,
     IProgressTracker progressTracker,
     TextWriter output)
 {
     this.Routine         = routine ?? throw new ArgumentNullException(nameof(routine));
     this.Parameter       = parameter;
     this.ProgressTracker = progressTracker;
     this.Output          = output;
 }
 public UserApplicationForm(string entryUrl, string inputFilePath, string outputPath, int nrSplits, string mapperClassName, string dllPath)
 {
     activateButton = new JobDelegate(activateSubmitButton);
     this.clientPort = DEFAULCLIENTPORT;
     this.entryUrl = entryUrl;
     this.inputFilePath = inputFilePath;
     this.outputFolderPath = outputPath;
     this.splits = nrSplits;
     this.dllClassName = mapperClassName;
     this.dllLocation = dllPath;
     InitializeComponent();
     Load += new EventHandler(UserApplicationForm_Load);
 }
Beispiel #8
0
        public void Routine_DisposedAndSet_ThrowsJobObjectDisposedException()
        {
            // Arrange
            using IJobManager jobManager = TestHelper.CreateJobManager(true);

            var start       = "2000-01-01Z".ToUtcDateOffset();
            var timeMachine = ShiftedTimeProvider.CreateTimeMachine(start);

            TimeProvider.Override(timeMachine);

            var job = jobManager.Create("my-job");

            JobDelegate routine1 = async(parameter, tracker, output, token) =>
            {
                await output.WriteAsync("First Routine!");

                await Task.Delay(1500, token);
            };

            JobDelegate routine2 = async(parameter, tracker, output, token) =>
            {
                await output.WriteAsync("Second Routine!");

                await Task.Delay(1500, token);
            };


            // Act
            job.Routine = routine1;
            var updatedRoutine1 = job.Routine;

            job.IsEnabled = true;

            job.Routine = routine2;
            var updatedRoutine2 = job.Routine;

            jobManager.Dispose();

            var updatedRoutineAfterDisposal = job.Routine;

            var ex = Assert.Throws <JobObjectDisposedException>(() => job.Routine = routine1);

            // Assert
            Assert.That(updatedRoutine1, Is.SameAs(routine1));
            Assert.That(updatedRoutine2, Is.SameAs(routine2));

            Assert.That(updatedRoutineAfterDisposal, Is.SameAs(routine2));

            Assert.That(ex.ObjectName, Is.EqualTo("my-job"));
        }
Beispiel #9
0
        public void Routine_SetValidValueForEnabledOrDisabledJob_SetsValue()
        {
            // Arrange
            using IJobManager jobManager = TestHelper.CreateJobManager(true);

            var start       = "2000-01-01Z".ToUtcDateOffset();
            var timeMachine = ShiftedTimeProvider.CreateTimeMachine(start);

            TimeProvider.Override(timeMachine);

            var job = jobManager.Create("my-job");

            JobDelegate routine1 = async(parameter, tracker, output, token) =>
            {
                await output.WriteAsync("First Routine!");

                await Task.Delay(1500, token);
            };

            JobDelegate routine2 = async(parameter, tracker, output, token) =>
            {
                await output.WriteAsync("Second Routine!");

                await Task.Delay(1500, token);
            };


            // Act
            job.Routine = routine1;
            var updatedRoutine1 = job.Routine;

            job.IsEnabled = true;

            job.Routine = routine2;
            var updatedRoutine2 = job.Routine;

            // Assert
            Assert.That(updatedRoutine1, Is.SameAs(routine1));

            Assert.That(updatedRoutine2, Is.SameAs(routine2));
        }
Beispiel #10
0
        public static bool queue(JobDelegate callback)
        {
            int threadRuntime = 0;

            lock (activeLock)
            {
                threadRuntime = activeRuntime;
            }
            return(System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state)
            {
                int currentRuntime = 0;
                lock (activeLock)
                {
                    currentRuntime = activeRuntime;
                }
                if (threadRuntime == currentRuntime)
                {
                    callback();
                }
            }));
        }
Beispiel #11
0
        public async Task Routine_SetAfterPreviousRunCompleted_SetsValueAndRunsWithIt()
        {
            // Arrange
            using IJobManager jobManager = TestHelper.CreateJobManager(true);
            var job = jobManager.Create("my-job");

            var start       = "2000-01-01Z".ToUtcDateOffset();
            var timeMachine = ShiftedTimeProvider.CreateTimeMachine(start);

            TimeProvider.Override(timeMachine);

            var output = new StringWriterWithEncoding(Encoding.UTF8);

            job.Output = output;

            JobDelegate routine1 = async(parameter, tracker, writer, token) =>
            {
                await writer.WriteAsync("First Routine!");

                await Task.Delay(1500, token);
            };

            JobDelegate routine2 = async(parameter, tracker, writer, token) =>
            {
                await writer.WriteAsync("Second Routine!");

                await Task.Delay(1500, token);
            };

            job.Schedule = new ConcreteSchedule(
                start.AddSeconds(1),
                start.AddSeconds(4));

            job.IsEnabled = true;

            // Act
            job.Routine = routine1;
            var updatedRoutine1 = job.Routine;

            await timeMachine.WaitUntilSecondsElapse(start, 2.9); // job with routine1 will complete

            var output1 = output.ToString();

            await timeMachine.WaitUntilSecondsElapse(start, 3.0);

            job.Routine = routine2;
            var updatedRoutine2 = job.Routine;

            await timeMachine.WaitUntilSecondsElapse(start, 6.0);

            var output2 = output.ToString();

            // Assert
            try
            {
                Assert.That(updatedRoutine1, Is.SameAs(routine1));
                Assert.That(output1, Is.EqualTo("First Routine!"));

                Assert.That(updatedRoutine2, Is.SameAs(routine2));
                Assert.That(output2, Is.EqualTo("First Routine!Second Routine!"));
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine("*** Test Failed ***");
                sb.AppendLine(ex.ToString());
                sb.AppendLine("*** Log: ***");

                var log = _logWriter.ToString();

                sb.AppendLine(log);

                Assert.Fail(sb.ToString());
            }
        }
Beispiel #12
0
 public DelegateJob(JobDelegate method)
 {
     this.method = method;
 }
Beispiel #13
0
 private Job(Guid jobID, JobDelegate jobDelegate, DateTimeOffset?enqueuedAt = null)
 {
     ID       = jobID;
     Delegate = jobDelegate;
 }
 private void button2_Click(object sender, EventArgs e)
 {
     jobDelegate = new JobDelegate(this.submitJob);
     jobDelegate.BeginInvoke(submitDone, null);
     button2.Enabled = false;
 }
Beispiel #15
0
 public static Job Create(JobDelegate jobDelegate)
 => Create(Guid.NewGuid(), jobDelegate);
Beispiel #16
0
 public static Job Create(Guid jobID, JobDelegate jobDelegate)
 => new Job(jobID, jobDelegate);
Beispiel #17
0
        public async Task Routine_Throws_LogsFaultedTask()
        {
            // Arrange
            using IJobManager jobManager = TestHelper.CreateJobManager(true);

            var start       = "2000-01-01Z".ToUtcDateOffset();
            var timeMachine = ShiftedTimeProvider.CreateTimeMachine(start);

            TimeProvider.Override(timeMachine);

            var job = jobManager.Create("my-job");

            var output = new StringWriterWithEncoding(Encoding.UTF8);

            job.Output = output;

            var exception = new NotSupportedException("Bye baby!");

            JobDelegate routine = (parameter, tracker, writer, token) =>
            {
                writer.WriteLine("Hi there!");
                throw exception;
            };

            job.Schedule = new ConcreteSchedule(
                start.AddSeconds(1));

            job.IsEnabled = true;

            // Act
            job.Routine = routine;
            var updatedRoutine = job.Routine;

            await timeMachine.WaitUntilSecondsElapse(start, 1.5); // will fail by this time

            var outputResult = output.ToString();

            var info = job.GetInfo(null);

            // Assert
            try
            {
                Assert.That(updatedRoutine, Is.SameAs(routine));
                Assert.That(outputResult, Does.Contain("Hi there!"));
                Assert.That(outputResult, Does.Contain(exception.ToString()));

                Assert.That(info.CurrentRun, Is.Null);

                Assert.That(info.RunCount, Is.EqualTo(1));
                var run = info.Runs.Single();

                Assert.That(run.Status, Is.EqualTo(JobRunStatus.Faulted));
                Assert.That(run.Exception, Is.SameAs(exception));
                Assert.That(run.Output, Does.Contain(exception.ToString()));

                var log = _logWriter.ToString();

                Assert.That(log, Does.Contain("Routine has thrown an exception."));
                Assert.That(log,
                            Does.Contain($"Job 'my-job' completed synchronously. Reason of start was 'ScheduleDueTime'."));
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine("*** Test Failed ***");
                sb.AppendLine(ex.ToString());
                sb.AppendLine("*** Log: ***");

                var log = _logWriter.ToString();

                sb.AppendLine(log);

                Assert.Fail(sb.ToString());
            }
        }
Beispiel #18
0
        public async Task Routine_ReturnsCanceledTask_LogsCanceledTask()
        {
            // Arrange
            using IJobManager jobManager = TestHelper.CreateJobManager(true);

            var start       = "2000-01-01Z".ToUtcDateOffset();
            var timeMachine = ShiftedTimeProvider.CreateTimeMachine(start);

            TimeProvider.Override(timeMachine);

            using var source = new CancellationTokenSource();
            source.Cancel();

            var job = jobManager.Create("my-job");

            var output = new StringWriterWithEncoding(Encoding.UTF8);

            job.Output = output;

            JobDelegate routine = (parameter, tracker, writer, token) =>
            {
                writer.WriteLine("Hi there!");
                return(Task.FromCanceled(source.Token));
            };

            job.Schedule = new ConcreteSchedule(
                start.AddSeconds(1));

            job.IsEnabled = true;

            // Act
            job.Routine = routine;
            var updatedRoutine = job.Routine;

            var inTime = await timeMachine.WaitUntilSecondsElapse(start, 1.5); // will be canceled by this time

            if (!inTime)
            {
                throw new Exception("Test failed. TPL was too slow.");
            }

            var outputResult = output.ToString();

            var info = job.GetInfo(null);

            // Assert
            try
            {
                Assert.That(updatedRoutine, Is.SameAs(routine));
                Assert.That(outputResult, Does.Contain("Hi there!"));

                Assert.That(info.CurrentRun, Is.Null);

                Assert.That(info.RunCount, Is.EqualTo(1));
                var run = info.Runs.Single();

                Assert.That(run.Status, Is.EqualTo(JobRunStatus.Canceled));
                Assert.That(run.Exception, Is.Null);

                var log = _logWriter.ToString();
                Assert.That(log,
                            Does.Contain($"Job 'my-job' completed synchronously. Reason of start was 'ScheduleDueTime'."));
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine("*** Test Failed ***");
                sb.AppendLine(ex.ToString());
                sb.AppendLine("*** Log: ***");

                var log = _logWriter.ToString();

                sb.AppendLine(log);

                Assert.Fail(sb.ToString());
            }
        }
        private void UserApplicationForm_Load(object sender, EventArgs e)
        {
            textBox3.Text = inputFilePath;
            textBox1.Text = entryUrl;
            numericUpDown1.Value = DEFAULCLIENTPORT;
            numericUpDown3.Value = splits;
            textBox4.Text = outputFolderPath;
            dllLocationValue.Text = dllLocation;
            classNameValue.Text = dllClassName;
            button1.Enabled = false;
            createClient();

            jobDelegate = new JobDelegate(this.submitJob);
            jobDelegate.BeginInvoke(submitDone, null);
            button2.Enabled = false;
        }
 public UserApplicationForm()
 {
     InitializeComponent();
     activateButton = new JobDelegate(activateSubmitButton);
 }
Beispiel #21
0
 public DelegateJob(JobDelegate method)
 {
     this.method = method;
 }