Example #1
0
 public TaskInfo(MasterTaskType type, TaskCompletion result, TaskId taskid, User user)
 {
     this.type   = type;
     this.result = result;
     this.taskid = taskid;
     this.user   = user;
 }
Example #2
0
        private async Task StartInternal(CancellationToken cancellationToken)
        {
            try
            {
                while (true)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var result = Dequeue();
                    if (result != null)
                    {
                        _outputStream.Write(result.Item1, result.Item2, result.Item3);
                    }
                    else
                    {
                        await Task.Delay(50, cancellationToken).ConfigureAwait(false);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("QueueStream cancelled");
                TaskCompletion.TrySetCanceled();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in QueueStream", ex);
                TaskCompletion.TrySetException(ex);
            }
            finally
            {
                OnClosed();
            }
        }
Example #3
0
        void ITaskCallback.OnComplete(TaskCompletion result)
        {
            completionSource.TrySetResult(result);

            if (proxy != null)
            {
                proxy.OnComplete(result);
            }
        }
        public async Task RePlayAsync()
        {
            if (TaskCompletion != null)
            {
                await TaskCompletion.ConfigureAwait(false);
            }

            TriggerTask();
        }
Example #5
0
        /// <summary>
        /// Completes a task (verb run).
        /// </summary>
        /// <remarks>
        /// Note that for Async verb workers, this method runs on a separate thread.
        /// </remarks>
        /// <param name="verb">The verb which was run.</param>
        /// <param name="worker">The verb's worker.</param>
        private void completeTask(IVerb verb, IVerbWorker worker)
        {
            this.taskCompletionsLock.AcquireWriterLock(Timeout.Infinite);
            Disposition    disp = worker.Complete();
            TaskCompletion tc   = new TaskCompletion(worker.GetWorkingDirectory(), verb, disp);

            this.taskCompletions.Add(tc);
            this.completionEvent.Set();
            this.taskCompletionsLock.ReleaseWriterLock();
        }
    public static void Explain(this TaskCompletion runnable, TextWriter writer)
    {
        writer.WriteLine(@"
- `TaskCompletionSource<TResult>` is a handy tool to achieve complex interop and custom async scenarios
- It represents a custom task that can be controled and transitioned into the state you like
- Attention: Awaiter completes on thread that called `SetResult` or `TrySetResult`
- Use `TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously)` with .NET 4.6.2 or higher to opt-out from sync completion.

");
    }
Example #7
0
        void completeTask(IVerb verb, IVerbWorker worker)
        {
            taskCompletionsLock.AcquireWriterLock(Timeout.Infinite);
            Disposition    disp = worker.complete();
            TaskCompletion tc   = new TaskCompletion(verb, disp);

            taskCompletions.Add(tc);
            completionEvent.Set();
            taskCompletionsLock.ReleaseWriterLock();
        }
 public BeginUpdateKeyChangeResult(
     TaskCompletion result,
     User user,
     System.UInt32 keyChangeSequenceNum,
     byte[] masterChallengeData,
     byte[] outstationChallengeData
     )
 {
     this.result = result;
     this.user   = user;
     this.keyChangeSequenceNum    = keyChangeSequenceNum;
     this.masterChallengeData     = masterChallengeData;
     this.outstationChallengeData = outstationChallengeData;
 }
Example #9
0
        private async Task StartInternal()
        {
            var cancellationToken = _cancellationToken;

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    _isActive = true;

                    var bytes = Dequeue();
                    if (bytes != null)
                    {
                        await _outputStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        await Task.Delay(50, cancellationToken).ConfigureAwait(false);
                    }
                }

                TaskCompletion.TrySetResult(true);
                _logger.Debug("QueueStream complete");
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("QueueStream cancelled");
                TaskCompletion.TrySetCanceled();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in QueueStream", ex);
                TaskCompletion.TrySetException(ex);
            }
            finally
            {
                _isActive = false;

                if (OnFinished != null)
                {
                    OnFinished(this);
                }
            }
        }
Example #10
0
        public void Write(byte[] bytes, int offset, int count)
        {
            //return _outputStream.WriteAsync(bytes, offset, count, cancellationToken);

            try
            {
                _outputStream.Write(bytes, offset, count);
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("QueueStream cancelled");
                TaskCompletion.TrySetCanceled();
                OnClosed();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in QueueStream", ex);
                TaskCompletion.TrySetException(ex);
                OnClosed();
            }
        }
Example #11
0
        public async Task ExecuteJob()
        {
            TRequest request;

            if (Dependencies != null && Dependencies.Count > 0)
            {
                var tasks     = Dependencies.Select(y => y.WaitOn).ToArray();
                var responses = await Task.WhenAll(tasks);

                request = Initialize(responses);
            }
            else
            {
                request = Initialize(null);
            }

            var med = new Mediator();

            Response = await med.Send <TRequest, TResponse>(request);

            TaskCompletion.SetResult(Response);
        }
Example #12
0
        public async Task WriteAsync(byte[] bytes, int offset, int count)
        {
            //return _outputStream.WriteAsync(bytes, offset, count, cancellationToken);
            var cancellationToken = _cancellationToken;

            try
            {
                await _outputStream.WriteAsync(bytes, offset, count, cancellationToken).ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("QueueStream cancelled");
                TaskCompletion.TrySetCanceled();
                OnClosed();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in QueueStream", ex);
                TaskCompletion.TrySetException(ex);
                OnClosed();
            }
        }
