Example #1
0
        public static ofTask CreateWithDestinationAndWorker(this ofTaskService taskService, ofTaskCreateOptions taskCreateOptions, string address, string workerID, ofRecipientsCreateOptions recipientCreateOptions = null, ofRequestOptions requestOptions = null)
        {
            ofDestinationCreateOptions destinationCreateOptions = new ofDestinationCreateOptions
            {
                Address = new ofAddress
                {
                    Unparsed = address
                }
            };

            ofDestinationService destinationService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofDestinationService() : new ofDestinationService(taskService.ApiKey);

            ofDestination destination = destinationService.Create(destinationCreateOptions, requestOptions);

            taskCreateOptions.DestinationId = destination.Id;

            if (recipientCreateOptions != null)
            {
                ofRecipientService recipientService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofRecipientService() : new ofRecipientService(taskService.ApiKey);
                var recipient = recipientService.Create(recipientCreateOptions, requestOptions);
                taskCreateOptions.Recipients = new List<string> { recipient.Id };
            }

            var task = taskService.Create(taskCreateOptions, requestOptions);

            ofWorkerService workerService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofWorkerService() : new ofWorkerService(taskService.ApiKey);
            ofWorkerUpdateOptions workerUpdateOptions = new ofWorkerUpdateOptions{
                Tasks = new List<string>{ task.Id}
            };
            workerService.Update(workerID, workerUpdateOptions, requestOptions);

            return taskService.Get(task.Id, requestOptions);
        }
Example #2
0
        public virtual ofWorker Update(string workerId, ofWorkerUpdateOptions updateOptions, ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            string serilizedObj = JsonConvert.SerializeObject(updateOptions, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }).ToString();
            var PostData = new StringContent(serilizedObj, Encoding.UTF8, "application/json");
            var worker = Requestor.Put<ofWorker>(string.Format("{0}/{1}", Urls.Workers, workerId), requestOptions, PostData);
            return worker;
        }
Example #3
0
        public static ofWorker AssignToWorker(this ofTaskService taskService, string taskId, string workerId,bool assignTaskDependencies = true, ofRequestOptions requestOptions = null)
        {
            var workerService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofWorkerService() : new ofWorkerService(taskService.ApiKey);
            var tasksIds = new List<string>();
            if (assignTaskDependencies == true)
            {
                var task = taskService.Get(taskId, requestOptions);
                tasksIds.AddRange(task.Dependencies);
            }
            tasksIds.Add(taskId);
            ofWorkerUpdateOptions updateoptions = new ofWorkerUpdateOptions { Tasks = tasksIds };

            var worker = workerService.Update(workerId, updateoptions, requestOptions);

            return worker;
        }