Example #1
0
        private void onTaskFinished(Task task, TaskProperties taskProps)
        {
            TaskState state = statusMapping[task.Status];

            taskProps.State = state;
            Clients.All.taskStateUpdated(taskProps.Id, state);
        }
Example #2
0
        public async Task <bool> UpdateTask(string id, ToodleDoTask toodleDoTask, TaskProperties properties)
        {
            // if only the "Modified" property has changed, do nothing
            if (properties == TaskProperties.Modified)
            {
                return(true);
            }

            var request = this.GetTaskChangeRequest(toodleDoTask, properties, true);

            string apiCall = null;

            if (string.IsNullOrEmpty(request.Options))
            {
                apiCall = string.Format("{0}/tasks/edit.php?key={1};tasks=[{2}];f=xml;t={3}",
                                        this.serverUrl, this.Key, request.JsonData, DateTime.UtcNow.Ticks);
            }
            else
            {
                apiCall = string.Format("{0}/tasks/edit.php?key={1};tasks=[{2}];fields={3};f=xml;t={4}",
                                        this.serverUrl, this.Key, request.JsonData, request.Options, DateTime.UtcNow.Ticks);
            }

            var result = await this.DownloadDataAsync(apiCall);

            if (result.HasError)
            {
                return(false);
            }

            return(true);
        }
Example #3
0
 public DeletedEntry(int folderId, string syncId)
     : this()
 {
     this.FolderId   = folderId;
     this.SyncId     = syncId;
     this.Properties = TaskProperties.None;
 }
Example #4
0
 public DeletedEntry(int folderId, string syncId, TaskProperties properties)
     : this()
 {
     this.FolderId   = folderId;
     this.SyncId     = syncId;
     this.Properties = properties;
 }
        public void TaskRemoved(ITask task)
        {
            if (this.ShouldIgnoreTask(task))
            {
                return;
            }

            if (this.AddedTasks.Contains(task.Id))
            {
                // task has been added then deleted
                this.AddedTasks.Remove(task.Id);
                this.EditedTasks.Remove(task.Id);
            }
            else
            {
                TaskProperties properties = TaskProperties.None;
                if (this.EditedTasks.ContainsKey(task.Id))
                {
                    properties |= this.EditedTasks[task.Id];
                    this.EditedTasks.Remove(task.Id);
                }

                this.DeletedTasks.Add(new DeletedEntry(task.Id, task.SyncId, properties));
            }
        }
        private void TaskEdited(ITask task, TaskProperties properties)
        {
            if (this.ShouldIgnoreTask(task))
            {
                return;
            }

            // if the task has been added, nothing more to track
            if (this.AddedTasks.Contains(task.Id))
            {
                return;
            }

            // if the task is not yet in the EditedTasks dictionary, add it without properties for the moment
            if (!this.EditedTasks.ContainsKey(task.Id))
            {
                this.EditedTasks.Add(task.Id, TaskProperties.None);
            }

            // setup properties
            TaskProperties oldEntry = this.EditedTasks[task.Id];
            TaskProperties newEntry = (oldEntry | properties);

            this.EditedTasks[task.Id] = newEntry;
        }
Example #7
0
        public TaskClient(TaskProperties taskProperties)
        {
            this.taskProperties = taskProperties;
            var vssBasicCredential = new VssBasicCredential(string.Empty, taskProperties.AuthToken);

            vssConnection = new VssConnection(taskProperties.PlanUri, vssBasicCredential);
            taskClient    = vssConnection.GetClient <TaskHttpClient>();
        }
Example #8
0
    public void OnTaskEnd(TaskProperties properties)
    {
        _state = State.TaskEnd;

        //Debug.Log (properties.taskEndMessage);

        MessageTopScreen(properties.taskEndMessage);
    }
Example #9
0
 public TaskLogger(TaskProperties taskProperties, TaskClient taskClient)
 {
     this.taskProperties = taskProperties;
     this.taskClient     = taskClient;
     pageId      = Guid.NewGuid().ToString();
     pagesFolder = Path.Combine(Path.GetTempPath(), "pages");
     Directory.CreateDirectory(pagesFolder);
 }
