Ejemplo n.º 1
0
        public override void Configure(Container container)
        {
            LogManager.LogFactory = new Log4NetFactory(true);
            container.Register(_appDbConnectionFactory);

            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                new IAuthProvider[] {new BasicAuthProvider(), new CredentialsAuthProvider(),}) {HtmlRedirect = null});

            //No use a custom one
            //Plugins.Add(new RegistrationFeature());

            var userRepo = new OrmLiteAuthRepository(_authDbConnectionFactory);

            container.Register<IUserAuthRepository>(userRepo);

            //wire-up a validator for the UserRegistrationService
            var userRegistrationValidator = new UserRegistrationRequestValidator {UserAuthRepo = userRepo};
            container.Register<IValidator<UserRegistrationRequest>>(userRegistrationValidator);

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

            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);
        }
Ejemplo n.º 2
0
        public override void Configure(Container container)
        {
            LogManager.LogFactory = new Log4NetFactory(true);
            container.Register(_appDbConnectionFactory);

            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[] { new BasicAuthProvider(), new CredentialsAuthProvider(), })
            {
                HtmlRedirect = null
            });

            //No use a custom one
            //Plugins.Add(new RegistrationFeature());

            var userRepo = new OrmLiteAuthRepository(_authDbConnectionFactory);

            container.Register <IUserAuthRepository>(userRepo);

            //wire-up a validator for the UserRegistrationService
            var userRegistrationValidator = new UserRegistrationRequestValidator {
                UserAuthRepo = userRepo
            };

            container.Register <IValidator <UserRegistrationRequest> >(userRegistrationValidator);

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

            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);
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
-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();
        }