private HttpSender(Builder builder) : base(ProtocolType.Binary, builder.MaxPacketSize) { Uri collectorUri = new UriBuilder(builder.Endpoint) { Query = HttpCollectorJaegerThriftFormatParam }.Uri; var customHeaders = new Dictionary <string, string>(); if (builder.AuthenticationHeaderValue != null) { customHeaders.Add("Authorization", builder.AuthenticationHeaderValue.ToString()); } var customProperties = new Dictionary <string, object> { // Note: This ensures that internal requests from the tracer are not instrumented // by https://github.com/opentracing-contrib/csharp-netcore { "ot-ignore", true } }; _transport = new THttpTransport(collectorUri, customHeaders, builder.HttpHandler, builder.Certificates, builder.UserAgent, customProperties); _protocol = ProtocolFactory.GetProtocol(_transport); }
// Login Password public override void addPassword(Scheme scheme, int port, String hostName, String user, String password) { Host host = new Host(ProtocolFactory.get().forScheme(scheme), hostName, port); host.getCredentials().setUsername(user); PreferencesFactory.get().setProperty(new HostUrlProvider().get(host), DataProtector.Encrypt(password)); }
// Login Password public override string getPassword(Scheme scheme, int port, String hostName, String user) { Host host = new Host(ProtocolFactory.get().forScheme(scheme), hostName, port); host.getCredentials().setUsername(user); return(getPassword(host)); }
static MainController() { StructureMapBootstrapper.Bootstrap(); if (!(Debugger.IsAttached || Utils.IsRunningAsUWP)) { // Add the event handler for handling UI thread exceptions to the event. System.Windows.Forms.Application.ThreadException += ExceptionHandler; // Set the unhandled exception mode to force all Windows Forms errors to go through // our handler. System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // Add the event handler for handling non-UI thread exceptions to the event. AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; } //make sure that a language change takes effect after a restart only StartupLanguage = PreferencesFactory.get().getProperty("application.language"); ProtocolFactory.get().register(new FTPProtocol(), new FTPTLSProtocol(), new SFTPProtocol(), new DAVProtocol(), new DAVSSLProtocol(), new SwiftProtocol(), new S3Protocol(), new GoogleStorageProtocol(), new AzureProtocol(), new IRODSProtocol(), new SpectraProtocol(), new B2Protocol(), new DriveProtocol(), new DropboxProtocol(), new HubicProtocol(), new LocalProtocol(), new OneDriveProtocol(), new SharepointProtocol(), new MantaProtocol(), new SDSProtocol(), new StoregateProtocol(), new BrickProtocol(), new NextcloudProtocol()); ProtocolFactory.get().loadDefaultProfiles(); }
public static void Execute___Should_return_last_registered_protocol___When_second_protocol_supporting_same_operation_is_registered_with_ProtocolAlreadyRegisteredForOperationStrategy_Replace() { // Arrange var systemUnderTest = new ProtocolFactory(); IProtocol protocol1 = new SharedOperationProtocol1(); IProtocol protocol2 = new SiblingOperationProtocol(); systemUnderTest.RegisterProtocolForSupportedOperations(typeof(SharedOperationProtocol1), () => new SharedOperationProtocol1()); systemUnderTest.RegisterProtocolForSupportedOperations(typeof(SiblingOperationProtocol), () => new SiblingOperationProtocol()); systemUnderTest.RegisterProtocolForSupportedOperations(typeof(SharedOperationProtocol1), () => protocol1, ProtocolAlreadyRegisteredForOperationStrategy.Replace); systemUnderTest.RegisterProtocolForSupportedOperations(typeof(SiblingOperationProtocol), () => protocol2, ProtocolAlreadyRegisteredForOperationStrategy.Replace); var operation1 = new GetProtocolOp(new SharedOperation()); var operation2 = new GetProtocolOp(new SiblingOperation1()); var operation3 = new GetProtocolOp(new SiblingOperation2()); // Act var actual1 = systemUnderTest.Execute(operation1); var actual2 = systemUnderTest.Execute(operation2); var actual3 = systemUnderTest.Execute(operation3); // Assert actual1.AsTest().Must().BeSameReferenceAs(protocol1); actual2.AsTest().Must().BeSameReferenceAs(protocol2); actual3.AsTest().Must().BeSameReferenceAs(protocol2); }
public static void Execute___Should_return_registered_protocol___When_called() { // Arrange var systemUnderTest = new ProtocolFactory(); IProtocol protocol1 = new SharedOperationProtocol1(); IProtocol protocol2 = new SiblingOperationProtocol(); systemUnderTest.RegisterProtocolForSupportedOperations(typeof(SharedOperationProtocol1), () => protocol1); systemUnderTest.RegisterProtocolForSupportedOperations(typeof(SiblingOperationProtocol), () => protocol2); var operation1 = new GetProtocolOp(new SharedOperation()); var operation2 = new GetProtocolOp(new SiblingOperation1()); var operation3 = new GetProtocolOp(new SiblingOperation2()); // Act var actual1 = systemUnderTest.Execute(operation1); var actual2 = systemUnderTest.Execute(operation2); var actual3 = systemUnderTest.Execute(operation3); // Assert actual1.AsTest().Must().BeSameReferenceAs(protocol1); actual2.AsTest().Must().BeSameReferenceAs(protocol2); actual3.AsTest().Must().BeSameReferenceAs(protocol2); }
private static void RegisterImplementations() { LicenseImpl.Register(); Proxy.Register(); LocalImpl.Register(); LocaleImpl.Register(); UserPreferences.Register(); Keychain.Register(); PlistWriter.Register(); PlistSerializer.Register(); PlistDeserializer.Register(); HostPlistReader.Register(); TransferPlistReader.Register(); ProtocolPlistReader.Register(); TcpReachability.Register(); GrowlImpl.Register(); TreePathReference.Register(); LoginController.Register(); HostKeyController.Register(); UserDefaultsDateFormatter.Register(); if (Preferences.instance().getBoolean("rendezvous.enable")) { Rendezvous.Register(); } ProtocolFactory.register(); }
public static void Constructor___Should_register_protocols_in_protocolTypeToGetProtocolFuncMap___When_called() { // Arrange IProtocol protocol1 = new SharedOperationProtocol1(); IProtocol protocol2 = new SiblingOperationProtocol(); var protocolTypeToGetProtocolFuncMap = new Dictionary <Type, Func <IProtocol> > { { typeof(SharedOperationProtocol1), () => protocol1 }, { typeof(SiblingOperationProtocol), () => protocol2 }, }; var systemUnderTest = new ProtocolFactory(protocolTypeToGetProtocolFuncMap); var operation1 = new GetProtocolOp(new SharedOperation()); var operation2 = new GetProtocolOp(new SiblingOperation1()); var operation3 = new GetProtocolOp(new SiblingOperation2()); // Act var actual1 = systemUnderTest.Execute(operation1); var actual2 = systemUnderTest.Execute(operation2); var actual3 = systemUnderTest.Execute(operation3); // Assert actual1.AsTest().Must().BeSameReferenceAs(protocol1); actual2.AsTest().Must().BeSameReferenceAs(protocol2); actual3.AsTest().Must().BeSameReferenceAs(protocol2); }
public virtual void Deal(LuaFunction dealFunc) { try { if (dealFunc != null) { GameMainLoopManager.Instance.AddActionDoInMainThread(() => { var luaState = LuaFileManager.Instance.luaState; if (luaState != null) { ProtoType type = ProtocolFactory.CheckIsLuaProto(ID); if (type == ProtoType.TcpLuaProto) { dealFunc.Call <int, string>(ID, Data.ToString()); } else { dealFunc.Call <int, string>(ID, JsonConvert.SerializeObject(this)); } } }); } } catch (System.Exception e) { Debug.LogWarning(e.Message); } }
/// <summary> /// 生成可发送命令(按时间排序) /// </summary> private void CreatePacketesToSend() { var packet = new List <byte>(); IMakeDataTransportPacket createbigDataTransportPacket = ProtocolFactory.CreateDataTransportPacket(TransportDataType.BigData); IMakeDataTransportPacket createGeneralDataTransportPacket = ProtocolFactory.CreateDataTransportPacket(TransportDataType.General); var datumList = new List <Data>(); while (datasTobesent.Count > 0) { Data data; if (datasTobesent.TryDequeue(out data)) { if (data != null) { datumList.Add(data); } } } var sortedList = datumList.OrderBy(i => i.CollectTime).ToList(); var N = sortedList.Count; for (var i = 0; i < N; i++) { var data = sortedList[i]; int structureId = GetStructureId(data); if (data.SafeTypeId == (int)SensorCategory.Vibration) { byte[][] packeBytes = createbigDataTransportPacket.MakeDataTransportPacket(data, structureId); foreach (byte[] packeByte in packeBytes) { this.packetsToSend.Enqueue(packeByte); // this.packetsToSend.Enqueue(null); } } else { var packeBytes = createGeneralDataTransportPacket.MakeDataTransportPacket(data, structureId); if (packet.Count + packeBytes[0].Length < 1024) { packet.AddRange(packeBytes[0]); if (i == N - 1) { this.packetsToSend.Enqueue(packet.ToArray()); packet.Clear(); } } else { this.packetsToSend.Enqueue(packet.ToArray()); packet.Clear(); packet.AddRange(packeBytes[0]); } } } }
private void OpenConnection(ConnectionInfo connectionInfo, ConnectionInfo.Force force, Form conForm) { try { if (connectionInfo.Hostname == "" && connectionInfo.Protocol != ProtocolType.IntApp) { Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, Language.strConnectionOpenFailedNoHostname); return; } StartPreConnectionExternalApp(connectionInfo); if (!force.HasFlag(ConnectionInfo.Force.DoNotJump)) { if (SwitchToOpenConnection(connectionInfo)) { return; } } var protocolFactory = new ProtocolFactory(); var newProtocol = protocolFactory.CreateProtocol(connectionInfo); var connectionPanel = SetConnectionPanel(connectionInfo, force); if (string.IsNullOrEmpty(connectionPanel)) { return; } var connectionForm = SetConnectionForm(conForm, connectionPanel); var connectionContainer = SetConnectionContainer(connectionInfo, connectionForm); SetConnectionFormEventHandlers(newProtocol, connectionForm); SetConnectionEventHandlers(newProtocol); BuildConnectionInterfaceController(connectionInfo, newProtocol, connectionContainer); newProtocol.Force = force; if (newProtocol.Initialize() == false) { newProtocol.Close(); return; } if (newProtocol.Connect() == false) { newProtocol.Close(); return; } connectionInfo.OpenConnections.Add(newProtocol); _activeConnections.Add(connectionInfo.ConstantID); FrmMain.Default.SelectedConnection = connectionInfo; } catch (Exception ex) { Runtime.MessageCollector.AddExceptionStackTrace(Language.strConnectionOpenFailed, ex); } }
public ChatConnection(IServiceProvider services, ChatHub chatHub, ProtocolFactory protocolFactory, IOptions <ProxyOptions> options, IOptions <SqlServerOptions> sqlOptions, ILogger <ChatConnection> logger) { _services = services; _chatHub = chatHub; _protocolFactory = protocolFactory; _options = options.Value; _sqlOptions = sqlOptions.Value; _logger = logger; }
private void DecodePacket() { // Since all protocol packets are encapsulated in the IP datagram // so we start by parsing the IP header and see what protocol data // is being carried by it IPHeader = new IPHeader(m_packet, m_dataLength); ProtocolHeader = ProtocolFactory.Factory(IPHeader.ProtocolType, IPHeader.DataGram, IPHeader.MessageLength); }
private void InitProtocols() { List <KeyValueIconTriple <Protocol, string> > protocols = new List <KeyValueIconTriple <Protocol, string> >(); foreach (Protocol p in ProtocolFactory.getKnownProtocols().toArray(new Protocol[] {})) { protocols.Add(new KeyValueIconTriple <Protocol, string>(p, p.getDescription(), p.getIdentifier())); } View.PopulateProtocols(protocols); }
internal JaegerThriftHttpSender(Uri uri) : base(new TBinaryProtocol.Factory()) { var collectorUri = new UriBuilder(uri) { Query = TransportConstants.CollectorHttpJaegerThriftFormatParam }.Uri; var httpTransport = new THttpClientTransport(collectorUri, null); _protocol = ProtocolFactory.GetProtocol(httpTransport); }
public TThreadPoolServer(Processor processor, ServerTransport serverTransport, TransportFactory transportFactory, ProtocolFactory protocolFactory) : this(processor, serverTransport, transportFactory, transportFactory, protocolFactory, protocolFactory, DEFAULT_MIN_THREADS, DEFAULT_MAX_THREADS, DefaultLogDelegate) { }
void Instance_OnLog(Protocol arg1, IPEndPoint arg2) { if (arg1.id == ProtocolMessage.Broadcast) { var b = ProtocolFactory.GetSubProtocol <BroadcastProtocol>(arg1); Invoke2(() => textBox1.AppendText(String.Format("{0} : {1}:{2} {3}" + Environment.NewLine, arg2.ToString(), b.ip, b.port, b.type))); return; } Invoke2(() => textBox2.AppendText(String.Format("{0} : {1} {2}" + Environment.NewLine, arg2.ToString(), arg1.id, arg1.host))); }
private static ChainOfResponsibilityProtocolFactory BuildProtocolFactoryToExecuteAllOperations( this ReportCache reportCache, DateTime timestampUtc, IReadOnlyCollection <Func <IProtocolFactory, IProtocolFactory> > protocolFactoryFuncs, IReadOnlyCollection <Type> additionalTypesForCoreCellOps, Func <RecalcPhase> getRecalcPhaseFunc) { protocolFactoryFuncs = protocolFactoryFuncs ?? new List <Func <IProtocolFactory, IProtocolFactory> >(); if (protocolFactoryFuncs.Any(_ => _ == null)) { throw new ArgumentException(Invariant($"{nameof(protocolFactoryFuncs)} contains a null element.")); } additionalTypesForCoreCellOps = additionalTypesForCoreCellOps ?? new List <Type>(); if (additionalTypesForCoreCellOps.Any(_ => _ == null)) { throw new ArgumentException(Invariant($"{nameof(additionalTypesForCoreCellOps)} contains a null element.")); } var result = new ChainOfResponsibilityProtocolFactory(); // Add caller's protocols to the chain of responsibility. foreach (var protocolFactoryFunc in protocolFactoryFuncs) { result.AddToEndOfChain(protocolFactoryFunc(result)); } // Add DataStructureCellProtocols{TValue} and DataStructureConvenienceProtocols{TResult} to chain of responsibility. var typesForCoreCellOps = DefaultTypesSupportedForCoreCellOps .Concat(additionalTypesForCoreCellOps) .ToList(); var coreProtocolsFactory = new ProtocolFactory(); ConstructorInfo GetCellProtocolsFunc(Type type) => typeof(DataStructureCellProtocols <>).MakeGenericType(type).GetConstructors().Single(); ConstructorInfo GetConvenienceProtocolsFunc(Type type) => typeof(DataStructureConvenienceProtocols <>).MakeGenericType(type).GetConstructors().Single(); var cellProtocolsConstructorInfoParams = new object[] { reportCache, result, timestampUtc, getRecalcPhaseFunc }; var convenienceProtocolsConstructorInfoParams = new object[] { result }; foreach (var typeForCoreCellOps in typesForCoreCellOps) { RegisterProtocols(typeForCoreCellOps, CachedTypeToCellProtocolsConstructorInfoMap, coreProtocolsFactory, GetCellProtocolsFunc, cellProtocolsConstructorInfoParams); RegisterProtocols(typeForCoreCellOps, CachedTypeToConvenienceProtocolsConstructorInfoMap, coreProtocolsFactory, GetConvenienceProtocolsFunc, convenienceProtocolsConstructorInfoParams); } result.AddToEndOfChain(coreProtocolsFactory); return(result); }
public static void RegisterProtocolForSupportedOperations___Should_throw_ArgumentException___When_protocol_does_not_execute_any_operations() { // Arrange var systemUnderTest = new ProtocolFactory(); // Act var actual = Record.Exception(() => systemUnderTest.RegisterProtocolForSupportedOperations(typeof(ProtocolWithNoOperations), A.Dummy <IProtocol>)); // Assert actual.AsTest().Must().BeOfType <ArgumentException>(); actual.Message.AsTest().Must().ContainString(Invariant($"Protocol '{nameof(ProtocolFactoryTest)}.{nameof(ProtocolWithNoOperations)}' does not execute any operations.")); }
public static void Execute___Should_throw_ArgumentNullException___When_parameter_operation_is_null() { // Arrange var systemUnderTest = new ProtocolFactory(); // Act var actual = Record.Exception(() => systemUnderTest.Execute(null)); // Assert actual.AsTest().Must().BeOfType <ArgumentNullException>(); actual.Message.AsTest().Must().ContainString("operation"); }
public static void RegisterProtocolForSupportedOperations___Should_throw_ArgumentNullException___When_parameter_getProtocolFunc_is_null() { // Arrange var systemUnderTest = new ProtocolFactory(); // Act var actual = Record.Exception(() => systemUnderTest.RegisterProtocolForSupportedOperations(A.Dummy <IProtocol>().GetType(), null)); // Assert actual.AsTest().Must().BeOfType <ArgumentNullException>(); actual.Message.AsTest().Must().ContainString("getProtocolFunc"); }
public static void RegisterProtocolForSupportedOperations___Should_throw_ArgumentException___When_parameter_protocolType_is_not_assignable_to_IProtocol() { // Arrange var systemUnderTest = new ProtocolFactory(); // Act var actual = Record.Exception(() => systemUnderTest.RegisterProtocolForSupportedOperations(typeof(object), A.Dummy <IProtocol>)); // Assert actual.AsTest().Must().BeOfType <ArgumentException>(); actual.Message.AsTest().Must().ContainString("protocolType 'object' is not assignable to IProtocol"); }
private void _server_DataReceived(object sender, Message e) { Console.WriteLine("Packet Weight : " + e.Data.Count() + " bytes"); Thread thread = new Thread(delegate() { var tmp = SimpleTcpAdapter.Convert(e.TcpClient); var packet = new BasicPacket(); if (!packet.Parse(e.Data)) { var packets = SplitPacket(e.Data); foreach (var pk in packets) { Thread.Sleep(500); Thread t = new Thread(delegate() { var pack = new BasicPacket(); if (!pack.Parse(pk)) { return; } var ptc = ProtocolFactory.CreateProtocol(pack.Opcode); if (!ptc.Parse(Encoding.Unicode.GetString(pack.Data))) { return; } var handling = HandleFactory.CreateHandle(pack.Opcode); string toview = handling.Handling(ptc, tmp); if (OnNewMessage != null) { OnNewMessage.Invoke(tmp, toview); } }); t.Start(); } return; } var protocol = ProtocolFactory.CreateProtocol(packet.Opcode); if (!protocol.Parse(Encoding.Unicode.GetString(packet.Data))) { return; } var handle = HandleFactory.CreateHandle(packet.Opcode); string toView = handle.Handling(protocol, tmp); if (OnNewMessage != null) { OnNewMessage.Invoke(tmp, toView); } }); thread.Priority = ThreadPriority.Highest; thread.Start(); }
private static void OpenConnectionFinal(ConnectionInfo ConnectionInfo, ConnectionInfo.Force Force, Form ConForm) { try { if (ConnectionInfo.Hostname == "" && ConnectionInfo.Protocol != ProtocolType.IntApp) { MessageCollector.AddMessage(MessageClass.WarningMsg, Language.strConnectionOpenFailedNoHostname); return; } StartPreConnectionExternalApp(ConnectionInfo); if ((Force & ConnectionInfo.Force.DoNotJump) != ConnectionInfo.Force.DoNotJump) { if (SwitchToOpenConnection(ConnectionInfo)) { return; } } ProtocolFactory protocolFactory = new ProtocolFactory(); ProtocolBase newProtocol = protocolFactory.CreateProtocol(ConnectionInfo); string connectionPanel = SetConnectionPanel(ConnectionInfo, Force); Form connectionForm = SetConnectionForm(ConForm, connectionPanel); Control connectionContainer = SetConnectionContainer(ConnectionInfo, connectionForm); SetConnectionFormEventHandlers(newProtocol, connectionForm); SetConnectionEventHandlers(newProtocol); BuildConnectionInterfaceController(ConnectionInfo, newProtocol, connectionContainer); newProtocol.Force = Force; if (newProtocol.Initialize() == false) { newProtocol.Close(); return; } if (newProtocol.Connect() == false) { newProtocol.Close(); return; } ConnectionInfo.OpenConnections.Add(newProtocol); SetTreeNodeImages(ConnectionInfo); frmMain.Default.SelectedConnection = ConnectionInfo; } catch (Exception ex) { MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strConnectionOpenFailed + Environment.NewLine + ex.Message); } }
public IDictionary <String, Bitmap> GetProtocolIcons() { if (null == _protocolIcons) { _protocolIcons = new Dictionary <string, Bitmap>(); foreach (Protocol p in ProtocolFactory.get().find().toArray(new Protocol[] {})) { _protocolIcons[p.getIdentifier()] = IconForName(p.icon(), 16); } } return(_protocolIcons); }
public static void OpenConnection(ConnectionInfo connectionInfo, ConnectionInfo.Force force, Form conForm) { try { if (connectionInfo.Hostname == "" && connectionInfo.Protocol != ProtocolType.IntApp) { Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, Language.strConnectionOpenFailedNoHostname); return; } StartPreConnectionExternalApp(connectionInfo); if ((force & ConnectionInfo.Force.DoNotJump) != ConnectionInfo.Force.DoNotJump) { if (SwitchToOpenConnection(connectionInfo)) { return; } } var protocolFactory = new ProtocolFactory(); var newProtocol = protocolFactory.CreateProtocol(connectionInfo); var connectionPanel = SetConnectionPanel(connectionInfo, force); var connectionForm = SetConnectionForm(conForm, connectionPanel); var connectionContainer = SetConnectionContainer(connectionInfo, connectionForm); SetConnectionFormEventHandlers(newProtocol, connectionForm); SetConnectionEventHandlers(newProtocol); BuildConnectionInterfaceController(connectionInfo, newProtocol, connectionContainer); newProtocol.Force = force; if (newProtocol.Initialize() == false) { newProtocol.Close(); return; } if (newProtocol.Connect() == false) { newProtocol.Close(); return; } connectionInfo.OpenConnections.Add(newProtocol); frmMain.Default.SelectedConnection = connectionInfo; } catch (Exception ex) { Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strConnectionOpenFailed + Environment.NewLine + ex.Message); } }
public static void RegisterProtocolForSupportedOperations___Should_throw_ArgumentOutOfRangeException___When_parameter_protocolAlreadyRegisteredForOperationStrategy_is_Unknown() { // Arrange var systemUnderTest = new ProtocolFactory(); // Act var actual = Record.Exception(() => systemUnderTest.RegisterProtocolForSupportedOperations(A.Dummy <IProtocol>().GetType(), () => A.Dummy <IProtocol>(), ProtocolAlreadyRegisteredForOperationStrategy.Unknown)); // Assert actual.AsTest().Must().BeOfType <ArgumentOutOfRangeException>(); actual.Message.AsTest().Must().ContainString("protocolAlreadyRegisteredForOperationStrategy"); actual.Message.AsTest().Must().ContainString("Unknown"); }
public TSimpleServer(Processor processor, ServerTransport serverTransport, TransportFactory transportFactory, ProtocolFactory protocolFactory) : base(processor, serverTransport, transportFactory, transportFactory, protocolFactory, protocolFactory, DefaultLogDelegate) { }
public static void Execute___Should_return_null___When_there_is_no_protocol_registered_for_the_operation_and_missingProtocolStrategy_is_ReturnNull() { // Arrange var systemUnderTest = new ProtocolFactory(); var operation = new GetProtocolOp(new SharedOperation(), MissingProtocolStrategy.ReturnNull); // Act var actual = systemUnderTest.Execute(operation); // Assert actual.AsTest().Must().BeNull(); }
void OnGUI() { if (GUI.Button(new Rect(10, 10, 100, 50), "连接测试")) { Debug.Log("开始连接"); string ip = "192.168.0.43"; int port = 6000; NetWorkManage s_NetWorkManage = NetWorkManage.getInstance(); s_NetWorkManage.setHostPort(ip, port); if (!s_NetWorkManage.Connect()) { Debug.Log("服务器连接失败,请检查网络!"); return; } } if (GUI.Button(new Rect(150, 10, 100, 50), "登陆")) { //登录请求 Debug.Log("登录请求"); Msg_2_2 msg = new Msg_2_2(); msg.aid = "Test02"; //先写死角色名 msg.zoneId = 1; //先写死1 SendDataStruct data = new SendDataStruct(); data.cmd = 2; data.dest = 2; data.instance = msg; //NetWorkManage.SendData(2, 2, msg); NetWorkManage.SendData(data); } if (GUI.Button(new Rect(350, 10, 100, 50), "login")) { //登录请求 Debug.Log("login界面"); GameObject obj = UILayerManage.getInstance().CreateRoot("UILogin", "UILogin"); } if (GUI.Button(new Rect(500, 10, 100, 50), "抽象工厂模式")) { IProtocolFactory factory = new ProtocolFactory(); factory.createProtocolType1().DeserializeData(null); factory.createProtocolType2().DeserializeData(null); } }
public static void ReturnProtocolThreadSafe(Protocol protocol) { if (RegisterProtocolFactory != null && protocol != null) { lock (RegisterProtocolFactory) { ProtocolFactory factory = null; if (RegisterProtocolFactory.TryGetValue(protocol.GetMessageID(), out factory)) { factory.Return(protocol); } } } }
public static Protocol GetProtocolThreadSafe(int type) { Protocol protocol = null; lock (RegisterProtocolFactory) { ProtocolFactory factory = null; if (RegisterProtocolFactory.TryGetValue(type, out factory)) { protocol = factory.Get(); } } return(protocol); }
public TThreadedServer(Processor processor, ServerTransport serverTransport, TransportFactory inputTransportFactory, TransportFactory outputTransportFactory, ProtocolFactory inputProtocolFactory, ProtocolFactory outputProtocolFactory, int maxThreads, LogDelegate logDel) : base(processor, serverTransport, inputTransportFactory, outputTransportFactory, inputProtocolFactory, outputProtocolFactory, logDel) { this.maxThreads = maxThreads; clientQueue = new Queue<TTransport>(); clientLock = new object(); clientThreads = new THashSet<Thread>(); }
public TThreadPoolServer(Processor processor, ServerTransport serverTransport, TransportFactory inputTransportFactory, TransportFactory outputTransportFactory, ProtocolFactory inputProtocolFactory, ProtocolFactory outputProtocolFactory, int minThreadPoolThreads, int maxThreadPoolThreads, LogDelegate logDel) : base(processor, serverTransport, inputTransportFactory, outputTransportFactory, inputProtocolFactory, outputProtocolFactory, logDel) { lock (typeof(TThreadPoolServer)) { if (!ThreadPool.SetMinThreads(minThreadPoolThreads, minThreadPoolThreads)) { throw new Exception("Error: could not SetMinThreads in ThreadPool"); } if (!ThreadPool.SetMaxThreads(maxThreadPoolThreads, maxThreadPoolThreads)) { throw new Exception("Error: could not SetMaxThreads in ThreadPool"); } } }
public Server(Processor processor, ServerTransport serverTransport, TransportFactory inputTransportFactory, TransportFactory outputTransportFactory, ProtocolFactory inputProtocolFactory, ProtocolFactory outputProtocolFactory, LogDelegate logDelegate) { this.processor = processor; this.serverTransport = serverTransport; this.inputTransportFactory = inputTransportFactory; this.outputTransportFactory = outputTransportFactory; this.inputProtocolFactory = inputProtocolFactory; this.outputProtocolFactory = outputProtocolFactory; this.logDelegate = logDelegate; }
public THttpHandler(Processor processor, ProtocolFactory inputProtocolFactory, ProtocolFactory outputProtocolFactory) { this.processor = processor; this.inputProtocolFactory = inputProtocolFactory; this.outputProtocolFactory = outputProtocolFactory; }
public THttpHandler(Processor processor, ProtocolFactory protocolFactory) : this(processor, protocolFactory, protocolFactory) { }
public void Start(Uri url, ProtocolFactory protocol, int seeds = 0) { if (url == null) throw new ArgumentNullException("url"); _protocol = protocol; EndPoint = url; try { StartService(); // seed initial listener threads. seeds = seeds > 0 ? seeds : Environment.ProcessorCount; _queued = seeds; while (seeds-- > 0) ListenOn(); } catch { Stop(); throw; } }