示例#1
0
    public void StartServer()
    {
        if (_Server != null)
        {
            return;
        }

        try
        {
            _Server = new Server
            {
                Services = { HelloService.BindService(new HelloServiceImpl()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };
            _Server.Start();

            DontDestroyOnLoad(gameObject);
            SceneManager.LoadScene("PlayScene");

            Debug.Log($"Server started on port : {_Server.Ports.FirstOrDefault().BoundPort}");
        }
        catch (Exception exception)
        {
            Debug.LogError(exception.Message);
            _Server = null;
        }
    }
示例#2
0
    public static void Main()
    {
// </Snippet5>
// <Snippet6>
        ChannelServices.RegisterChannel(new TcpChannel());

        RemotingConfiguration.RegisterWellKnownClientType(
            typeof(HelloService),
            "tcp://localhost:8082/HelloServiceApplication/MyUri"
            );

        HelloService service = new HelloService();

// </Snippet6>
// <Snippet7>

        if (service == null)
        {
            Console.WriteLine("Could not locate server.");
            return;
        }


        // Calls the remote method.
        Console.WriteLine();
        Console.WriteLine("Calling remote object");
        Console.WriteLine(service.HelloMethod("Caveman"));
        Console.WriteLine(service.HelloMethod("Spaceman"));
        Console.WriteLine(service.HelloMethod("Client Man"));
        Console.WriteLine("Finished remote object call");
        Console.WriteLine();
    }
示例#3
0
            public override void Configure(Funq.Container container)
            {
                Routes
                    .Add<Hello>("/hello")
                    .Add<Hello>("/hello/{Name}");
                helloService = container.Resolve<HelloService>();

                AuthFeature authFeature = new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {new BasicAuthProvider(), new TwitterAuthProvider(new AppSettings()),});
                //authFeature.HtmlRedirect
                Plugins.Add(authFeature);
                MemoryCacheClient memoryCacheClient = new MemoryCacheClient();
                container.Register<ICacheClient>(memoryCacheClient);

                var userRepository = new InMemoryAuthRepository();
                container.Register<IUserAuthRepository>(userRepository);

                string hash;
                string salt;
                string password = "******";
                new SaltedHash().GetHashAndSaltString(password, out hash, out salt);
                userRepository.CreateUserAuth(
                    new UserAuth {
                        Id = 1,
                        DisplayName = "JoeUser",
                        Email = "*****@*****.**",
                        UserName = "******",
                        FirstName = "Joe",
                        LastName = "User",
                        PasswordHash = hash,
                        Salt = salt,
                    }, password);
                //IHttpResult authenticationRequired = helloService.AuthenticationRequired(); // ????
            }
        public void Any_returns_greeting_with_name()
        {
            var request = new Hello {
                Name = "integration name"
            };

            var mockRequestContext = new MockRequestContext();

            var mockRespository = new Mock <IRepository>();

            mockRespository.Setup(a => a.GetGreeting())
            .Returns(new Greeting {
                Greet = "Hiya"
            });

            var service = new HelloService {
                RequestContext = mockRequestContext,
                Repository     = mockRespository.Object
            };


            HelloResponse response = (HelloResponse)service.Get(request);

            response.Result.Should().Be("Hiya, " + request.Name);
        }
    static void Main()
    {
        // Register a channel.
        TcpChannel myChannel = new TcpChannel();

        ChannelServices.RegisterChannel(myChannel);
        RemotingConfiguration.RegisterActivatedClientType(
            typeof(HelloService), "tcp://localhost:8085/");

        // Get the remote object.
        HelloService myService = new HelloService();

        // Get a sponsor for renewal of time.
        ClientSponsor mySponsor = new ClientSponsor();

        // Register the service with sponsor.
        mySponsor.Register(myService);

        // Set renewaltime.
        mySponsor.RenewalTime = TimeSpan.FromMinutes(2);

        // Renew the lease.
        ILease   myLease = (ILease)mySponsor.InitializeLifetimeService();
        TimeSpan myTime  = mySponsor.Renewal(myLease);

        Console.WriteLine("Renewed time in minutes is " + myTime.Minutes.ToString());

        // Call the remote method.
        Console.WriteLine(myService.HelloMethod("World"));

        // Unregister the channel.
        mySponsor.Unregister(myService);
        mySponsor.Close();
    }
示例#6
0
    public static void Main()
    {
        try
        {
// <Snippet2>
            IClientChannelSinkProvider mySoapProvider =
                new SoapClientFormatterSinkProvider();
            IClientChannelSinkProvider myClientProvider = new MyClientProvider();
            // Set the custom provider as the next 'IClientChannelSinkProvider' in the sink chain.
            mySoapProvider.Next = myClientProvider;
// </Snippet2>
            TcpChannel myTcpChannel = new TcpChannel(null, mySoapProvider, null);

            ChannelServices.RegisterChannel(myTcpChannel);

            RemotingConfiguration.RegisterWellKnownClientType(typeof(HelloService),
                                                              "tcp://localhost:8082/HelloServiceApplication/MyUri");

            HelloService myService = new HelloService();

            Console.WriteLine(myService.HelloMethod("Welcome to .Net"));
        }
        catch (Exception ex)
        {
            Console.WriteLine("The following  exception is raised at client side :" + ex.Message);
        }
    }
示例#7
0
        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();
                }
            }
        }
