public async Task PatternRpcTest(string procedureToInvoke, string matchedProcedure) { WampPlayground playground = new WampPlayground(); playground.Host.Open(); IWampChannel calleeChannel = playground.CreateNewChannel("realm1"); await calleeChannel.Open(); Action <MyOperation, InvocationDetails> action = (operation, details) => { Assert.That(details.Procedure, Is.EqualTo(procedureToInvoke)); Assert.That(operation.Procedure, Is.EqualTo(matchedProcedure)); }; await Register(calleeChannel, "com.myapp.manage.47837483.create", "exact", action); await Register(calleeChannel, "com.myapp", "prefix", action); await Register(calleeChannel, "com.myapp.manage", "prefix", action); await Register(calleeChannel, "com....", "wildcard", action); await Register(calleeChannel, ".myapp...create", "wildcard", action); IWampChannel callerChannel = playground.CreateNewChannel("realm1"); await callerChannel.Open(); var callback = new MyCallback(); callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions(), procedureToInvoke); Assert.That(callback.Called, Is.EqualTo(true)); }
public async Task ProgressiveCallsCallerProgressCancelObservable() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; var service = new LongOpObsService(); await calleeChannel.RealmProxy.Services.RegisterCallee(service); MyCallback callback = new MyCallback(); var invocation = callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions() { ReceiveProgress = true }, "com.myapp.longop", new object[] { 10, false }); Assert.That(service.State, Is.EqualTo(LongOpObsService.EState.Called)); invocation.Cancel(new CancelOptions()); Assert.That(service.State, Is.EqualTo(LongOpObsService.EState.Cancelled)); }
private static async Task RawTest(bool hasSessionId, RegisterOptions registerOptions, CallOptions callOptions) { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyOperation myOperation = new MyOperation(); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, registerOptions); MyCallback myCallback = new MyCallback(); callerChannel.RealmProxy.RpcCatalog.Invoke(myCallback, callOptions, myOperation.Procedure); long?expectedCaller = null; if (hasSessionId) { expectedCaller = dualChannel.CallerSessionId; } if (callOptions.DiscloseMe == false && registerOptions.DiscloseCaller == true) { Assert.That(myCallback.ErrorUri, Is.EqualTo(WampErrors.DiscloseMeNotAllowed)); } else { Assert.That(myOperation.Details.Caller, Is.EqualTo(expectedCaller)); } }
public static void Test() { string baseAddress = "net.tcp://" + Environment.MachineName + ":8000/Service"; ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress)); host.AddServiceEndpoint(typeof(ITest), new NetTcpBinding(SecurityMode.None), ""); host.Open(); Console.WriteLine("Host opened"); AutoResetEvent evt = new AutoResetEvent(false); MyCallback callback = new MyCallback(evt); DuplexChannelFactory<ITest> factory = new DuplexChannelFactory<ITest>( new InstanceContext(callback), new NetTcpBinding(SecurityMode.None), new EndpointAddress(baseAddress)); ITest proxy = factory.CreateChannel(); Console.WriteLine(proxy.Hello("foo bar")); evt.WaitOne(); ((IClientChannel)proxy).Close(); factory.Close(); Console.Write("Press ENTER to close the host"); Console.ReadLine(); host.Close(); }
public bool Subscribe(string Name) { MyCallback current = OperationContext.Current.GetCallbackChannel <MyCallback>(); Console.WriteLine("hi " + Name); People Usver = new People(); if (AllUser.Count == 0) { Usver.Name = Name; Usver.Rooms.Add("Общая"); Usver.Callback = current; AllUser.Add(Usver); return(true); } else { for (int i = 0; i < AllUser.Count; i++) { if (AllUser[i].Name == Name) { return(false); } } } Usver.Name = Name; Usver.Rooms.Add("Общая"); Usver.Callback = current; AllUser.Add(Usver); return(true); }
public static void Test() { string baseAddress = "net.tcp://" + Environment.MachineName + ":8000/Service"; ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress)); host.AddServiceEndpoint(typeof(ITest), new NetTcpBinding(SecurityMode.None), ""); host.Open(); Console.WriteLine("Host opened"); AutoResetEvent evt = new AutoResetEvent(false); MyCallback callback = new MyCallback(evt); DuplexChannelFactory <ITest> factory = new DuplexChannelFactory <ITest>( new InstanceContext(callback), new NetTcpBinding(SecurityMode.None), new EndpointAddress(baseAddress)); ITest proxy = factory.CreateChannel(); Console.WriteLine(proxy.Hello("foo bar")); evt.WaitOne(); ((IClientChannel)proxy).Close(); factory.Close(); Console.Write("Press ENTER to close the host"); Console.ReadLine(); host.Close(); }
public async Task CancelCallsCalleeCancellationToken() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; CancellableService service = new CancellableService(); await calleeChannel.RealmProxy.Services.RegisterCallee(service); MyCallback callback = new MyCallback(); IWampCancellableInvocationProxy cancellable = callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions() { ReceiveProgress = true }, "com.myapp.cancellable", new object[] { 100 }); Assert.That(service.CancellationToken, Is.Not.Null); Assert.That(service.CancellationToken.IsCancellationRequested, Is.False); cancellable.Cancel(new CancelOptions()); Assert.That(service.CancellationToken.IsCancellationRequested, Is.True); }
public async Task ProgressiveCallsCallerProgress() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; await calleeChannel.RealmProxy.Services.RegisterCallee(new LongOpService()); MyCallback callback = new MyCallback(); callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions() { ReceiveProgress = true }, "com.myapp.longop", new object[] { 10 }); callback.Task.Wait(2000); CollectionAssert.AreEquivalent(Enumerable.Range(0, 10), callback.ProgressiveResults); Assert.That(callback.Task.Result, Is.EqualTo(10)); }
public ListControl() { InitializeComponent(); foreach (SystemNotificationCode systemNotificationCode in Enum.GetValues(typeof(SystemNotificationCode))) { GlobalInterface.Instance.RegisterNotification((new GlobalDelegates.Delegate5(OnChanged)), null, systemNotificationCode); } MyCallback cb = new MyCallback(listView); IISceneEventManager sceneEventMgr = Global.ISceneEventManager; sceneEventMgr.RegisterCallback(cb, false, 50, true); }
public bool solveProb() { try { // Solve initial problem with the auto algorithm cplex.SetParam(Cplex.IntParam.RootAlg, Cplex.Algorithm.Auto); cplex.SetParam(Cplex.DoubleParam.TiLim, Program.MAXTIME_SECOND); cplex.SetParam(Cplex.IntParam.ClockType, 2); cplex.SetParam(Cplex.DoubleParam.TreLim, Program.MAXMEMORY_MB); //cplex.SetOut(null); //cplex.SetParam(Cplex.IntParam.MIPDisplay, 5);//display all details cplex.SetParam(Cplex.IntParam.ParallelMode, Cplex.ParallelMode.Deterministic); cplex.SetParam(Cplex.IntParam.Threads, this.threadNumber); cplex.SetOut(null);// ; setOut(env.getNullStream()); if (relaxationcontinue == true) { MyCallback c = new MyCallback(); cplex.Use((ILOG.CPLEX.Cplex.ControlCallback)c); cplex.SetParam(Cplex.Param.MIP.Limits.Nodes, (long)1); } if (UBrootnode == true) { cplex.SetParam(Cplex.Param.MIP.Limits.Nodes, (long)0); } TimeSpan start = new TimeSpan(DateTime.Now.Ticks); flagsolveur = false; bool resSolve = cplex.Solve(); TimeSpan end = new TimeSpan(DateTime.Now.Ticks); TimeSpan usingtime = end.Subtract(start).Duration(); this.timeUse = usingtime.TotalMilliseconds; if (resSolve) //A Boolean value reporting whether a feasible solution has been found. { //Console.Out.WriteLine(cplex.Nnodes); return(true); } } catch (ILOG.Concert.Exception e) { System.Console.WriteLine("Concert exception '" + e + "' caught");//A Modifier } return(false); }
public bool UnSubscribe() { MyCallback currentContext = OperationContext.Current.GetCallbackChannel <MyCallback>(); for (int i = 0; i < AllUser.Count; i++) { if (AllUser[i].Callback == currentContext) { Console.WriteLine("Goodbye " + AllUser[i].Name); AllUser.Remove(AllUser[i]); return(true); } } return(false); }
/* * Function name : manageServerMessages(Object str) * * Parameters : Object str : store the messge to print in the textbox. * * Return : void * * Description : This function is used to access the textbox as thread safe to print all the messages. * */ private void manageServerMessages(Object str) { if (Run) { // InvokeRequired property is true if child thread if (serverDataTB.InvokeRequired) { // Callback is instance of delegate MyCallback callback = new MyCallback(manageServerMessages); Invoke(callback, new object[] { str }); } else { // Direct access to Control if parent thread serverDataTB.Text += (String)str + "\n"; } } }
public static void StaticDelegateDemo() { Counter(1, 3, null); Counter(1, 3,new Feedback(FeedbackToConsole)); Counter(1, 3, FeedbackToConsole); FileStream fs = new FileStream(@"C:\Users\lideng\Desktop\1.txt", FileMode.Append); MyCallback m = new MyCallback(FileStr); Console.WriteLine(m(fs)); ThreadPool.QueueUserWorkItem(new WaitCallback(FeedbackToConsole1),4); ThreadPool.QueueUserWorkItem(FeedbackToConsole1, 5); ThreadPool.QueueUserWorkItem(obj=>Console.WriteLine("Lambda:"+obj),10); Func<Int32, string> f1 = (Int32 n) => n.ToString(); Console.WriteLine("f1:"+f1(123)); }
public static void MainDelegateTest() { // StaticDelegateDemo(); // InstanceDelegateDemo(); // ChainDelegateDemo1(); // ChainDelegateDemo2(); MyCallback mcb = new MyCallback(SomeMethod); GetStatus getStatus = null; getStatus += new GetStatus(new Light().SwitchPosition); getStatus += new GetStatus(new Fan().Speed); getStatus += new GetStatus(new Speaker().Volume); Console.WriteLine(getStatus()); UsingLocalVariablesInTheCallbackCode(10); UsingCreateDelegateOrDynamicInvoke("ConsoleApp.TwoInt32", "Add"); Console.Read(); }
public void Test(int arg) { float f = arg / 2f; double d = 0.25; int i = (int)f; int j = (int)d; float f2 = (float)d; int a = 1; int b = 2; int n1 = a / b; int n2 = (int)(a / b); double d2 = a / b; Action action = (Action) delegate() { }; Action secondAction = action as Action; if (action is Action) { } MyCallback cb = action as MyCallback; if (action is MyCallback) { cb = (MyCallback)action; } Action <bool> action2 = action as Action <bool>; if (action2 != null) { } }
/// <summary> ///receive的callback內容 /// </summary> private void ReceiveCallback(IAsyncResult ar) { Socket current = (Socket)ar.AsyncState; CheckIfConnected(_clientSockets); try { MyCallback callback = new MyCallback(UpdataTb); int received = current.EndReceive(ar);// 結束非同步讀取,並回傳收到幾個Byte if (received == 0) { return; } int index = _clientSockets.IndexOf(current);//取得此client是列表中的哪個 int code = BitConverter.ToInt16(_bufferList[index], 0); //加車 if (code == -70) { Point point = new Point(); point.X = BitConverter.ToInt16(_bufferList[index], 2); point.Y = BitConverter.ToInt16(_bufferList[index], 4); } Console.WriteLine("接收到東西"); _bufferList[index] = new byte[current.ReceiveBufferSize]; current.BeginReceive(_bufferList[index], 0, _bufferList[index].Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), current); } catch (SocketException ex) { ShowErrorDialog(ex.Message); current.Close(); _clientSockets.Remove(current); } catch (ObjectDisposedException ex) { ShowErrorDialog(ex.Message); } }
static void Main(string[] args) { var fac = new INativeFactory(CreateNativeFactory()); var test = fac.CreateTest(); using (var cb = new MyCallback()) test.SetCallback(cb); test.DoCallback("123"); Console.WriteLine("Removing callback"); test.SetCallback(null); Console.WriteLine("Removed callback"); using (var concat = fac.Concat((Utf8String)"foo", (Utf8String)"bar")) { Console.WriteLine(concat.String); } }
static void Main(string[] args) { var program = new Program(); MyCallback callback= MyMethod; callback += program.MyPrinter; var combined=Delegate.Combine(callback, new MyCallback(program.MyPrinter)); callback.Invoke(5,"hello"); callback(5, "hello"); Delegate[] invocationList = callback.GetInvocationList(); foreach (MyCallback littleCallback in invocationList) { try { callback(5, "hello"); } catch (Exception ex) { Debug.WriteLine("There was an error"); } } _callback = callback; IAsyncResult ar=callback.BeginInvoke(5, "hello", CallbackEnded, "tamir"); }
/* *METHOD : CurrentStatusThread * *DESCRIPTION : Thread that will updat the current status * *PARAMETERS : void * *RETURNS : void * */ private void CurrentStatusThread() { while(!Done) { output.WriteLine("GetCurrentStatus."); output.Flush(); MyCallback callback = new MyCallback(txtbxInvoke); // Callback is instance of delegate try { Invoke(callback, new object[] { input.ReadLine() }); } catch (Exception) { //form has closed } Thread.Sleep(5000); } }
public static extern void start_polling(int gpio, MyCallback callback);
public static extern void InvokeCallback(MyCallback callback);
public static extern void InvokeCallbackOnNewThread(MyCallback callback);
static extern void SetCCallback(MyCallback cb);
public static extern unsafe int RegisterApplicationRecoveryCallback(MyCallback callback, void *param, int dwPingInterval, int dwFlags);
static extern double Calc(double x, double y, [MarshalAs(UnmanagedType.FunctionPtr)] MyCallback func);
void RegisterCallback(MyCallback <T> callback) { eventTable.Add("test", callback); }