Esempio n. 1
0
        public Result <T> RunSteps(TransferTask task, Step <T>[] steps, UpdateProgressHandler update)
        {
            var ctx    = CreateContext(task);
            var result = Fail("unknown", WorkerStatus.UNKNOWN);

            for (var i = 0; i < steps.Length; i++)
            {
                var step   = steps[i];
                var stepNo = i + 1;
                var info   = StepInfo.From <T>(step);
                update(stepNo, info.Desc, WorkerStatus.IN_PROCESS);
                result = Retry(ctx, task, step, info);

                //???
                try
                {
                    result.Status.CurrentStep = stepNo;
                }
                catch (Exception)
                {
                    //skip
                }

                if (!result.IsSuccess)
                {
                    break;
                }
            }

            Dispose(ctx, result);

            return(result);
        }
Esempio n. 2
0
        public static StepInfo From <T>(Step <T> step)
        {
            var info  = new StepInfo();
            var attrs = Attribute.GetCustomAttributes(step.Method).Where(a => a is BaseAttribute).Select(a => a as BaseAttribute);

            foreach (var attr in attrs)
            {
                attr.Apply(info);
            }
            if (info.DefaultError == 0)
            {
                info.DefaultError = info.AfterSubmitTransfer ? WorkerStatus.NETWORK_ERROR_AFTER_OTP : WorkerStatus.NETWORK_ERROR_BEFORE_OTP;
            }
            return(info);
        }
Esempio n. 3
0
        public Result <T> Retry(T ctx, TransferTask task, Step <T> step, StepInfo info)
        {
            var result = Fail(info.Desc, WorkerStatus.UNKNOWN);
            var times  = info.Retry;

            while (times > 0)
            {
                times--;
                logger.Info("TaskID-{0} try operation {1} at {2} times", task.ID, info.Desc, info.Retry - times);
                try {
                    result = step.Invoke(ctx);
                    break;
                } catch (AggregateException err) {
                    result = Fail(err.ToString(), info.DefaultError);
                } catch (Exception err) {
                    result = Fail(err.ToString(), info.AfterSubmitTransfer ? WorkerStatus.UNKNOWN_ERROR_AFTER_OTP : WorkerStatus.UNKNOWN_ERROR_BEFORE_OTP);
                }
            }
            return(result);
        }
Esempio n. 4
0
 public override void Apply(StepInfo info)
 {
     info.DefaultError = Code;
 }
Esempio n. 5
0
 public abstract void Apply(StepInfo info);
Esempio n. 6
0
 public override void Apply(StepInfo info)
 {
     info.AfterSubmitTransfer = true;
     info.Successful          = EnsureSuccessful;
 }
Esempio n. 7
0
 public override void Apply(StepInfo info)
 {
     info.Desc = Content;
 }
Esempio n. 8
0
 public override void Apply(StepInfo info)
 {
     info.Retry = Times;
 }