コード例 #1
0
 public StepState(SQLiteQuery query, StepCallback callback, QueryCallback complete, object state)
 {
     this.query    = query;
     this.callback = callback;
     this.complete = complete;
     this.state    = state;
 }
コード例 #2
0
        public SagaDefinitionBuilder <FormType> SetRemoteAction(StepCallback action)
        {
            buildingStep.Local  = false;
            buildingStep.Action = ToStepCallback(action);

            var compensableAttrs = action.Method.GetCustomAttributes(typeof(Compensable), true);

            if (compensableAttrs.Count() > 0)
            {
                var compensableAttr       = compensableAttrs.First();
                var compensableAttrObj    = compensableAttr as Compensable;
                var compensableActionName = compensableAttrObj.ActionName;
                var compensableMethod     = action.Method.DeclaringType.GetMethod(compensableActionName);
                if (compensableMethod == null)
                {
                    throw new SagaAbortException($"can't find compensable method {compensableMethod} in class {action.Method.DeclaringType.FullName}");
                }
                var actionInvoker = action.Target;
                SagaStep.StepCallback compensableStepCallback = (SagaData form) =>
                {
                    object res = compensableMethod.Invoke(actionInvoker, new object[] { form });
                    return(res as Task);
                };
                buildingStep.Compensation = compensableStepCallback;
            }
            return(this);
        }
コード例 #3
0
 /// <summary>
 /// Create a new pedometer and start listening for updates
 /// </summary>
 public Pedometer(StepCallback callback)
 {
     // Save the callback
     this.callback = callback;
     // Register callback
     Implementation.OnStep += OnStep;
 }
コード例 #4
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="StepperMotor" /> class.
 /// </summary>
 /// <param name="limitOfTravel">The limit of travel in steps.</param>
 /// <param name="stepper">The hardware driver that will perform the actual microstep.</param>
 /// <param name="performMicrostep">A method to write the current microstep value to the motor hardware.</param>
 /// <param name="microSteps">The number of micro steps per whole step.</param>
 protected StepperMotor(int limitOfTravel, IStepSequencer stepper, StepCallback performMicrostep = null)
 {
     //ToDo: this can be improved by deprecating the use of a delegate and instead providing
     // an implementation of IStepSequencer (defined in the Adafruit motor shield assembly).
     this.limitOfTravel  = limitOfTravel;
     this.stepper        = stepper;
     performStepCallback = performMicrostep ?? NullStepCallback;
     stepTimer           = new Timer(StepTimerTick, null, Timeout.Infinite, Timeout.Infinite); // Stopped
 }
コード例 #5
0
 private SagaStep.StepCallback ToStepCallback(StepCallback action)
 {
     if (action == null)
     {
         return(null);
     }
     return((SagaData sd) =>
     {
         return action(sd as FormType);
     });
 }
コード例 #6
0
 /// <summary>
 /// Create a new pedometer and start listening for updates
 /// </summary>
 public Pedometer(StepCallback callback)
 {
     if (Implementation == null)
     {
         Debug.LogError("Pedometer Error: Step counting is not supported on this platform");
         return;
     }
     if (callback == null)
     {
         Debug.LogError("Pedometer Error: Cannot create pedometer instance with null callback");
         return;
     }
     this.callback          = callback;
     Implementation.OnStep += OnStep;
 }
コード例 #7
0
        public async Task InvokeAsync(StepCallback branchStep, FormType sagaData)
        {
            // 注册branch tx id
            var branchStepInfo = getBranchStepInfo(branchStep);

            var branchTxId = await _sagaCollaborator.CreateBranchTxAsync(_xid,
                                                                         branchStepInfo.BranchServiceKey,
                                                                         branchStepInfo.BranchCompensationServiceKey);

            // 本次执行的jobId
            var jobId = Guid.NewGuid().ToString();

            _logger.LogInformation($"created branch txid {branchTxId} jobId {jobId} in xid {_xid}");


            try
            {
                // invoke branchStep
                await branchStep(sagaData);

                // 调用成功,通知saga server状态变化
                var oldBranchTxDetail = await _sagaCollaborator.QueryBranchTxAsync(branchTxId);

                var sagaDataBytes = _sagaDataConverter.Serialize(sagaData.GetType(), sagaData);

                var newState = await _sagaCollaborator.SubmitBranchTxStateAsync(_xid, branchTxId,
                                                                                oldBranchTxDetail.Detail.State, saga_server.TxState.Committed,
                                                                                oldBranchTxDetail.Detail.Version, jobId, "",
                                                                                sagaDataBytes);

                _logger.LogInformation($"branch txid {branchTxId} state changed to {newState}");
            }
            catch (Exception e)
            {
                _logger.LogError($"invoke branch service {branchStepInfo.BranchServiceKey} error", e);
                // 如果有异常,通知saga server回滚后台执行回滚,然后再抛出异常
                var oldBranchTxDetail = await _sagaCollaborator.QueryBranchTxAsync(branchTxId);

                await _sagaCollaborator.SubmitBranchTxStateAsync(_xid, branchTxId,
                                                                 oldBranchTxDetail.Detail.State, saga_server.TxState.CompensationDoing,
                                                                 oldBranchTxDetail.Detail.Version, jobId, e.Message, null);

                throw e;
            }

            return;
        }
