public void RaiseOpen(OpenArgs openArgs) { if (Open != null) { Open(this, openArgs); } }
public void DynamicRpcGenericEvent() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); HelloService aService = new HelloService(); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); AutoResetEvent anEventReceived = new AutoResetEvent(false); string aReceivedEvent = ""; EventHandler <OpenArgs> anEventHandler = (x, y) => { aReceivedEvent = y.Name; anEventReceived.Set(); }; // Subscribe. anRpcClient.SubscribeRemoteEvent("Open", anEventHandler); // Raise the event in the service. OpenArgs anOpenArgs = new OpenArgs() { Name = "Hello" }; aService.RaiseOpen(anOpenArgs); Assert.IsTrue(anEventReceived.WaitOne()); Assert.AreEqual("Hello", aReceivedEvent); // Unsubscribe. anRpcClient.UnsubscribeRemoteEvent("Open", anEventHandler); // Try to raise again. aService.RaiseOpen(anOpenArgs); Assert.IsFalse(anEventReceived.WaitOne(1000)); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void RpcGenericEvent() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); HelloService aService = new HelloService(); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; AutoResetEvent anEventReceived = new AutoResetEvent(false); Action <object, OpenArgs> anEventHandler = (x, y) => { anEventReceived.Set(); }; // Subscribe. aServiceProxy.Open += anEventHandler.Invoke; // Raise the event in the service. OpenArgs anOpenArgs = new OpenArgs() { Name = "Hello" }; aService.RaiseOpen(anOpenArgs); Assert.IsTrue(anEventReceived.WaitOne()); // Unsubscribe. aServiceProxy.Open -= anEventHandler.Invoke; // Try to raise again. aService.RaiseOpen(anOpenArgs); Assert.IsFalse(anEventReceived.WaitOne(1000)); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public string GetInstanceId() { if (Open != null) { OpenArgs anArgs = new OpenArgs() { InstanceId = myInstanceId, Name = "Hello" }; Open(this, anArgs); } return(myInstanceId); }
public void Execute(OpenArgs args) { var dest = $"../../../{Path.GetFileNameWithoutExtension(args.Source)}"; Repository.Clone(args.Source, dest); using (var repo = new Repository(dest)) { var branchName = "development"; Branch trackedBranch = repo.Branches[$"origin/{branchName}"]; Debug.Assert(trackedBranch.IsRemote); var branch = repo.CreateBranch(branchName, trackedBranch.Tip); repo.Branches.Update(branch, b => b.TrackedBranch = trackedBranch.CanonicalName); LibGit2Sharp.Commands.Checkout(repo, branch); } }
private void OpenThread(OpenArgs oa) { Stopwatch sw = new Stopwatch(); sw.Start(); Open(oa.Price, oa.Qty, oa.Opentype, oa.Si, oa.Tickdata, oa.Zhuidan, oa.Tr); sw.Stop(); try { using (StreamWriter file = new StreamWriter(string.Format("{0}\\{1}.log", Application.StartupPath, "speed"), true)) { file.WriteLine(string.Format("下单耗时:{0}", sw.Elapsed.TotalMilliseconds)); file.Close(); } } catch { } }
public void MultipleClients_RemoteEvent_10() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.StartProfiler(); HelloService aService = new HelloService(); RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService); IRpcClient <IHello>[] aClients = new IRpcClient <IHello> [10]; for (int i = 0; i < aClients.Length; ++i) { aClients[i] = anRpcFactory.CreateClient <IHello>(); } try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); // Clients open connection. foreach (IRpcClient <IHello> aClient in aClients) { aClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); } // Subscribe to remote event from the service. AutoResetEvent anOpenReceived = new AutoResetEvent(false); AutoResetEvent aCloseReceived = new AutoResetEvent(false); AutoResetEvent anAllCleintsSubscribed = new AutoResetEvent(false); int anOpenCounter = 0; int aCloseCounter = 0; int aSubscribedClientCounter = 0; object aCounterLock = new object(); foreach (IRpcClient <IHello> aClient in aClients) { IRpcClient <IHello> aClientTmp = aClient; ThreadPool.QueueUserWorkItem(xx => { aClientTmp.Proxy.Open += (x, y) => { lock (aCounterLock) { ++anOpenCounter; if (anOpenCounter == aClients.Length) { anOpenReceived.Set(); } } }; aClientTmp.Proxy.Close += (x, y) => { lock (aCounterLock) { ++aCloseCounter; if (aCloseCounter == aClients.Length) { aCloseReceived.Set(); } } }; lock (aCounterLock) { ++aSubscribedClientCounter; if (aSubscribedClientCounter == aClients.Length) { anAllCleintsSubscribed.Set(); } } Thread.Sleep(1); }); } // Wait until all clients are subscribed. anAllCleintsSubscribed.WaitOne(); // Servicde raises two different events. OpenArgs anOpenArgs = new OpenArgs() { Name = "Hello" }; aService.RaiseOpen(anOpenArgs); aService.RaiseClose(); anOpenReceived.WaitOne(); aCloseReceived.WaitOne(); } finally { foreach (IRpcClient <IHello> aClient in aClients) { aClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void RpcGenericEvent_SerializerPerClient() { string aFirstClientId = null; RpcFactory anRpcClientFactory1 = new RpcFactory(new XmlStringSerializer()); RpcFactory anRpcClientFactory2 = new RpcFactory(new BinarySerializer()); RpcFactory anRpcServiceFactory = new RpcFactory() { SerializerProvider = x => (x == aFirstClientId) ? (ISerializer) new XmlStringSerializer() : (ISerializer) new BinarySerializer() }; HelloService aService = new HelloService(); IRpcService <IHello> anRpcService = anRpcServiceFactory.CreateSingleInstanceService <IHello>(aService); anRpcService.ResponseReceiverConnected += (x, y) => aFirstClientId = aFirstClientId ?? y.ResponseReceiverId; IRpcClient <IHello> anRpcClient1 = anRpcClientFactory1.CreateClient <IHello>(); IRpcClient <IHello> anRpcClient2 = anRpcClientFactory2.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient1.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId, "Client1")); anRpcClient2.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId, "Client2")); AutoResetEvent anEvent1Received = new AutoResetEvent(false); Action <object, OpenArgs> anEventHandler1 = (x, y) => { anEvent1Received.Set(); }; AutoResetEvent anEvent2Received = new AutoResetEvent(false); Action <object, OpenArgs> anEventHandler2 = (x, y) => { anEvent2Received.Set(); }; // Subscribe. anRpcClient1.Proxy.Open += anEventHandler1.Invoke; anRpcClient2.Proxy.Open += anEventHandler2.Invoke; // Raise the event in the service. OpenArgs anOpenArgs = new OpenArgs() { Name = "Hello" }; aService.RaiseOpen(anOpenArgs); anEvent1Received.WaitIfNotDebugging(1000); anEvent2Received.WaitIfNotDebugging(1000); // Unsubscribe. anRpcClient1.Proxy.Open -= anEventHandler1.Invoke; anRpcClient2.Proxy.Open -= anEventHandler2.Invoke; // Try to raise again. aService.RaiseOpen(anOpenArgs); Assert.IsFalse(anEvent1Received.WaitOne(1000)); Assert.IsFalse(anEvent2Received.WaitOne(1000)); } finally { if (anRpcClient1.IsDuplexOutputChannelAttached) { anRpcClient1.DetachDuplexOutputChannel(); } if (anRpcClient2.IsDuplexOutputChannelAttached) { anRpcClient2.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
protected override void dataReceiver_Data_Arrival(object sender, StockData.TickData tickdata) { //Console.WriteLine("openSide:{0},signInHighPrice:{1},signInLowPrice:{2},tickdata.Last:{3},dealState:{4},openComplete:{5},closeComplete:{6}", openSide, signInHighPrice, signInLowPrice, tickdata.Last, dealState, openComplete, closeComplete); //Console.WriteLine("Ratio:{0}", Ratio); if (tickdata.Code == string.Empty) { IsSimulateFinished = true; HistoryFinished(); LiveDataUpdate(tickdata); } else { if (currentDay != tickdata.Time.Date) { currentDay = tickdata.Time.Date; this.Reset(); } if (tickdata.Last == 0) { return; } liveDataProcessor.ReceiveTick(tickdata); currentTick = tickdata; if (parameter.StartTime <= tickdata.Time.TimeOfDay && parameter.EndTime >= tickdata.Time.TimeOfDay && init) { if (IsSimulateFinished || (!IsSimulateFinished && !tickdata.IsReal)) { if (dealState == true && openComplete && closeComplete) { dealState = false; } if (dealState == false) { if (openHands > 0) { } if (tickdata.Last > signInHighPrice && openSide != 1) { if (openSide == 2) { foreach (TradePoints tp in tps) { if (!tp.Finished) { if (!tickdata.IsReal) { tp.Finished = true; Leave(tp.EnterPoint.OpenQty, tickdata.Last, tp.TradeGuid); } else { //平空 closeComplete = false; dealState = true; CloseDelete od = new CloseDelete(CloseThread); od.BeginInvoke(parameter.qty, tickdata.Last, tp.TradeGuid, null, null); } } } } if (Ratio <= parameter.Ratio) { if (!tickdata.IsReal) { openSide = 1; openComplete = false; dealState = true; openHands = parameter.qty; OpenArgs oa = new OpenArgs( tickdata.Last, parameter.qty, OpenType.KaiDuo, SecInfo, tickdata, -1, ""); OpenDelete od = new OpenDelete(OpenThread); od.BeginInvoke(oa, null, null); } else { openSide = 1; holdHands += (decimal)parameter.Qty; Open(tickdata.Last, parameter.qty, OpenType.KaiDuo, SecInfo, tickdata, -1, ""); } } } else if (tickdata.Last < signInLowPrice && openSide != 2) { if (openSide == 1) { foreach (TradePoints tp in tps) { if (!tp.Finished) { if (!tickdata.IsReal) { tp.Finished = true; Leave(tp.EnterPoint.OpenQty, tickdata.Last, tp.TradeGuid); } else { //平多 closeComplete = false; dealState = true; CloseDelete od = new CloseDelete(CloseThread); od.BeginInvoke(parameter.qty, tickdata.Last, tp.TradeGuid, null, null); } } } } if (Ratio <= parameter.Ratio) { if (!tickdata.IsReal) { openSide = 2; openComplete = false; dealState = true; openHands = parameter.qty; OpenArgs oa = new OpenArgs( tickdata.Last, parameter.qty, OpenType.KaiKong, SecInfo, tickdata, -1, ""); OpenDelete od = new OpenDelete(OpenThread); od.BeginInvoke(oa, null, null); } else { openSide = 2; Open(tickdata.Last, parameter.qty, OpenType.KaiKong, SecInfo, tickdata, -1, ""); } } } } } } LiveDataUpdate(tickdata); if (parameter.IsReal) { try { UpdateChart(); } catch { } } } }
public static extern FT_Error Open_Face( FT_Library lib, OpenArgs args, FT_Long face_index, out FT_Face face);