Esempio n. 1
0
 protected override decimal CalculateLevy(ExecuteContext context)
 {
     return(0m);
 }
Esempio n. 2
0
 protected override decimal CalculateLevy(ExecuteContext context)
 {
     return(this.CalculateHelper(FeeType.Levy));
 }
Esempio n. 3
0
 protected abstract IFees GetResult(ExecuteContext context);
Esempio n. 4
0
 private void UpdateCloseOrder(PhysicalOrderRelation orderRelation, ExecuteContext context)
 {
     _physicalOrder.PaidPledgeBalance += orderRelation.PayBackPledgeOfCloseOrder;
     _physicalOrder.AddBill(new Bill(_physicalOrder.AccountId, _physicalOrder.CurrencyId, orderRelation.PayBackPledgeOfOpenOrder, BillType.PayBackPledge, BillOwnerType.Order, context.ExecuteTime ?? DateTime.Now));
 }
Esempio n. 5
0
        internal Tuple <Settings.Instrument, Settings.Account, Settings.TradePolicyDetail, Settings.SpecialTradePolicyDetail, Settings.CurrencyRate> GetHistorySettings(ExecuteContext context)
        {
            var instrument               = this.Tran.SettingInstrument(context.TradeDay);
            var account                  = this.Tran.Owner.Setting(context.TradeDay);
            var tradePolicyDetail        = this.Tran.TradePolicyDetail(context.TradeDay);
            var specialTradePolicyDetail = this.Tran.SpecialTradePolicyDetail(context.TradeDay);
            var currencyRate             = this.Tran.CurrencyRate(context.TradeDay);

            return(Tuple.Create(instrument, account, tradePolicyDetail, specialTradePolicyDetail, currencyRate));
        }
 public override void ExplicitVisit(ExecuteContext fragment)
 {
     _fragments.Add(fragment);
 }
Esempio n. 7
0
        internal bool IsInValueDate(Guid accountId, ExecuteContext context)
        {
            var tradeDay = Setting.Default.GetTradeDay(context.TradeDay);

            return(this.ValueDate < tradeDay.Day);
        }
Esempio n. 8
0
 protected ExecuteContextProxy(ExecuteContext <TArguments> context)
     : base(context)
 {
     _context   = context;
     _arguments = context.Arguments;
 }
