public JsonRpcDispatcher(IRpcService service, IServiceProvider serviceProvider) { if (service == null) throw new ArgumentNullException("service"); _service = service; if (serviceProvider == null) { // // No service provider supplied so check if the RPC service // itself is our service provider. // serviceProvider = service as IServiceProvider; // // If no service provider found so far, then create a default // one. // if (serviceProvider == null) serviceProvider = new ServiceContainer(); } _serviceProvider = serviceProvider; }
public void RpcCallError() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; Assert.Throws <RpcException>(() => aServiceProxy.Fail()); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public Form1() { aFactory = new RpcFactory(); aService = aFactory.CreateSingleInstanceService <IMyService>(new MyService()); // Use TCP for the communication. // You also can use other protocols e.g. WebSockets. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://192.168.1.102:8041/"); // Attach the input channel to the RpcService and start listening. aService.AttachDuplexInputChannel(anInputChannel); //IS THIS SERVICE MULTITHREADED ? InitializeComponent(); button2.Enabled = false; button3.Enabled = true; var materialSkinManager = MaterialSkinManager.Instance; materialSkinManager.AddFormToManage(this); materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT; materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE); formContext = this; //don't run more than 1 instances of this form }
public RpcServer(IRpcService rpcService, string host = "*", int responsePort = -1) : base(responsePort, 0, host) { _rpcService = rpcService; foreach (var methodInfo in rpcService.GetType().GetMethods()) { foreach (var attr in methodInfo.GetCustomAttributes(typeof(ServiceFuncAttribute))) { var funcAttr = (ServiceFuncAttribute)attr; var args = methodInfo.GetParameters(); var requestType = args[0].ParameterType; var retType = methodInfo.ReturnType; var info = new RpcServiceFuncInfo() { ArgType = requestType, ReturnType = retType, Method = methodInfo, }; _serviceFuncs[requestType] = info; Logger.Info("Register Service Func, RequestType: {0}, ResponseType: {1}", requestType, info.ReturnType); } } if (_serviceFuncs.Count <= 0) { Logger.Error("RpcServcice(Type:{0}), has no funcs mark with ServiceFuncAttribute", rpcService.GetType()); } }
public static void ProcessRequest(IRpcService service, HttpContext httpContext) { if (service == null) throw new ArgumentNullException("service"); if (httpContext == null) throw new ArgumentNullException("httpContext"); // // Create a context to service the request and configure it. // RpcServiceContext context = new RpcServiceContext(service); // // Cross-connect the service and HTTP context so that one // can be found given the other. // context.ContextServices.AddService(typeof(HttpContext), httpContext); httpContext.Items.Add(typeof(RpcServiceContext), context); context.ContextServices.AddService(typeof(RpcServiceFeatureRegistry), RpcServiceFeatureRegistry.FromConfig()); JsonRpcServiceWebBinder binder = new JsonRpcServiceWebBinder(context); IRpcServiceFeature feature = binder.Bind(); IHttpHandler handler = feature as IHttpHandler; if (handler == null) throw new JsonRpcException(string.Format("The {0} feature does not support the HTTP protocol.", feature.GetType().FullName)); handler.ProcessRequest(httpContext); }
public TransactionService(ITransactionRepository transactionRepository, IRpcService rpcService, IMapper mapper) { this.mapper = mapper; this.rpcService = rpcService; this.transactionRepository = transactionRepository; }
public void RpcCall_NullArgument() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; string k = aServiceProxy.CreateString(null); Assert.AreEqual(null, k); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void DynamicRpcCall() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); int k = (int)anRpcClient.CallRemoteMethod("Sum", 1, 2); Assert.AreEqual(3, k); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public virtual void RpcTimeout() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); anRpcFactory.RpcTimeout = TimeSpan.FromSeconds(1); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; Assert.Throws <TimeoutException>(() => aServiceProxy.Timeout()); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void SubscribeBeforeAttachOutputChannel() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); HelloService aService = new HelloService(); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { IHello aServiceProxy = anRpcClient.Proxy; AutoResetEvent aClientConnected = new AutoResetEvent(false); anRpcClient.ConnectionOpened += (x, y) => { aClientConnected.Set(); }; AutoResetEvent anEventReceived = new AutoResetEvent(false); Action <object, EventArgs> anEventHandler = (x, y) => { anEventReceived.Set(); }; // Subscribe before the connection is open. aServiceProxy.Close += anEventHandler.Invoke; // Open the connection. anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); // Wait until the client is connected. aClientConnected.WaitOne(); // Raise the event in the service. aService.RaiseClose(); Assert.IsTrue(anEventReceived.WaitOne()); // Unsubscribe. aServiceProxy.Close -= anEventHandler.Invoke; // Try to raise again. aService.RaiseClose(); Assert.IsFalse(anEventReceived.WaitOne(1000)); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void PerClientInstanceService() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreatePerClientInstanceService <IHello>(() => new HelloService()); IRpcClient <IHello> anRpcClient1 = anRpcFactory.CreateClient <IHello>(); IRpcClient <IHello> anRpcClient2 = anRpcFactory.CreateClient <IHello>(); try { ManualResetEvent aClient2Connected = new ManualResetEvent(false); string aService1IdFromEvent = null; anRpcClient1.Proxy.Open += (x, y) => { aService1IdFromEvent = y.InstanceId; }; string aService2IdFromEvent = null; anRpcClient2.Proxy.Open += (x, y) => { aService2IdFromEvent = y.InstanceId; aClient2Connected.Set(); }; anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient1.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); anRpcClient2.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); aClient2Connected.WaitOne(1000); string aServiceId1 = anRpcClient1.Proxy.GetInstanceId(); string aServiceId2 = anRpcClient2.Proxy.GetInstanceId(); Assert.IsFalse(string.IsNullOrEmpty(aServiceId1)); Assert.IsFalse(string.IsNullOrEmpty(aService1IdFromEvent)); Assert.IsFalse(string.IsNullOrEmpty(aServiceId2)); Assert.IsFalse(string.IsNullOrEmpty(aService2IdFromEvent)); Assert.AreEqual(aServiceId1, aService1IdFromEvent); Assert.AreEqual(aServiceId2, aService2IdFromEvent); Assert.AreNotEqual(aServiceId1, aServiceId2); } finally { if (anRpcClient1.IsDuplexOutputChannelAttached) { anRpcClient1.DetachDuplexOutputChannel(); } if (anRpcClient2.IsDuplexOutputChannelAttached) { anRpcClient2.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void RegisterCallee(string realmName, IRpcService instance) { var realm = _host.RealmContainer.GetRealmByName(realmName); var registrationTask = realm.Services.RegisterCallee(instance); registrationTask.Wait(); }
public SerialService(ILogService log, IEventAggregator eventAggregator, IRpcService rpcService) { _log = log; _eventAggregator = eventAggregator; _rpcService = rpcService; _eventAggregator.GetEvent <ShutDownEvent>().Subscribe(RestoreRpcStatus); }
/// <summary> /// Registers a service instance. /// </summary> /// <param name="service">Service instance.</param> public void RegisterService(IRpcService service) { this.log.InfoFormat( "Registered service '{0}' with name '{1}'", service.GetType().AssemblyQualifiedName, service.Name); this.objectManager.RegisterService(service); }
public WalletService(IWalletRepository walletRepository, IRpcService rpcService, IMapper mapper) { this.mapper = mapper; this.rpcService = rpcService; this.walletRepository = walletRepository; }
public void RpcNonGenericEvent_10000() { 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; int aCounter = 0; AutoResetEvent anEventReceived = new AutoResetEvent(false); Action <object, EventArgs> anEventHandler = (x, y) => { ++aCounter; if (aCounter == 10000) { anEventReceived.Set(); } }; // Subscribe. aServiceProxy.Close += anEventHandler.Invoke; Stopwatch aStopWatch = new Stopwatch(); aStopWatch.Start(); // Raise the event in the service. for (int i = 0; i < 10000; ++i) { aService.RaiseClose(); } Assert.IsTrue(anEventReceived.WaitOne()); aStopWatch.Stop(); Console.WriteLine("Remote event. Elapsed time = " + aStopWatch.Elapsed); // Unsubscribe. aServiceProxy.Close -= anEventHandler.Invoke; } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void RegisterService(IRpcService service) { if (service == null) { throw new ArgumentNullException("service"); } this.RegisterService(service, service.Name); }
public virtual void Init(ActorNodeConfig conf) { IsActive = true; Conf = conf; RpcService = NewRpcCaller(); RpcServer = new RpcServer(RpcService, "*", conf.RpcPort); _discovery = new Discovery(Conf.AppToken, Conf.DiscoveryMode, Conf.DiscoveryParam); }
/// <summary> /// Constructs a new EventGridRpcFunction class /// </summary> /// <param name="jsonRpc">The JsonRpc instance we'll use monitor for message processing completion</param> /// <param name="messageHandler">The message handler we'll use to dispatch Message to the RPC service</param> /// <param name="rpcService"> /// The service instance the RPC will call against. This is not needed to be used, but we need to have /// a constructor reference to it so DI will generate it and the JsonRpc instance can call methods against it. ///</param> public EventGridRpcFunction( JsonRpc jsonRpc, DispatchingClientMessageHandler messageHandler, IRpcService rpcService ) { _JsonRpc = jsonRpc; _MessageHandler = messageHandler; _RpcService = rpcService; }
void IRpcServiceFeature.Initialize(IRpcService targetService) { if (_targetService != null) throw new InvalidOperationException(); if (targetService == null) throw new ArgumentNullException("targetService"); _targetService = targetService; }
public void RpcCall_10000() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; Stopwatch aStopWatch = new Stopwatch(); aStopWatch.Start(); //EneterTrace.StartProfiler(); for (int i = 0; i < 10000; ++i) { aServiceProxy.Sum(1, 2); } //EneterTrace.StopProfiler(); aStopWatch.Stop(); Console.WriteLine("Rpc call. Elapsed time = " + aStopWatch.Elapsed); HelloService aService = new HelloService(); Stopwatch aStopWatch2 = new Stopwatch(); aStopWatch2.Start(); for (int i = 0; i < 10000; ++i) { aService.Sum(1, 2); } aStopWatch2.Stop(); Console.WriteLine("Local call. Elapsed time = " + aStopWatch2.Elapsed); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
/// <summary> /// Method for registering callee /// </summary> /// <param name="instance"></param> /// <returns></returns> public static bool RegisterCallee(IRpcService instance) { var wampRouter = ServiceLocator.GetRequiredService <WampRouter>(); if (wampRouter == null) { return(false); } wampRouter.RegisterCallee(instance); return(true); }
private void AddEndpoint <TRequest, TResponse>(IRpcServiceResolver rpcServiceResolver) where TRequest : class, new() where TResponse : class, new() { Post[typeof(TRequest).Name, true] = async(ctx, ct) => { IRpcService <TRequest, TResponse> rpcService = rpcServiceResolver.GetRpcService <TRequest, TResponse>(); var request = this.Bind <TRequest>(); return(await rpcService.Execute(request, ct)); }; }
public NodeTestData(IRpcService rpcService, OutputWriter writer) { this.rpcService = rpcService; this.writer = writer ?? new OutputWriter(); this.unspentTxIds = new List <string>(); this.addresses = new List <string>(); this.rawTxHex = new List <string>(); this.random = new Random(); this.Initialize(); }
public JsonRpcWebGateway(HttpContext context, IRpcService service) { if (context == null) throw new ArgumentNullException("context"); if (service == null) throw new ArgumentNullException("service"); _context = context; _service = service; }
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(); } } }
private static void AddBatchCallResult(IRpcService service, string calledMethod, int batchSize, TimeSpan elapsed) { if (!initialized) { return; } if (BatchCallResults.TryGetValue(service, out TestSummary summary)) { summary.RegisterBatchCallResult(calledMethod, batchSize, elapsed); } }
private static void ImportKeys(IRpcService service, string privateKeysFilePath) { verbosityLevel.Writer.WriteLine($"Importing private keys"); if (service == null) { verbosityLevel.Writer.WriteLine("No X node found to import keys into."); return; } if (!File.Exists(privateKeysFilePath)) { verbosityLevel.Writer.WriteLine($"{privateKeysFilePath} file not found."); } var keysToImport = JsonConvert.DeserializeObject <List <ImportedKey> >(File.ReadAllText(privateKeysFilePath)); verbosityLevel.Writer.WriteLine($"Found {keysToImport.Count} private keys to import."); for (int i = 0; i < keysToImport.Count; i++) { var keyToImport = keysToImport[i]; var request = new GenericCall( "importprivkey", ("privkey", keyToImport.PrivateKey), ("label", keyToImport.Path), ("rescan", false) //i == keysToImport.Count - 1) ); var result = service.CallSingle(request); Console.Write($"\rImporting key {i + 1}/{keysToImport.Count}"); if (result.HasError) { verbosityLevel.Writer.WriteLine($"\rimportprivkey error on key {i + 1}/{keysToImport.Count}: {result.Error}"); } } verbosityLevel.Writer.WriteLine($"Check if first key has been imported"); var dumpPrivKeyResult = service.CallSingle(new GenericCall("dumpprivkey", ("address", keysToImport.First().Address))); if (dumpPrivKeyResult.HasError) { verbosityLevel.Writer.WriteLine($"dumpprivkey error: {dumpPrivKeyResult.Error}"); } else { verbosityLevel.Writer.WriteLine($"dumpprivkey result: {dumpPrivKeyResult.Result}"); } }
/// <summary> /// Returns the name of the service or an anonymous default if it does /// not have a name. /// </summary> public static string GetServiceName(IRpcService service, string anonymousName) { if (service == null) throw new ArgumentNullException("service"); string name = null; IRpcServiceDescriptor descriptor = service.GetDescriptor(); if (descriptor != null) name = descriptor.Name; return Mask.EmptyString(name, anonymousName); }
/// <summary> /// Returns the name of the service or an anonymous default if it does /// not have a name. /// </summary> public static string GetServiceName(IRpcService service, string anonymousName) { if (service == null) throw new ArgumentNullException("service"); string name = null; JsonRpcServiceClass clazz = service.GetClass(); if (clazz != null) name = clazz.Name; return Mask.EmptyString(name, anonymousName); }
public RpcServiceContext(IRpcService service) { if (service == null) throw new ArgumentNullException("service"); _service = service; _contextServices = new ServiceContainer(); _contextServices.AddService(typeof(IRpcService), service); _container = new Container(this); IComponent component = service as IComponent; if (component != null) _container.Add(component); }
public void DynamicRpcNonGenericEvent() { 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); EventHandler <EventArgs> anEventHandler = (x, y) => { anEventReceived.Set(); }; // Subscribe. anRpcClient.SubscribeRemoteEvent <EventArgs>("Close", anEventHandler); // Raise the event in the service. aService.RaiseClose(); Assert.IsTrue(anEventReceived.WaitOne()); // Unsubscribe. anRpcClient.UnsubscribeRemoteEvent("Close", anEventHandler); // Try to raise again. aService.RaiseClose(); Assert.IsFalse(anEventReceived.WaitOne(1000)); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public TalkFlow() { var talk = new Talk(); IRpcFactory factory = new RpcFactory(); IRpcService <ITalk> service = factory.CreateSingleInstanceService <ITalk>(talk); IMessagingSystemFactory messaging = new TcpMessagingSystemFactory(); IDuplexInputChannel inputChannel = messaging.CreateDuplexInputChannel("tcp://127.0.0.1:8045/"); service.AttachDuplexInputChannel(inputChannel); Console.WriteLine("Service started. Press ENTER to stop."); Console.ReadLine(); service.DetachDuplexInputChannel(); }
public void RegisterRpcService <TRequest, TResponse>(IRpcService <TRequest, TResponse> service) where TRequest : class, new() where TResponse : class, new() { MethodInfo addEndpointMethod = typeof(RpcModule) .GetMethod("AddEndpoint", BindingFlags.NonPublic | BindingFlags.Instance); var typeArguments = service .GetType() .GetInterfaces() .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRpcService <,>)) .SelectMany(i => i.GetGenericArguments()) .ToArray(); addEndpointMethod .MakeGenericMethod(typeArguments) .Invoke(this, new object[] { _rpcServiceResolver }); }
IAsyncResult IRpcMethodDescriptor.BeginInvoke(IRpcService service, object[] args, AsyncCallback callback, object asyncState) { throw new NotImplementedException(); }
public object Invoke(IRpcService service, object[] args) { if (service == null) throw new ArgumentNullException("service"); try { return _dispatcher.Invoke(service, args); } catch (ArgumentException e) { // // The type of the parameters parameter does not match the // signature of the method or constructor reflected by this // instance. // throw new InvocationException(e); } catch (TargetParameterCountException e) { // // The parameters array does not have the correct number of // arguments. // throw new InvocationException(e.Message, e); } catch (TargetInvocationException e) { throw new TargetMethodException(e.InnerException); } }
internal RpcPromise(IRpcService service, Expression<Action> call) { _service = service; _call = ExpressionSimplifier.Simplify(call.Body); }
/// <remarks> /// The default implementation calls Invoke synchronously and returns /// an IAsyncResult that also indicates that the operation completed /// synchronously. If a callback was supplied, it will be called /// before BeginInvoke returns. Also, if Invoke throws an exception, /// it is delayed until EndInvoke is called to retrieve the results. /// </remarks> public IAsyncResult BeginInvoke(IRpcService service, object[] args, AsyncCallback callback, object asyncState) { if (service == null) throw new ArgumentNullException("service"); SynchronousAsyncResult asyncResult; try { object result = Invoke(service, args); asyncResult = SynchronousAsyncResult.Success(asyncState, result); } catch (Exception e) { asyncResult = SynchronousAsyncResult.Failure(asyncState, e); } if (callback != null) callback(asyncResult); return asyncResult; }
/// <summary> /// Initialize mock objects. /// </summary> public PoolTests() { _jobManagerFactory = Substitute.For<IJobManagerFactory>(); _jobTrackerFactory = Substitute.For<IJobTrackerFactory>(); _hashAlgorithmFactory = Substitute.For<IHashAlgorithmFactory>(); _shareManagerFactory = Substitute.For<IShareManagerFactory>(); _minerManagerFactory = Substitute.For<IMinerManagerFactory>(); _serverFactory = Substitute.For<IServerFactory>(); _serviceFactory = Substitute.For<IServiceFactory>(); _storageManagerFactory = Substitute.For<IStorageFactory>(); _globalConfigFactory = Substitute.For<IGlobalConfigFactory>(); _daemonClient = Substitute.For<IDaemonClient>(); _minerManager = Substitute.For<IMinerManager>(); _jobManager = Substitute.For<IJobManager>(); _jobTracker = Substitute.For<IJobTracker>(); _shareManager = Substitute.For<IShareManager>(); _miningServer = Substitute.For<IMiningServer>(); _rpcService = Substitute.For<IRpcService>(); _storage = Substitute.For<IStorage>(); }
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 static string GetServiceName(IRpcService service) { return GetServiceName(service, "(anonymous)"); }
public JsonRpcDispatcher(IRpcService service) : this(service, null) {}
RpcPromise(IRpcService service, Expression call, bool continueOnCapturedContext) { _service = service; _call = call; _continueOnCapturedContext = continueOnCapturedContext; }
public void RegisterService(IRpcService service) { this.RegisterService(service, service.Name); }
object IRpcMethodDescriptor.Invoke(IRpcService service, object[] args) { LastArguments = args; return NextResult; }
public object Invoke(IRpcService service, object[] args) { return _method.Invoke(service, args); }
public IAsyncResult BeginInvoke(IRpcService service, object[] args, AsyncCallback callback, object asyncState) { throw new NotImplementedException(); }
public object Invoke(IRpcService service, object[] args) { throw new NotImplementedException(); }
public object EndInvoke(IRpcService service, IAsyncResult asyncResult) { throw new NotImplementedException(); }