private void Form1Load(object sender, EventArgs e) { _loggerRef = Reference <ILogger> .Create(new TextBoxLogger(txtLog)); // init controls pnlRuntimeState.BackColor = CoreHelper.CoreStateColor(CoreStateEnum.Initial); pnlRuntimeState.Text = Resources.CoreViewerForm_Form1Load__unknown_; foreach (EnvId env in Enum.GetValues(typeof(EnvId))) { if ((env != EnvId.Undefined) && (env <= BuildEnv)) { cbEnvId.Items.Add(EnvHelper.EnvName(env)); } } cbEnvId.SelectedIndex = ((int)BuildEnv - 1); // - form title WinFormHelper.SetAppFormTitle(this, BuildConst.BuildEnv); // known data types cbDataTypeValues.Items.Clear(); cbDataTypeValues.Sorted = true; cbDataTypeValues.Items.Add(typeof(Instrument).FullName); cbDataTypeValues.Items.Add(typeof(Market).FullName); cbDataTypeValues.Items.Add(typeof(QuotedAssetSet).FullName); cbDataTypeValues.Items.Add(typeof(Trade).FullName); cbDataTypeValues.Items.Add(typeof(ValuationReport).FullName); cbDataTypeValues.Items.Add(typeof(AppCfgRuleV2).FullName); cbDataTypeValues.SelectedIndex = 0; // connect StartUp(); }
private void SendAlertSignalEmail(InternalSignal signal, NamedValueSet props) { try { var smtpHost = props.GetValue <string>(AlertRule.MailHost); IEnumerable <string> recipients = ResolveMultipleEmailAddresses(props.GetArray <string>(AlertRule.MailTo)); string sender = ResolveSingleEmailAddress(props.GetValue <string>(AlertRule.MailFrom)); var email = new MailMessage(); string instanceMsg = GetInstanceMsg(signal.ReminderCount); signal.ReminderCount += 1; email.Subject = $"QDS Alert {EnvHelper.EnvName(IntClient.Target.ClientInfo.ConfigEnv)}. {signal.RuleName}: {signal.Status}"; if (signal.Status == AlertStatus.Alerted) { email.Subject += $"({instanceMsg})"; } var body = new StringBuilder(signal.SignalMessage); if (props.GetValue <bool>("rule.DebugEnabled", false)) { body.AppendLine(); body.AppendLine(); body.AppendLine("[debug-begin]"); props.LogValues(text => body.AppendLine(" " + text)); body.AppendLine("[debug-end]"); } email.Body = body.ToString(); SendEmail(smtpHost, email, sender, recipients); } catch (Exception excp) { ReportUncaughtError("EmailAlertSignal", signal.RuleName, excp, props); } }
private void SendEmail(string smtpHost, MailMessage email, string sender, IEnumerable <string> recipients) { foreach (string recipient in recipients) { Logger.LogDebug("EmailAlertSignal: Recipient : {0}", recipient); email.To.Add(recipient); } Logger.LogDebug("EmailAlertSignal: Sender : {0}", sender); email.From = new MailAddress(sender, $"QDS AlertServer {EnvHelper.EnvName(IntClient.Target.ClientInfo.ConfigEnv)}"); string[] hostAndPorts = smtpHost.Split(':'); int port = 25; if (hostAndPorts.Length > 1) { smtpHost = hostAndPorts[0]; port = int.Parse(hostAndPorts[1]); } Logger.LogDebug("EmailAlertSignal: Connecting: {0}:{1}", smtpHost, port); var client = new SmtpClient(smtpHost, port); client.Send(email); Logger.LogDebug("EmailAlertSignal: Body:"); Logger.LogDebug(email.Body); Logger.LogDebug("EmailAlertSignal: Sent."); }
private void StartUp() { try { var factory = new CoreClientFactory(_loggerRef) .SetEnv("Dev") .SetApplication(Assembly.GetExecutingAssembly()) .SetProtocols(WcfConst.AllProtocolsStr) .SetServers("localhost"); var client = factory.Create(); _clientRef = Reference <ICoreClient> .Create(client); _cache = _clientRef.Target.CreateCache(); // init controls // - form title var env = _clientRef.Target.ClientInfo.ConfigEnv; Text += String.Format(" ({0})", EnvHelper.EnvName(env)); // - server port int defaultPort = EnvHelper.SvcPort(env, SvcId.GridSwitch); chkChangePort.Text = String.Format("Change server port from default ({0}) to:", defaultPort); _syncContext.Post(OnClientStateChange, new CoreStateChange(CoreStateEnum.Initial, _clientRef.Target.CoreState)); _clientRef.Target.OnStateChange += _Client_OnStateChange; } catch (Exception excp) { _loggerRef.Target.Log(excp); } }
private void StartUp() { // start the service string env = EnvHelper.EnvName((EnvId)cbEnvironment.SelectedIndex); var settings = new NamedValueSet(); settings.Set(CfgPropName.NodeType, cbServerMode.SelectedIndex); settings.Set(CfgPropName.EnvName, env); settings.Set(CfgPropName.DbServer, txtDbCfg.Text); _coreServer = new CoreServer(_coreLogger, settings); _coreServer.Start(); }
private static void AddRuleSetUnitTest(string buildCfg, List <HostConfigRule> rules) { string envName = EnvHelper.EnvName(EnvId.Utt_UnitTest); // default host instance rules.Add(new HostConfigRule { buildConfig = buildCfg, hostEnvName = envName, Priority = 1, serverApplName = "DataExportServer", serverImplType = "Orion.Server.DataExporter.DataExportServer", serverAssmName = "Orion.Server.DataExporter", serverAssmPath = new[] { $@"..\..\..\..\..\Services\TradeExport\TradeExporter\bin\{buildCfg}" }, serverEnabled = true }); // start a 2-node trade reval grid // - host instance A rules.Add(new HostConfigRule { buildConfig = buildCfg, hostEnvName = envName, hostInstance = "A", Priority = 1, serverApplName = "TradeValuationServer", serverImplType = "Orion.Server.TradeRevaluer.TradeValuationServer", serverAssmName = "Orion.Server.TradeRevaluer", serverAssmPath = new[] { $@"..\..\..\..\..\Services\TradeRevaluer\bin\{buildCfg}" }, serverEnabled = true, serverInstanceTotalCount = 5, serverInstanceLocalCount = 1, serverInstanceLocalStart = 0 }); // - host instance B rules.Add(new HostConfigRule { buildConfig = buildCfg, hostEnvName = envName, hostInstance = "B", Priority = 1, serverApplName = "TradeValuationServer", serverImplType = "Orion.Server.TradeRevaluer.TradeValuationServer", serverAssmName = "Orion.Server.TradeRevaluer", serverAssmPath = new[] { $@"..\..\..\..\..\Services\TradeRevaluer\bin\{buildCfg}" }, serverEnabled = true, serverInstanceTotalCount = 5, serverInstanceLocalCount = 4, serverInstanceLocalStart = 1 }); }
private static HostConfigRule SetRuleEnv(EnvId env, string hostComputer, string hostInstance, string buildCfg, bool enabled, HostConfigRule rule) { rule.hostEnvName = EnvHelper.EnvName(env); rule.hostComputer = hostComputer; rule.hostInstance = hostInstance; rule.buildConfig = buildCfg; rule.Priority = 1; var assemblyPaths = new List <string>(rule.serverAssmPath) { $@"C:\_qrsc\Builds\{EnvHelper.EnvName(env)}\Current\{buildCfg}" }; rule.serverAssmPath = assemblyPaths.ToArray(); rule.serverEnabled = enabled; return(rule); }
protected override void OnFirstCallback() { // subscribe to import rules _ruleCache = IntClient.Target.CreateCache(delegate(CacheChangeData update) { Interlocked.Increment(ref _dispatchedEventCount); MainThreadQueue.Dispatch(update, ProcessRuleUpdate); }, null); _ruleCache.Subscribe <AlertRule>( RuleObject.MakeRuleFilter( EnvHelper.EnvName(IntClient.Target.ClientInfo.ConfigEnv), IntClient.Target.ClientInfo.HostName, AppName, IntClient.Target.ClientInfo.UserName)); // start a 30 second timer to periodically check the rules _timer = new Timer(RecvTimerEvent, null, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30)); }
protected override void OnFirstCallback() { _hostConfigRuleSubs = Client.CreateCache( delegate(CacheChangeData update) { Interlocked.Increment(ref _ruleUpdatesQueued); _MainThreadQueue.Dispatch <object>(null, OnRuleUpdate); }, null); _hostConfigRuleSubs.SubscribeWait <HostConfigRule>(RuleHelper.MakeRuleFilter( EnvHelper.EnvName(Client.ClientInfo.ConfigEnv), Client.ClientInfo.HostName, ServerInstance, Client.ClientInfo.UserName)); Interlocked.Increment(ref _ruleUpdatesQueued); _MainThreadQueue.Dispatch <object>(null, OnRuleUpdate); }
protected override void OnFirstCallback() { // subscribe to import rules _importRuleSet = IntClient.Target.CreateCache(delegate(CacheChangeData update) { Interlocked.Increment(ref _updateRequestsDispatched); MainThreadQueue.Dispatch(update, ProcessRuleUpdate); }, null); _importRuleSet.Subscribe <FileImportRule>( RuleObject.MakeRuleFilter( EnvHelper.EnvName(IntClient.Target.ClientInfo.ConfigEnv), IntClient.Target.ClientInfo.HostName, AppName, IntClient.Target.ClientInfo.UserName)); // start a 1 minute timer to periodically check the rules _timer = new Timer(RecvTimerEvent, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1)); }
private void StartUp() { try { var factory = new CoreClientFactory(_loggerRef) .SetEnv("Dev") .SetApplication(Assembly.GetExecutingAssembly()) .SetProtocols(WcfConst.AllProtocolsStr) .SetServers("localhost"); var client = factory.Create(); _clientRef = Reference <ICoreClient> .Create(client); _cache = _clientRef.Target.CreateCache(); // init controls // - form title EnvId env = _clientRef.Target.ClientInfo.ConfigEnv; Text += String.Format(" ({0})", EnvHelper.EnvName(env)); // - server port int defaultPort = EnvHelper.SvcPort(env, SvcId.GridSwitch); _qasDefViewHelper = new QASDefViewHelper(); _qasDefDataHelper = new QASDefDataHelper(); _qasDefFilters = new ComboxBoxFilterGroup(panelQASDef, _qasDefViewHelper, QASDefSelectionChanged); _qasDefSelecter = new QASDefSelecter( _qasDefFilters, _qasDefViewHelper, _qasDefDataHelper); _qasDefView = new ListViewManager <RatesObj>( _loggerRef.Target, lvQASDef, _qasDefViewHelper, _qasDefSelecter, _qasDefFilters, new QASDefSorter(), _qasDefDataHelper); //Get the starting configuration // chkChangePort.Text = String.Format("Change server port from default ({0}) to:", defaultPort); //Set up the timer and the random number generator. // _timer = new System.Timers.Timer(10000); _rand = new Random(); } catch (Exception excp) { _loggerRef.Target.Log(excp); } }
private void PublishHostConfigResult(ServerFarmNode node, string comment) { var result = new HostConfigResult { hostEnvName = EnvHelper.EnvName(Client.ClientInfo.ConfigEnv), hostComputer = Client.ClientInfo.HostName, hostUserName = Client.ClientInfo.UserName }; // create config Result if (node != null) { result.serverApplName = node.Key; if (node.Rule != null) { result.serverImplType = node.Rule.serverImplType; } } result.serverEnabled = false; result.serverComment = "Stopped"; if (node != null && node.Server != null) { result.serverEnabled = true; result.serverComment = "Starting"; if (node.Server.HasStarted) { result.serverComment = "Running"; } if (node.Server.HasStopped) { result.serverComment = "Stopped"; } } if (comment != null) { result.serverComment = comment; } // publish Result Client.SaveObject <HostConfigResult>(result, true, TimeSpan.FromDays(30)); }
public CurveUnitTestEnvironment(string nameSpace) { NameSpace = nameSpace; string env = EnvHelper.EnvName(EnvId.Utt_UnitTest); var stopwatch = new Stopwatch(); stopwatch.Start(); var random = new Random(Environment.TickCount); int port = random.Next(8000, 8099); _server = new CoreServer(_logRef, env, NodeType.Router, port, WcfConst.NetTcp); _server.Start(); _client = new CoreClientFactory(_logRef) .SetEnv(env) .SetServers("localhost:" + port.ToString(CultureInfo.InvariantCulture)) .SetProtocols(WcfConst.NetTcp) .Create(); Cache = _client.CreateCache(); LoadConfigDataHelper.LoadCurveConfigurationData(_logRef.Target, Cache, nameSpace); stopwatch.Stop(); Debug.Print("Initialized test environment, in {0} seconds", stopwatch.Elapsed.TotalSeconds); }
private void ReportUncaughtError(string method, string ruleName, Exception ex, NamedValueSet debugProps) { // first log to EventLog string message = string.IsNullOrEmpty(ruleName) ? $"Exception in '{method}': \n\n{ex}" : $"Exception in '{method}', Rule '{ruleName}': \n\n{ex}'"; Logger.LogError(message); // then email try { string smtpHost = _defaultSmtpServer; IEnumerable <string> recipients = ResolveMultipleEmailAddresses(_defaultMailTo); string sender = ResolveSingleEmailAddress(_defaultMailFrom); var email = new MailMessage { Subject = $"QDS Alert {EnvHelper.EnvName(IntClient.Target.ClientInfo.ConfigEnv)}. UNHANDLED ERROR" }; //new var body = new StringBuilder(message); if (debugProps != null) { body.AppendLine(); body.AppendLine(); body.AppendLine("[debug-begin]"); debugProps.LogValues(text => body.AppendLine(" " + text)); body.AppendLine("[debug-end]"); } email.Body = body.ToString(); //end new SendEmail(smtpHost, email, sender, recipients); } catch (Exception excp) { Logger.LogError(excp); } }
private void ProcessRule(ICoreClient client, InternalRule rule, DateTimeOffset currentTime) { RuleStatusEnum ruleStatus; ILogger logger = new FilterLogger( Logger, $"Rule {rule.RuleName}: ", rule.DebugEnabled ? LogSeverity.Debug : LogSeverity.Info); using (var settings = new SettingsTracker(client, "FileImporter." + rule.RuleName)) { bool lastCheckFailed = false; string lastCheckException = "(null)"; DateTimeOffset lastCheckDateTime = currentTime; //logger.LogDebug("Processing..."); try { ruleStatus = RuleStatusEnum.Disabled; if (!rule.Disabled) { // evaluate rule constraint and condition var properties = new NamedValueSet(settings.GetAllValues(true)); properties.Add(rule.Properties); // last import date/time (default to 4 days ago) var lastImportDateTime = settings.GetSetValue(RuleConst.LastImportDateTime, DateTimeOffset.Now.AddDays(-4)); properties.Set(RuleConst.LastImportDateTime, lastImportDateTime); // calculate effective "as at" date var thisImportDateTime = Expr.CastTo(rule.EffectiveDateExpr.Evaluate(properties, currentTime), currentTime); properties.Set(RuleConst.EffectiveDateTime, thisImportDateTime); // add useful date/time tokens //foreach (string token in new string[] { "dd", "ddd", "MM", "MMM", "yyyy" }) //{ // properties.Set(token, thisImportDateTime.ToString(token)); //} // calculate import delay var thisImportDelay = Expr.CastTo(rule.ImportDelayExpr.Evaluate(properties, currentTime), TimeSpan.Zero); properties.Set(RuleConst.ImportDelay, thisImportDelay); // evaluate rule check constraint and import condition logger.LogDebug("Evaluation Params :"); properties.LogValues(text => logger.LogDebug(" " + text)); logger.LogDebug("Check Constraint : {0}", rule.CheckConstraint); ruleStatus = RuleStatusEnum.Inactive; if (Expr.CastTo(rule.CheckConstraint.Evaluate(properties, currentTime), false)) { logger.LogDebug("Import Condition : {0}", rule.ImportCondition); ruleStatus = RuleStatusEnum.NotReady; if (Expr.CastTo(rule.ImportCondition.Evaluate(properties, currentTime), false)) { ruleStatus = RuleStatusEnum.Failed; // import condition is true // process date/time tokens string targetLocation = StringHelper.ReplaceDateTimeTokens(rule.TargetLocation, thisImportDateTime); string sourceLocation = StringHelper.ReplaceDateTimeTokens(rule.SourceLocation, thisImportDateTime); var importedFiles = new List <string>(); logger.LogInfo("Source Location : {0}", sourceLocation); logger.LogInfo("Target Location : {0}", targetLocation); logger.LogInfo("Filenames to copy: {0}", rule.CopyFilePatterns); string thisImportException = "(null)"; try { // import the file // - optionally clean up old files aged more than 7 days if (rule.RemoveOldTargetFiles) { try { string[] oldTargetFiles = Directory.GetFiles(targetLocation, "*.*", SearchOption.TopDirectoryOnly); foreach (string oldTargetFile in oldTargetFiles) { var targetFileInfo = new FileInfo(oldTargetFile); if ((currentTime - targetFileInfo.LastWriteTime) > TimeSpan.FromDays(2)) { File.Delete(oldTargetFile); } } } catch (IOException removeExcp) { logger.LogWarning("Error removing old files: {0}", removeExcp.GetType().Name); // ignored } } // - create target directory if required if (!Directory.Exists(targetLocation)) { Directory.CreateDirectory(targetLocation); } // - copy file(s) from source to target foreach (string ruleFilePattern in rule.CopyFilePatterns.Split(';')) { string filePattern = StringHelper.ReplaceDateTimeTokens(ruleFilePattern, thisImportDateTime); string[] sourceFiles = Directory.GetFiles(sourceLocation, filePattern, SearchOption.TopDirectoryOnly); logger.LogInfo("Copying file(s): {0} ({1} found)", filePattern, sourceFiles.Length); int copiedCount = 0; int skippedCount = 0; foreach (string sourceFileFullname in sourceFiles) { string sourceFileBaseName = Path.GetFileName(sourceFileFullname); string targetFileFullname = $@"{targetLocation}\{sourceFileBaseName}"; bool copyRequired = true; if (File.Exists(targetFileFullname) && rule.OnlyCopyUpdatedFiles) { var sourceFileInfo = new FileInfo(sourceFileFullname); var targetFileInfo = new FileInfo(targetFileFullname); copyRequired = (sourceFileInfo.LastWriteTime > targetFileInfo.LastWriteTime); } if (copyRequired) { logger.LogInfo("Copying file : {0}", sourceFileBaseName); logger.LogInfo(" From source: {0}", sourceLocation); logger.LogInfo(" To target: {0}", targetLocation); DateTime copyCommenced = DateTime.Now; File.Copy(sourceFileFullname, targetFileFullname, true); TimeSpan copyDuration = DateTime.Now - copyCommenced; importedFiles.Add(sourceFileBaseName); var targetFileInfo = new FileInfo(targetFileFullname); copiedCount++; logger.LogInfo(" Copied {0}MB in {1}s ({2}KB/sec)", (targetFileInfo.Length / 1000000.0).ToString("N"), copyDuration.TotalSeconds.ToString("N"), (targetFileInfo.Length / (1000.0 * copyDuration.TotalSeconds)).ToString("N")); // publish rule import status var importFileResult = new ImportFileResult { hostEnvName = EnvHelper.EnvName(IntClient.Target.ClientInfo.ConfigEnv), hostComputer = IntClient.Target.ClientInfo.HostName, hostInstance = null, hostUserName = client.ClientInfo.UserName, RuleName = rule.RuleName, FileName = sourceFileBaseName, DebugEnabled = rule.DebugEnabled, DebugProperties = rule.DebugProperties.Serialise(), FileContentType = rule.FileContentType, ImportResult = RuleStatusEnum.Completed.ToString(), ImportException = null, ImportDateTime = currentTime.ToString("o"), SourceSystem = rule.SourceSystem, SourceLocation = sourceLocation, TargetLocation = targetLocation }; IntClient.Target.SaveObject(importFileResult, true, TimeSpan.FromDays(30)); } else { skippedCount++; logger.LogDebug("Skipping file : {0}", sourceFileBaseName); } } // foreach file logger.LogInfo("Copied {0} file(s), skipped {1} file(s).", copiedCount, skippedCount); } // - optionally decompress target // todo // done ruleStatus = RuleStatusEnum.Completed; lastImportDateTime = Expr.CastTo(rule.DateUpdateExpr.Evaluate(properties, currentTime), currentTime); } catch (Exception e2) { logger.Log(e2); thisImportException = e2.ToString(); ruleStatus = RuleStatusEnum.Failed; } finally { settings.SetNewValue(RuleConst.LastImportResult, ruleStatus.ToString()); settings.SetNewValue(RuleConst.LastImportException, thisImportException); settings.SetNewValue(RuleConst.LastImportDateTime, lastImportDateTime); } // publish rule import status var importRuleResult = new ImportRuleResult { hostEnvName = EnvHelper.EnvName(IntClient.Target.ClientInfo.ConfigEnv), hostComputer = IntClient.Target.ClientInfo.HostName, hostInstance = null, hostUserName = client.ClientInfo.UserName, RuleName = rule.RuleName, ImportResult = ruleStatus.ToString(), ImportException = thisImportException, ImportDateTime = currentTime.ToString("o"), SourceSystem = rule.SourceSystem, SourceLocation = sourceLocation, TargetLocation = targetLocation, FileNames = importedFiles.ToArray() }; IntClient.Target.SaveObject(importRuleResult, true, TimeSpan.FromDays(30)); } } } } catch (Exception e) { logger.Log(e); lastCheckFailed = true; lastCheckException = e.ToString(); ruleStatus = RuleStatusEnum.Failed; } settings.SetNewValue(RuleConst.LastCheckFailed, lastCheckFailed); settings.SetNewValue(RuleConst.LastCheckException, lastCheckException); settings.SetNewValue(RuleConst.LastCheckDateTime, lastCheckDateTime); } // commit unsaved settings logger.LogDebug("Status={0}", ruleStatus); }
private void Form1Load(object sender, EventArgs e) { // create loggers _loggerRef = Reference <ILogger> .Create(new TextBoxLogger(txtMainLog)); // create client factory and client _clientFactory = new CoreClientFactory(_loggerRef); _clientFactory.SetEnv(BuildConst.BuildEnv); _clientFactory.SetApplication(Assembly.GetExecutingAssembly()); _client = _clientFactory.Create(); // - form title WinFormHelper.SetAppFormTitle(this, EnvHelper.EnvName(BuildEnv)); // setup the AlertRule view _alertRuleViewHelper = new AlertRuleViewHelper(); _alertRuleDataHelper = new AlertRuleDataHelper(); _alertRuleFilters = new ComboxBoxFilterGroup( panelAlertRule, _alertRuleViewHelper, AlertRuleSelectionChanged); _alertRuleSelecter = new AlertRuleSelecter( _alertRuleFilters, _alertRuleViewHelper, _alertRuleDataHelper); _alertRuleView = new ListViewManager <AlertRule>( _loggerRef.Target, lvAlertRule, _alertRuleViewHelper, _alertRuleSelecter, _alertRuleFilters, new AlertRuleSorter(), _alertRuleDataHelper); ICoreCache alertRuleCache = _client.CreateCache( update => _alertRuleView.UpdateData(new ViewChangeNotification <AlertRule> { Change = update.Change, OldData = (AlertRule)update.OldItem?.Data, NewData = (AlertRule)update.NewItem?.Data }), SynchronizationContext.Current); alertRuleCache.SubscribeNoWait <AlertRule>(Expr.ALL, null, null); // setup the AlertSignal view _alertSignalViewHelper = new AlertSignalViewHelper(); _alertSignalDataHelper = new AlertSignalDataHelper(); _alertSignalFilters = new ComboxBoxFilterGroup( panelAlertSignal, _alertSignalViewHelper, AlertSignalSelectionChanged); _alertSignalSelecter = new AlertSignalSelecter( _alertSignalFilters, _alertSignalViewHelper, _alertSignalDataHelper); _alertSignalView = new ListViewManager <AlertSignal>( _loggerRef.Target, lvAlertSignal, _alertSignalViewHelper, _alertSignalSelecter, _alertSignalFilters, new AlertSignalSorter(), _alertSignalDataHelper); ICoreCache alertSignalCache = _client.CreateCache( update => _alertSignalView.UpdateData(new ViewChangeNotification <AlertSignal> { Change = update.Change, OldData = (AlertSignal)update.OldItem?.Data, NewData = (AlertSignal)update.NewItem?.Data }), SynchronizationContext.Current); alertSignalCache.SubscribeNoWait <AlertSignal>(Expr.ALL, null, null); // setup the LogEvent view _logEventViewHelper = new LogEventViewHelper(); _logEventDataHelper = new LogEventDataHelper(); _logEventFilters = new ComboxBoxFilterGroup( panelLogEvent, _logEventViewHelper, LogEventSelectionChanged); _logEventSelecter = new LogEventSelecter( _logEventFilters, _logEventViewHelper, _logEventDataHelper); _logEventView = new ListViewManager <DebugLogEvent>( _loggerRef.Target, lvLogEvent, _logEventViewHelper, _logEventSelecter, _logEventFilters, new LogEventSorter(), _logEventDataHelper); ICoreCache logEventCache = _client.CreateCache( update => _logEventView.UpdateData(new ViewChangeNotification <DebugLogEvent> { Change = update.Change, OldData = (DebugLogEvent)update.OldItem?.Data, NewData = (DebugLogEvent)update.NewItem?.Data }), SynchronizationContext.Current); logEventCache.SubscribeNoWait <DebugLogEvent>(Expr.ALL, null, null); // init controls // server 0 _serverAddress[0] = txtServer0Address; _ping[0] = chkServer0Ping; _lastChecked[0] = txtServer0LastChecked; _lastReplied[0] = txtServer0LastReplied; _serverStatus[0] = txtServer0Status; _serverReason[0] = txtServer0OtherInfo; // server 1 _serverAddress[1] = txtServer1Address; _ping[1] = chkServer1Ping; _lastChecked[1] = txtServer1LastChecked; _lastReplied[1] = txtServer1LastReplied; _serverStatus[1] = txtServer1Status; _serverReason[1] = txtServer1OtherInfo; // server 2 _serverAddress[2] = txtServer2Address; _ping[2] = chkServer2Ping; _lastChecked[2] = txtServer2LastChecked; _lastReplied[2] = txtServer2LastReplied; _serverStatus[2] = txtServer2Status; _serverReason[2] = txtServer2OtherInfo; // server 3 _serverAddress[3] = txtServer3Address; _ping[3] = chkServer3Ping; _lastChecked[3] = txtServer3LastChecked; _lastReplied[3] = txtServer3LastReplied; _serverStatus[3] = txtServer3Status; _serverReason[3] = txtServer3OtherInfo; // server 4 _serverAddress[4] = txtServer4Address; _ping[4] = chkServer4Ping; _lastChecked[4] = txtServer4LastChecked; _lastReplied[4] = txtServer4LastReplied; _serverStatus[4] = txtServer4Status; _serverReason[4] = txtServer4OtherInfo; // server 5 _serverAddress[5] = txtServer5Address; _ping[5] = chkServer5Ping; _lastChecked[5] = txtServer5LastChecked; _lastReplied[5] = txtServer5LastReplied; _serverStatus[5] = txtServer5Status; _serverReason[5] = txtServer5OtherInfo; for (int i = 0; i < NServers; i++) { _lastChecked[i].BackColor = Color.FromKnownColor(KnownColor.Window); _lastReplied[i].BackColor = Color.FromKnownColor(KnownColor.Window); _serverStatus[i].BackColor = Color.FromKnownColor(KnownColor.Window); _serverReason[i].BackColor = Color.FromKnownColor(KnownColor.Window); } }
/// <summary> /// /// </summary> public void Freeze() { if (_frozen) { return; } if (Name == null) { throw new ApplicationException("Item name not set!"); } TimeSpan maxLifetime = DateTimeOffset.MaxValue - DateTimeOffset.Now - TimeSpan.FromDays(1); if (_lifetime > maxLifetime) { _lifetime = maxLifetime; } if (_lifetime < TimeSpan.Zero) { _lifetime = TimeSpan.Zero; } Created = DateTimeOffset.Now; Expires = Created.Add(_lifetime); // serialise the data if required Serialise(); if (DataTypeName == null) { DataTypeName = ""; } if (_text == null) { //_Text = ""; SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Undefined); } SysProps.Set(SysPropName.TLen, _text?.Length ?? 0); // compress the data _zData = CompressionHelper.CompressToBuffer(_text); SysProps.Set(SysPropName.ZAlg, 1); SysProps.Set(SysPropName.ZLen, _zData?.Length ?? 0); // do symmetric encryption 1st, if required var xtki = SysProps.GetValue <String>(SysPropName.XTKI, null); if (xtki != null) { _xData = _cryptoManager.EncryptWithTranspKey(xtki, _zData); SysProps.Set(SysPropName.XAlg, 1); } else { _xData = _zData; } SysProps.Set(SysPropName.XLen, _xData?.Length ?? 0); // do asymmetric encryption 2nd, if required var yrki = SysProps.GetValue <String>(SysPropName.YRKI, null); if (yrki != null) { SysProps.Set(SysPropName.YAlg, 1); YData = _cryptoManager.EncryptWithPublicKey(yrki, _xData); } else { YData = _xData; } YDataHash = CalculateBufferHash(YData); SysProps.Set(SysPropName.YLen, YData?.Length ?? 0); // do public signature 3rd, if required var yski = SysProps.GetValue <String>(SysPropName.YSKI, null); if (yski != null) { SysProps.Set(SysPropName.YAlg, 1); YSign = _cryptoManager.CreateSignature(yski, YData); } // add other publisher properties SysProps.Set(SysPropName.ApplName, _moduleInfo.ApplName); SysProps.Set(SysPropName.ApplFVer, _moduleInfo.ApplFVer); SysProps.Set(SysPropName.ApplPTok, _moduleInfo.ApplPTok); SysProps.Set(SysPropName.CoreFVer, _moduleInfo.CoreFVer); SysProps.Set(SysPropName.CorePTok, _moduleInfo.CorePTok); SysProps.Set(SysPropName.HostName, _moduleInfo.HostName); SysProps.Set(SysPropName.UserName, _moduleInfo.UserName); SysProps.Set(SysPropName.UserWDom, _moduleInfo.UserWDom); SysProps.Set(SysPropName.UserIdentity, _moduleInfo.Name); SysProps.Set(SysPropName.UserFullName, _moduleInfo.UserFullName); SysProps.Set(SysPropName.OrgEnvId, EnvHelper.EnvName(_moduleInfo.ConfigEnv)); SysProps.Set(SysPropName.NodeGuid, _moduleInfo.NodeGuid); // done _frozen = true; }
protected override void OnServerStarted() { // default configuration _activeProviders = new[] { MDSProviderId.Bloomberg }; // custom configuration string[] enabledProviders = OtherSettings.GetArray <string>(MdsPropName.EnabledProviders); if (enabledProviders != null && enabledProviders.Length > 0) { _activeProviders = enabledProviders.Select(providerName => EnumHelper.Parse <MDSProviderId>(providerName, true)).ToArray(); } // derived configuration EnvId envId = IntClient.Target.ClientInfo.ConfigEnv; string envName = EnvHelper.EnvName(envId); var port = OtherSettings.GetValue(MdsPropName.Port, EnvHelper.SvcPort(envId, SvcId.MarketData)); // service endpoints string transEndpoints = ServiceHelper.FormatEndpoint(WcfConst.NetTcp, port); string discoEndpoints = ServiceHelper.FormatEndpoint(WcfConst.NetTcp, port); transEndpoints = OtherSettings.GetValue(MdsPropName.Endpoints, transEndpoints); // add default port to endpoints if required var tempEndpoints = new List <string>(); foreach (string ep in transEndpoints.Split(';')) { var epParts = ep.Split(':'); var scheme = epParts[0]; var tport = port; if (epParts.Length > 1) { tport = Int32.Parse(epParts[1]); } tempEndpoints.Add($"{scheme}:{tport}"); } transEndpoints = String.Join(";", tempEndpoints.ToArray()); // get user identity and full name WindowsIdentity winIdent = WindowsIdentity.GetCurrent(); UserPrincipal principal = null; try { var principalContext = new PrincipalContext(ContextType.Domain); principal = UserPrincipal.FindByIdentity(principalContext, IdentityType.SamAccountName, winIdent.Name); } catch (PrincipalException principalException) { // swallow - can occur on machines not connected to domain controller Logger.LogWarning("UserPrincipal.FindByIdentity failed: {0}: {1}", principalException.GetType().Name, principalException.Message); } string userFullName = null; if (principal != null) { userFullName = principal.GivenName + " " + principal.Surname; } _serverCfg = new ServerCfg( new ModuleInfo(envName, Guid.NewGuid(), winIdent.Name, userFullName, null, null), transEndpoints, discoEndpoints); foreach (MDSProviderId providerId in _activeProviders) { _providers[(int)providerId] = new MarketDataRealtimeClient(LoggerRef, MainThreadQueue, IntClient.Target, providerId); } string svcName = EnvHelper.SvcPrefix(SvcId.MarketData); // V2.2 _mrktDataV221ServerHost = new CustomServiceHost <IMrktDataV221, MrktDataRecverV221>( Logger, new MrktDataRecverV221(this), _serverCfg.TransEndpoints, svcName, typeof(IMrktDataV221).Name, true); _sessCtrlV131ServerHost = new CustomServiceHost <ISessCtrlV131, SessCtrlRecverV131>( Logger, new SessCtrlRecverV131(this), _serverCfg.DiscoEndpoints, svcName, typeof(ISessCtrlV131).Name, true); _discoServerHostV111 = new CustomServiceHost <IDiscoverV111, DiscoverRecverV111>( Logger, new DiscoverRecverV111(this), _serverCfg.DiscoEndpoints, svcName, typeof(IDiscoverV111).Name, true); }
private void Launch(object state) { try { using (LaunchPackage package = (LaunchPackage)state) { try { string workDir = Path.GetDirectoryName(_RequestHandlerFullPath); string exeFile = _RequestHandlerFullPath; string arguments = String.Format("/env:{0} /hiid:{1} /reqid:{2}", EnvHelper.EnvName(package.Client.ClientInfo.ConfigEnv), HostInstance ?? "Default", package.Request.RequestId); ProcessStartInfo psi = new ProcessStartInfo(exeFile, arguments); psi.WorkingDirectory = workDir; psi.UseShellExecute = true; // default - no io redir psi.ErrorDialog = true; psi.WindowStyle = ProcessWindowStyle.Normal; //psi.UserName = xxx; //psi.Password = xxx; Process p = new Process(); p.StartInfo = psi; if (p.Start()) { Logger.LogDebug("{0} Started: {1} {2}", package.Request.RequestId, exeFile, arguments); while (!p.WaitForExit(5000)) // 5 seconds { Logger.LogDebug("{0} Running...", package.Request.RequestId); } // exit codes: // 1 success // 0 failed (exception was published) // -1 catastrophic failure (logged to local file) // -2 catastrophic failure (logged to console only) int exitCode = p.ExitCode; TimeSpan duration = p.ExitTime - p.StartTime; Logger.LogDebug("{0} Stopped: ExitCode={1} (Duration={2})", package.Request.RequestId, exitCode, duration); if (exitCode < 0) { // request handler failed to publish faulted request status - so we do it here throw new ApplicationException(String.Format("Request '{0}' terminated abnormally: {1}", package.Request.RequestId, exitCode)); } } else { throw new ApplicationException(String.Format("Request '{0}' failed to start.", package.Request.RequestId)); } } catch (Exception ex) { Logger.Log(ex); package.Request.Status = RequestStatusEnum.Faulted; package.Request.FaultDetail = new ExceptionDetail(ex); PublishWorkerResponse(package.Client, package.Request, HostInstance); } } } finally { Interlocked.Decrement(ref _HandlersExecuting); Interlocked.Increment(ref _HandlersAvailable); Interlocked.Increment(ref _AvailabilityChangeCount); _EventQueue.Dispatch(null); } }
public void TestServerBridge() { // required environment: // - local env (eg. DEV) server // - lower env (eg. UTT) server // creates the bridge, and check all messages published // in local env are re-published correctly in lower env EnvId localEnvId = EnvId.Dev_Development; string localEnvName = EnvHelper.EnvName(localEnvId); EnvId lowerEnvId = (localEnvId - 1); string lowerEnvName = EnvHelper.EnvName(lowerEnvId); int localPort = 9214; int lowerPort = 9114; using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true))) { CoreClientFactory clientfactory = new CoreClientFactory(loggerRef); using (CoreServer localServer = new CoreServer(loggerRef, localEnvName, NodeType.Router, localPort)) using (CoreServer lowerServer = new CoreServer(loggerRef, lowerEnvName, NodeType.Router, lowerPort)) { // start servers localServer.Start(); lowerServer.Start(); // create clients using (Reference <ICoreClient> localClientRef = Reference <ICoreClient> .Create(clientfactory.SetEnv(localEnvName).SetServers("localhost:" + localPort).Create())) using (ICoreClient lowerClient = clientfactory.SetEnv(lowerEnvName).SetServers("localhost:" + lowerPort).Create()) { using (ServerBridge bridge = new ServerBridge()) { bridge.LoggerRef = loggerRef; bridge.Client = localClientRef; bridge.TargetClient = lowerClient; // test begins here // - start the bridge bridge.Start(); const int sendCount = 500; const int maxWaitSeconds = 5; long excpCount = 0; long recdCount = 0; // subscribe to objects on downstream server ISubscription subs = lowerClient.Subscribe <TestData>(Expr.ALL, delegate(ISubscription subscription, ICoreItem item) { // receiver long count = Interlocked.Increment(ref recdCount); try { TestData data = (TestData)item.Data; //loggerRef.Target.LogDebug("Recd[{0}]", data.field2); Assert.AreEqual <long>(count, data.field2); } catch (Exception) { Interlocked.Increment(ref excpCount); } }, null); long sentCount = 0; // publish n Server events for (int i = 1; i <= sendCount; i++) { Interlocked.Increment(ref sentCount); localClientRef.Target.SaveObject <TestData>(new TestData("Test", i), "Test", null, TimeSpan.MaxValue); } // wait for a short period DateTimeOffset waitStart = DateTimeOffset.Now; DateTimeOffset waitExpiry = waitStart.AddSeconds(maxWaitSeconds); while ((Interlocked.Add(ref recdCount, 0) < Interlocked.Add(ref sentCount, 0)) && (DateTimeOffset.Now < waitExpiry) && (Interlocked.Add(ref excpCount, 0) == 0)) { Thread.Sleep(TimeSpan.FromSeconds(1.0)); loggerRef.Target.LogDebug("Recd/Sent: {0}/{1} items...", Interlocked.Add(ref recdCount, 0), Interlocked.Add(ref sentCount, 0)); } loggerRef.Target.LogDebug("Duration: {0}", (DateTimeOffset.Now - waitStart)); Assert.AreEqual <long>(0, excpCount); Assert.AreEqual <long>(sendCount, recdCount); // done Assert.IsTrue(true); } } } } }
/// <summary> /// </summary> public ICoreClient Create(string instanceName) { string cacheKey = null; string env = null; string servers = null; string protocols = null; bool debugRequests = false; TimeSpan requestTimeout = TimeSpan.Zero; TimeSpan offlineTimeout = TimeSpan.Zero; CoreModeEnum coreMode = CoreModeEnum.Standard; Assembly applAssembly = null; bool useFallbackServers = true; //bool cacheEnabled = false; _factoryState.Locked(state => { useFallbackServers = state.UseFallbackServers; //cacheEnabled = state.CacheEnabled; env = state.Env; servers = state.Servers; protocols = state.Protocols; debugRequests = state.DebugRequests; requestTimeout = state.RequestTimeout; offlineTimeout = state.OfflineTimeout; coreMode = state.CoreMode; applAssembly = state.ApplAssembly; cacheKey = $"[{env}][{(protocols ?? "").ToLower()}][{(servers ?? "").ToLower()}]"; if (state.SettingsCache.TryGetValue(cacheKey, out var cachedSettings)) { env = cachedSettings.Env; servers = $"{cachedSettings.ServerAddress.Host}:{cachedSettings.ServerAddress.Port}"; protocols = cachedSettings.ServerAddress.Protocol; useFallbackServers = false; debugRequests = cachedSettings.DebugRequests; requestTimeout = cachedSettings.RequestTimeout; offlineTimeout = cachedSettings.OfflineTimeout; coreMode = cachedSettings.CoreMode; applAssembly = cachedSettings.ApplAssembly; //_Logger.LogDebug("Using cached settings: {0} --> {1}://{2}", cacheKey, scheme, servers); } }); ICoreClient client = new CoreClient( _loggerRef, instanceName, env, servers, protocols, useFallbackServers, debugRequests, requestTimeout, offlineTimeout, coreMode, applAssembly); // save settings _factoryState.Locked(state => { state.SettingsCache[cacheKey] = new ClientSettings { Env = EnvHelper.EnvName(client.ClientInfo.ConfigEnv), ServerAddress = client.ServerAddress, DebugRequests = debugRequests, RequestTimeout = requestTimeout, OfflineTimeout = offlineTimeout, CoreMode = coreMode, ApplAssembly = applAssembly }; }); return(client); }