示例#8
0
 public HelloServer()
 {
     _server = new Server
     {
         Services = { HelloService.BindService(new HelloServiceImplementation()) },
         Ports    = { new ServerPort("localhost", 1234, ServerCredentials.Insecure) }
     };
 }
示例#9
0
        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();
                }
            }
        }
示例#10
0
 public RPCServiceProxy(Uri uri, int links = 4, int retry = 5, int timeOut = 10 *1000)
 {
     ExceptionCollector.OnErr += ExceptionCollector_OnErr;
     _serviceConsumer          = new ServiceConsumer(uri, links, retry, timeOut);
     _groupService             = new GroupService(_serviceConsumer);
     _helloService             = new HelloService(_serviceConsumer);
     _dicService     = new DicService(_serviceConsumer);
     _genericService = new GenericService(_serviceConsumer);
 }
示例#11
0
 void OnEnable()
 {
     _grpcServer = new Server
     {
         Ports = { new ServerPort("0.0.0.0", ServerPort, ServerCredentials.Insecure) }
     };
     _grpcServer.Services.Add(HelloService.BindService(new HelloServiceImpl(this)));
     _grpcServer.Start();
     Debug.Log($"GRPC Server running on port {ServerPort}");
 }
示例#12
0
 public RPCServiceProxy(string uri, int links = 4, int retry = 5, int timeOut = 10 * 1000)
 {
     ExceptionCollector.OnErr += ExceptionCollector_OnErr;
     _serviceConsumer          = new ServiceConsumer(new Uri(uri), links, retry, timeOut);
     _En = new EnumService(_serviceConsumer);
     _Gr = new GroupService(_serviceConsumer);
     _He = new HelloService(_serviceConsumer);
     _Di = new DicService(_serviceConsumer);
     _Ge = new GenericService(_serviceConsumer);
 }
示例#13
0
        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();
                }
            }
        }
示例#14
0
        public void GetShouldReturnHelloWorld()
        {
            // Arrange
            var service = new HelloService();

            // Act
            var result = service.SayHello();

            // Assert
            Assert.Equal("Hello world!", result);
        }
示例#15
0
        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();
                }
            }
        }
示例#16
0
        public async Task <IActionResult> Get()
        {
            await HelloService.SayHello();

            return(Ok(new
            {
                //name = await HelloService.SetMeta(("token", "bearer .....")).SayHello(Guid.NewGuid().ToString()),
                age = await HelloService.Age(),
                //entity = await HelloService.SayHello(new TestModel { Id = 1, Name = "owen" })
            }));
        }
示例#17
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            tokenService = new TokenService();
            authService  = new AuthService();
            helloService = new HelloService();

            if (tokenService.IsTokenExist())
            {
                InitializeWelcomeUIElements();
            }
        }
        public void Greeting_正常系()
        {
            // Arrange
            var service = new HelloService();

            // Act
            var result = service.Greeting();

            // Assert
            Assert.That(result, Is.EqualTo("Hello World!"));
        }
示例#19
0
        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();
                }
            }
        }
示例#20
0
        static void Main(string[] args)
        {
            _server = new Server {
                Services = { HelloService.BindService(new GrpcImpl()) },
                Ports    = { new ServerPort("localhost", 8088, ServerCredentials.Insecure) }
            };
            _server.Start();
            Console.WriteLine("grpc ServerListening On Port 8088");
            Console.WriteLine("任意键退出...");
            Console.ReadKey();

            _server?.ShutdownAsync().Wait();
        }
