private static void PrepareCommonData(string sessionId) { if (common_data_size > 0) { #if HPCPACK byte[] common_data = new byte[common_data_size]; Random r = new Random(); r.NextBytes(common_data); commonData_dataClientId = sessionId.ToString(); Log("Begin to write common data."); data.CreateDataClientStart = DateTime.Now; using (DataClient dataClient = DataClient.Create(headnode, commonData_dataClientId, null, !onDemand)) { data.CreateDataClientEnd = DateTime.Now; dataClient.SetDataLifeCycle(new DataLifeCycle(sessionId)); data.WriteDataClientStart = DateTime.Now; dataClient.WriteRawBytesAll(common_data, common_data_compress); data.WriteDataClientEnd = DateTime.Now; dataClient.Close(); } Log("Common data written done."); #else throw new NotSupportedException("No common data support yet."); #endif } else { Log("Common data size is 0, skip creating common data."); } }
internal void Init(ConfigEntity config) { try { if (null == client) { client = new DataClient(ushort.MaxValue); client.DataReceived += new DataReceived(client_DataReceived); client.MessageReceived += new MessageReceived(client_MessageReceived); client.Disconnected += new EventHandler(client_Disconnected); } if (client.Connected) { client.Close(); } iotConfig = config; } catch (Exception ex) { NLogHelper.ExceptionInfo(ex, "InitClientException:{0}", ex.Message); } }
private void GetClicked(object sender, RoutedEventArgs e) { var client = new DataClient(); int i = int.Parse(param.Text); var trades = client.GetData(i); result.Content = string.Empty; foreach (var t in trades) { result.Content += string.Format("{0}: {1} £{2} of {3}\n", t.ID, t.IsBuy ? "Buy" : "Sell", t.Amount, t.MarketName); } client.Close(); }
// So, the algorithm is next: // client connects with login and password -> server check credentials, //// if exist => generate token, add it to db and send to client, //// if not exist => send message with error // all user actions need a token to complete // then user send message -> server takes it -> add to db // and then clients should request new updates public void Process() { try { bool done = false; while (!done) { var request = client.ReadMessage(); switch (request.Command !) { case Command.Login: Login(request); break; case Command.Logout: done = true; break; case Command.Register: Register(request); break; case Command.SendMessage: SendMessage(request); break; case Command.GetMessages: GetMessage(request); break; case Command.GetMessagesFromTimestamp: GetMessagesFromTimestamp(request); break; case Command.SendFile: SendFile(request); break; case Command.GetFile: GetFile(request); break; default: UnknownCommand(); break; } } } catch (Exception ex) { //throw; Logger.Exception($"{ex.GetType()}: {ex.Message}"); } finally { if (_user != null) { Logout(); } client.Close(); Active = false; Logger.Info($"Client <{User?.UserId.ToString() ?? "00000000-0000-0000-0000-000000000000"}> disconnected."); } }