Example #10
0
    public void OnStimulationStart(TaskProperties properties)
    {
        startTime = Time.time;

        isPulseSent         = false; isPulseEnd = false;
        _stimuliCounter     = 0;
        stimuliSequenceData = properties.Stimuli;

        MessageTopScreen(properties.stimulationMessage);

        _state = State.Stimulation;
    }
    private void SpawnTask(TaskProperties props)
    {
        Vector3 nextTaskPos = ParentTaskTransform.position;

        nextTaskPos.z = _lastTaskZPos + props.overallLength;
        _lastTaskZPos = nextTaskPos.z;

        GameObject     taskGO = Instantiate(TaskTemplatePrefab, nextTaskPos, Quaternion.identity, ParentTaskTransform);
        TaskController tc     = taskGO.GetComponent <TaskController> ();

        tc.uiOutputController = uiTaskController;
        tc.properties         = props;
    }
Example #12
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            TaskProperties.PersistProperties();

            if (clbFiles.Items.Count > 0)
            {
                List <string> files = new List <string>(clbFiles.Items.Count);
                foreach (string file in clbFiles.Items)
                {
                    files.Add(file);
                }
                TaskControl.FilesToCheck = string.Join("|", files);
            }
            else
            {
                TaskControl.FilesToCheck = string.Empty;
            }
        }
Example #13
0
        public async Task <string> StartTask(string name, int delay, int failAfter)
        {
            var tokenSource = new CancellationTokenSource();

            string taskId = Guid.NewGuid().ToString();

            var item = new TaskProperties(taskId, name, tokenSource);

            item.State = TaskState.Running;
            CurrentTasks.TryAdd(taskId, item);

            Clients.All.taskStarted(item);

            var task = SampleAsyncTask.StartCalculation(delay, failAfter, tokenSource.Token, new Progress <int>(percent => onProgressChange(taskId, percent)));

            // ReSharper disable CSharpWarnings::CS4014
            task.ContinueWith(t => onTaskFinished(t, item), tokenSource.Token);
            task.ContinueWith(t => onTaskFinished(t, item), TaskContinuationOptions.OnlyOnCanceled);
            // ReSharper restore CSharpWarnings::CS4014
            await task;

            return(taskId);
        }
