public void AccessClientTest() { var a1_localPort = 231; var a1_id = "a1Id"; var a2_localPort = 241; var a2_id = "a2Id"; var a3_localPort = 261; var a3_id = "a3Id"; ComService.AddUdpClient(a1_id, a1_localPort); ComService.AddUdpClient(a2_id, a2_localPort); ComService.AddUdpClient(a3_id, a3_localPort); var pb = ComService.GetClient(a2_id); Assert.AreEqual(a2_localPort, pb.getConnectedPort()); ComService.RemoveClient(a1_id); ComService.RemoveClient(a2_id); ComService.RemoveClient(a3_id); }
public ComPanel(Window parent, ComService comService) : base(parent) { _comService = comService; _comService.DataArrived += ComDataArrived; _comService.StatusChanged += ComStatusChanged; var sizer = new BoxSizer(Orientation.Vertical); _dataFont = new Font(10, FontFamily.Teletype, FontStyle.Normal, FontWeight.Normal); Panel controlPanel = CreateControlPanel(); sizer.Add(controlPanel, 0, SizerFlag.Expand | SizerFlag.All, 0); _history = new TextCtrl(this, "", WxDefaultPosition, WxDefaultSize, WindowStyles.TextCtrlMultiline | WindowStyles.TextCtrlReadonly) { Font = _dataFont }; sizer.Add(_history, 1, SizerFlag.Expand | SizerFlag.All, 0); Panel sendPanel = CreateSendPanel(); sizer.Add(sendPanel, 0, SizerFlag.Expand | SizerFlag.All, 5); SetSizer(sizer); sizer.SetSizeHints(this); EvtSize((e, s) => Sizer.SetDimension(0, 0, Width, Height)); EvtClose((e, s) => OnClose()); DisableInput(); }
private static void Main(string[] args) { Log.Debug($"{nameof(Main)} (enter)"); SignatureService.LoadPublicKey("Team1/StockServer"); ConversationManager.Start(ConversationBuilder); ComService.AddUdpClient(Config.DEFAULT_UDP_CLIENT, Config.GetInt(Config.BROKER_PORT)); RequestStockStream(); PrintMenu(); PortfolioManager.LoadPortfolios(); var input = Console.ReadLine(); while (!input.Equals("exit")) { RequestStockStream(); PrintMenu(); input = Console.ReadLine(); } ConversationManager.Stop(); Log.Debug($"{nameof(Main)} (exit)"); }
public static void Start(ConversationBuilder method) { Log.Debug($"{nameof(Start)} (enter)"); if (!IsRunning) { SetConversationBuilder(method); ComService.SetIncomingMessageHandler(ProcessIncomingMessage); IsRunning = true; new Task(() => { var timeout = Config.GetInt(Config.DEFAULT_TIMEOUT); while (IsRunning) { foreach (var conv in conversations.Values) { var timeSinceUpdate = (int)(DateTime.Now - conv.LastUpdateTime).TotalMilliseconds; if (timeSinceUpdate > timeout) { conv.HandleTimeout(); } } Thread.Sleep(15); } }).Start(); } else { Log.Warn("ConversationManager already running. Did you try to start it more than once?"); } Log.Debug($"{nameof(Start)} (exit)"); }
static void Main(string[] args) { Log.Debug($"{nameof(Main)} (enter)"); SignatureService.LoadPrivateKey("Team1/StockServer"); StockData.Init(); ConversationManager.Start(ConversationBuilder); ComService.AddUdpClient(Config.DEFAULT_UDP_CLIENT, Config.GetInt(Config.STOCK_SERVER_PORT)); ComService.AddTcpListener(Config.DEFAULT_TCP_CLIENT, Config.GetInt(Config.STOCK_SERVER_TCP_PORT)); Log.Info("Starting simulation."); Task.Run(() => RunSimulation()); Log.Info("Waiting for StockStreamRequestMessages."); Log.Info("Pres any key to close program."); Console.ReadKey(); lock (RunSimLock) { IsSimRunning = false; } Log.Debug($"{nameof(Main)} (exit)"); }
public FrontPanelPanel(MainFrame parent, ComService comService) : base(parent) { _comService = comService; _comService.DataArrived += ComDataArrived; FlexGridSizer sizer = new FlexGridSizer(4, 0, 0); sizer.Add(new StaticText(this, "External\nVoltage", WxDefaultPosition, WxDefaultSize, WindowStyles.AlignRight), 0, SizerFlag.AlignCenterVertical | SizerFlag.All, 5); _externalVoltage = new ValueDisplay(this) { Value = "0.0", Unit = "mV" }; sizer.Add(_externalVoltage, 0, SizerFlag.All, 5); sizer.Add(new StaticText(this, "Load\nVoltage", WxDefaultPosition, WxDefaultSize, WindowStyles.AlignRight), 0, SizerFlag.AlignCenterVertical | SizerFlag.All, 5); _loadVoltage = new ValueDisplay(this) { Value = "0.0", Unit = "mV" }; sizer.Add(_loadVoltage, 0, SizerFlag.All, 5); sizer.Add(new StaticText(this, "External\nCurrent", WxDefaultPosition, WxDefaultSize, WindowStyles.AlignRight), 0, SizerFlag.AlignCenterVertical | SizerFlag.All, 5); _externalCurrent = new ValueDisplay(this) { Value = "0.0", Unit = "mA" }; sizer.Add(_externalCurrent, 0, SizerFlag.All, 5); sizer.Add(new StaticText(this, "Load\nCurrent", WxDefaultPosition, WxDefaultSize, WindowStyles.AlignRight), 0, SizerFlag.AlignCenterVertical | SizerFlag.All, 5); _loadCurrent = new ValueDisplay(this) { Value = "0.0", Unit = "mV" }; sizer.Add(_loadCurrent, 0, SizerFlag.All, 5); sizer.Add(0, 0); sizer.Add(0, 0); sizer.Add(new StaticText(this, "Target\nCurrent", WxDefaultPosition, WxDefaultSize, WindowStyles.AlignRight), 0, SizerFlag.AlignCenterVertical | SizerFlag.All, 5); Panel targetCurrentPanel = new Panel(this); var targetCurrentSizer = new FlexGridSizer(2, 5, 5); _targetCurrentSet = new Button(targetCurrentPanel, ID_TargetCurrentSet, "Set"); EvtButton(ID_TargetCurrentSet, (s, e) => SetTargetCurrent()); _targetCurrent = new TextCtrl(targetCurrentPanel, "0.0mA", WxDefaultPosition, new Size(70, _targetCurrentSet.Size.Height)); targetCurrentSizer.Add(_targetCurrent); targetCurrentSizer.Add(_targetCurrentSet); targetCurrentPanel.SetSizer(targetCurrentSizer); targetCurrentSizer.SetSizeHints(targetCurrentPanel); sizer.Add(targetCurrentPanel, 0, SizerFlag.All, 5); SetSizer(sizer); sizer.SetSizeHints(this); EvtDestroy((s, e) => { OnDestory(); e.Skip(true); }); _targetCurrent.EvtSetFocus((s, e) => _targetCurrentHasFocus = true); _targetCurrent.EvtKillFocus((s, e) => _targetCurrentHasFocus = false); }
public Login() { InitializeComponent(); ConversationManager.Start(ConversationBuilder.Builder); ComService.AddUdpClient(Config.DEFAULT_UDP_CLIENT, 0); TraderModel.Current = new TraderModel(); }
public void AddClientTest() { var a1_localPort = 354; var a1_id = "a1Id"; Assert.IsFalse(ComService.HasClient()); ComService.AddUdpClient(a1_id, a1_localPort); Assert.IsTrue(ComService.HasClient()); ComService.RemoveClient(a1_id); }
private bool Run(Config config, Logger log) { System.Console.WriteLine($"Listening for Dispatches on Device: {config.InputDevice}"); audioStorage = new WatcherAudioStorage(log); evaluator = new AudioEvaluator(log); recorder = new AudioRecorder(evaluator, audioStorage); processor = new AudioProcessor(recorder, evaluator, audioStorage); com = new ComService(log, processor); com.CallCreatedEvent += Com_CallCreatedEvent; System.Console.WriteLine("Hooking into Events"); recorder.SampleAggregator.MaximumCalculated += SampleAggregator_MaximumCalculated; recorder.SampleAggregator.WaveformCalculated += SampleAggregator_WaveformCalculated; processor.TriggerProcessingStarted += Processor_TriggerProcessingStarted; processor.TriggerProcessingFinished += Processor_TriggerProcessingFinished; evaluator.WatcherTriggered += Evaluator_WatcherTriggered; ResgridV3ApiClient.Init(config.ApiUrl, config.Username, config.Password); System.Console.WriteLine( $"Config Loaded with {config.Watchers.Count} watchers ({config.Watchers.Count(x => x.Active)} active)"); System.Console.WriteLine("Initializing Processor"); processor.Init(config); System.Console.WriteLine("Starting Processor"); processor.Start(); System.Console.WriteLine("Starting Communication Service"); com.Init(config); System.Console.WriteLine("Communication Service: Validating API Connection"); if (com.IsConnectionValid()) { System.Console.WriteLine("Communication Service: API Connection is Valid"); } else { System.Console.WriteLine( "Communication Service: CANNOT TALK TO RESGRID API, CHECK YOUR CONFIG APIURL AND ENSURE YOUR COMPUTER CAN TALK TO THAT URL"); } System.Console.WriteLine("Ready, Listening to Audio. Press Ctrl+C to exit."); while (recorder.RecordingState == RecordingState.Monitoring || recorder.RecordingState == RecordingState.Recording) { Thread.Sleep(250); } return(true); }
public void TestCleanup() { ConversationManager.Stop(); ComService.RemoveClient(Config.DEFAULT_UDP_CLIENT); foreach (Portfolio p in PortfolioManager.Portfolios.Values) { PortfolioManager.TryToRemove(p.PortfolioID); } Assert.IsTrue(PortfolioManager.Portfolios.Count == 0); }
public void StartService(string port = "50051") { servicePort = Int32.Parse(port); service = new ComService(); serviceServer = new Server { Services = { BindService(new ComService()) }, Ports = { new ServerPort("localhost", servicePort, ServerCredentials.Insecure) } }; serviceServer.Start(); running = true; Debug.Log("ComService server listening on port " + servicePort); }
public virtual void Send() { Log.Debug($"{nameof(Send)} (enter)"); if (OutboundMessage != null) { var sender = Config.DEFAULT_UDP_CLIENT; if (OutboundMessage is TcpEnvelope) { sender = (OutboundMessage as TcpEnvelope).Key; } ComService.Send(sender, OutboundMessage); } Log.Debug($"{nameof(Send)} (exit)"); }
public override Envelope Prepare() { var mes = MessageFactory.GetMessage <StockHistoryRequestMessage>(Config.GetClientProcessNumber(), 0); mes.ConversationID = Conversation.Id; var stockServerIp = Config.GetString(Config.STOCK_SERVER_IP); var stockSerevrPort = Config.GetInt(Config.STOCK_SERVER_TCP_PORT); var stockServer = new IPEndPoint(IPAddress.Parse(stockServerIp), stockSerevrPort); ComService.AddTcpClient(0, stockServer); var env = new TcpEnvelope(mes, stockServerIp, stockSerevrPort); return(env); }
/// <summary> /// Method used to handle a timeout event. Note: default behavior is to re-send the /// pre-prepared envelope as many times as defined in the program configuration file. /// After that, this handler ends the conversation. /// You may override this method if you want different behavior. /// </summary> public virtual void HandleTimeout() { if (++CountRetrys <= Config.GetInt(Config.DEFAULT_RETRY_COUNT)) { Log.Warn($"Initiating retry for conversation {Conversation.Id}."); Send(); } else { Log.Warn($"Timeout event is forcing conversation {Conversation.Id} into the Done state."); Conversation.UpdateState(new ConversationDoneState(Conversation, this)); if (OutboundMessage != null && OutboundMessage is TcpEnvelope) { ComService.RemoveClient(OutboundMessage.To.ToString()); } } }
public void RemoveClientTest() { var a1_localPort = 231; var a1_id = "a1Id"; var a2_localPort = 241; var a2_id = "a2Id"; ComService.AddUdpClient(a1_id, a1_localPort); ComService.AddUdpClient(a2_id, a2_localPort); Assert.IsNotNull(ComService.GetClient(a2_id)); ComService.RemoveClient(a2_id); Assert.IsNull(ComService.GetClient(a2_id)); ComService.RemoveClient(a1_id); }
public static void Stop() { Log.Debug($"{nameof(Stop)} (enter)"); if (IsRunning) { IsRunning = false; conversationBuilder = null; ComService.ClearIncomingMessageHandler(); conversations.Clear(); } else { Log.Warn("ConversationManager already stopped."); } Log.Debug($"{nameof(Stop)} (exit)"); }
public void TestInitialize() { ComService.AddUdpClient(Config.DEFAULT_UDP_CLIENT, 0); ConversationManager.Start(null); //create fake portfolios to populate leaderboard PortfolioManager.TryToCreate("port1", "pass1", out Portfolio port); PortfolioManager.PerformTransaction(port.PortfolioID, user1VStock.Symbol, 1, 1, out port, out string error); PortfolioManager.TryToCreate("port2", "pass2", out port); PortfolioManager.PerformTransaction(port.PortfolioID, user2VStock.Symbol, 1, 1, out port, out error); PortfolioManager.TryToCreate("port3", "pass3", out port); PortfolioManager.PerformTransaction(port.PortfolioID, user3VStock.Symbol, 1, 1, out port, out error); //clear connected clients (if any leftover from other tests) ClientManager.Clients.Clear(); }
public void InvalidMessageResponderTest() { //Simulate remote application-level ids string incomingConversationID = "5-23"; int remoteProcessId = 2; int remotePortfolioId = 3; //Create a fake incoming message to simulate an ack StockStreamRequest var message = MessageFactory.GetMessage <AckMessage>(remoteProcessId, remotePortfolioId); message.ConversationID = incomingConversationID; var messageEnvelope = new Envelope(message); //Handle "incoming" message var replyConversation = ComService.HandleIncomingMessage(messageEnvelope); //Verify conversation was NOT built from message Assert.IsNull(replyConversation); Assert.IsFalse(ConversationManager.ConversationExists(incomingConversationID)); }
public override Envelope Prepare() { Log.Debug($"{nameof(Prepare)} (enter)"); Envelope env = null; //Build request message var processNum = Config.GetInt(Config.BROKER_PROCESS_NUM); var message = MessageFactory.GetMessage <StockHistoryRequestMessage>(processNum, 0); message.ConversationID = Conversation.Id; var stockServerIp = Config.GetString(Config.STOCK_SERVER_IP); var stockSerevrPort = Config.GetInt(Config.STOCK_SERVER_TCP_PORT); var address = new IPEndPoint(IPAddress.Parse(stockServerIp), stockSerevrPort); ComService.AddTcpClient(0, address); env = new TcpEnvelope(message, Config.GetString(Config.STOCK_SERVER_IP), Config.GetInt(Config.STOCK_SERVER_TCP_PORT)); Log.Debug($"{nameof(Prepare)} (exit)"); return(env); }
public void TestCleanup() { ComService.RemoveClient(Config.DEFAULT_UDP_CLIENT); }
public void TestInitialize() { PortfolioManager.Clear(); ComService.AddUdpClient(Config.DEFAULT_UDP_CLIENT, 0); ConversationManager.Start(ConversationBuilder); }
public MainWindow() { InitializeComponent(); _ComService = ComService.Instance(); }
public void TestInitialize() { ComService.AddUdpClient(Config.DEFAULT_UDP_CLIENT, 0); ConversationManager.Start(null); }
private void Inject_Click(object sender, RoutedEventArgs e) { Console.WriteLine("injecting"); ComService.Instance().StartService(); Console.WriteLine("injecting Complete"); }
public void TestCleanup() { ConversationManager.Stop(); ComService.RemoveClient(Config.DEFAULT_UDP_CLIENT); }
public override void Send() { base.Send(); Conversation.UpdateState(new ConversationDoneState(Conversation, this)); ComService.RemoveClient(To.ToString()); }