internal bool IsPlaying(UserContext client) { if (client == null) { return(false); } var playing = false; var stopLoop = 0; OnEventDelegate tempReceive = (ctx) => { playing = (ctx.DataFrame.ToString() == "PLAYING"); stopLoop = 10000; }; client.SetOnReceive(tempReceive); client.Send("shutupify:PLAYING?"); while (stopLoop < 50) { stopLoop++; Thread.Sleep(10); } client.SetOnReceive(this.OnReceive); return(playing); }
public void On(string eventName, OnEventDelegate action) { if (EventTable == null) { EventTable = new Dictionary <string, OnEventDelegate>(); } EventTable[eventName] = action; }
protected override void OnStart(string[] args) { FEvent = new OnEventDelegate(Event); FEchoLog = new StreamWriter(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\EchoLog.txt"); FServer = new SocketServer(CallbackThreadType.ctWorkerThread, new EchoSocketService.EchoSocketService(FEvent), DelimiterType.dtMessageTailExcludeOnReceive, Encoding.GetEncoding(1252).GetBytes("ALAZ"), 1024 * 2, 1024 * 16); FServer.AddListener("Commom Port - 8090", new IPEndPoint(IPAddress.Any, 8090), EncryptType.etRijndael, CompressionType.ctNone, new EchoCryptService.EchoCryptService(), 50, 3); FServer.Start(); }
protected override void OnStart(string[] args) { FEvent = new OnEventDelegate(Event); FEchoLog = new StreamWriter(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\EchoLog.txt"); FServer = new SocketServer(new EchoSocketService.EchoSocketService(FEvent), DelimiterType.dtMessageTailExcludeOnReceive, Encoding.GetEncoding(1252).GetBytes("ALAZ"), 1024 * 2, 1024 * 16); FServer.AddListener("Commom Port - 8090", new IPEndPoint(IPAddress.Any, 8090), EncryptType.etRijndael, CompressionType.ctNone, new EchoCryptService.EchoCryptService(), 50, 3); FServer.Start(); }
public override void Unload() { base.Unload(); //BEGIN UNMANAGED FUNCTIONS _getTeamInfo = null; _onEvent = null; _getInstruction = null; _getPlacement = null; //END UNMANAGED FUNCTIONS }
private void RaiseTopControlsEvent <T>(T e, OnEventDelegate <T> del) where T : EventArgs, IHandelable { for (int i = 0; i < topLevelControls.Count; i++) { RaiseControlsEvent(topLevelControls[i], e, del); if (e.Handled) { break; } } }
/// <summary> /// With this function an event handler can be subscribed for an event name. /// </summary> public void On(string eventName, OnEventDelegate action) { if (EventTable == null) { EventTable = new Dictionary <string, OnEventDelegate>(); } EventTable[eventName] = action; #if UNITY_WEBGL && !UNITY_EDITOR ES_AddEventHandler(this.Id, eventName); #endif }
public CallTimer(OnEventDelegate onEvent, int DelaySec, bool RunOneTimeOnly) { LastTime = DateTime.Now.Ticks; this.Delay = DelaySec; this.OnEvent = onEvent; this.RunOneTime = RunOneTimeOnly; WaitingThead = new Thread(new ThreadStart(OnTimer)); WaitingThead.Name = "Timer"; WaitingThead.IsBackground = true; WaitingThead.Start(); }
public CallTimer(OnEventDelegate onEvent, int DelaySec, bool RunOneTimeOnly) { LastTime = DateTime.Now.Ticks; this.Delay = DelaySec; this.OnEvent = onEvent; this.RunOneTime = RunOneTimeOnly; WaitingThead = new Thread(new ThreadStart(OnTimer)); WaitingThead.Name = "Timer"; WaitingThead.IsBackground = true; WaitingThead.Start(); }
/// <summary> /// 初始化行情组件 /// </summary> private void InitRealtimeMarketComponent() { //登陆处理 GTASocketSingletonForRealTime.StartLogin("Apex", "Apex", ShowConnectMessage); //数据接受注册事件 this.FEvent += Event; SocketService = GTASocketSingletonForRealTime.SocketService; GTASocketSingletonForRealTime.SocketStateChanged += GTASocketSingleton_SocketStateChanged; SocketService.AddEventDelegate(this.FEvent); GTASocketSingletonForRealTime.SocketStatusHandle(SocketStatusChange); IRealtimeMarketService rms = RealtimeMarketServiceFactory.GetService(); }
private void RaiseControlsEvent <T>(GuiControl control, T e, OnEventDelegate <T> del) where T : EventArgs, IHandelable { if (e.Handled) { return; } for (int i = 0; i < control.Controls.Count; i++) { RaiseControlsEvent(control.Controls[i], e, del); } del(control, e); }
/// <summary> /// 初始化行情组件1 /// </summary> private void InitRealtimeMarketComponent1() { //登陆处理 //string username = "******"; //string password = "******"; string username = Utils.GetRealTimeUserName(); string password = Utils.GetRealTimePassword(); GTASocketSingletonForRealTime.StartLogin(username, password, ShowConnectMessage); //数据接受注册事件 this.FEvent += Event; SocketService = GTASocketSingletonForRealTime.SocketService; GTASocketSingletonForRealTime.SocketStateChanged += GTASocketSingleton_SocketStateChanged; SocketService.AddEventDelegate(this.FEvent); GTASocketSingletonForRealTime.SocketStatusHandle(SocketStatusChange); IRealtimeMarketService rms = RealtimeMarketServiceFactory.GetService(); }
/// <summary> /// Helper method to automatically invoke an event /// call if the value has changed. /// </summary> /// <typeparam name="TSender"></typeparam> /// <typeparam name="TArgs"></typeparam> /// <param name="eventDelegate"></param> /// <param name="valid">Whether or not the event should be invoked.</param> /// <param name="sender">The sender instance.</param> /// <param name="reference">A reference to be updated with the new value if valid.</param> /// <param name="value">The value to set the reference if valid.</param> public static Boolean InvokeIf <TSender, TArgs>( this OnEventDelegate <TSender, TArgs> eventDelegate, Boolean valid, TSender sender, ref TArgs reference, TArgs value) { if (valid) { reference = value; eventDelegate?.Invoke(sender, reference); return(true); } return(false); }
/// <summary> /// 移除广播监听 /// </summary> /// <param name="eventId"></param> /// <param name="handler"></param> public void Remove(T eventId, OnEventDelegate handler) { if (handler == null) { //LogUtils.Error("ObjectListenerEvent::Remove handler is null. eventId = ", eventId.ToString()); } List <OnEventDelegate> list; if (m_dic.ContainsKey(eventId)) { list = m_dic[eventId]; list.Remove(handler); if (list.Count == 0) { m_dic.Remove(eventId); } } }
/// <summary> /// 增加广播监听 /// </summary> /// <param name="eventId"></param> /// <param name="handler"></param> public void Add(T eventId, OnEventDelegate handler) { if (handler == null) { //LogUtils.Error("ObjectListenerEvent::Add handler is null. eventId = ", eventId.ToString()); } List <OnEventDelegate> list; if (m_dic.ContainsKey(eventId)) { list = m_dic[eventId]; list.Add(handler); } else { list = new List <OnEventDelegate>(); list.Add(handler); m_dic[eventId] = list; } }
public static void UnSubscrib <T>(OnEventDelegate <T> del) { ConcurrentBag <IEventHandle> bag; if (mDelegateMap.TryGetValue(typeof(T), out bag)) { ConcurrentBag <IEventHandle> removeBag = new ConcurrentBag <IEventHandle>(); foreach (DelWrapper <T> w in bag) { if (w.Delegate == del) { removeBag.Add(w); } } foreach (IEventHandle r in removeBag) { IEventHandle one = r; bag.TryTake(out one); } } }
/// <summary> /// 订阅事件 /// </summary> /// <param name="del"></param> public static void Subscrib <T>(OnEventDelegate <T> del) { DelWrapper <T> wrapper = new DelWrapper <T>(del); ConcurrentBag <IEventHandle> bag; if (mDelegateMap.TryGetValue(typeof(T), out bag)) { foreach (DelWrapper <T> w in bag) { if (w.Delegate == del) { return; } } } else { bag = new ConcurrentBag <IEventHandle>(); mDelegateMap.TryAdd(typeof(T), bag); } bag.Add(wrapper); }
public override bool Load(string dllPath, bool reverse, out Exception exception) { if (IsLoaded) { exception = new Exception("DLL has loaded."); return(false); } ReverseCoordinate = reverse; _lastDllPath = dllPath; var hModule = LoadLibrary(dllPath); var errorCode = Marshal.GetLastWin32Error(); if (hModule == IntPtr.Zero) { exception = new Exception($"Error load {dllPath}, code {errorCode}"); return(false); } CurrentModule = hModule; try { //BEGIN UNMANAGED FUNCTIONS _getTeamInfo = LoadFunction <GetTeamInfoDelegate>("GetTeamInfo"); _onEvent = LoadFunction <OnEventDelegate>("OnEvent"); _getInstruction = LoadFunction <GetInstructionDelegate>("GetInstruction"); _getPlacement = LoadFunction <GetPlacementDelegate>("GetPlacement"); _getControlInfo = LoadFunction <GetControlInfoDelegate>("GetControlInfo"); //END UNMANAGED FUNCTIONS } catch (ArgumentNullException e) { Unload(); exception = new Exception("Missing function", e); return(false); } exception = null; return(true); }
static void Main(string[] args) { Console.SetWindowSize(60, 25); ThreadPool.SetMinThreads(4, 4); ThreadPool.SetMaxThreads(32, 32); EncryptType et = EncryptType.etNone; CompressionType ct = CompressionType.ctNone; int port = 8090; int connections = 50; if (args.Length >= 1) { port = Convert.ToInt32(args[0]); } if (args.Length >= 2) { et = (EncryptType)Enum.Parse(typeof(EncryptType), args[1], true); } if (args.Length >= 3) { ct = (CompressionType)Enum.Parse(typeof(CompressionType), args[2], true); } //----- Socket Client! OnEventDelegate FEvent = new OnEventDelegate(Event); SocketClient echoClient = new SocketClient(new EchoSocketService.EchoSocketService(FEvent)); echoClient.Delimiter = new byte[] { 0xAA, 0xFF }; echoClient.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive; echoClient.SocketBufferSize = 4096; echoClient.MessageBufferSize = 4096 * 4; echoClient.IdleCheckInterval = 60000; echoClient.IdleTimeOutValue = 120000; //----- Socket Connectors! SocketConnector connector = null; for (int i = 0; i < connections; i++) { connector = echoClient.AddConnector("Connector " + i.ToString(), new IPEndPoint(IPAddress.Loopback, 8090)); /* * connector.ProxyInfo = new ProxyInfo( * ProxyType.ptHTTP, * new IPEndPoint(IPAddress.Loopback, 8000), * new NetworkCredential("user", "pass")); */ connector.CryptoService = new EchoCryptService.EchoCryptService(); connector.CompressionType = ct; connector.EncryptType = et; connector.ReconnectAttempts = 2; connector.ReconnectAttemptInterval = 5000; } Console.Title = "EchoConsoleClient / " + connections.ToString() + " Connections / " + Enum.GetName(typeof(EncryptType), et) + " / " + Enum.GetName(typeof(CompressionType), ct); echoClient.Start(); Console.WriteLine("Started!"); Console.WriteLine("----------------------"); Console.ReadLine(); try { echoClient.Stop(); echoClient.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } echoClient = null; Console.WriteLine("Stopped!"); Console.WriteLine("----------------------"); Console.ReadLine(); }
private static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); EncryptType et = EncryptType.etNone; CompressionType ct = CompressionType.ctNone; int port = 8090; int connections = 10; if (args.Length >= 1) { port = Convert.ToInt32(args[0]); } if (args.Length >= 2) { et = (EncryptType)Enum.Parse(typeof(EncryptType), args[1], true); } if (args.Length >= 3) { ct = (CompressionType)Enum.Parse(typeof(CompressionType), args[2], true); } //----- Socket Client! OnEventDelegate FEvent = new OnEventDelegate(Event); SocketClient echoClientProvider = new SocketClient(CallbackThreadType.ctWorkerThread, new EchoSocketService.EchoSocketService(FEvent)); echoClientProvider.Context.DelimiterEncrypt = new byte[] { 0xFF, 0x00, 0xFE, 0x01, 0xFD, 0x02 }; echoClientProvider.Context.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive; echoClientProvider.Context.SocketBufferSize = 1024; echoClientProvider.Context.MessageBufferSize = 2048; echoClientProvider.Context.IdleCheckInterval = 60000; echoClientProvider.Context.IdleTimeOutValue = 120000; //----- Socket Connectors! SocketConnector connector = null; for (int i = 0; i < connections; i++) { connector = echoClientProvider.AddConnector("Connector " + i.ToString(), new IPEndPoint(IPAddress.Loopback, 8090)); connector.Context.Host = echoClientProvider; /* connector.ProxyInfo = new ProxyInfo( ProxyType.ptHTTP, new IPEndPoint(IPAddress.Loopback, 8080), new NetworkCredential("test", "1234")); */ connector.Context.CryptoService = new EchoCryptService.EchoCryptService(); connector.Context.CompressionType = ct; connector.Context.EncryptType = et; connector.ReconnectAttempts = 10; connector.ReconnectAttemptInterval = 5000; } Console.Title = "EchoConsoleClient / " + connections.ToString() + " Connections / " + Enum.GetName(typeof(EncryptType), et) + " / " + Enum.GetName(typeof(CompressionType), ct); echoClientProvider.Start(); Console.WriteLine("Started!"); Console.WriteLine("----------------------"); Console.ReadLine(); try { echoClientProvider.Stop(); echoClientProvider.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } echoClientProvider = null; Console.WriteLine("Stopped!"); Console.WriteLine("----------------------"); Console.ReadLine(); }
public DelWrapper(OnEventDelegate <T> del) { mDelegate = del; }
/// <summary> /// Sets the on send event. /// </summary> /// <param name="ADelegate">The Event Delegate.</param> public void SetOnSend(OnEventDelegate ADelegate) { _OnSend = ADelegate; }
private void frmServer_Load(object sender, EventArgs e) { FEvent = new OnEventDelegate(Event); FConnectionCount = 0; }
/// <summary> /// Sets the on receive event. /// </summary> /// <param name="aDelegate">The Event Delegate.</param> public void SetOnReceive(OnEventDelegate aDelegate) { OnReceiveDelegate = aDelegate; }
/// <summary> /// Sets the on disconnect event. /// </summary> /// <param name="aDelegate">The Event Delegate.</param> public void SetOnDisconnect(OnEventDelegate aDelegate) { OnDisconnectDelegate = aDelegate; }
/// <summary> /// Sets the on disconnect event. /// </summary> /// <param name="ADelegate">The Event Delegate.</param> public void SetOnDisconnect(OnEventDelegate ADelegate) { _OnDisconnect = ADelegate; }
/// <summary> /// Sets the on receive event. /// </summary> /// <param name="ADelegate">The Event Delegate.</param> public void SetOnReceive(OnEventDelegate ADelegate) { _OnReceive = ADelegate; }
private static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); //----- Socket Server! OnEventDelegate FEvent = new OnEventDelegate(Event); SocketServer echoServerProvider = new SocketServer(CallbackThreadType.ctWorkerThread, new EchoSocketService.EchoSocketService(FEvent)); echoServerProvider.Context.DelimiterEncrypt = new byte[] { 0xFF, 0x00, 0xFE, 0x01, 0xFD, 0x02 }; echoServerProvider.Context.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive; echoServerProvider.Context.SocketBufferSize = 1024; echoServerProvider.Context.MessageBufferSize = 2048; echoServerProvider.Context.IdleCheckInterval = 60000; echoServerProvider.Context.IdleTimeOutValue = 120000; //----- Socket Listener! SocketListener listener = echoServerProvider.AddListener("Commom Port - 8090", new IPEndPoint(IPAddress.Any, 8090)); listener.AcceptThreads = 3; listener.BackLog = 100; listener.Context.Host = echoServerProvider; listener.Context.EncryptType = EncryptType.etNone; listener.Context.CompressionType = CompressionType.ctNone; listener.Context.CryptoService = new EchoCryptService.EchoCryptService(); echoServerProvider.Start(); Console.WriteLine("Started!"); Console.WriteLine("----------------------"); int iot = 0; int wt = 0; ThreadPool.GetAvailableThreads(out wt, out iot); Console.WriteLine("Threads Work - " + wt.ToString()); Console.WriteLine("Threads I/O - " + iot.ToString()); string s; do { s = Console.ReadLine(); if (s.Equals("g")) { ThreadPool.GetAvailableThreads(out wt, out iot); Console.WriteLine("Threads Work " + iot.ToString()); Console.WriteLine("Threads I/O " + wt.ToString()); } } while (s.Equals("g")); try { echoServerProvider.Stop(); echoServerProvider.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } echoServerProvider = null; Console.WriteLine("Stopped!"); Console.WriteLine("----------------------"); Console.ReadLine(); }
public EchoSocketService(OnEventDelegate eventDelegate) { FOnEventDelegate = eventDelegate; }
/// <summary> /// Sets the on connect event. /// </summary> /// <param name="ADelegate">The Event Delegate.</param> public void SetOnConnect(OnEventDelegate ADelegate) { _onConnect = ADelegate; }
/// <summary> /// Sets the on receive event. /// </summary> /// <param name="aDelegate">The Event Delegate.</param> public void SetOnReceive(OnEventDelegate aDelegate) { OnReceiveDelegate = aDelegate; }
/// <summary> /// Sets the on send event. /// </summary> /// <param name="aDelegate">The Event Delegate.</param> public void SetOnSend(OnEventDelegate aDelegate) { OnSendDelegate = aDelegate; }
/// <summary> /// Sets the on connected event. /// </summary> /// <param name="aDelegate">The Event Delegate.</param> public void SetOnConnected(OnEventDelegate aDelegate) { OnConnectedDelegate = aDelegate; }
public CallTimer(OnEventDelegate onEvent, int DelaySec) : this(onEvent,DelaySec,false) { }
/// <summary> /// Sets the on disconnect event. /// </summary> /// <param name="aDelegate">The Event Delegate.</param> public void SetOnDisconnect(OnEventDelegate aDelegate) { OnDisconnectDelegate = aDelegate; }
/// <summary> /// Sets the on disconnect event. /// </summary> /// <param name="ADelegate">The Event Delegate.</param> public void SetOnDisconnect(OnEventDelegate ADelegate) { _OnDisconnect = ADelegate; }
/// <summary> /// Sets the on send event. /// </summary> /// <param name="aDelegate">The Event Delegate.</param> public void SetOnSend(OnEventDelegate aDelegate) { OnSendDelegate = aDelegate; }
/// <summary> /// Sets the on connected event. /// </summary> /// <param name="aDelegate">The Event Delegate.</param> public void SetOnConnected(OnEventDelegate aDelegate) { OnConnectedDelegate = aDelegate; }
/// <summary> /// Sets the on send event. /// </summary> /// <param name="ADelegate">The Event Delegate.</param> public void SetOnSend(OnEventDelegate ADelegate) { _OnSend = ADelegate; }
public EchoSocketService() { FOnEventDelegate = null; }
public static extern IntPtr GetClassObject(IntPtr module, string name, OnErrorDelegate onError, OnEventDelegate onEvent, OnStatusDelegate onStatus);
private void frmServer_Load(object sender, EventArgs e) { FEvent = new OnEventDelegate(Event); FConnectionCount = 0; }
static void Main(string[] args) { Console.SetWindowSize(60, 25); ThreadPool.SetMinThreads(4, 4); ThreadPool.SetMaxThreads(32, 32); EncryptType et = EncryptType.etNone; CompressionType ct = CompressionType.ctNone; int port = 8090; int connections = 50; if (args.Length >= 1) { port = Convert.ToInt32(args[0]); } if (args.Length >= 2) { et = (EncryptType) Enum.Parse(typeof(EncryptType), args[1], true); } if (args.Length >= 3) { ct = (CompressionType) Enum.Parse(typeof(CompressionType), args[2], true); } //----- Socket Client! OnEventDelegate FEvent = new OnEventDelegate(Event); SocketClient echoClient = new SocketClient(new EchoSocketService.EchoSocketService(FEvent)); echoClient.Delimiter = new byte[] {0xAA, 0xFF}; echoClient.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive; echoClient.SocketBufferSize = 4096; echoClient.MessageBufferSize = 4096 * 4; echoClient.IdleCheckInterval = 60000; echoClient.IdleTimeOutValue = 120000; //----- Socket Connectors! SocketConnector connector = null; for (int i = 0; i < connections; i++) { connector = echoClient.AddConnector("Connector " + i.ToString(), new IPEndPoint(IPAddress.Loopback, 8090)); /* connector.ProxyInfo = new ProxyInfo( ProxyType.ptHTTP, new IPEndPoint(IPAddress.Loopback, 8000), new NetworkCredential("user", "pass")); */ connector.CryptoService = new EchoCryptService.EchoCryptService(); connector.CompressionType = ct; connector.EncryptType = et; connector.ReconnectAttempts = 2; connector.ReconnectAttemptInterval = 5000; } Console.Title = "EchoConsoleClient / " + connections.ToString() + " Connections / " + Enum.GetName(typeof(EncryptType), et) + " / " + Enum.GetName(typeof(CompressionType), ct); echoClient.Start(); Console.WriteLine("Started!"); Console.WriteLine("----------------------"); Console.ReadLine(); try { echoClient.Stop(); echoClient.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } echoClient = null; Console.WriteLine("Stopped!"); Console.WriteLine("----------------------"); Console.ReadLine(); }
public EchoSocketService() { FOnEventDelegate = null; }
/// <summary> /// Sets the on receive event. /// </summary> /// <param name="ADelegate">The Event Delegate.</param> public void SetOnReceive(OnEventDelegate ADelegate) { _OnReceive = ADelegate; }
public EchoSocketService(OnEventDelegate eventDelegate) { FOnEventDelegate = eventDelegate; }
/// <summary> /// With this function an event handler can be subscribed for an event name. /// </summary> public void On(string eventName, OnEventDelegate action) { if (EventTable == null) EventTable = new Dictionary<string, OnEventDelegate>(); EventTable[eventName] = action; }
public CallTimer(OnEventDelegate onEvent, int DelaySec) : this(onEvent, DelaySec, false) { }