Example #14
0
        private async Task TaskSync()
        {
            // add new local tasks in ToodleDo
            int count      = this.Metadata.AddedTasks.Count;
            var addedTasks = new List <ITask>(count);

            foreach (var addedTaskId in this.Metadata.AddedTasks.ToList())
            {
                var task = this.Workbook.Tasks.FirstOrDefault(t => t.Id == addedTaskId);
                if (task != null)
                {
                    addedTasks.Add(task);
                }
                this.Metadata.AddedTasks.Remove(addedTaskId);
            }

            foreach (var task in addedTasks)
            {
                this.OnSynchronizationProgressChanged(string.Format(StringResources.SyncProgress_AddingTaskFormat, task.Title));

                string taskId = await this.service.AddTask(new ToodleDoTask(task));

                if (!string.IsNullOrEmpty(taskId))
                {
                    this.PrepareTaskUpdate(task);

                    task.SyncId = taskId;
                    this.Changes.WebAdd++;
                }
            }

            // remove deleted local tasks from ToodleDo
            if (this.Metadata.DeletedTasks.Count > 0)
            {
                var message = StringResources.SyncProgress_DeletingTaskFormat.Replace(" {0}...", string.Empty);
                this.OnSynchronizationProgressChanged(message);

                var tasks = this.Metadata.DeletedTasks
                            .Where(d => !string.IsNullOrEmpty(d.SyncId))
                            .Select(deletedEntry => deletedEntry.SyncId)
                            .ToList();

                if (tasks.Count > 0)
                {
                    await this.service.DeleteTasks(tasks);

                    this.Changes.WebDelete += tasks.Count;
                    this.Metadata.DeletedTasks.Clear();
                }
            }

            // if TaskEditTimestamp newer than the last sync
            // it means we have edited task in ToodleDo since the last sync
            if (this.account.TaskEditTimestamp > this.taskEditTimestamp)
            {
                this.OnSynchronizationProgressChanged(StringResources.SyncProgress_GettingTasks);

                // there are probably changed in ToodleDo we must do locally... start by fetching tasks
                // ask the server to give us all the task that have changed since the last sync
                var toodleTasks = await this.service.GetTasks(false, this.taskEditTimestamp);

                // does the server have tasks we don't have ?
                this.EnsureWorkbookHasTasks(toodleTasks, true);

                // does tasks exist in both place, resolve conflicts and update
                await this.UpdateWorkbookTasks(toodleTasks);
            }

            // is TaskDeleteTimestamp newer than the last sync
            if (this.account.TaskDeleteTimestamp > this.taskDeleteTimestamp)
            {
                this.OnSynchronizationProgressChanged(StringResources.SyncProgress_UpdatingTasks);

                var deletedTasks = await this.service.GetDeletedTasks(this.taskDeleteTimestamp);

                foreach (string syncId in deletedTasks)
                {
                    var task = this.Workbook.Tasks.FirstOrDefault(t => t.SyncId == syncId);
                    if (task != null)
                    {
                        this.DeleteTask(task);
                        this.Changes.LocalDelete++;
                    }
                }
            }

            // do we need to edit tasks
            foreach (var kvp in this.Metadata.EditedTasks.ToList())
            {
                ITask task = this.Workbook.Tasks.FirstOrDefault(t => t.Id == kvp.Key);

                if (task != null)
                {
                    TaskProperties changes = kvp.Value;

                    this.OnSynchronizationProgressChanged(string.Format(StringResources.SyncProgress_UpdatingTaskFormat, task.Title));

                    var result = await this.service.UpdateTask(task.SyncId, new ToodleDoTask(task), changes);

                    if (result)
                    {
                        this.Changes.WebEdit++;
                        this.Metadata.EditedTasks.Remove(kvp.Key);
                    }
                }
            }

            this.RemoveDefaultFolderIfNeeded();
        }
Example #15
0
 private ExchangeTask CreateExchangeTask(ITask task, TaskProperties taskProperties)
 {
     return(task.ToExchangeTask(setCategory: !this.IsInDefaultFolder(task), properties: taskProperties));
 }
Example #16
0
        public async static Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log,
            WebJobsExecutionContext executionContext)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            log.LogInformation("function directory: " + executionContext.FunctionDirectory);
            log.LogInformation("function app directory: " + executionContext.FunctionAppDirectory);

            EvaluationRequest request;

            try
            {
                string requestBody = await new StreamReader(req.Body).ReadToEndAsync().ConfigureAwait(false);
                request = JsonConvert.DeserializeObject <EvaluationRequest>(requestBody);
            }
            catch (Exception e)
            {
                return(new BadRequestObjectResult(string.Format(
                                                      CultureInfo.InvariantCulture,
                                                      "Request body is invalid. Encountered error : {0}",
                                                      e.ToString())));
            }

            string imageProvenance = JsonConvert.SerializeObject(request.ImageProvenance);

            if (string.IsNullOrWhiteSpace(imageProvenance))
            {
                return(new BadRequestObjectResult("Image provenance is empty"));
            }

            if (string.IsNullOrWhiteSpace(request.PolicyData))
            {
                return(new BadRequestObjectResult("Policy data is empty"));
            }

            if (!string.IsNullOrWhiteSpace(request.AuthToken))
            {
                TaskProperties taskProperties = CommonUtilities.CreateTaskProperties(request);
                new Thread(async() => await ExecuteUsingTimelineLogs(
                               executionContext,
                               log,
                               imageProvenance,
                               request.PolicyData,
                               request.CheckSuiteId,
                               taskProperties,
                               request.Variables));
                return(new NoContentResult());
            }
            else
            {
                StringBuilder syncLogger = new StringBuilder();
                var           violations = CommonUtilities.ExecutePolicyCheck(
                    executionContext,
                    log,
                    imageProvenance,
                    request.PolicyData,
                    null,
                    request.Variables,
                    syncLogger,
                    out ViolationType violationType,
                    out string outputLog);
                return(new OkObjectResult(new EvaluationResponse {
                    Violations = violations.ToList(), Logs = syncLogger.ToString(), ViolationType = violationType
                }));
            }
        }