Esempio n. 9
0
        private void ScheduleBuildStep(BuilderContext builderContext, BuildStep instigator, BuildStep buildStep, IDictionary <string, string> variables)
        {
            if (buildStep.ExecutionId == 0)
            {
                if (buildStep.Parent != null && buildStep.Parent != instigator)
                {
                    throw new InvalidOperationException("Scheduling a BuildStep with a different instigator that its parent");
                }
                if (buildStep.Parent == null)
                {
                    buildStep.Parent = instigator;
                }

                // Compute content dependencies before scheduling the build
                GenerateDependencies(buildStep);

                // TODO: Big review of the log infrastructure of CompilerApp & BuildEngine!
                // Create a logger that redirects to various places (BuildStep.Logger, timestampped log, global log, etc...)
                var buildStepLogger = new BuildStepLogger(buildStep, Logger, startTime);
                var logger          = (Logger)buildStepLogger;
                // Apply user-registered callbacks to the logger
                buildStep.TransformExecuteContextLogger?.Invoke(ref logger);

                // Create execute context
                var executeContext = new ExecuteContext(this, builderContext, buildStep, logger)
                {
                    Variables = new Dictionary <string, string>(variables)
                };
                //buildStep.ExpandStrings(executeContext);

                if (runMode == Mode.Build)
                {
                    MicroThread microThread = scheduler.Create();

                    // Set priority from this build step, if we have one.
                    if (buildStep.Priority.HasValue)
                    {
                        microThread.Priority = buildStep.Priority.Value;
                    }

                    buildStep.ExecutionId = microThread.Id;

                    foreach (var threadMonitor in currentThreadMonitors)
                    {
                        threadMonitor.RegisterBuildStep(buildStep, buildStepLogger.StepLogger);
                    }

                    microThread.Name = buildStep.ToString();

                    // Default:
                    // Schedule continuations as early as possible to help EnumerableBuildStep finish when all its task are finished.
                    // Otherwise, it would wait for all leaf to finish first before finishing parent EnumerableBuildStep.
                    // This should also reduce memory usage, and might improve cache coherency as well.
                    microThread.ScheduleMode = ScheduleMode.First;

                    microThread.Start(async() =>
                    {
                        // Wait for prerequisites
                        await Task.WhenAll(buildStep.PrerequisiteSteps.Select(x => x.ExecutedAsync()).ToArray());

                        // Check for failed prerequisites
                        var status = ResultStatus.NotProcessed;

                        if (buildStep.ArePrerequisitesSuccessful)
                        {
                            try
                            {
                                var outputObjectsGroups = executeContext.GetOutputObjectsGroups();
                                MicrothreadLocalDatabases.MountDatabase(outputObjectsGroups);

                                // Execute
                                status = await buildStep.Execute(executeContext, builderContext);
                            }
                            catch (TaskCanceledException e)
                            {
                                // Benlitz: I'm NOT SURE this is the correct explanation, it might be a more subtle race condition, but I can't manage to reproduce it again
                                executeContext.Logger.Warning("A child task of build step " + buildStep + " triggered a TaskCanceledException that was not caught by the parent task. The command has not handled cancellation gracefully.");
                                executeContext.Logger.Warning(e.Message);
                                status = ResultStatus.Cancelled;
                            }
                            catch (Exception e)
                            {
                                executeContext.Logger.Error("Exception in command " + buildStep + ": " + e);
                                status = ResultStatus.Failed;
                            }
                            finally
                            {
                                MicrothreadLocalDatabases.UnmountDatabase();

                                // Ensure the command set at least the result status
                                if (status == ResultStatus.NotProcessed)
                                {
                                    throw new InvalidDataException("The build step " + buildStep + " returned ResultStatus.NotProcessed after completion.");
                                }
                            }
                            if (microThread.Exception != null)
                            {
                                executeContext.Logger.Error("Exception in command " + buildStep + ": " + microThread.Exception);
                                status = ResultStatus.Failed;
                            }
                        }
                        else
                        {
                            status = ResultStatus.NotTriggeredPrerequisiteFailed;
                        }

                        //if (completedTask.IsCanceled)
                        //{
                        //    completedStep.Status = ResultStatus.Cancelled;
                        //}
                        var logType    = LogMessageType.Info;
                        string logText = null;

                        switch (status)
                        {
                        case ResultStatus.Successful:
                            logType = LogMessageType.Verbose;
                            logText = "BuildStep {0} was successful.".ToFormat(buildStep.ToString());
                            break;

                        case ResultStatus.Failed:
                            logType = LogMessageType.Error;
                            logText = "BuildStep {0} failed.".ToFormat(buildStep.ToString());
                            break;

                        case ResultStatus.NotTriggeredPrerequisiteFailed:
                            logType = LogMessageType.Error;
                            logText = "BuildStep {0} failed of previous failed prerequisites.".ToFormat(buildStep.ToString());
                            break;

                        case ResultStatus.Cancelled:
                            logType = LogMessageType.Warning;
                            logText = "BuildStep {0} cancelled.".ToFormat(buildStep.ToString());
                            break;

                        case ResultStatus.NotTriggeredWasSuccessful:
                            logType = LogMessageType.Verbose;
                            logText = "BuildStep {0} is up-to-date and has been skipped".ToFormat(buildStep.ToString());
                            break;

                        case ResultStatus.NotProcessed:
                            throw new InvalidDataException("BuildStep has neither succeeded, failed, nor been cancelled");
                        }
                        if (logText != null)
                        {
                            var logMessage = new LogMessage(null, logType, logText);
                            executeContext.Logger.Log(logMessage);
                        }

                        buildStep.RegisterResult(executeContext, status);
                        stepCounter.AddStepResult(status);
                    });
                }
                else
                {
                    buildStep.Clean(executeContext, builderContext, runMode == Mode.CleanAndDelete);
                }
            }
        }
