public PosStoreClient() { var config = SocketClientConfig.GetConfig(); if (string.IsNullOrEmpty(config.StoreId) || config.CompanyId == 0) { Thread.CurrentThread.Abort(); return; } ReflectCommand(); isDispose = false; this.Initialize(new PosStoreFixedHeaderReceiveFilter(new PosStoreCommandNameProvider()), (package) => { if (cmdRount.ContainsKey(package.Key) && cmdRount[package.Key] != null) { var type = cmdRount[package.Key]; var cmd = (ICommand)AppDomain.CurrentDomain.CreateInstance(type.Assembly.FullName, type.ToString()).Unwrap(); if (cmd.Key == package.Key) { cmd.Execute(this, package); } } }); var connected = this.ConnectAsync(new IPEndPoint(IPAddress.Parse(config.Ip), config.Port)); connected.Wait(); SendHeartbeatPacket(); SubscribeStoreMesssage(); }
public void SendObject(byte[] cmdCode, object obj) { JsonSerializer serializer = new JsonSerializer(); serializer.NullValueHandling = NullValueHandling.Ignore; MemoryStream s = new MemoryStream(); StreamWriter sw = new StreamWriter(s); using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, obj); } var body = s.ToArray(); sw.Close(); s.Close(); // Send data to the server var content = this.Format(cmdCode, body); if (!this.IsConnected) { var config = SocketClientConfig.GetConfig(); var connected = this.ConnectAsync(new IPEndPoint(IPAddress.Parse(config.Ip), config.Port)); connected.Wait(); } this.Send(new ArraySegment <byte>(content)); }
public ServiceSettings GetServiceSettings() { var uri = GetEndpointAddress("WSHttpBinding_PosServerDbSyncService"); return(new ServiceSettings() { Redis = RedisConfiguration.GetConfig().ConnectionString, SocketIp = SocketClientConfig.GetConfig().Ip, SocketPort = SocketClientConfig.GetConfig().Port, WCFIp = (uri == default(Uri) ? "192.168.10.122" : uri.Host), WCFPort = (uri == default(Uri) ? 808 : uri.Port) }); }
private void SendHeartbeatPacket() { Task.Factory.StartNew((s) => { if (isDispose) { return; } while (!cancelTokenSource.IsCancellationRequested) { try { var config = SocketClientConfig.GetConfig(); this.SendObject(new byte[4] { 0x00, 0x00, 0x00, 0x01 }, new StoreInfo { CompanyId = config.CompanyId, StoreId = config.StoreId }); Thread.Sleep(5000); } catch { } } }, cancelTokenSource.Token); }
private void SendHeartbeatPacket() { Task.Factory.StartNew(() => { if (isDispose) { return; } while (true) { try { var config = SocketClientConfig.GetConfig(); this.SendObject(new byte[4] { 0x00, 0x00, 0x00, 0x01 }, new StoreInfo { CompanyId = config.CompanyId, StoreId = config.StoreId }); Thread.Sleep(5000); } catch { } } }); }