Example #17
0
        private static async Task ExecuteUsingTimelineLogs(
            WebJobsExecutionContext executionContext,
            ILogger log,
            string imageProvenance,
            string policy,
            Guid checkSuiteId,
            TaskProperties taskProperties,
            IDictionary <string, string> variables)
        {
            using (var taskClient = new TaskClient(taskProperties))
            {
                var taskLogger = new TaskLogger(taskProperties, taskClient);
                try
                {
                    // create timelinerecord if not provided
                    await taskLogger.CreateTaskTimelineRecordIfRequired(taskClient, default(CancellationToken)).ConfigureAwait(false);

                    // report task started
                    string taskStartedLog = string.Format("Initializing evaluation. Execution id - {0}", executionContext.InvocationId);
                    CommonUtilities.LogInformation(taskStartedLog, log, taskLogger, variables, null);

                    string outputLog;
                    var    violations = CommonUtilities.ExecutePolicyCheck(
                        executionContext,
                        log,
                        imageProvenance,
                        policy,
                        taskLogger,
                        variables,
                        null,
                        out ViolationType violationType,
                        out outputLog);

                    bool succeeded = !(violations?.Any() == true);
                    CommonUtilities.LogInformation($"Policy check succeeded: {succeeded}", log, taskLogger, variables, null);

                    var telemetryProperties = new Dictionary <string, object>();
                    telemetryProperties.Add("projectId", taskProperties.ProjectId);
                    telemetryProperties.Add("jobId", taskProperties.JobId);
                    telemetryProperties.Add("checkSuiteId", checkSuiteId);
                    telemetryProperties.Add("result", succeeded ? "succeeded" : "failed");
                    telemetryProperties.Add("layer", "Azure function");
                    telemetryProperties.Add(ArtifactPolicyTelemetryReasonKey, $"Found violations in evaluation. Violation type: {violationType}");

                    await UpdateCheckSuiteResult(
                        taskProperties.PlanUrl,
                        taskProperties.AuthToken,
                        taskProperties.ProjectId,
                        checkSuiteId,
                        succeeded,
                        outputLog,
                        log,
                        taskLogger,
                        variables);

                    await CustomerIntelligenceClient.GetClient(taskProperties.PlanUrl, taskProperties.AuthToken)
                    .PublishArtifactPolicyEventAsync(telemetryProperties).ConfigureAwait(false);

                    return;
                }
                catch (Exception e)
                {
                    if (taskLogger != null)
                    {
                        await taskLogger.Log(e.ToString()).ConfigureAwait(false);
                    }

                    throw;
                }
                finally
                {
                    if (taskLogger != null)
                    {
                        await taskLogger.End().ConfigureAwait(false);
                    }
                }
            }
        }