Esempio n. 10
0
        public async Task <ExecutionResult> Execute(ExecuteContext <AddressArguments> context)
        {
            Console.WriteLine("Address: {0}", context.Arguments.Address);

            return(context.Completed(new Log(context.Arguments.Address)));
        }
Esempio n. 11
0
 public ExecuteContextProxy(ExecuteContext <TArguments> context, TArguments arguments)
     : base(context)
 {
     _context   = context;
     _arguments = arguments;
 }
Esempio n. 12
0
 public override ExecState ExecuteImmediate(ExecuteContext context)
 {
     context.Execute($"Result.res = {{Url:'{Url}', Method: '{Method}', Body:'{Body}' }}");
     return(ExecuteNext(context));
 }
 public async Task <ExecutionResult> Execute(ExecuteContext <TestArguments> context)
 {
     return(context.CompletedWithVariables(new { ToBeRemoved = (string)null }));
 }
Esempio n. 14
0
 public override void Visit(ExecuteContext node) { this.action(node); }
Esempio n. 15
0
 protected override IFees DoCalculate(ExecuteContext context)
 {
     return(new OrderFees(this.CalculateCommission(context), this.CalculateLevy(context), this.CalculateOtherFee(context)));
 }
Esempio n. 16
0
 protected override FunctionResult OnExecute(ExecuteContext context)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
 protected abstract decimal CalculateCommission(ExecuteContext context);
Esempio n. 18
0
 public void Run(ExecuteContext context, TextWriter writer)
 {
     throw new NotImplementedException();
 }
Esempio n. 19
0
 protected override bool ShouldDoValue(OrderRelation orderRelation, ExecuteContext context)
 {
     return(base.ShouldDoValue(orderRelation, context) && this.IsInValueDate(context));
 }
Esempio n. 20
0
 public abstract Task <ExecutionResult> Execute(ExecuteContext <TArguments> context);
Esempio n. 21
0
        protected override void UpdateOpenOrder(OrderRelation orderRelation, bool isLast, ExecuteContext context)
        {
            var physicalOrderRelation = orderRelation as PhysicalOrderRelation;
            var openOrder             = orderRelation.OpenOrder as PhysicalOrder;

            physicalOrderRelation.IsFullPayment = openOrder.IsPayoff;
            this.CalculateOrderRelaiton(physicalOrderRelation, isLast, context);
            this.UpdateForOpenOrder(physicalOrderRelation, openOrder);
            this.UpdateCloseOrder(physicalOrderRelation, context);
        }
        public void TestChangeContextByWindowHandle()
        {
            //フォームの取得
            WindowControl targetForm = WindowControl.FromZTop(app);

            //別スレッドウィンドウを表示
            WindowControl _buttonOtherThread = targetForm.IdentifyFromZIndex(0);
            _buttonOtherThread["PerformClick"]();

            //表示待ち
            IntPtr nextHandle = IntPtr.Zero;
            while (nextHandle == IntPtr.Zero)
            {
                EnumWindowsDelegate callBack = delegate(IntPtr hWnd, int lParam)
                {
                    int lpdwProcessId;
                    GetWindowThreadProcessId(hWnd, out lpdwProcessId);
                    if (lpdwProcessId != app.ProcessId)
                    {
                        return 1;
                    }

                    StringBuilder lpString = new StringBuilder(1000);
                    GetWindowText(hWnd, lpString, 1000);
                    if (lpString.ToString() == "NormalGuiForm")
                    {
                        nextHandle = hWnd;
                        return 0;
                    }
                    return 1;
                };
                EnumWindows(callBack, 0);
                GC.KeepAlive(callBack);
            }

            //実行コンテキストを変更
            using (ExecuteContext context = new ExecuteContext(app, nextHandle))
            {
                ExecuteContext oldContext = app.ChangeContext(context);

                //ウィンドウコントロール生成
                WindowControl next = new WindowControl(app, nextHandle);

                //別スレッドウィンドウを操作
                AppVar _textBoxSrc = next["_textBoxSrc"]();
                _textBoxSrc["Text"]("xxx");
                AppVar _buttonCopyText = next["_buttonCopyText"]();
                _buttonCopyText["PerformClick"]();
                AppVar _textBoxDst = next["_textBoxDst"]();
                //操作の結果_textBoxDstにxxxが入力される
                Assert.AreEqual(_textBoxDst["Text"]().ToString(), "xxx");
                try
                {
                    next["Close"]();
                }
                catch (FriendlyOperationException) { }//スレッドが終了してしまうので、通信途中で通信不能となる これは仕様

                //コンテキストをもとに戻す
                app.ChangeContext(oldContext);
            }
            //ウィンドウを操作しても例外が発生しない
            targetForm["Handle"]();
            targetForm["Text"]("xxx");
        }