コード例 #8
0
        public int CallSteps(StepCallback stepFunc)
        {
            // Get current delta
            int delta = _rawDelta;

            if (_recordedFPS != 0)
            {
                delta = 1000 / _recordedFPS;
            }

            int updatesCount = 0;

            // Accumulate delta time
            _storedDelta += delta;

            // If the accumulated delta time is enough to trigger an update step
            if (_storedDelta >= _minDelta)
            {
                // Call update steps one or more times to match the elapsed time
                int cycles = _storedDelta / _maxDelta;
                for (int i = 0; i < cycles; ++i)
                {
                    stepFunc(_maxDelta);
                    ++updatesCount;
                }

                // Update remainder time
                int remainder = _storedDelta % _maxDelta;
                if (remainder > _minDelta)
                {
                    stepFunc(remainder);
                    _storedDelta = 0;
                    ++updatesCount;
                }
                else
                {
                    _storedDelta = remainder;
                }
            }

            return(updatesCount);
        }
コード例 #9
0
 private BranchStepInfo getBranchStepInfo(StepCallback branchStep)
 {
     return(_cachedBranchStepInfos.GetOrAdd(branchStep.Method, (method) =>
     {
         var methodName = method.Name;
         var compensableAttr = MethodUtils.GetDeclaredAttribute <Compensable>(method, typeof(Compensable));
         var branchServiceKey = _sagaResolver.GetServiceKey(method.DeclaringType, methodName);
         var branchCompensationServiceKey = "";
         if (compensableAttr != null)
         {
             var compensationMethodName = (compensableAttr as Compensable).ActionName;
             branchCompensationServiceKey = _sagaResolver.GetServiceKey(method.DeclaringType, compensationMethodName);
         }
         return new BranchStepInfo()
         {
             BranchServiceKey = branchServiceKey,
             BranchCompensationServiceKey = branchCompensationServiceKey
         };
     }));
 }
コード例 #10
0
 public static extern int sqlite3_create_function(IntPtr db, byte[] functionNameBytes, int argsNumber, int encodingType, IntPtr userDataFunc, FuncCallback func, StepCallback step, FinalCallback final);
コード例 #11
0
ファイル: SQLiteAsync.cs プロジェクト: Avatarchik/Duel-Off
	public void Step(SQLiteQuery qr, StepCallback callback, object state)
	{
		ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(StepQuery), new WaitCallback(StepQueryComplete), new StepState(qr,callback,state));
	}
コード例 #12
0
 public ThreadQueue.TaskControl Step(SQLiteQuery qr, StepCallback callback, object state)
 {
     return(ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(StepQuery), new WaitCallback(StepQueryComplete), new StepState(qr, callback, state)));
 }
コード例 #13
0
ファイル: SQLiteAsync.cs プロジェクト: swrn365/Duel-Off
 public void Step(SQLiteQuery qr, StepCallback callback, object state)
 {
     ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(StepQuery), new WaitCallback(StepQueryComplete), new StepState(qr, callback, state));
 }
コード例 #14
0
 public SagaDefinitionBuilder <FormType> SetLocalAction(StepCallback action)
 {
     buildingStep.Local  = true;
     buildingStep.Action = ToStepCallback(action);
     return(this);
 }
コード例 #15
0
		public StepState(SQLiteQuery query, StepCallback callback, object state){
			this.query = query; 
			this.callback = callback;
			this.state = state;
		}
コード例 #16
0
 public SagaDefinitionBuilder <FormType> WithCompensation(StepCallback compensation)
 {
     buildingStep.Compensation = ToStepCallback(compensation);
     return(this);
 }
コード例 #17
0
	public ThreadQueue.TaskControl Step(SQLiteQuery qr, StepCallback callback, object state)
	{
		return ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(StepQuery), new WaitCallback(StepQueryComplete), new StepState(qr,callback,state));
	}
コード例 #18
0
 /// <summary>
 /// Create a new pedometer and start listening for updates
 /// </summary>
 public Pedometer(StepCallback callback)
 {
     this.callback          = callback;
     Implementation.OnStep += OnStep;
 }