Example #18
0
        private TaskChangeRequest GetTaskChangeRequest(ToodleDoTask toodleDoTask, TaskProperties properties, bool includeId)
        {
            var           request = new TaskChangeRequest();
            StringBuilder sb      = new StringBuilder();
            StringWriter  sw      = new StringWriter(sb);

            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = Formatting.None;
                jsonWriter.WriteStartObject();

                if (includeId)
                {
                    jsonWriter.WritePropertyName("id");
                    jsonWriter.WriteValue(toodleDoTask.Id);
                }

                if ((properties & TaskProperties.Title) == TaskProperties.Title)
                {
                    jsonWriter.WritePropertyName("title");
                    jsonWriter.WriteValue(toodleDoTask.Title);
                }

                if ((properties & TaskProperties.Note) == TaskProperties.Note)
                {
                    string note = string.Empty;
                    if (!string.IsNullOrEmpty(toodleDoTask.Note))
                    {
                        note = toodleDoTask.Note;
                    }

                    jsonWriter.WritePropertyName("note");
                    jsonWriter.WriteValue(note);
                    request.Options += "note,";
                }

                if ((properties & TaskProperties.Tags) == TaskProperties.Tags)
                {
                    if (!string.IsNullOrEmpty(toodleDoTask.Tags))
                    {
                        jsonWriter.WritePropertyName("tag");
                        jsonWriter.WriteValue(toodleDoTask.Tags);
                        request.Options += "tag,";
                    }
                }

                if ((properties & TaskProperties.Folder) == TaskProperties.Folder)
                {
                    jsonWriter.WritePropertyName("folder");
                    jsonWriter.WriteValue(toodleDoTask.FolderId);
                    request.Options += "folder,";
                }

                if ((properties & TaskProperties.Context) == TaskProperties.Context)
                {
                    string contextId = toodleDoTask.ContextId;
                    if (string.IsNullOrEmpty(contextId))
                    {
                        contextId = "0";
                    }

                    jsonWriter.WritePropertyName("context");
                    jsonWriter.WriteValue(contextId);
                    request.Options += "context,";
                }

                if ((properties & TaskProperties.Due) == TaskProperties.Due)
                {
                    int duedate = 0;

                    if (toodleDoTask.Due.HasValue)
                    {
                        duedate = toodleDoTask.Due.Value.DateTimeToTimestamp();
                    }

                    jsonWriter.WritePropertyName("duedate");
                    jsonWriter.WriteValue(duedate);

                    request.Options += "duedate,";
                }

                if ((properties & TaskProperties.Start) == TaskProperties.Start)
                {
                    int startdate = 0;
                    int starttime = 0;

                    if (toodleDoTask.Start.HasValue)
                    {
                        startdate = toodleDoTask.Start.Value.Date.DateTimeToTimestamp();
                        starttime = (int)toodleDoTask.Start.Value.TimeOfDay.TotalSeconds;
                    }

                    jsonWriter.WritePropertyName("startdate");
                    jsonWriter.WriteValue(startdate);

                    request.Options += "starttime,";

                    jsonWriter.WritePropertyName("starttime");
                    jsonWriter.WriteValue(starttime);

                    request.Options += "starttime,";
                }

                if ((properties & TaskProperties.Frequency) == TaskProperties.Frequency)
                {
                    jsonWriter.WritePropertyName("repeat");
                    jsonWriter.WriteValue(toodleDoTask.Repeat);

                    request.Options += "repeat,";
                }

                if ((properties & TaskProperties.RepeatFrom) == TaskProperties.RepeatFrom)
                {
                    jsonWriter.WritePropertyName("repeatfrom");
                    jsonWriter.WriteValue(toodleDoTask.RepeatFrom);

                    request.Options += "repeatfrom,";
                }

                if ((properties & TaskProperties.Completed) == TaskProperties.Completed)
                {
                    if (toodleDoTask.Completed.HasValue)
                    {
                        jsonWriter.WritePropertyName("completed");
                        jsonWriter.WriteValue(toodleDoTask.Completed.Value.DateTimeToTimestamp());
                    }
                    else
                    {
                        jsonWriter.WritePropertyName("completed");
                        jsonWriter.WriteValue(0);
                    }
                }

                if ((properties & TaskProperties.Added) == TaskProperties.Added)
                {
                    jsonWriter.WritePropertyName("added");
                    jsonWriter.WriteValue(toodleDoTask.Added.DateTimeToTimestamp());

                    request.Options += "added,";
                }

                if ((properties & TaskProperties.Priority) == TaskProperties.Priority)
                {
                    jsonWriter.WritePropertyName("priority");
                    jsonWriter.WriteValue(toodleDoTask.Priority);

                    request.Options += "priority,";
                }

                if ((properties & TaskProperties.Parent) == TaskProperties.Parent)
                {
                    jsonWriter.WritePropertyName("parent");
                    jsonWriter.WriteValue(toodleDoTask.ParentId);

                    request.Options += "parent,";
                }

                jsonWriter.WriteEndObject();
            }

            request.JsonData = Escape(sb.ToString());

            return(request);
        }