示例#21
0
        static void Main(string[] args)
        {
            var server = new Server()
            {
                Services = { HelloService.BindService(new HelloServiceImp()) },
                Ports    = { new ServerPort("localhost", 8888, ServerCredentials.Insecure) }
            };

            server.Start();
            Console.WriteLine("Enter any key to stop");
            Console.ReadKey();
            Console.WriteLine("Hello World!");
        }
示例#22
0
        private static void Main(string[] args)
        {
            var wcfService = new HelloService();

            using (var host = new ServiceHost(wcfService))
            {
                Console.WriteLine(host.Credentials.ServiceCertificate.Certificate);
                host.Open();
                Console.WriteLine("Press enter to stop");
                while (Console.ReadKey(true).Key != ConsoleKey.Enter)
                {
                }
                host.Close();
            }
        }
示例#23
0
        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();
                }
            }
        }
示例#24
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                throw new InvalidOperationException("args.Length must be 2 but is " + args.Length);
            }
            var command = args[0];
            var port    = 8088;

            if (command.ToLower() == "server")
            {
                Server server = new Server
                {
                    Services = { HelloService.BindService(new HelloServiceImpl()) },
                    Ports    = { new ServerPort("localhost", port, ServerCredentials.Insecure) }
                };
                server.Start();

                Console.WriteLine("RouteGuide server listening on port " + port);
                Console.WriteLine("Press any key to stop the server...");
                Console.ReadKey();

                server.ShutdownAsync().Wait();
            }
            else if (command.ToLower() == "client")
            {
                Channel channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
                var     client  = new HelloService.HelloServiceClient(channel);

                // YOUR CODE GOES HERE
                var reply = client.SayHello(new HelloRequest
                {
                    Name = "jiannan"
                });

                Console.WriteLine("Reply: " + reply.Message);
                channel.ShutdownAsync().Wait();
            }
            else
            {
                throw new InvalidOperationException("do not support command: " + command);
            }
        }
示例#25
0
 public static void Main()
 {
     try
     {
         IClientChannelSinkProvider myFormatterProvider =
             new MyClientFormatterProvider();
         myFormatterProvider.Next =
             new SoapClientFormatterSinkProvider();
         TcpChannel myTcpChannel = new TcpChannel(null,
                                                  myFormatterProvider, null);
         ChannelServices.RegisterChannel(myTcpChannel, false);
         RemotingConfiguration.RegisterWellKnownClientType(typeof(HelloService),
                                                           "tcp://localhost:8082/HelloServiceApplication/MyUri");
         HelloService myService = new HelloService();
         Console.WriteLine(myService.HelloMethod("Welcome to .Net"));
     }
     catch (Exception ex)
     {
         Console.WriteLine("The following exception is raised at client side" + ex.Message);
     }
 }
示例#26
0
        public async Task <IHttpActionResult> DeploySampleContract(int userId)
        {
            bool isContractAlreadyExist = _contractRepository.GetAll().ToList()
                                          .Where(item => item.Name == CONTRACT_NAME).FirstOrDefault() != null ? true : false;

            if (!isContractAlreadyExist)
            {
                var user = _userRepository.GetByID(userId);
                if (user != null)
                {
                    var userAccount = _userAccountRepository.GetAll().ToList().Where(item => item.UserId == user.Id).FirstOrDefault();

                    var node = _nodeRepository.GetByID(user.NodeId);
                    if (node != null && userAccount != null)
                    {
                        var accessKey = _accessKeyRepository.GetAll().ToList().Where(item => item.NodeId == node.Id).FirstOrDefault();
                        if (accessKey != null)
                        {
                            var managedAccount = new ManagedAccount(userAccount.Address, userAccount.PrivateKey);
                            var web3Managed    = new Web3(managedAccount, accessKey.UrlKey);
                            var service        = await HelloService.DeployContractAndGetServiceAsync(web3Managed,
                                                                                                     new HelloDeployment());

                            var message = await service.GetMessageQueryAsync(new GetMessageFunction());

                            _contractRepository.Save(new DLL.DataModels.Contract()
                            {
                                Name          = CONTRACT_NAME,
                                Address       = service.ContractHandler.ContractAddress,
                                NodeId        = node.Id,
                                UserId        = user.Id,
                                UserAccountId = userAccount.Id
                            });
                            return(Ok(message));
                        }
                    }
                }
            }
            return(Ok("Contract Already Exist"));
        }