Example #13
0
        protected void addTask_OnClick(object sender, EventArgs e)
        {
            //var checkDate = CheckPreviousDate(dueDate.Text);


            //if (checkDate)
            //{
            //    lblError.Visible = true;
            //    return;
            //}

            //lblError.Visible = false;
            var taskDescription = taskDesciption.Text;
            var id             = Convert.ToInt64(Session["ID"]);
            var taskDoc        = new TaskDocument();
            var stats          = 0;
            var selectedUserId = Convert.ToInt32(userList.SelectedValue);


            if (attachments.HasFile)
            {
                var files = attachments.PostedFiles;

                foreach (var file in files)
                {
                    var fileName = Page.Server.MapPath("~/Uploads/TaskDocuments/" + Path.GetFileName(file.FileName));

                    file.SaveAs(fileName);

                    var fileByte = _imageService.ReadToEnd(file.InputStream);

                    taskDoc = _insedlu.TaskDocuments.Add(
                        new TaskDocument
                    {
                        name       = fileName,
                        created_at = DateTime.Today,
                        file       = fileByte
                    });

                    try
                    {
                        _insedlu.SaveChanges();
                    }
                    catch (DbEntityValidationException exception)
                    {
                        Console.WriteLine(exception.EntityValidationErrors);
                        throw;
                    }
                }
            }

            if (!string.IsNullOrEmpty(taskDescription))
            {
                var date       = DateTime.ParseExact(dueDate.Text, "dd/MM/yyyy", null);
                var todaysDate = DateTime.Today;

                var numberOfDays = GetRemainingDays(date, todaysDate);

                var task = new Task
                {
                    created_at          = DateTime.Now,
                    body                = taskDescription,
                    modified_at         = DateTime.Now,
                    due_date            = date,
                    user_id             = (int)id,
                    status              = (int)TaskStatus.Assigned,
                    task_document_id    = taskDoc.id,
                    number_of_days_left = numberOfDays
                };

                myTasksList.Text = task.body;
                var check = _projectService.SaveTask(task);

                var taskComplete = new TaskCompletion {
                    completion = numberOfDays.ToString(), task_id = (int)task.id
                };
                _insedlu.TaskCompletions.Add(taskComplete);
                _insedlu.SaveChanges();

                stats = Status("Assigned");
                var taskStatus = Convert.ToInt32(stats);
                //var task = _insedlu.Tasks.Single(x => x.id == taskId);

                task.status      = taskStatus;
                task.assigned_to = selectedUserId;

                _insedlu.Entry(task).State = EntityState.Modified;
                _insedlu.SaveChanges();

                if (check == 1)
                {
                    Page.ClientScript.RegisterClientScriptBlock(GetType(), "alert", "alert('Task saved successfully')", true);
                }
            }

            SetTasks(_id);
        }
Example #14
0
 public TaskInfo(MasterTaskType type, TaskCompletion result, TaskId taskid)
 {
     this.type   = type;
     this.result = result;
     this.taskid = taskid;
 }
Example #15
0
 /// <summary>
 /// Completes a task (verb run).
 /// </summary>
 /// <remarks>
 /// Note that for Async verb workers, this method runs on a separate thread.
 /// </remarks>
 /// <param name="verb">The verb which was run.</param>
 /// <param name="worker">The verb's worker.</param>
 private void completeTask(IVerb verb, IVerbWorker worker)
 {
     this.taskCompletionsLock.AcquireWriterLock(Timeout.Infinite);
     Disposition disp = worker.Complete();
     TaskCompletion tc = new TaskCompletion(worker.GetWorkingDirectory(), verb, disp);
     this.taskCompletions.Add(tc);
     this.completionEvent.Set();
     this.taskCompletionsLock.ReleaseWriterLock();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskCompletionEventArgs"/> class
 /// </summary>
 /// <param name="completion">The completion state</param>
 public TaskCompletionEventArgs(TaskCompletion completion)
 {
     Completion = completion;
 }
 void ITaskCallback.OnComplete(TaskCompletion result)
 {
     tcs.SetResult(result);
 }
 public static void PrintEnd(this TaskCompletion runnable)
 {
     Console.WriteLine($"Continue on {Thread.CurrentThread.ManagedThreadId}");
 }
Example #19
0
 void ITaskCallback.OnComplete(TaskCompletion result)
 {
     tcs.SetResult(result);
 }
Example #20
0
 public void OnComplete(TaskCompletion result)
 {
     tcs.SetResult(result);
 }
Example #21
0
 public CommandResponse(TaskCompletion result, CommandStatus status)
 {
     this.result = result;
     this.status = status;
 }
 public static void PrintStart(this TaskCompletion runnable)
 {
     Console.WriteLine($"Start on {Thread.CurrentThread.ManagedThreadId}");
 }
Example #23
0
 public RestartResultType(TaskCompletion summary, TimeSpan restartTime)
 {
     this.summary     = summary;
     this.restartTime = restartTime;
 }
Example #24
0
 void IMasterApplication.OnTaskComplete(MasterTaskType type, TaskCompletion result, int userId)
 {
     // ignore these in the default application
 }
Example #25
0
 public CommandTaskResult(TaskCompletion summary, IEnumerable <CommandPointResult> results)
 {
     this.summary = summary;
     this.results = results;
 }