void HandleMessage(string msg, dynamic args, Request request) { LogDebug("(in) " + request.type + " " + msg); LogVerbose("... " + JsonConvert.SerializeObject(request)); args = args ?? new { }; try { switch (msg) { case "initialize": var cap = new Capabilities(); InitializeEvent?.Invoke(request, cap); Send(request, cap); Initialized(); break; case "configurationDone": ConfigurationDoneEvent?.Invoke(request); break; case "launch": LaunchEvent?.Invoke(request, JsonConvert.SerializeObject(args)); break; case "attach": AttachEvent?.Invoke(request, JsonConvert.SerializeObject(args)); break; case "disconnect": DisconnectEvent?.Invoke(request); break; case "next": StepOverEvent?.Invoke(request); break; case "continue": ContinueEvent?.Invoke(request); break; case "stepIn": StepInEvent?.Invoke(request); break; case "stepOut": StepOutEvent?.Invoke(request); break; case "pause": PauseEvent?.Invoke(request); break; case "threads": GetThreadsEvent?.Invoke(request); break; case "scopes": GetScopesEvent?.Invoke(request, (int)args.frameId); break; case "stackTrace": GetStackTraceEvent?.Invoke(request); break; case "variables": _tempVariables.Clear(); GetVariablesEvent?.Invoke(request, (int)args.variablesReference, _tempVariables); Send(request, new VariablesResponseBody(_tempVariables)); break; case "setVariable": var variable = new Variable((string)args.name, (string)args.value, "", (int)args.variablesReference); SetVariableEvent?.Invoke( request, variable ); Send( request, new SetVariableResponseBody(variable.value, variable.variablesReference) ); break; case "loadedSources": GetLoadedSourcesEvent?.Invoke(request); break; case "source": GetSourceEvent?.Invoke(request); break; case "evaluate": string resultEval = ""; EvaluateEvent?.Invoke( request, (int)args.frameId, (string)args.context, (string)args.expression, (bool)(args.format?.hex ?? false), ref resultEval ); Send( request, new EvaluateResponseBody( resultEval ) ); break; case "completions": GetCompletionsEvent?.Invoke( request, (int)args.frameId, (int)args.line, (int)args.column, (string )args.text ); break; case "setBreakpoints": SetBreakpointsEvent?.Invoke(request); break; // case "runInTerminal": // OnRunInTerminal?.Invoke( pRequest ); // break; // case "setFunctionBreakpoints": // SetFunctionBreakpoints( pResponse, pArgs ); // break; // case "setExceptionBreakpoints": // SetExceptionBreakpoints( pResponse, pArgs ); // break; default: CustomRequestEvent?.Invoke(request); if (!request.responded) { Log( Logging.Severity.Error, string.Format("Request not handled: '{0}' [{1}]", msg, Convert.Encode(request.arguments.ToString())) ); } break; } } catch (Exception e) { Log( Logging.Severity.Error, $"Error during request '{Convert.Encode( request.arguments.ToString() )}' [{msg}] (exception: {e.Message})\n{e}" ); Send(new Response(request, errorMsg: e.Message)); } }
static public void ApplyTerm(bool isFull, Trade trade, SimpleDate tradeDate, SimpleDate effectiveDate, string party, double fee, Market market, StringBuilder sb) { CleanUpFees(trade); trade.Product.ClearFlows(); var tradeTime = tradeDate.ToDateTime(); //tradeTime = tradeTime.AddSeconds(count); var settleDate = effectiveDate; var stepOutPartyId = GetPartyIdFromCode(party); bool isStepout = stepOutPartyId > 0 && stepOutPartyId != trade.PartyId; if (isFull) { TerminationEvent pevent; if (isStepout) { pevent = new StepOutEvent(trade); (pevent as StepOutEvent).InitialParty = trade.PartyId; (pevent as StepOutEvent).TargetParty = GetPartyIdFromCode(party); pevent.FullCalculationPeriod = true; } else { pevent = new TerminationEvent(trade); } pevent.TradeTime = tradeTime; // pevent.Price = price; // pevent.PriceType = QuotationType.CleanPrice; pevent.EffectiveDate = settleDate; pevent.AmountCurrency = trade.Product.Currency; pevent.Amount = fee; pevent.InterestPaymentDate = settleDate; //Termination Regular var handler = (TerminationProductEventHandler)ProductEvent.Handler(pevent.EventType, trade.Product.ProcessingType); var newTrades = new List<Trade>(); var modifiedTrades = new List<Trade>(); double accrual = 0; try { accrual = handler.ComputeAccrual(trade, tradeTime, pevent.EffectiveDate, market, pevent.FXRate); } catch (Exception ac) { sb.Append("*** Error computing Acrual for " + trade.Product.GetType().Name + " " + ac.Message + "\n"); } pevent.Accrual = accrual; handler.Process(pevent, market, trade, newTrades, modifiedTrades, new List<IProductEvent>()); if (trade.Fees != null) { foreach (Fee f in trade.Fees) { if (f.Date != pevent.EffectiveDate) continue; if (f.FeeType != FeeType.AccrualOffset) f.InputAmount = accrual + pevent.Amount; } } trade.Status = "Terminated"; } else { //Partial PartialTerminationEvent pevent; var termamount = fee; if (isStepout) { pevent = new PartialStepOutEvent(trade); (pevent as PartialStepOutEvent).InitialParty = trade.PartyId; (pevent as PartialStepOutEvent).TargetParty = GetPartyIdFromCode(party); pevent.FullCalculationPeriod = true; pevent.PreviousNotional = Math.Abs(trade.Product.CurrentNominal(trade.Product.ContractMaturity, tradeTime.AddSeconds(-1), false)); pevent.CurrentNotional = pevent.PreviousNotional - Math.Abs(termamount); } else { pevent = new PartialTerminationEvent(trade) { FullCalculationPeriod = true, PreviousNotional = Math.Abs(trade.Product.CurrentNominal(trade.Product.ContractMaturity, tradeTime.AddSeconds(-1), false)) }; pevent.CurrentNotional = pevent.PreviousNotional - Math.Abs(termamount); } pevent.EffectiveDate = settleDate; pevent.TradeTime = tradeTime; // pevent.Price = price; // pevent.PriceType = QuotationType.CleanPrice; pevent.EffectiveDate = settleDate; pevent.AmountCurrency = trade.SettleCurrency; // pevent.Amount = -termamount * (pevent.Price - 1); pevent.InterestPaymentDate = settleDate; //Termination Regular var handler = (PartialTerminationProductEventHandler)ProductEvent.Handler(pevent.EventType, trade.Product.ProcessingType); var newTrades = new List<Trade>(); var modifiedTrades = new List<Trade>(); double accrual = 0; try { accrual = handler.ComputeAccrual(trade, tradeTime, pevent.EffectiveDate, market, pevent.PreviousNotional, pevent.CurrentNotional, true, pevent.FXRate); } catch (Exception ac) { sb.Append("*** Error computing Acrual for " + trade.Product.GetType().Name + " " + ac.Message + "\n"); } pevent.Accrual = accrual; handler.Process(pevent, market, trade, newTrades, modifiedTrades, new List<IProductEvent>()); if (trade.Fees != null) { foreach (Fee f in trade.Fees) { if (f.Date == pevent.EffectiveDate && f.FeeType != FeeType.AccrualOffset) f.InputAmount = accrual + pevent.Amount; } } } }