public MethodNameMatcher(Predicate<string> isMethodOfInterest, ExecutionOrder executionOrder) { IsMethodOfInterest = isMethodOfInterest; ExecutionOrder = executionOrder; Asserts = false; ShouldReport = true; }
private static void AssertStep(Step step, string stepTitle, ExecutionOrder order, bool asserts = false, bool shouldReport = true) { Assert.That(step.Title.Trim(), Is.EqualTo(stepTitle)); Assert.That(step.Asserts, Is.EqualTo(asserts)); Assert.That(step.ExecutionOrder, Is.EqualTo(order)); Assert.That(step.ShouldReport, Is.EqualTo(shouldReport)); }
public static ExecutionOrder Resolve(MT4TradeSignal signal, int login, double balance, double equity, SubscriptionSettings settings) { //Close only if (((SubscriptionStatus)settings.Status == SubscriptionStatus.CloseOnly && signal.ActionType != ActionType.Close)) { return(null); } //Side if (((SignalOrderType)settings.OrdersType == SignalOrderType.Buy && signal.Side == TradeSide.Sell) || ((SignalOrderType)settings.OrdersType == SignalOrderType.Sell && signal.Side == TradeSide.Buy)) { return(null); } var execution = new ExecutionOrder { ActionType = signal.ActionType, Login = login, //Reverse Side = GetSide(settings.Reverse, signal.Side), Symbol = signal.Symbol, OrderID = signal.OrderID }; //Max volume execution.Volume = CalculateVolume(signal, balance, equity, settings); if (settings.MaxVolume != -1) { execution.Volume = execution.Volume > (settings.MaxVolume / 100d) ? (settings.MaxVolume / 100d) : execution.Volume; } execution.Commission = 1.7d; return(execution); }
public MethodNameMatcher(Predicate <string> isMethodOfInterest, bool asserts, ExecutionOrder executionOrder, bool shouldReport) { IsMethodOfInterest = isMethodOfInterest; Asserts = asserts; ExecutionOrder = executionOrder; ShouldReport = shouldReport; }
void VerifyStepAndItsProperties(Action stepMethodAction, ExecutionOrder expectedOrder, int expectedCount = 1) { var matchingSteps = _scenario.Steps.Where(s => s.Title.Trim() == Configurator.Scanners.Humanize(Helpers.GetMethodInfo(stepMethodAction).Name)); Assert.That(matchingSteps.Count(), Is.EqualTo(expectedCount)); Assert.IsTrue(matchingSteps.All(s => s.ExecutionOrder == expectedOrder)); }
private static void AssertStep(Step step, string stepTitle, ExecutionOrder order, bool asserts = false, bool shouldReport = true) { step.Title.Trim().ShouldBe(stepTitle); step.Asserts.ShouldBe(asserts); step.ExecutionOrder.ShouldBe(order); step.ShouldReport.ShouldBe(shouldReport); }
private List<MethodInfo> GetAllMethodsInType(IMethodInvocationContext context, IEnumerable<AspectAttributeBase> attributes, ExecutionOrder order) { string key = string.Format("{0}:{1}:{2}", context.ProxyType.Name, context.Method.Name, order); Type attributeExecutionOrderType; switch (order) { default: case ExecutionOrder.Before: attributeExecutionOrderType = typeof(WorksBeforeAttribute); break; case ExecutionOrder.After: attributeExecutionOrderType = typeof(WorksAfterAttribute); break; case ExecutionOrder.Exception: attributeExecutionOrderType = typeof(WorksOnExceptionAttribute); break; } List<MethodInfo> methods = new List<MethodInfo>(); foreach (var attribute in attributes) { foreach (var m in attribute.GetType().GetMethods().Where(m => m.GetCustomAttributes(attributeExecutionOrderType, true).Length > 0).ToList()) { methods.Add(m); } } return methods; }
public void ExecuteInMainThread(Lambda fn, ExecutionOrder order = ExecutionOrder.Any) { if (InUnityThread()) { fn.Invoke(); return; } lock (executionChain[order]) { executionChain[order].Enqueue(fn); } while (true) { resultFlag.WaitOne(); Tuple <ReturnState, object> result = Tuple <ReturnState, object> ._(ReturnState.Pending, null); lock (executed) { if (executed.ContainsKey(fn)) { result = executed[fn]; executed.Remove(fn); } } if (result.car == ReturnState.Exception) { throw (System.Exception)result.cdr; } if (result.car == ReturnState.Done) { return; } } }
public MethodNameMatcher(Predicate<string> isMethodOfInterest, bool asserts, ExecutionOrder executionOrder, bool shouldReport) { IsMethodOfInterest = isMethodOfInterest; Asserts = asserts; ExecutionOrder = executionOrder; ShouldReport = shouldReport; }
private ExecutionOrder FixConsecutiveStep(ExecutionOrder executionOrder) { if (executionOrder == ExecutionOrder.ConsecutiveStep) { var lastStep = _steps.LastOrDefault(); if (lastStep != null) { switch (lastStep.ExecutionOrder) { case ExecutionOrder.Initialize: case ExecutionOrder.SetupState: case ExecutionOrder.ConsecutiveSetupState: return(ExecutionOrder.ConsecutiveSetupState); case ExecutionOrder.Transition: case ExecutionOrder.ConsecutiveTransition: return(ExecutionOrder.ConsecutiveTransition); case ExecutionOrder.Assertion: case ExecutionOrder.ConsecutiveAssertion: case ExecutionOrder.TearDown: return(ExecutionOrder.ConsecutiveAssertion); } } } return(executionOrder); }
public MethodNameMatcher(Predicate <string> isMethodOfInterest, ExecutionOrder executionOrder) { IsMethodOfInterest = isMethodOfInterest; ExecutionOrder = executionOrder; Asserts = false; ShouldReport = true; }
void Execute(ExecutionOrder chain) { if (executionChain[chain].Count > 0) { lock (executionChain[chain]) { //while(executionChain[chain].Count > 0) //{ Lambda fn = executionChain[chain].Dequeue(); Tuple <ReturnState, object> result; try { fn.Invoke(); result = Tuple <ReturnState, object> ._(ReturnState.Done, null); } catch (System.Exception e) { result = Tuple <ReturnState, object> ._(ReturnState.Exception, e); } lock (executed) { executed.Add(fn, result); resultFlag.Set(); } //} } } }
void VerifyStepAndItsProperties(Action stepMethodAction, ExecutionOrder expectedOrder, int expectedCount = 1) { var matchingSteps = _scenario.Steps.Where(s => s.Title.Trim() == Configurator.Scanners.Humanize(Helpers.GetMethodInfo(stepMethodAction).Name)); matchingSteps.Count().ShouldBe(expectedCount); matchingSteps.All(s => s.ExecutionOrder == expectedOrder).ShouldBe(true); }
/// <summary> /// 实例化一个新的监听信息 /// </summary> /// <param name="listenTo">监听对象</param> /// <param name="interestedAction">感兴趣的动作</param> /// <param name="interestedOrder">感兴趣的动作的当前执行顺序</param> /// <param name="excite">满足条件时候将要激发的动作</param> public MonitorInfo(Type listenTo, object interestedAction, ExecutionOrder interestedOrder , Action<InfoOfSendOnManagerService> excite) { this.ListenTo = listenTo; this.InterestedAction = interestedAction; this.InterestedOrder = interestedOrder; this.Excite = excite; }
public AbstractInitializeSubscription( IEvent @event, ExecutionOrder executionOrder ) { _event = @event; _executionOrder = executionOrder; }
public InitializeSubscription( IEvent @event, ExecutionOrder executionOrder, Action <InitializeEventArgs> handler ) : base(@event, executionOrder) { _handler = handler; }
static string PrefixWithSpaceIfRequired(string stepTitle, ExecutionOrder executionOrder) { if (executionOrder == ExecutionOrder.ConsecutiveAssertion || executionOrder == ExecutionOrder.ConsecutiveSetupState || executionOrder == ExecutionOrder.ConsecutiveTransition) { stepTitle = " " + stepTitle; // add two spaces in the front for indentation. } return(stepTitle); }
/// <summary> /// 实例化一个新的用于向信使服务传递信息的数据集(监听) /// </summary> /// <param name="db">数据库连接对象</param> /// <param name="sender">触发对象</param> /// <param name="actionName">当前执行的动作</param> /// <param name="order">相对于出发动作的操作顺序</param> /// <param name="model">当前操作的数据模型的实例</param> /// <param name="args">额外传递的信息</param> public InfoOfSendOnManagerService(IModelToDbContext db, Type sender, object actionName, ExecutionOrder order , object model, object args = null) { this.Db = db; this.Sender = sender; this.ActionName = actionName; this.Order = order; this.Model = model; this.Args = args; }
/// <summary> /// Initializes a new instance of the <see cref="ProgramRunner"/> class. /// </summary> /// <param name="lines">The program lines to run.</param> public ProgramRunner(IEnumerable <ILine> lines) { if (lines == null) { throw new ArgumentNullException("lines"); } this.lines = new List <ILine>(lines); this.runningLineIndex = BeforeFirstLine; this.isBroke = false; this.executionOrder = ExecutionOrder.LineByLine; }
private bool IterateAttributesAndReturnTrueIfCancel(IMethodInvocationContext context, IEnumerable<AspectAttributeBase> attributes, ExecutionOrder order, Exception ex = null) { List<MethodInfo> methods = GetAllMethodsInType(context, attributes, order); context.Exception = ex; bool cancelExecution = false; foreach (MethodInfo method in methods) { method.Invoke(Activator.CreateInstance(method.ReflectedType), new object[] { context }); cancelExecution = context.Cancel; } return cancelExecution; }
public void ExecuteSequence(ICollection <Lambda> t, ExecutionOrder order = ExecutionOrder.Any) { if (InUnityThread()) { throw new System.Exception("Cannot call UnityExecutionThread::ExecuteInSequence in Unity thread."); } foreach (Lambda step in t) { ExecuteInMainThread(step, order); } }
public HierarchicalEventSubscription( IEvent <TArgs> @event, Action <TArgs> handler, ExecutionOrder executionOrder, IEventCondition[] conditions, TTarget target ) : base(@event, handler, executionOrder, conditions) { Check.NotNull(target, nameof(target)); _target = target; }
public void constraints_are_executed_in_order_of_registration() { int[] expected = { 1, 2, 3, 4, 5, 6, 7 }; var obj = new ExecutionOrder(); obj.Validate(); Expect(obj.ExecutionList.Count, Is.EqualTo(expected.Length)); for (int i = 0; i < expected.Length; i++) { Expect(obj.ExecutionList[i], Is.EqualTo(expected[i])); } }
private void Assert(ExecutionOrder when, IEnumerable <IValidator> validators) { var erros = validators.Where(w => w.ExecuteWhen == when) .Where(w => !w.IsValid(this)) .Select(s => s.ErrorMessage) .ToArray(); if (!erros.Any()) { return; } throw new InvalidOperationException(erros.Aggregate((seed, value) => seed += "\n" + value)); }
/// <summary> /// Advances the <see cref="ProgramRunner"/> to the line with the specified label. /// </summary> /// <param name="labelr">The label of the line to go.</param> /// <exception cref="ArgumentOutOfRangeException">The line with the specified label is not exists.</exception> public void Goto(string label) { var lineIndex = lines.FindIndex(line => line.Label == label); if (lineIndex == -1) { var message = string.Format(ErrorMessages.LabelNotFound, label); throw new ArgumentOutOfRangeException(message); } runningLineIndex = lineIndex; executionOrder = ExecutionOrder.ArbitraryLine; }
private bool FixAsserts(bool asserts, ExecutionOrder executionOrder) { if (executionOrder == ExecutionOrder.ConsecutiveStep) { var lastStep = _steps.LastOrDefault(); if (lastStep != null) { return(lastStep.Asserts); } } return(asserts); }
public T ExecuteInMainThread <T>(Future <T> fn, ExecutionOrder order = ExecutionOrder.Any) { if (InUnityThread()) { return(fn.Invoke()); } T val = default(T); ExecuteInMainThread(() => { val = fn.Invoke(); }, order); return(val); }
public EventSubscription( IEvent <TPayload> @event, Action <TPayload> handler, ExecutionOrder executionOrder, IEventCondition[] conditions = null ) { Check.NotNull(handler, nameof(handler)); _event = @event; _handler = handler; _executionOrder = executionOrder; _conditions = conditions ?? NoConditions; }
public ExecutionStep( Action <object> stepAction, string stepTitle, bool asserts, ExecutionOrder executionOrder, bool shouldReport) { Asserts = asserts; ExecutionOrder = executionOrder; ShouldReport = shouldReport; Result = StepExecutionResult.NotExecuted; Id = Guid.NewGuid(); StepTitle = stepTitle; StepAction = stepAction; }
public Step( Action<object> action, string title, bool asserts, ExecutionOrder executionOrder, bool shouldReport) { Asserts = asserts; ExecutionOrder = executionOrder; ShouldReport = shouldReport; Result = Result.NotExecuted; Title = title; Action = action; Id = Configurator.IdGenerator.GetStepId(this); }
public Step(LambdaExpression stepAction, string stepTextTemplate, bool includeInputsInStepTitle, Func <LambdaExpression, MethodInfo> getMethodInfo, string stepPrefix, Func <string, bool, MethodInfo, StepArgument[], string, StepTitle> createTitle, Func <object, object> action, StepTitle title, bool assert, ExecutionOrder executionOrder, bool shouldReport, List <StepArgument> args) { _stepAction = stepAction; _stepTextTemplate = stepTextTemplate; _includeInputsInStepTitle = includeInputsInStepTitle; _getMethodInfo = getMethodInfo; _stepPrefix = stepPrefix; Action = action; _title = title; Asserts = assert; ExecutionOrder = executionOrder; ShouldReport = shouldReport; Arguments = args; _createTitle = createTitle; }
public IEnumerable <YieldingOperationRow> Execute(DefaultProcessContext context, IEnumerable <YieldingOperationRow> data) { Console.WriteLine("Start of first yielding operation"); ExecutionOrder.Add(ProcessEvent.OperationStart); foreach (var row in data) { Console.WriteLine("Running first yielding operation for row " + row.RowId); ExecutionOrder.Add(ProcessEvent.RowProcessed); yield return(row); } Console.WriteLine("End of first yielding operation"); ExecutionOrder.Add(ProcessEvent.OperationEnd); }
public ExecutionStep( Action<object> stepAction, string stepTitle, bool asserts, ExecutionOrder executionOrder, bool shouldReport) { Asserts = asserts; ExecutionOrder = executionOrder; ShouldReport = shouldReport; Result = StepExecutionResult.NotExecuted; Id = Guid.NewGuid(); StepTitle = stepTitle; StepAction = stepAction; }
public Step( Action <object> action, string title, bool asserts, ExecutionOrder executionOrder, bool shouldReport) { Asserts = asserts; ExecutionOrder = executionOrder; ShouldReport = shouldReport; Result = Result.NotExecuted; Title = title; Action = action; Id = Configurator.IdGenerator.GetStepId(this); }
private void AddStep(Action <TScenario> action, LambdaExpression stepAction, string stepTextTemplate, bool includeInputsInStepTitle, bool reports, ExecutionOrder executionOrder, bool asserts, string stepPrefix) { var inputArguments = new StepArgument[0]; if (includeInputsInStepTitle) { inputArguments = stepAction.ExtractArguments(_testObject).ToArray(); } var args = inputArguments.Where(s => !string.IsNullOrEmpty(s.Name)).ToList(); _steps.Add(new Step(stepAction, stepTextTemplate, includeInputsInStepTitle, GetMethodInfo, stepPrefix, _createTitle, StepActionFactory.GetStepAction(action), null, FixAsserts(asserts, executionOrder), FixConsecutiveStep(executionOrder), reports, args)); }
public Step( Action<object> action, string title, bool asserts, ExecutionOrder executionOrder, bool shouldReport) { Asserts = asserts; ExecutionOrder = executionOrder; ShouldReport = shouldReport; Result = Result.NotExecuted; Id = Guid.NewGuid(); Title = title; Action = action; }
private void SubscribeTo( TestEvent @event, TestSubscriber target, Action <TestEventArgs> handler, ExecutionOrder order ) { var sm = new EventSubscriptionManager(Aggregator); sm.Subscribe(b => { b.On(@event, target) .When(args => true) .Execute(handler, order); }); }
public static RoutineExecutionHandler Add(Routine routine, RoutineExecutionScope executionScope, ExecutionOrder executionOrder, bool prelude) { // if (prelude && !RoutineUtilities.OneStep(routine)) // return new RoutineExecutionHandler(routine, executionScope, executionOrder); var worker = executionScope == RoutineExecutionScope.Scene ? GetSceneWorker() : GetPermanentWorker(); worker.Add(routine, executionOrder); return(new RoutineExecutionHandler(routine, executionScope, executionOrder)); }
private bool IterateAttributesAndReturnTrueIfCancel(IMethodInvocationContext context, IEnumerable<AspectAttributeBase> attributes, ExecutionOrder order, Exception ex = null) { var methods = GetAllMethodsInType(context, attributes, order); context.Exception = ex; bool cancelExecution = false; foreach (var method in methods) { Delegate @delegate = DelegateUtils.GetMethod(method, context.Proxy); @delegate.DynamicInvoke(new object[] {context}); // method.Invoke(Activator.CreateInstance(method.ReflectedType), new object[] { context }); cancelExecution = context.Cancel; } return cancelExecution; }
public void BeforeScenario() { ExecutionOrder executionOrder = new ExecutionOrder(); context.Set(executionOrder); Log.Logger = new DelegateLogger(AddToExecutionOrder); void AddToExecutionOrder(LogEventLevel level, Exception exception, string messageTemplate, object[] propertyValues) { if (level == LogEventLevel.Verbose && propertyValues.OfType <AgentLog>().Count() == 1) { executionOrder.Add(propertyValues.OfType <AgentLog>().Single()); } } }
public Step( Func <object, object> action, StepTitle title, bool asserts, ExecutionOrder executionOrder, bool shouldReport, List <StepArgument> arguments) { Id = Configurator.IdGenerator.GetStepId(); Asserts = asserts; ExecutionOrder = executionOrder; ShouldReport = shouldReport; Result = Result.NotExecuted; Action = action; Arguments = arguments; _title = title; }
public Step( Action<object> action, StepTitle title, bool asserts, ExecutionOrder executionOrder, bool shouldReport, List<StepArgument> arguments) { Id = Configurator.IdGenerator.GetStepId(); Asserts = asserts; ExecutionOrder = executionOrder; ShouldReport = shouldReport; Result = Result.NotExecuted; Action = action; Arguments = arguments; _title = title; }
private void Mutate(ref ExecutionOrder eo) { int tmp, r1, r2; for (int i = 0; i < CMUTATIONS; i++) { r1 = rnd.Next(eo.Count); r2 = rnd.Next(eo.Count); tmp = eo[r1]; eo[r1] = eo[r2]; eo[r2] = tmp; } }
void VerifyStepAndItsProperties(Action stepMethodAction, ExecutionOrder expectedOrder, int expectedCount = 1) { var matchingSteps = _scenario.Steps.Where(s => s.StepTitle.Trim() == Configurator.Scanners.Humanize(Helpers.GetMethodInfo(stepMethodAction).Name)); Assert.That(matchingSteps.Count(), Is.EqualTo(expectedCount)); Assert.IsTrue(matchingSteps.All(s => s.ExecutionOrder == expectedOrder)); }
public ExecutableAttribute(ExecutionOrder order, string stepTitle) { ExecutionOrder = order; StepTitle = stepTitle; ShouldReport = true; }
public ExecutableAttribute(ExecutionOrder order, string stepTitle) { ExecutionOrder = order; StepTitle = stepTitle; }
/// <summary> /// 标记该方法将注册到信使服务的监听池 /// </summary> /// <param name="listenTo">监听对象</param> /// <param name="interestedAction">感兴趣的动作</param> /// <param name="interestedOrder">感兴趣的动作的当前执行顺序</param> public ListenAttribute(Type listenTo, object interestedAction, ExecutionOrder interestedOrder) { this.ListenTo = listenTo; this.InterestedAction = interestedAction; this.InterestedOrder = interestedOrder; }
void VerifyStepAndItsProperties(Expression<Action> stepMethodAction, ExecutionOrder expectedOrder, int expectedCount = 1) { var matchingSteps = _scenario.Steps.Where(s => s.Title.Trim() == Configurator.Scanners.Humanize(Helpers.GetMethodInfo(stepMethodAction).Name)); matchingSteps.Count().ShouldBe(expectedCount); matchingSteps.All(s => s.ExecutionOrder == expectedOrder).ShouldBe(true); }
/// <summary> Initialize the scheduler to execute the given query </summary> /// <param name="breakOut">Should the query operators run in their own thread?</param> /// <param name="qs">The query plans to execute</param> public override IResults[] Init(bool breakOut, params Query[] qs) { rnd = new Random(9); IResults[] res = base.Init(breakOut, qs); pool.Init(ots, NextOperatorGenetic); //Note, pool.Length is a bit expensive. Caching its value // may speed things up. //TODO: Should really improve speed of pool.Length int cOp = pool.Length; //First, find the leaf nodes in the query for (int i = 0; i < cOp; i++) { if (pool[i].QueryOperator is IStreamDataSource) { leafNodes.Add((IStreamDataSource)pool[i].QueryOperator); dataCounts.Add(0); } } //Now, make up a population with the existing operators for (int p = 0; p < POPULATION; p++) { orders[p] = new ExecutionOrder(); for (int i = 0; i < cOp; i++) orders[p].Add(i); //Add p duplicates to the population for (int iDup = 0; iDup < p; iDup++) orders[p].Add(rnd.Next(cOp-1)); Mutate(ref orders[p]); } Console.Write("Order: "); for (int i = 0; i < orders[iOrder].Count; i++) Console.Write("{0}, ", orders[iOrder][i]); Console.WriteLine(); return res; }
public MethodNameMatcher(Predicate<string> isMethodOfInterest, bool asserts, ExecutionOrder executionOrder, bool shouldReport) : this(isMethodOfInterest, executionOrder) { Asserts = asserts; ShouldReport = shouldReport; }
static string PrefixWithSpaceIfRequired(string stepTitle, ExecutionOrder executionOrder) { if (executionOrder == ExecutionOrder.ConsecutiveAssertion || executionOrder == ExecutionOrder.ConsecutiveSetupState || executionOrder == ExecutionOrder.ConsecutiveTransition) stepTitle = " " + stepTitle; // add two spaces in the front for indentation. return stepTitle; }