예제 #1
0
        public BasicRequest(IMessage message = null,
                            RequestAttributes requestAttributes = RequestAttributes.LocalSubnet | RequestAttributes.MessageQueue)
        {
            Message     = message ?? new Message();
            ContentType = this.ResponseContentType = MimeTypes.Json;
            if (Message.Body != null)
            {
                PathInfo = "/json/oneway/" + OperationName;
                RawUrl   = AbsoluteUri = "mq://" + PathInfo;
                Headers  = Message.ToHeaders().ToNameValueCollection();
            }

            this.IsLocal           = true;
            Response               = new BasicResponse(this);
            this.RequestAttributes = requestAttributes;

            this.Headers     = new NameValueCollection();
            this.Cookies     = new Dictionary <string, Cookie>();
            this.Items       = new Dictionary <string, object>();
            this.QueryString = new NameValueCollection();
            this.FormData    = new NameValueCollection();
            this.Files       = new IHttpFile[0];
        }
예제 #2
0
        public string RenderToHtml(RazorPage razorPage, out IRazorView razorView, object model = null, string layout = null)
        {
            if (razorPage == null)
                throw new ArgumentNullException("razorPage");

            var mqContext = new BasicRequestContext();

            var httpReq = new BasicRequest(mqContext);
            if (layout != null)
            {
                httpReq.Items[RazorPageResolver.LayoutKey] = layout;
            }

            var httpRes = new BasicResponse(mqContext);

            razorView = PageResolver.ResolveAndExecuteRazorPage(
                httpReq: httpReq,
                httpRes: httpRes,
                model: model,
                razorPage: razorPage);

            var ms = (MemoryStream)httpRes.OutputStream;
            return ms.ToArray().FromUtf8Bytes();
        }
