public void StartTask(ITask task, ITaskJobSettings settings)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            SampleTask demoTask = (SampleTask)task;

            int totalDurationInSeconds = demoTask.Details.Sum(d => d.DurationInSeconds);

            int pastDurationInSeconds = 0;

            foreach (SampleTaskDetail duration in demoTask.Details)
            {
                if (this.isCanceled)
                {
                    break;
                }

                Thread.Sleep(TimeSpan.FromSeconds(duration.DurationInSeconds));

                pastDurationInSeconds += duration.DurationInSeconds;

                var reportProgressEventHandler = this.ReportProgress;

                if (reportProgressEventHandler != null)
                {
                    double percent = 100.0 * pastDurationInSeconds / totalDurationInSeconds;

                    reportProgressEventHandler(this, new TaskWorkerProgressEventArgs(percent));
                }
            }
        }
        public object Deserialize(byte[] content)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            SampleTask result = new SampleTask();

            result.Details = Encoding.UTF8.GetString(content)
                             .Split(',')
                             .Select(value => new SampleTaskDetail()
            {
                DurationInSeconds = int.Parse(value)
            })
                             .ToArray();

            return(result);
        }
        public byte[] Serialize(object entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            SampleTask sampleTask = entity as SampleTask;

            if (sampleTask == null)
            {
                throw new NotSupportedException(string.Format("Type '{0}' is not supported.", entity.GetType().Name));
            }

            if (sampleTask.Details == null)
            {
                return(new byte[0]);
            }

            return(Encoding.UTF8.GetBytes(string.Join(",", sampleTask.Details.Select(detail => detail.DurationInSeconds))));
        }