Example #19
0
        private void WaitForFileForm_Load(object sender, EventArgs e)
        {
            try
            {
                Loading = true;

                this.Text = string.Format(Resources.EditorFor, UIHelper.TaskHost.Name);

                _taskProperties = new TaskProperties(UIHelper.TaskHost.InnerObject as VariablesToXmlTask);

                propControlProperties.SelectedObject = _taskProperties;

                string controlPath = UIHelper.TaskHost.GetPackagePath();

                List <string> selected = new List <string>(TaskControl.ExportVariables.Count);
                foreach (string var in TaskControl.ExportVariables)
                {
                    if (UIHelper.TaskHost.Variables.Contains(var))
                    {
                        Variable v = UIHelper.TaskHost.Variables[var];
                        selected.Add(v.QualifiedName);
                    }
                }


                lvVariables.SuspendLayout();
                lvVariables.Items.Clear();
                lbSelectedVariables.SuspendLayout();
                lbSelectedVariables.Items.Clear();
                cmbXmlVariable.SuspendLayout();
                cmbXmlVariable.Items.Clear();

                foreach (Variable var in UIHelper.TaskHost.Variables)
                {
                    if (var.GetPackagePath() == string.Format("{0}.Variables[{1}]", controlPath, var.QualifiedName))
                    {
                        continue;
                    }

                    ListViewGroup lvg = lvVariables.Groups[var.Namespace];

                    if (lvg == null)
                    {
                        lvg = lvVariables.Groups.Add(var.Namespace, var.Namespace);
                    }

                    ListViewItem lvi = new ListViewItem(var.Name, lvg);
                    lvi.Tag  = var.QualifiedName;
                    lvi.Name = var.QualifiedName;

                    lvi.SubItems.Add(var.DataType.ToString());
                    lvi.SubItems.Add(var.Description);
                    lvi.SubItems.Add(var.QualifiedName);
                    lvi.SubItems.Add(var.GetPackagePath());

                    if (selected.Contains(var.QualifiedName))
                    {
                        lvi.Checked = true;
                    }

                    if (var.Namespace == "User" && (var.DataType == TypeCode.String || var.DataType == TypeCode.Object) && var.EvaluateAsExpression == false)
                    {
                        cmbXmlVariable.Items.Add(var.QualifiedName);
                    }

                    lvVariables.Items.Add(lvi);
                }

                cmbXmlVariable.SelectedItem = -1;
                if (!string.IsNullOrEmpty(TaskControl.XmlVariable) && UIHelper.TaskHost.Variables.Contains(TaskControl.XmlVariable) && cmbXmlVariable.Items.Count > 0)
                {
                    Variable xv = UIHelper.TaskHost.Variables[TaskControl.XmlVariable];
                    if ((xv.DataType == TypeCode.Object || xv.DataType == TypeCode.String) && xv.Namespace == "User" && xv.EvaluateAsExpression == false)
                    {
                        cmbXmlVariable.SelectedItem = xv.QualifiedName;
                    }
                }

                lbSelectedVariables.Items.AddRange(selected.ToArray());
            }
            finally
            {
                lbSelectedVariables.ResumeLayout(true);
                lvVariables.ResumeLayout(true);
                cmbXmlVariable.ResumeLayout(true);
                Loading = false;
            }
        }
 public ExecutionHandler(ITaskExecutionHandler taskExecutionHandler, string taskMessageBody, TaskProperties taskProperties)
 {
     this.taskExecutionHandler = taskExecutionHandler;
     this.taskProperties       = taskProperties;
     taskMessage = new TaskMessage(taskMessageBody, taskProperties);
 }
