コード例 #1
0
        public override void Configure(Container container)
        {
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[] {
                new CredentialsAuthProvider(AppSettings),
            }));

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

            var authRepo = container.Resolve <IUserAuthRepository>();

            authRepo.CreateUserAuth(new UserAuth {
                Id          = 1,
                UserName    = "******",
                FirstName   = "First",
                LastName    = "Last",
                DisplayName = "Display",
            }, "p@55word");

            container.Register(c => createMqServerFn());

            var mqServer = container.Resolve <IMessageService>();

            mqServer.RegisterHandler <HelloIntro>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler <MqAuthOnly>(m => {
                var req = new BasicRequest {
                    Verb = HttpMethods.Post
                };
                req.Headers["X-ss-id"] = m.GetBody().SessionId;
                var response           = ServiceController.ExecuteMessage(m, req);
                return(response);
            });
            mqServer.Start();
        }
コード例 #2
0
        public override void Configure(Container container)
        {
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(ValidateTestMqValidator).Assembly);

            container.Register(c => createMqServerFn());

            var mqServer = container.Resolve <IMessageService>();

            mqServer.RegisterHandler <AnyTestMq>(q =>
            {
                return(ServiceController.ExecuteMessage(q));
            });
            mqServer.RegisterHandler <AnyTestMqAsync>(msg
                                                      => ServiceController.ExecuteMessage(msg));
            mqServer.RegisterHandler <PostTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler <ValidateTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler <ThrowGenericError>(ServiceController.ExecuteMessage);


            mqServer.RegisterHandler <QueueMessage>(m =>
            {
                Interlocked.Increment(ref count);
                var result = ServiceController.ExecuteMessage(m);
                if (count == 100)
                {
                    evt.Set();
                }
                return(result);
            });

            mqServer.Start();
        }
コード例 #3
0
ファイル: TestExecuteMessage.cs プロジェクト: EBassie/Potato
        public void TestObservableStarted()
        {
            var service = new ServiceController() {
                Packages = new MockServicePackageManager(),
                Settings = {
                    ServiceUpdateCore = false
                },
                ServiceLoaderProxyType = typeof(MockServiceLoaderProxy)
            };

            service.ExecuteMessage(new ServiceMessage());

            Assert.AreEqual(ServiceStatusType.Started, service.Observer.Status);

            service.Dispose();
        }
コード例 #4
0
ファイル: TestExecuteMessage.cs プロジェクト: EBassie/Potato
        public void TestMethodCalledExecuteMessage()
        {
            var service = new ServiceController() {
                Packages = new MockServicePackageManager(),
                Settings = {
                    ServiceUpdateCore = false
                },
                ServiceLoaderProxyType = typeof(MockServiceLoaderProxy)
            };

            service.ExecuteMessage(new ServiceMessage());

            Assert.IsTrue(((MockServiceLoaderProxy)service.ServiceLoaderProxy).OnExecuteMessage);

            service.Dispose();
        }
コード例 #5
0
        public override void Configure(Container container)
        {
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(ValidateTestMqValidator).Assembly);

            container.Register(c => createMqServerFn());

            var mqServer = container.Resolve <IMessageService>();

            mqServer.RegisterHandler <AnyTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler <AnyTestMqAsync>(msg
                                                      => ServiceController.ExecuteMessage(msg));
            mqServer.RegisterHandler <PostTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler <ValidateTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler <ThrowGenericError>(ServiceController.ExecuteMessage);

            mqServer.Start();
        }
コード例 #6
0
            public TResponse Send <TResponse>(object request)
            {
                var message    = MessageFactory.Create(request);
                var response   = ServiceManager.ExecuteMessage(message);
                var httpResult = response as IHttpResult;

                if (httpResult != null)
                {
                    if (httpResult.StatusCode >= HttpStatusCode.BadRequest)
                    {
                        var webEx = new WebServiceException(httpResult.StatusDescription)
                        {
                            ResponseDto = httpResult.Response,
                            StatusCode  = httpResult.Status,
                        };
                        throw webEx;
                    }
                    return((TResponse)httpResult.Response);
                }

                var responseStatus = response.GetResponseStatus();
                var isError        = responseStatus != null && responseStatus.ErrorCode != null;

                if (isError)
                {
                    var webEx = new WebServiceException(responseStatus.Message)
                    {
                        ResponseDto = response,
                        StatusCode  = responseStatus.Errors != null && responseStatus.Errors.Count > 0
                            ? 400
                            : 500,
                    };
                    throw webEx;
                }

                return((TResponse)response);
            }
コード例 #7
0
 public virtual object ExecuteMessage(IMessage dto, IRequest req)
 {
     return(ServiceController.ExecuteMessage(dto, req));
 }
コード例 #8
0
 public virtual object ExecuteMessage(IMessage mqMessage)
 {
     return(ServiceController.ExecuteMessage(mqMessage, new BasicRequest(mqMessage)));
 }
コード例 #9
0
ファイル: TestExecuteMessage.cs プロジェクト: EBassie/Potato
        public void TestResultMessageProcessed()
        {
            var signaled = false;

            var service = new ServiceController() {
                Packages = new MockServicePackageManager(),
                Settings = {
                    ServiceUpdateCore = false
                },
                ServiceLoaderProxyType = typeof(MockServiceLoaderProxy),
                SignalResult = (controller, message) => signaled = true
            };

            service.Start();

            ((MockServiceLoaderProxy)service.ServiceLoaderProxy).ExecuteResultMessage = new ServiceMessage() {
                Name = "result"
            };

            service.ExecuteMessage(new ServiceMessage());

            Assert.IsTrue(signaled);

            service.Dispose();
        }