public ServiceClient(IClientLogic logic, IPAddress hostIP, int port, int interfaceId, long ticket) { this.logic = logic; client = new DynamicClient(hostIP, port); tree = new ProtocolTree(); root = new DummyHandler <DummyProtocol>(); auth = new LeafProtocolHandler <AuthenticationProtocol>(); tree.Register(root); tree.Register(auth); tree.Entry(root); tree.ConnectToLeaf(root, auth); tree.Connect(root, logic.ProtocolTree); app = new ApplicationConnectionManager(client, tree, 3000, 6000); auth.NewData += data => { switch (data.statusCode) { case AuthenticationProtocol.StatusCode.Request: Logger.Log("receiving auth request", "ServiceClient"); auth.Send(new AuthenticationProtocol { interfaceId = interfaceId, ticket = ticket, resumeToken = ResumeToken, statusCode = AuthenticationProtocol.StatusCode.Ack }); break; case AuthenticationProtocol.StatusCode.Accept: Logger.Log("auth accepted by the host", "ServiceClient"); ResumeToken = data.resumeToken; ConnectionAccepted?.Invoke(); break; case AuthenticationProtocol.StatusCode.Reject: Logger.Log($"auth rejected by the host, {data.reason}", "ServiceClient", Logger.LogType.WARNING); rejected = true; client.CloseConnection(); app.Dispose(); ConnectionRejected?.Invoke(); break; default: Logger.Log("invalid auth msg from host", "ServiceClient", Logger.LogType.WARNING); break; } }; app.ConnectionLost += () => { if (!rejected) { ConnectionLost?.Invoke(); } }; }
public void GetMemberName() { dynamic client = new DynamicClient(); var output = client.New.GetAsync(); Assert.Equal("New.GetAsync", output); }
public void DI_Container_ShouldResolveDynamicallyWithoutRegistration() { var builder = new ContainerBuilder(); builder.RegisterType <DynamicComponent>().InstancePerDependency(); builder.RegisterType <DynamicClient>().InstancePerDependency(); using (var container = builder.Build()) using (var scope = container.BeginLifetimeScope()) { DynamicClient np = scope.Resolve <DynamicClient>(); Assert.Equal("satoshi", np.GetMessage()); } }
static void Main(string[] args) { string filePath = "E:/r.txt"; if (!File.Exists(filePath)) { Console.WriteLine("transfer complete"); return; } StreamReader r = new StreamReader(filePath); ST state = new ST(); state.seq = Convert.ToInt64(r.ReadLine()); r.Close(); DynamicClient client = new DynamicClient(IPAddress.Parse("192.168.1.73"), 54321); //WsClient client = new WsClient("ws://192.168.1.73:54322/ws"); ProtocolTree tree = new ProtocolTree(); LeafProtocolHandler <Data> leaf = new LeafProtocolHandler <Data>(); LeafProtocolHandler <Rec> rec = new LeafProtocolHandler <Rec>(); LeafProtocolHandler <Done> done = new LeafProtocolHandler <Done>(); tree.Register(leaf); tree.Register(rec); tree.Register(done); tree.EntryToLeaf(leaf); tree.EntryToLeaf(rec); tree.EntryToLeaf(done); ApplicationConnectionManager app = new ApplicationConnectionManager(client, tree, state, 1000, 2000); bool finish = false; void conn() { while (true) { Console.WriteLine("connecting... "); if (client.Connect()) { Console.WriteLine("connected!!!! "); break; } else { Console.WriteLine("connect failed"); Thread.Sleep(1000); } } } /*client.ConnectionLost += () => * { * conn(); * };*/ app.ConnectionLost += () => { conn(); }; string wpath = "E:/recv.zip"; FileStream ws = new FileStream(wpath, FileMode.Append, FileAccess.Write); ws.Seek(state.seq, SeekOrigin.Begin); leaf.NewData += d => { try { ws.Write(d.data, 0, d.data.Length); ws.Flush(); state.seq += d.data.Length; File.WriteAllText(filePath, state.seq.ToString()); Console.WriteLine($"received {d.data.Length}, now pointer is {state.seq} "); } catch (Exception e) { Console.WriteLine(e.Message); } }; done.NewData += obj => { finish = true; File.Delete(filePath); }; conn(); while (true) { if (finish) { Console.WriteLine("finished!!"); break; } Thread.Sleep(100); } }