예제 #3
-1
        public override void Configure(Container container)
        {
            LogManager.LogFactory = new Log4NetFactory(true);

            container.Register(_dbConnectionFactory);
            var basicAuthProvider = new BasicAuthProvider();
            container.Register(basicAuthProvider);

            Plugins.Add(new AuthFeature( () => new AuthUserSession(), new IAuthProvider[] {basicAuthProvider, }, SystemConstants.LoginUrl ));

            var userRepo = new OrmLiteAuthRepository(_dbConnectionFactory);
            container.Register<IAuthRepository>(userRepo);

            var cacheClient = new MemoryCacheClient();
            container.Register(cacheClient);

            var currencyTypeRepository = new CurrencyTypeRepository { DbConnectionFactory = _dbConnectionFactory };
            var transactionTypeRepository = new TransactionTypeRepository { DbConnectionFactory = _dbConnectionFactory };
            var transactionStatusTypeRepository = new TransactionStatusTypeRepository { DbConnectionFactory = _dbConnectionFactory };
            var transactionNotificationStatusTypeRepository = new TransactionNotificationStatusTypeRepository { DbConnectionFactory = _dbConnectionFactory };
            var transactionRepository = new TransactionRepository { DbConnectionFactory = _dbConnectionFactory };

            var currencyTypeLogic = new CurrencyTypeLogic { Repository = currencyTypeRepository };
            var transactionTypeLogic = new TransactionTypeLogic { Repository = transactionTypeRepository };
            var transactionStatusTypeLogic = new TransactionStatusTypeLogic { Repository = transactionStatusTypeRepository };
            var transactionNotificationStatusTypeLogic = new TransactionNotificationStatusTypeLogic { Repository = transactionNotificationStatusTypeRepository };
            var transactionLogic = new TransactionLogic {Repository = transactionRepository};

            container.Register<IRest<CurrencyType, GetCurrencyTypes>>(currencyTypeLogic);
            container.Register<IRest<TransactionType, GetTransactionTypes>>(transactionTypeLogic);
            container.Register<IRest<TransactionStatusType, GetTransactionStatusTypes>>(transactionStatusTypeLogic);
            container.Register<IRest<TransactionNotificationStatusType, GetTransactionNotificationStatusTypes>>(transactionNotificationStatusTypeLogic);
            container.Register<IRest<Transaction, GetTransactions>>(transactionLogic);

            CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => pathInfo.StartsWith("/favicon.ico") ? new FavIconHandler() : null);

            var redisLocation = ConfigurationManager.AppSettings["ReddisService"];
            Container.Register<IRedisClientsManager>(new PooledRedisClientManager(redisLocation));
            var mqService = new RedisMqServer(container.Resolve<IRedisClientsManager>());
            var messagingHandlers = new MessageService { Log = new Logger(typeof(MessageService).Name) };

            Func<IMessage, IMessage> filterSecureRequests = (message) =>
            {
                /*
                var tag = message.Tag;

                if (string.IsNullOrWhiteSpace(tag))
                    return message;

                if (tag.StartsWith("basic ", StringComparison.InvariantCultureIgnoreCase))
                {
                    var creds = Encoding.UTF8.GetString(Convert.FromBase64String(tag.Substring(5)));

                    var i = creds.IndexOf(':');
                    var userName = creds.Substring(0, i);
                    var userPass = creds.Substring(i + 1);

                    if (userName != SystemConstants.AllowedUser || userPass != SystemConstants.AllowedPass)
                    {
                        message.Tag = null;
                        return message;
                    }

                    _currentSessionGuid = Guid.NewGuid();
                    var sessionKey = userName + "/" + _currentSessionGuid.ToString("N");

                    SessionContext = new SessionContext { SessionKey = sessionKey, Username = userName };
                    container.Register(SessionContext);
                    message.Tag = sessionKey;
                    return message;
                }

                message.Tag = null;*/

                return message;
            };

            mqService.RequestFilter = filterSecureRequests;

            Func<IMessage<Transaction>, PostResponse<Transaction>> handlePostTransactions = (message) =>
            {
                var service = new TransactionWebService { Logic = transactionLogic };
                var request = new BasicRequest {Message = message, Dto = message.GetBody()};
                var response = new BasicResponse(request);

                //userRepo.TryAuthenticate()

                service.SessionFactory.GetOrCreateSession(request, response);
                var session = service.GetSession();

                session.UserName = "******";

                var results = new PostResponse<Transaction> {Result = (Transaction) service.Post(message.GetBody())};
                return results;
            };

            // Dto Get Operations

            mqService.RegisterHandler<GetCurrencyTypes>(m => messagingHandlers.MessagingGetWrapper(m.GetBody(), currencyTypeLogic));
            mqService.RegisterHandler<GetTransactions>(m => messagingHandlers.MessagingGetWrapper(m.GetBody(), transactionLogic));
            mqService.RegisterHandler<GetTransactionStatusTypes>(m => messagingHandlers.MessagingGetWrapper(m.GetBody(), transactionStatusTypeLogic));
            mqService.RegisterHandler<GetTransactionNotificationStatusTypes>(m => messagingHandlers.MessagingGetWrapper(m.GetBody(), transactionNotificationStatusTypeLogic));
            mqService.RegisterHandler<GetTransactionTypes>(m => messagingHandlers.MessagingGetWrapper(m.GetBody(), transactionTypeLogic));

            // Dto Post Operations
            mqService.RegisterHandler<CurrencyType>(m => messagingHandlers.MessagingPostRequest(m.GetBody(), currencyTypeLogic.Post));

            mqService.RegisterHandler<Transaction>(handlePostTransactions);
            mqService.RegisterHandler<TransactionStatusType>(m => messagingHandlers.MessagingPostRequest(m.GetBody(), transactionStatusTypeLogic.Post));
            mqService.RegisterHandler<TransactionNotificationStatusType>(m => messagingHandlers.MessagingPostRequest(m.GetBody(), transactionNotificationStatusTypeLogic.Post));
            mqService.RegisterHandler<TransactionType>(m => messagingHandlers.MessagingPostRequest(m.GetBody(), transactionTypeLogic.Post));

            // Dto Put Opertations
            mqService.RegisterHandler<DeleteCurrencyType>(m => messagingHandlers.MessagingDeleteWrapper(m.GetBody(), currencyTypeLogic));
            mqService.RegisterHandler<DeleteTransaction>(m => messagingHandlers.MessagingDeleteWrapper(m.GetBody(), transactionLogic));
            mqService.RegisterHandler<DeleteTransactionStatusType>(m => messagingHandlers.MessagingDeleteWrapper(m.GetBody(), transactionStatusTypeLogic));
            mqService.RegisterHandler<DeleteTransactionNotificationStatusType>(m => messagingHandlers.MessagingDeleteWrapper(m.GetBody(), transactionNotificationStatusTypeLogic));
            mqService.RegisterHandler<DeleteTransactionType>(m => messagingHandlers.MessagingDeleteWrapper(m.GetBody(), transactionTypeLogic));

            mqService.Start();
        }