Example #21
0
 void btnReset_Click(object sender, EventArgs e)
 {
     TaskProperties.InitializeProperties();
     propGrid.SelectedObject = TaskProperties;
 }
 public TaskMessage(string taskMessageBody, TaskProperties taskProperties)
 {
     this.taskMessageBody = taskMessageBody;
     this.taskProperties  = taskProperties;
 }
Example #23
0
    public void OnCueStart(TaskProperties properties)
    {
        _state = State.Cue;

        MessageTopScreen(properties.cueMessage);
    }
Example #24
0
    public void OnInputStart(TaskProperties properties)
    {
        _state = State.UserInput;

        MessageTopScreen(properties.inputStartMessage);
    }
Example #25
0
        public static ExchangeTask ToExchangeTask(this ITask task, bool setCategory, TaskProperties properties)
        {
            var exchangeTask = new ExchangeTask
            {
                Subject    = task.Title,
                Importance = task.Priority.GetImportance(),
                Completed  = task.Completed,
                Due        = task.Due,
                Start      = task.Start,
                LocalId    = task.Id,
                Id         = task.SyncId,
                Note       = task.Note,
                Created    = task.Added,
                Alarm      = task.Alarm,
                Properties = (ExchangeTaskProperties?)properties
            };

            // flag must be set to false when the folder that owns the task is the default
            // folder we create for task without category in Exchange
            if (setCategory)
            {
                exchangeTask.Category = task.Folder.Name;
            }

            if (task.Progress.HasValue)
            {
                exchangeTask.ProgressPercent = task.Progress.Value;
            }

            if (task.IsPeriodic && task.Due.HasValue)
            {
                exchangeTask.IsRecurring  = true;
                exchangeTask.UseFixedDate = task.UseFixedDate;

                if (task.CustomFrequency is DailyFrequency)
                {
                    var frequency = (DailyFrequency)task.CustomFrequency;

                    exchangeTask.RecurrenceType = ExchangeRecurrencePattern.Daily;
                    exchangeTask.Interval       = 1;
                }
                else if (task.CustomFrequency is DaysOfWeekFrequency)
                {
                    var frequency = (DaysOfWeekFrequency)task.CustomFrequency;

                    exchangeTask.RecurrenceType = ExchangeRecurrencePattern.Weekly;
                    exchangeTask.Interval       = 1;

                    if (frequency.IsMonday)
                    {
                        exchangeTask.DaysOfWeek |= ExchangeDayOfWeek.Monday;
                    }
                    if (frequency.IsTuesday)
                    {
                        exchangeTask.DaysOfWeek |= ExchangeDayOfWeek.Tuesday;
                    }
                    if (frequency.IsWednesday)
                    {
                        exchangeTask.DaysOfWeek |= ExchangeDayOfWeek.Wednesday;
                    }
                    if (frequency.IsThursday)
                    {
                        exchangeTask.DaysOfWeek |= ExchangeDayOfWeek.Thursday;
                    }
                    if (frequency.IsFriday)
                    {
                        exchangeTask.DaysOfWeek |= ExchangeDayOfWeek.Friday;
                    }
                    if (frequency.IsSaturday)
                    {
                        exchangeTask.DaysOfWeek |= ExchangeDayOfWeek.Saturday;
                    }
                    if (frequency.IsSunday)
                    {
                        exchangeTask.DaysOfWeek |= ExchangeDayOfWeek.Sunday;
                    }
                }
                else if (task.CustomFrequency is EveryXPeriodFrequency)
                {
                    var frequency = (EveryXPeriodFrequency)task.CustomFrequency;
                    exchangeTask.Interval = frequency.Rate;

                    switch (frequency.Scale)
                    {
                    case CustomFrequencyScale.Day:
                        if (exchangeTask.UseFixedDate)
                        {
                            exchangeTask.RecurrenceType = ExchangeRecurrencePattern.Daily;
                        }
                        else
                        {
                            exchangeTask.RecurrenceType = ExchangeRecurrencePattern.DailyRegeneration;
                        }
                        break;

                    case CustomFrequencyScale.Week:
                        if (exchangeTask.UseFixedDate)
                        {
                            exchangeTask.DaysOfWeek     = task.Due.Value.DayOfWeek.ToExchangeDayOfWeek();
                            exchangeTask.RecurrenceType = ExchangeRecurrencePattern.Weekly;
                        }
                        else
                        {
                            exchangeTask.RecurrenceType = ExchangeRecurrencePattern.WeeklyRegeneration;
                        }
                        break;

                    case CustomFrequencyScale.Month:
                        if (exchangeTask.UseFixedDate)
                        {
                            exchangeTask.RecurrenceType = ExchangeRecurrencePattern.Monthly;
                            exchangeTask.DayOfMonth     = task.Due.Value.Day;
                        }
                        else
                        {
                            exchangeTask.RecurrenceType = ExchangeRecurrencePattern.MonthlyRegeneration;
                        }
                        break;

                    case CustomFrequencyScale.Year:
                        if (exchangeTask.UseFixedDate)
                        {
                            exchangeTask.RecurrenceType = ExchangeRecurrencePattern.Yearly;
                            exchangeTask.DayOfMonth     = task.Due.Value.Day;
                            exchangeTask.Month          = task.Due.Value.Month;
                        }
                        else
                        {
                            exchangeTask.RecurrenceType = ExchangeRecurrencePattern.YearlyRegeneration;
                        }
                        break;
                    }
                }
                else if (task.CustomFrequency is WeeklyFrequency)
                {
                    var frequency = (WeeklyFrequency)task.CustomFrequency;

                    exchangeTask.IsRecurring = true;
                    if (!task.Start.HasValue)
                    {
                        exchangeTask.DaysOfWeek = task.Due.Value.DayOfWeek.ToExchangeDayOfWeek();
                    }
                    else
                    {
                        exchangeTask.DaysOfWeek = task.Start.Value.DayOfWeek.ToExchangeDayOfWeek();
                    }
                    exchangeTask.RecurrenceType = ExchangeRecurrencePattern.Weekly;
                    exchangeTask.Interval       = 1;
                }
                else if (task.CustomFrequency is MonthlyFrequency && task.Due.HasValue)
                {
                    var frequency = (MonthlyFrequency)task.CustomFrequency;

                    exchangeTask.IsRecurring    = true;
                    exchangeTask.RecurrenceType = ExchangeRecurrencePattern.Monthly;
                    exchangeTask.Interval       = 1;
                    exchangeTask.DayOfMonth     = task.Due.Value.Date.Day;
                }
                else if (task.CustomFrequency is OnXDayFrequency)
                {
                    var frequency = (OnXDayFrequency)task.CustomFrequency;

                    exchangeTask.RecurrenceType = ExchangeRecurrencePattern.MonthlyRelative;
                    exchangeTask.Interval       = 1;
                    exchangeTask.DaysOfWeek     = frequency.DayOfWeek.ToExchangeDayOfWeek();
                    exchangeTask.DayOfWeekIndex = frequency.RankingPosition.ToExchangeDayIndex();
                }
                else if (task.CustomFrequency is YearlyFrequency && task.Due.HasValue)
                {
                    var frequency = (YearlyFrequency)task.CustomFrequency;

                    exchangeTask.IsRecurring    = true;
                    exchangeTask.RecurrenceType = ExchangeRecurrencePattern.Yearly;
                    exchangeTask.Interval       = 1;
                    exchangeTask.DayOfMonth     = task.Due.Value.Date.Day;
                    exchangeTask.Month          = task.Due.Value.Date.Month;
                }
            }

            return(exchangeTask);
        }
Example #26
0
 void btnReset_Click(object sender, EventArgs e)
 {
     TaskProperties.InitProperties();
     propControlProperties.SelectedObject = TaskProperties;
 }