Esempio n. 23
0
 private void CalculateOrderRelaiton(PhysicalOrderRelation orderRelation, bool isLast, ExecuteContext context)
 {
     orderRelation.CalculateClosedPhysicalValue(context.TradeDay);
     orderRelation.CalculatePayBackPledge(isLast, context);
 }
        public void TestChangeContextByWindowObject()
        {
            //フォームの取得
            WindowControl targetForm = WindowControl.FromZTop(app);

            //別スレッドウィンドウを表示
            WindowControl _buttonOtherThread = targetForm.IdentifyFromZIndex(0);
            _buttonOtherThread["PerformClick"]();

            //表示待ち
            AppVar next = null;
            while (next == null)
            {
                Thread.Sleep(10);
                AppVar all = app["System.Windows.Forms.Application.OpenForms"]();
                foreach (AppVar element in new Enumerate(all))
                {
                    if (!(bool)targetForm.AppVar["Equals"](element).Core)
                    {
                        next = element;
                        break;
                    }
                }
            }

            //実行コンテキストを変更
            using (ExecuteContext context = new ExecuteContext(app, next))
            {
                ExecuteContext oldContext = app.ChangeContext(context);
                AppVar _textBoxSrc = next["_textBoxSrc"]();
                _textBoxSrc["Text"]("xxx");
                AppVar _buttonCopyText = next["_buttonCopyText"]();
                _buttonCopyText["PerformClick"]();
                AppVar _textBoxDst = next["_textBoxDst"]();
                //操作の結果_textBoxDstにxxxが入力される
                Assert.AreEqual(_textBoxDst["Text"]().ToString(), "xxx");
                try
                {
                    next["Close"]();
                }
                catch (FriendlyOperationException) { }//スレッドが終了してしまうので、通信途中で通信不能となる これは仕様

                //コンテキストをもとに戻す
                app.ChangeContext(oldContext);
            }
            //ウィンドウを操作しても例外が発生しない
            targetForm["Handle"]();
            targetForm["Text"]("xxx");
        }
Esempio n. 25
0
 protected override decimal CalculateCommission(ExecuteContext context)
 {
     return(this.CalculateHelper(FeeType.Commission));
 }
        public void TestInvalidContext()
        {
            WindowsAppFriend app2 = null;
            if (IntPtr.Size == 4)
            {
                app2 = new WindowsAppFriend(Process.Start(TargetPath.Path32), "2.0");
            }
            else
            {
                app2 = new WindowsAppFriend(Process.Start(TargetPath.Path64), "2.0");
            }

            try
            {
                WindowControl targetForm = WindowControl.FromZTop(app2);
                //実行コンテキストを変更
                ExecuteContext context = new ExecuteContext(app2, targetForm.AppVar);
                app2.ChangeContext(context);
                //破棄
                context.Dispose();

                //通信に失敗すること
                try
                {
                    app2.Dim();
                    Assert.IsTrue(false);
                }
                catch (FriendlyOperationException e)
                {
                    string message = "アプリケーションとの通信に失敗しました。" + Environment.NewLine +
                                        "対象アプリケーションが通信不能な状態になったか、" + Environment.NewLine +
                                        "シリアライズ不可能な型のデータを転送しようとした可能性があります。";
                    Assert.AreEqual(e.Message, message);
                }
            }
            finally
            {
                Process.GetProcessById(app2.ProcessId).CloseMainWindow();
            }
        }
