public void ValidateDurableAbortReconnection() { IOperationDispatcher serverDispatcher = new OperationDispatcher(); StatelessServerEndpoint server = new StatelessServerEndpoint(url, serverDispatcher); serverDispatcher.RegisterHandler <IWeakCalculator>(new WeakCalculator { Destroyed = () => server.Dispose() }); server.Start(); using (DurableClientConnection client = new DurableClientConnection(url)) { client.ConnectionPaused = response => response.Abort = true; client.Open(); IWeakCalculator calculator = client.RemoteExecutor.Create <IWeakCalculator>(); Assert.AreEqual(4, calculator.Add(2, 2)); calculator.Destroy(); server = new StatelessServerEndpoint(url2, serverDispatcher); server.Start(); bool exceptionThrown = false; try { calculator.Add(5, 6); } catch (NotConnectedException ex) { exceptionThrown = ex.Message == "Network connection is not opened."; } Assert.IsTrue(exceptionThrown); server.Dispose(); } }
public void ValidateCloseShared() { // Arrange bool exceptionThrown = false; IOperationDispatcher serverDispatcher = new OperationDispatcher() .RegisterHandler <ICalculator>(new Calculator()); IOperationDispatcher clienDispatcher = new OperationDispatcher(); // Act using (StatelessServerEndpoint server1 = new StatelessServerEndpoint(url2, serverDispatcher)) using (StatelessServerEndpoint server2 = new StatelessServerEndpoint(url3, serverDispatcher)) { using (ClientConnection c1 = CreateClientConnection("a", Port2, clienDispatcher)) using (ClientConnection c2 = CreateClientConnection("a", Port3, clienDispatcher)) { server1.Start(); server2.Start(); c1.Open(); c2.Open(); c1.Dispose(); try { c2.RemoteExecutor.Create <ICalculator>().Add(2, 2); } catch (NotConnectedException) { exceptionThrown = true; } } } // Assert Assert.IsTrue(exceptionThrown); }
public void ValidateStartWithDistinct() { // Arrange IOperationDispatcher dispatcher = new OperationDispatcher() .RegisterHandler <ICalculator>(new Calculator()); // Act using (StatelessServerEndpoint server = new StatelessServerEndpoint(url, dispatcher)) using (StatelessServerEndpoint server2 = new StatelessServerEndpoint(url2, dispatcher)) using (StatelessServerEndpoint server3 = new StatelessServerEndpoint(url3, dispatcher)) { using (ClientConnection c1 = new ClientConnection(url)) using (ClientConnection c2 = CreateClientConnection("a", Port2, new OperationDispatcher())) using (ClientConnection c3 = CreateClientConnection("b", Port3, new OperationDispatcher())) { server.Start(); server2.Start(); server3.Start(); c1.Open(); c2.Open(); c3.Open(); // Assert Assert.AreEqual(4, c1.RemoteExecutor.Create <ICalculator>().Add(2, 2)); Assert.AreEqual(4, c2.RemoteExecutor.Create <ICalculator>().Add(2, 2)); Assert.AreEqual(4, c3.RemoteExecutor.Create <ICalculator>().Add(2, 2)); Assert.AreNotEqual(c1.GetClientEndpoint(), c2.GetClientEndpoint()); Assert.AreNotEqual(c2.GetClientEndpoint(), c3.GetClientEndpoint()); } } }
public void ValidateSharedActuallyWorks() { // Arrange IOperationDispatcher serverDispatcher = new OperationDispatcher() .RegisterHandler <ICalculator>(new Calculator()); IOperationDispatcher clienDispatcher = new OperationDispatcher(); // Act using (StatelessServerEndpoint server2 = new StatelessServerEndpoint(url2, serverDispatcher)) using (StatelessServerEndpoint server3 = new StatelessServerEndpoint(url3, serverDispatcher)) { using (ClientConnection c1 = CreateClientConnection("a", Port2, clienDispatcher)) using (ClientConnection c2 = CreateClientConnection("a", Port3, clienDispatcher)) { server2.Start(); server3.Start(); c1.Open(); c2.Open(); // Assert Assert.AreEqual(4, c1.RemoteExecutor.Create <ICalculator>().Add(2, 2)); Assert.AreEqual(4, c2.RemoteExecutor.Create <ICalculator>().Add(2, 2)); } } }
public void ValidateSharedPorts() { // Arrange IOperationDispatcher serverDisaptcher = new OperationDispatcher() .RegisterHandler <ICalculator>(new Calculator()); IOperationDispatcher clienDispatcher = new OperationDispatcher(); // Act using (StatelessServerEndpoint server1 = new StatelessServerEndpoint(url, serverDisaptcher)) using (StatelessServerEndpoint server2 = new StatelessServerEndpoint(url2, serverDisaptcher)) { using (ClientConnection c1 = CreateClientConnection("a", Port, clienDispatcher)) using (ClientConnection c2 = CreateClientConnection("a", Port2, clienDispatcher)) { server1.Start(); server2.Start(); c1.Open(); c2.Open(); // Assert Assert.AreEqual(c1.GetClientEndpoint(), c2.GetClientEndpoint()); } } }
static void Main(string[] args) { BasicLidgrenCryptoProviderResolver resolver = new BasicLidgrenCryptoProviderResolver(); EncryptedConfigurator.Configure(resolver); IOperationDispatcher callbackDispatcher = new OperationDispatcher(); SessionEncryptedCallback callback = new SessionEncryptedCallback(); callbackDispatcher.RegisterHandler <ISessionEncryptedCallback>(callback); using (ClientConnection client = new ClientConnection("net://localhost:3133/EncryptedServices", callbackDispatcher)) { Console.WriteLine("Opening client..."); Console.WriteLine(); client.Open(); IAuthenticator authenticator = client.RemoteExecutor.Create <IAuthenticator>(); Console.WriteLine("Note that encryption is not strictly enforced. Enforcement is left up to the developer."); Console.WriteLine("11 + 6 = " + authenticator.Add(11, 6)); Console.WriteLine(); Console.WriteLine("Generating secret key..."); byte[] secretBytes = CreateByteKey(96); string secretString = Convert.ToBase64String(secretBytes); Console.WriteLine("Secret key is " + secretString); Console.WriteLine(); Console.WriteLine("Encrypting secret key..."); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.ImportParameters(authenticator.GetRsaParameters().ToParams()); byte[] encryptedBytes = rsa.Encrypt(secretBytes, false); Console.WriteLine("Encrypted key is " + Convert.ToBase64String(encryptedBytes)); Console.WriteLine(); Console.WriteLine("Establishing encrypted session..."); authenticator.EncryptSession(encryptedBytes); Console.WriteLine("Awaiting encryption confirmation..."); callback.Wait(); Console.WriteLine("Encryption confirmed; registering crypto provider..."); resolver.Register(new IPEndPoint(IPAddress.Loopback, 3133), new DebugNetAESEncryption(EmptyPeer, secretString)); Console.WriteLine("Connection is encrypted."); const int wait = 160; Console.WriteLine($"Pausing for {wait} milliseconds to ensure server has time to register crypto provider..."); Thread.Sleep(wait); Console.WriteLine("Done waiting."); Console.WriteLine(); Console.WriteLine("5 + 6 = " + authenticator.Add(5, 6)); Console.WriteLine(); Console.WriteLine("Done. Press enter to exit."); Console.ReadLine(); } }
public ArangoClient() { _dispatcher = new OperationDispatcher(); _database = new ArangoDatabaseDispatcher(); _document = new ArangoDocumentDispatcher(); _edge = new ArangoEdgeDispatcher(); _collection = new ArangoCollectionDispatcher(); _importer = new ArangoImportDispatcher(); _simpleQuery = new ArangoSimpleQueryDispatcher(); }
public override void Init(OperationDispatcher dispatcher) { base.Init(dispatcher); Document.Init(dispatcher); Edge.Init(dispatcher); Collection.Init(dispatcher); Importer.Init(dispatcher); SimpleQuery.Init(dispatcher); }
public OperationSystem(OperationMap map, ISerializationService serializer, IOperationTransport transport, Func<Type, IOperationHandler> handlerFactory) { var writer = new NetworkOperationWriter(map, serializer, transport); var reader = new NetworkOperationReader(map, serializer); var activeOperations = new ActiveOperationsManager(); Dispatcher = new OperationDispatcher(activeOperations, writer); Processor = new OperationProcessor(new OperationService(activeOperations, writer, handlerFactory), reader); }
/// <summary> /// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests. /// </summary> /// <returns>A collection of listeners.</returns> protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { OperationDispatcher dispatcher = new OperationDispatcher(); dispatcher.RegisterHandler <IWeakCalculator>(new WeakCalculator { Crashed = () => loop = false }); return(new[] { new ServiceInstanceListener(c => new StatelessCommunicationListener(c, "WeakCalculator", dispatcher)) }); }
static void Main(string[] args) { SharedConfigurator.Configure(); var dispatcher = new OperationDispatcher() .RegisterHandler <IBasicService>(new BasicService()); using (var host = new StatelessServerEndpoint("net://127.0.0.1:3132/SharedAppId", dispatcher)) { host.Start(); Console.WriteLine("Server started...\nPress enter to stop"); Console.ReadLine(); } }
static void Main(string[] args) { Configurator.Configure(); var dispatcher = new OperationDispatcher() .RegisterHandler <ICalculator>(new CalculatorService()) .RegisterHandler <IGreeter>(new GreeterService()); using (var host = new StatelessServerEndpoint("net://127.0.0.1:3131/StatelessServices", dispatcher)) { host.Start(); Console.WriteLine("Server started...\nPress enter to stop"); Console.ReadLine(); } }
public void ValidateBasicMethodCall() { IOperationDispatcher serverDisaptcher = new OperationDispatcher() .RegisterHandler <ICalculator>(new Calculator()); using (StatelessServerEndpoint server = new StatelessServerEndpoint(Url, serverDisaptcher)) { server.Start(); using (ClientConnection client = MakeFacadeConnection(AppId, Host, Port)) { client.Open(); ICalculator calculator = client.RemoteExecutor.Create <ICalculator>(); Assert.AreEqual(4, calculator.Add(2, 2)); } } }
public void ValidateSingle() { // Arrange IOperationDispatcher dispatcher = new OperationDispatcher() .RegisterHandler <ICalculator>(new Calculator()); // Act using (StatelessServerEndpoint server1 = new StatelessServerEndpoint(url, dispatcher)) { using (ClientConnection c1 = CreateClientConnection("a", Port, new OperationDispatcher())) { server1.Start(); c1.Open(); Assert.AreEqual(4, c1.RemoteExecutor.Create <ICalculator>().Add(2, 2)); } } }
static void Main(string[] args) { Configurator.Configure(); IOperationDispatcher callbackDispatcher = new OperationDispatcher(); callbackDispatcher.RegisterHandler <IClientCallback>(new ClientCallback()); using (var client = new ClientConnection("net://localhost:3133/CallbackServices", callbackDispatcher)) { client.Open(); var userInfoService = client.RemoteExecutor.Create <ILongRunningOperation>(); userInfoService.Perform(5); Console.WriteLine("Done. Press enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { Configurator.Configure(); IOperationDispatcher callbackDispatcher = new OperationDispatcher(); callbackDispatcher.RegisterHandler(Aspects.WithTimeMeasure <IClientCallback>(new ClientCallback(), ConsoleColor.DarkCyan)); using (var client = new ClientConnection("net://localhost:3134/CallbackDispatcher", callbackDispatcher)) { client.Open(); var longRunningOperation = Aspects.WithTimeMeasure(client.RemoteExecutor.Create <ILongRunningOperation>(ReturnPolicy.OneWay)); longRunningOperation.Repeat("a", 3); longRunningOperation.RepeatWithCallback("b", 3); longRunningOperation.RepeatWithOneWayCallback("c", 3); Console.WriteLine("Done. Please wait few seconds for callbacks and press enter to exit."); Console.ReadLine(); } }
public void ValidateDurableSilentFailover() { IOperationDispatcher serverDispatcher = new OperationDispatcher(); StatelessServerEndpoint server = new StatelessServerEndpoint(url, serverDispatcher); serverDispatcher.RegisterHandler <IWeakCalculator>(new WeakCalculator { Destroyed = () => server.Dispose() }); server.Start(); using (ClientConnection client = new ClientConnection(url)) { client.Open(); IWeakCalculator calculator = client.RemoteExecutor.Create <IWeakCalculator>(); Assert.AreEqual(4, calculator.Add(2, 2)); calculator.Destroy(); server = new StatelessServerEndpoint(url, serverDispatcher); server.Start(); Assert.AreEqual(11, calculator.Add(5, 6)); server.Dispose(); } }
protected override void ProcessRecordCore() { if (string.IsNullOrEmpty(Scaffolder)) { throw new InvalidOperationException(string.Format("Please specify a value for the 'Scaffolder' parameter.")); } var project = SolutionManager.GetProject(string.IsNullOrEmpty(Project) ? SolutionManager.DefaultProjectName : Project); if (project == null) { WriteError(string.Format("Could not find project '{0}'", Project ?? string.Empty)); return; } var scaffolders = _scaffolderLocator.Value.GetScaffolders(project, Scaffolder, true) ?? new List <ScaffolderInfo>(); switch (scaffolders.Count()) { case 0: WriteError(string.Format("Cannot find scaffolder '{0}'", Scaffolder)); break; case 1: if (BlockUi.IsPresent) { OperationDispatcher.RunOnUiThread(() => InvokeScaffolderCore(project, scaffolders.Single())); } else { InvokeScaffolderCore(project, scaffolders.Single()); } break; default: WriteError(string.Format("More than one scaffolder matches the name '{0}'", Scaffolder)); break; } }
static void Main(string[] args) { Configurator.Configure(); IOperationDispatcher callbackDispatcher = new OperationDispatcher(); IBroadcastService broadcastService = Aspects.WithTimeMeasure <IBroadcastService>(new BroadcastService(), ConsoleColor.DarkCyan); callbackDispatcher.RegisterHandler(broadcastService); using (var client = new ClientConnection("net://localhost:3135/BroadcastServices", callbackDispatcher)) { client.Open(); var userInfoService = Aspects.WithTimeMeasure(client.RemoteExecutor.Create <IUserInfoService>()); var registrationService = Aspects.WithTimeMeasure(client.RemoteExecutor.Create <IRegistrationService>()); GetUsers(userInfoService); RegisterUser(registrationService); GetUsers(userInfoService); Console.WriteLine("Done. Press enter to exit."); Console.ReadLine(); } }
public void Run() { var netConfiguration = new NetPeerConfiguration("ChatApp") { ConnectionTimeout = 10000, }; var messageFactory = new MessageFactory(ProtocolDescription.GetAllMessages()); var dispatcher = new OperationDispatcher(messageFactory, ProtocolDescription.GetAllProxies()); var client = new NetNode<NetPeer>(new LidgrenNetProvider(netConfiguration), messageFactory, dispatcher); client.Start(); client.PeerDisconnectedEvent.Subscribe((_) => Console.WriteLine("OnDisconnected")); client.PeerConnectedEvent.Subscribe((_) => Console.WriteLine("OnConnected")); var connFuture = client.ConnectToServer("127.0.0.1:5055"); while (connFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } NetPeer peer = connFuture.Result; peer.MessageEvent.Subscribe((msg) => Console.WriteLine("OnReceived " + msg)); var loginService = peer.GetProxy<IChatLogin>(); var loginFuture = loginService.Login("UnityTester"); while (loginFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } Console.WriteLine("Login Reply:" + loginFuture.Result); var chatServiceProxy = peer.GetProxy<IChatService>(); var joinRoomFuture = chatServiceProxy.JoinOrCreateRoom("TestRoom"); while (joinRoomFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } Console.WriteLine("CreateRoom RoomId:" + joinRoomFuture.Result.RoomActorId); connFuture = client.ConnectToServer(joinRoomFuture.Result.ServerEndpoint); while (connFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } var roomPeer = connFuture.Result; roomPeer.SetHandler<IChatRoomServiceCallback>(this); var chatRoomServiceProxy = roomPeer.GetProxy<IChatRoomService>(joinRoomFuture.Result.RoomActorId); var connectRoomFuture = chatRoomServiceProxy.Join(joinRoomFuture.Result.Ticket); while (connectRoomFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } foreach (var msg in connectRoomFuture.Result) Console.WriteLine(msg); while (true) { client.Update(); Thread.Sleep(10); } }
/// <summary> /// Apply the operation behavior /// </summary> public void ApplyOperationBehavior(EndpointOperation operation, OperationDispatcher dispatcher) { dispatcher.AddOperationPolicy(this); }
public EntityDomainDescriptionTests() { _protocolDesc = new OperationDispatcher(Substitute.For<IMessageFactory>(), new NetProxy[] { new ISomeServiceProxy() }); _contractDesc = _protocolDesc.GetContract(ServiceTypeId); }
/// <summary> /// Apply operation behavior /// </summary> public void ApplyOperationBehavior(EndpointOperation operation, OperationDispatcher dispatcher) { dispatcher.DispatchFormatter = new FhirMessageDispatchFormatter(); }
public virtual void Init(OperationDispatcher dispatcher) { Dispatcher = dispatcher; }
public void Run() { var netConfiguration = new NetPeerConfiguration("ChatApp") { ConnectionTimeout = 10000, }; var messageFactory = new MessageFactory(ProtocolDescription.GetAllMessages()); var dispatcher = new OperationDispatcher(messageFactory, ProtocolDescription.GetAllProxies()); var client = new NetNode <NetPeer>(new LidgrenNetProvider(netConfiguration), messageFactory, dispatcher); client.Start(); client.PeerDisconnectedEvent.Subscribe((_) => Console.WriteLine("OnDisconnected")); client.PeerConnectedEvent.Subscribe((_) => Console.WriteLine("OnConnected")); var connFuture = client.ConnectToServer("127.0.0.1:5055"); while (connFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } NetPeer peer = connFuture.Result; peer.MessageEvent.Subscribe((msg) => Console.WriteLine("OnReceived " + msg)); var loginService = peer.GetProxy <IChatLogin>(); var loginFuture = loginService.Login("UnityTester"); while (loginFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } Console.WriteLine("Login Reply:" + loginFuture.Result); var chatServiceProxy = peer.GetProxy <IChatService>(); var joinRoomFuture = chatServiceProxy.JoinOrCreateRoom("TestRoom"); while (joinRoomFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } Console.WriteLine("CreateRoom RoomId:" + joinRoomFuture.Result.RoomActorId); connFuture = client.ConnectToServer(joinRoomFuture.Result.ServerEndpoint); while (connFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } var roomPeer = connFuture.Result; roomPeer.SetHandler <IChatRoomServiceCallback>(this); var chatRoomServiceProxy = roomPeer.GetProxy <IChatRoomService>(joinRoomFuture.Result.RoomActorId); var connectRoomFuture = chatRoomServiceProxy.Join(joinRoomFuture.Result.Ticket); while (connectRoomFuture.State == FutureState.InProgress) { client.Update(); Thread.Sleep(10); } foreach (var msg in connectRoomFuture.Result) { Console.WriteLine(msg); } while (true) { client.Update(); Thread.Sleep(10); } }
/// <summary> /// Apply operation behavior /// </summary> public void ApplyOperationBehavior(EndpointOperation operation, OperationDispatcher dispatcher) { dispatcher.DispatchFormatter = RestMessageDispatchFormatter.CreateFormatter(operation.Description.Contract.Type); }
public EntityOperationDispatcherTests() { _protocolDesc = new OperationDispatcher(new MessageFactory(ProtocolDescription.GetAllMessages()), ProtocolDescription.GetAllProxies()); }
public EntityOperationDispatcherTests() { _protocolDesc = new OperationDispatcher(new MessageFactory(ProtocolDescription.GetAllMessages()), ProtocolDescription.GetAllProxies() ); }
public EntityDomainDescriptionTests() { _protocolDesc = new OperationDispatcher(Substitute.For <IMessageFactory>(), new NetProxy[] { new ISomeServiceProxy() }); _contractDesc = _protocolDesc.GetContract(ServiceTypeId); }