示例#27
0
        public async Task <IHttpActionResult> GetValueForX(int userId)
        {
            var contract = _contractRepository.GetAll().ToList()
                           .Where(item => item.Name == CONTRACT_NAME).FirstOrDefault();

            if (contract != null)
            {
                var user = _userRepository.GetByID(userId);
                if (user != null)
                {
                    var userAccount = _userAccountRepository.GetAll().ToList().Where(item => item.UserId == user.Id).FirstOrDefault();

                    var node = _nodeRepository.GetByID(user.NodeId);
                    if (node != null && userAccount != null)
                    {
                        var accessKey = _accessKeyRepository.GetAll().ToList().Where(item => item.NodeId == node.Id).FirstOrDefault();
                        if (accessKey != null)
                        {
                            var managedAccount = new QuorumAccount(userAccount.Address);
                            var web3Managed    = new Web3Quorum(managedAccount, accessKey.UrlKey);
                            var unlocked       = await web3Managed.Personal.UnlockAccount.SendRequestAsync(userAccount.Address, userAccount.Password, 120);

                            var service         = new HelloService(web3Managed, contract.Address);
                            var contractHandler = service.ContractHandler;

                            /// Receipt is coming  as null
                            var receipt2 = await service.GetMessageQueryAsync(
                                new GetMessageFunction()
                                );


                            return(Ok(receipt2));
                        }
                    }
                }
            }

            return(Ok("Cannot value for X "));
        }
示例#28
0
        static void Main(string[] args)
        {
            //AbpApplicationFactory.Create 加载 Abp_Module 启动模块.块. Initialize()方法初始化.
            var application = AbpApplicationFactory.Create <Abp_Module>();

            application.Initialize();

            // ServiceProvider 引用应用程序使用的根服务提供者。在初始化应用程序之前不能使用它。
            // GetService/GetRequiredService  必须using Microsoft.Extensions.DependencyInjection;
            // 注入依赖 这里感觉更像是 通过反射获取服务
            // 这个服务是通过继承依赖接口来实现将服务放到容器中  当前服务是继承了 ITransientDependency
            // 获取服务时,会进行依赖注入
            // 最好使用GetRequiredService  因为如果出错 报错更快 https://www.cnblogs.com/yilezhu/p/11107648.html
            var helloWoldService = application.ServiceProvider.GetRequiredService <HelloWorldService>();

            helloWoldService.DoIt();
            HelloWorldService.TFWrite();

            var helloService1 = application.ServiceProvider.GetRequiredService <HelloService>();

            helloService1.Writer();
            HelloService.TFWrite();
            var helloService2 = application.ServiceProvider.GetRequiredService <Hello2Service>();

            helloService2.Writer();
            //使用Fac
            var Afcapplication = AbpApplicationFactory.Create <Afc_Module>(options =>
            {
                options.UseAutofac();
            });

            Afcapplication.Initialize();

            var AfcService = Afcapplication.ServiceProvider.GetRequiredService <AfcService>();

            AfcService.DoIt();
        }
示例#29
0
            public override void Configure(Funq.Container container)
            {
                Routes
                .Add <Hello>("/hello")
                .Add <Hello>("/hello/{Name}");
                helloService = container.Resolve <HelloService>();

                AuthFeature authFeature = new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new BasicAuthProvider(), new TwitterAuthProvider(new AppSettings()), });

                //authFeature.HtmlRedirect
                Plugins.Add(authFeature);
                MemoryCacheClient memoryCacheClient = new MemoryCacheClient();

                container.Register <ICacheClient>(memoryCacheClient);

                var userRepository = new InMemoryAuthRepository();

                container.Register <IUserAuthRepository>(userRepository);

                string hash;
                string salt;
                string password = "******";

                new SaltedHash().GetHashAndSaltString(password, out hash, out salt);
                userRepository.CreateUserAuth(
                    new UserAuth {
                    Id           = 1,
                    DisplayName  = "JoeUser",
                    Email        = "*****@*****.**",
                    UserName     = "******",
                    FirstName    = "Joe",
                    LastName     = "User",
                    PasswordHash = hash,
                    Salt         = salt,
                }, password);
                //IHttpResult authenticationRequired = helloService.AuthenticationRequired(); // ????
            }
示例#30
0
        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();
                }
            }
        }
示例#31
0
 public void Initialize()
 {
     HelloService = new HelloService(helloText, WriterService);
 }
示例#32
0
文件: client.cs 项目: Diullei/Storm
 static void Main(string[] args)
 {
     HelloService p = new HelloService();
     Console.WriteLine(p.SayHello());
 }