Esempio n. 27
0
 protected override decimal CalculateOtherFee(ExecuteContext context)
 {
     return(this.CalculateHelper(FeeType.OtherFee));
 }
Esempio n. 28
0
        internal static CurrencyRate GetCGSELevyCurrencyRate(Settings.Account account, Settings.Instrument instrument, SpecialTradePolicyDetail specialTradePolicyDetail, CurrencyRate defaultCurrencyRate, ExecuteContext context)
        {
            if (specialTradePolicyDetail.CGSELevyCurrecyType == CGSELevyCurrecyType.UseInstrumentCurrencyType)
            {
                return(defaultCurrencyRate);
            }
            else
            {
                Guid sourceCurrencyId = account.CurrencyId;
                Guid targetCurrencyId = account.IsMultiCurrency ? instrument.CurrencyId : account.CurrencyId;

                return(context != null && context.ShouldUseHistorySettings ? Settings.Setting.Default.GetCurrencyRate(sourceCurrencyId, targetCurrencyId, context.TradeDay)
                                                                            : Settings.Setting.Default.GetCurrencyRate(sourceCurrencyId, targetCurrencyId));
            }
        }
Esempio n. 29
0
        internal decimal CalculateInstalmentAdministrationFee(ExecuteContext context)
        {
            var phsyicalOrder = _order as PhysicalOrder;

            return(phsyicalOrder.CalculateInstalmentAdministrationFee(context));
        }
Esempio n. 30
0
 protected CompletedExecutionResult(ExecuteContext <TArguments> context, IRoutingSlipEventPublisher publisher, Activity activity,
                                    RoutingSlip routingSlip)
     : this(context, publisher, activity, routingSlip, RoutingSlipBuilder.NoArguments)
 {
 }
Esempio n. 31
0
 protected override decimal CalculateOtherFee(ExecuteContext context)
 {
     return(0m);
 }
Esempio n. 32
0
 protected virtual bool ShouldDoValue(OrderRelation orderRelation, ExecuteContext context)
 {
     return(!orderRelation.IsValued);
 }
Esempio n. 33
0
 protected abstract IFees DoCalculate(ExecuteContext context);
Esempio n. 34
0
 protected bool IsInValueDate(ExecuteContext context)
 {
     return(_order.Owner.SettingInstrument(context.TradeDay).IsInValueDate(_order.Owner.Owner.Id, context));
 }
Esempio n. 35
0
 protected abstract decimal CalculateLevy(ExecuteContext context);
Esempio n. 36
0
        private void ScheduleBuildStep(BuilderContext builderContext, BuildStep instigator, BuildStep buildStep, IDictionary<string, string> variables)
        {
            if (buildStep.ExecutionId == 0)
            {
                if (buildStep.Parent != null && buildStep.Parent != instigator)
                    throw new InvalidOperationException("Scheduling a BuildStep with a different instigator that its parent");
                if (buildStep.Parent == null)
                {
                    buildStep.Parent = instigator;
                }

                // Compute content dependencies before scheduling the build
                GenerateDependencies(buildStep);

                var executeContext = new ExecuteContext(this, builderContext, buildStep) { Variables = new Dictionary<string, string>(variables) };
                //buildStep.ExpandStrings(executeContext);

                if (runMode == Mode.Build)
                {
                    MicroThread microThread = scheduler.Create();

                    // Find priority from this build step, or one of its parent.
                    var buildStepPriority = buildStep;
                    while (buildStepPriority != null)
                    {
                        if (buildStepPriority.Priority.HasValue)
                        {
                            microThread.Priority = buildStepPriority.Priority.Value;
                            break;
                        }

                        buildStepPriority = buildStepPriority.Parent;
                    }

                    buildStep.ExecutionId = microThread.Id;

                    foreach (var threadMonitor in threadMonitors)
                    {
                        threadMonitor.RegisterBuildStep(buildStep, ((BuildStepLogger)executeContext.Logger).StepLogger);
                    }

                    microThread.Name = buildStep.ToString();

                    // Default:
                    // Schedule continuations as early as possible to help EnumerableBuildStep finish when all its task are finished.
                    // Otherwise, it would wait for all leaf to finish first before finishing parent EnumerableBuildStep.
                    // This should also reduce memory usage, and might improve cache coherency as well.
                    microThread.ScheduleMode = ScheduleMode.First;

                    microThread.Start(async () =>
                    {
                        // Wait for prerequisites
                        await Task.WhenAll(buildStep.PrerequisiteSteps.Select(x => x.ExecutedAsync()).ToArray());

                        // Check for failed prerequisites
                        var status = ResultStatus.NotProcessed;

                        if (buildStep.ArePrerequisitesSuccessful)
                        {
                            try
                            {
                                IndexFileCommand.MountDatabase(executeContext.GetOutputObjectsGroups());

                                // Execute
                                status = await buildStep.Execute(executeContext, builderContext);
                            }
                            catch (TaskCanceledException e)
                            {
                                // Benlitz: I'm NOT SURE this is the correct explanation, it might be a more subtle race condition, but I can't manage to reproduce it again
                                executeContext.Logger.Warning("A child task of build step " + buildStep + " triggered a TaskCanceledException that was not caught by the parent task. The command has not handled cancellation gracefully.");
                                executeContext.Logger.Warning(e.Message);
                                status = ResultStatus.Cancelled;
                            }
                            catch (Exception e)
                            {
                                executeContext.Logger.Error("Exception in command " + buildStep + ": " + e);
                                status = ResultStatus.Failed;
                            }
                            finally
                            {
                                IndexFileCommand.UnmountDatabase();
                                
                                // Ensure the command set at least the result status
                                if (status == ResultStatus.NotProcessed)
                                    throw new InvalidDataException("The build step " + buildStep + " returned ResultStatus.NotProcessed after completion.");
                            }
                            if (microThread.Exception != null)
                            {
                                executeContext.Logger.Error("Exception in command " + buildStep + ": " + microThread.Exception);
                                status = ResultStatus.Failed;
                            }
                        }
                        else
                        {
                            status = ResultStatus.NotTriggeredPrerequisiteFailed;
                        }

                        //if (completedTask.IsCanceled)
                        //{
                        //    completedStep.Status = ResultStatus.Cancelled;
                        //}
                        var logType = LogMessageType.Info;
                        string logText = null;
                        
                        switch (status)
                        {
                            case ResultStatus.Successful:
                                logType = LogMessageType.Verbose;
                                logText = "BuildStep {0} was successful.".ToFormat(buildStep.ToString());
                                break;
                            case ResultStatus.Failed:
                                logType = LogMessageType.Error;
                                logText = "BuildStep {0} failed.".ToFormat(buildStep.ToString());
                                break;
                            case ResultStatus.NotTriggeredPrerequisiteFailed:
                                logType = LogMessageType.Error;
                                logText = "BuildStep {0} failed of previous failed prerequisites.".ToFormat(buildStep.ToString());
                                break;
                            case ResultStatus.Cancelled:
                                logType = LogMessageType.Warning;
                                logText = "BuildStep {0} cancelled.".ToFormat(buildStep.ToString());
                                break;
                            case ResultStatus.NotTriggeredWasSuccessful:
                                logType = LogMessageType.Verbose;
                                logText = "BuildStep {0} is up-to-date and has been skipped".ToFormat(buildStep.ToString());
                                break;
                            case ResultStatus.NotProcessed:
                                throw new InvalidDataException("BuildStep has neither succeeded, failed, nor been cancelled");
                        }
                        if (logText != null)
                        {
                            var logMessage = new LogMessage(buildStep.Module, logType, logText);
                            Logger.Log(logMessage);
                        }

                        buildStep.RegisterResult(executeContext, status);
                        stepCounter.AddStepResult(status);
                    });
                }
                else
                {
                    buildStep.Clean(executeContext, builderContext, runMode == Mode.CleanAndDelete);
                }
            }
        }