示例#1
0
 public static void MessagesModule(
     this ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator config,
     IMessageListViewModelRetriever messageListViewModelRetriever)
 {
     config.Module<MessagesNancyModule>();
     config.Dependencies<IMessageListViewModelRetriever>(messageListViewModelRetriever);
 }
示例#2
0
        public MessagesNancyModule(IMessageListViewModelRetriever messageListViewModelRetriever
                                   , IHandlerFactory handlerFactory)
            : base("/messages")
        {
            Get("/{storeName}/{pageNumber?1}", parameters =>
            {
                var logger = LogProvider.GetLogger("MessagesNancyModule");
                logger.Log(LogLevel.Debug, () => "GET on messages");

                string storeName = parameters.storeName;
                int pageNumber   = parameters.pageNumber;
                ViewModelRetrieverResult <MessageListModel, MessageListModelError> messageListModelResult = messageListViewModelRetriever.Get(storeName, pageNumber);

                if (!messageListModelResult.IsError)
                {
                    return(Response.AsJson(messageListModelResult.Result));
                }
                switch (messageListModelResult.Error)
                {
                case (MessageListModelError.StoreNotFound):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unknown store {0}", storeName)), HttpStatusCode.NotFound));

                case (MessageListModelError.StoreMessageViewerNotImplemented):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Found store {0} does not implement IMessageStoreViewer", storeName)), HttpStatusCode.NotFound));

                case (MessageListModelError.StoreMessageViewerGetException):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unable to retrieve messages for store {0}", storeName)), HttpStatusCode.InternalServerError));

                case (MessageListModelError.GetActivationStateFromConfigError):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Misconfigured Message Viewer, unable to retrieve messages for store {0}", storeName)), HttpStatusCode.InternalServerError));

                default:
                    throw new Exception("Code can't reach here");
                }
            });

            Post("/{storeName}/repost/{msgList}", parameters =>
            {
                try
                {
                    var handler        = handlerFactory.GetHandler <RepostCommand>();
                    string ids         = parameters.msgList;
                    var repostModelIds = ids.Split(',');
                    var repostCommand  = new RepostCommand {
                        StoreName = parameters.storeName, MessageIds = repostModelIds.ToList()
                    };
                    handler.Handle(repostCommand);

                    return(Response.AsJson <int>(0, HttpStatusCode.OK));
                }
                catch (Exception e)
                {
                    return(e);
                }
            });
        }
 public static void MessagesModule(
     this ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator config,
     IMessageListViewModelRetriever messageListViewModelRetriever,
     IHandlerFactory handlerFactory)
 {
     config.Module <MessagesNancyModule>();
     config.Dependencies <IMessageListViewModelRetriever>(messageListViewModelRetriever);
     config.Dependencies <IHandlerFactory>(handlerFactory);
 }
示例#4
0
 public static void StoresModule(
     this ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator config,
     IMessageStoreActivationStateListViewModelRetriever storeListRetriever,
     IMessageStoreViewerModelRetriever storeRetriever,
     IMessageListViewModelRetriever messageListRetriver)
 {
     config.Module<StoresNancyModule>();
     config.Dependencies<IMessageStoreActivationStateListViewModelRetriever>(storeListRetriever);
     config.Dependencies<IMessageStoreViewerModelRetriever>(storeRetriever);
     config.Dependencies<IMessageListViewModelRetriever>(messageListRetriver);
 }
 public static void StoresModule(
     this ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator config,
     IMessageStoreActivationStateListViewModelRetriever storeListRetriever,
     IMessageStoreViewerModelRetriever storeRetriever,
     IMessageListViewModelRetriever messageListRetriver)
 {
     config.Module <StoresNancyModule>();
     config.Dependencies <IMessageStoreActivationStateListViewModelRetriever>(storeListRetriever);
     config.Dependencies <IMessageStoreViewerModelRetriever>(storeRetriever);
     config.Dependencies <IMessageListViewModelRetriever>(messageListRetriver);
 }
示例#6
0
        public MessagesNancyModule(IMessageListViewModelRetriever messageListViewModelRetriever, IHandlerFactory handlerFactory)
            : base("/messages")
        {
            Get("/{storeName}/{pageNumber?1}", parameters =>
            {
                string storeName = parameters.storeName;
                int pageNumber = parameters.pageNumber;
                ViewModelRetrieverResult<MessageListModel, MessageListModelError> messageListModelResult = messageListViewModelRetriever.Get(storeName, pageNumber);

                if (!messageListModelResult.IsError)
                {
                    return Response.AsJson(messageListModelResult.Result);
                }
                switch (messageListModelResult.Error)
                {
                    case(MessageListModelError.StoreNotFound):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unknown store {0}", storeName)), HttpStatusCode.NotFound);
                    
                    case (MessageListModelError.StoreMessageViewerNotImplemented):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Found store {0} does not implement IMessageStoreViewer", storeName)), HttpStatusCode.NotFound);

                    case (MessageListModelError.StoreMessageViewerGetException):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unable to retrieve messages for store {0}", storeName)), HttpStatusCode.InternalServerError);

                    case (MessageListModelError.GetActivationStateFromConfigError):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Misconfigured Message Viewer, unable to retrieve messages for store {0}", storeName)), HttpStatusCode.InternalServerError);
                    default:
                        throw new Exception("Code can't reach here");
                }
            });

            Post("/{storeName}/repost/{msgList}", parameters =>
            {
                try
                {
                    var handler = handlerFactory.GetHandler<RepostCommand>();
                    string ids = parameters.msgList;
                    var repostModelIds = ids.Split(',');
                    var repostCommand = new RepostCommand { StoreName = parameters.storeName, MessageIds = repostModelIds.ToList() };
                    handler.Handle(repostCommand);

                    return Response.AsJson<int>(0, HttpStatusCode.OK);
                }
                catch (Exception e)
                {
                    return e;
                }
            });
        }
示例#7
0
        public MessagesNancyModule(IMessageListViewModelRetriever messageListViewModelRetriever)
            : base("/messages")
        {
            Get["/{storeName}/{pageNumber}"] = parameters =>
            {
                var logger = LogProvider.GetLogger("MessagesNancyModule");
                logger.Log(LogLevel.Debug, () => "GET on messages");

                string storeName = parameters.storeName;
                int pageNumber = parameters.pageNumber;
                var messageListModelResult = messageListViewModelRetriever.Get(storeName, pageNumber);

                if (!messageListModelResult.IsError)
                {
                    return Response.AsJson(messageListModelResult.Result);                    
                }
                switch (messageListModelResult.Error)
                {
                    case(MessageListModelError.StoreNotFound):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unknown store {0}", storeName)), HttpStatusCode.NotFound);
                    
                    case (MessageListModelError.StoreMessageViewerNotImplemented):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Found store {0} does not implement IMessageStoreViewer", storeName)), HttpStatusCode.NotFound);

                    case (MessageListModelError.StoreMessageViewerGetException):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unable to retrieve messages for store {0}", storeName)), HttpStatusCode.InternalServerError);

                    case (MessageListModelError.GetActivationStateFromConfigError):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Misconfigured Message Viewer, unable to retrieve messages for store {0}", storeName)), HttpStatusCode.InternalServerError);
                    default:
                        throw new SystemException("Code can't reach here");
                }
            };
        }
示例#8
0
        public StoresNancyModule(
            IMessageStoreActivationStateListViewModelRetriever messageStoreActivationStateListViewModelRetriever,
            IMessageStoreViewerModelRetriever messageStoreViewerModelRetriever,
            IMessageListViewModelRetriever messageSearchListItemRetriever)
            : base("/stores")
        {
            Get("/", x =>
            {
                var result = messageStoreActivationStateListViewModelRetriever.Get();
                if (!result.IsError)
                {
                    return Response.AsJson(result.Result);
                }
                switch (result.Error)
                {
                    case (MessageStoreActivationStateListModelError.GetActivationStateFromConfigError):
                        return Response.AsJson(new MessageViewerError("Mis-configured message viewer - unable to read config store"), HttpStatusCode.InternalServerError);
                    default:
                        throw new Exception("Code can't reach here");
                }
            });
            
            Get("/{name}", parameters =>
            {
                string storeName = parameters.Name;

                var result = messageStoreViewerModelRetriever.Get(storeName);
                if (!result.IsError)
                {
                    return Response.AsJson(result.Result);
                }
                switch (result.Error)
                {
                    case (MessageStoreViewerModelError.StoreNotFound):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unknown store {0}", storeName)), HttpStatusCode.NotFound);

                    case (MessageStoreViewerModelError.StoreMessageViewerNotImplemented):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Found store {0} does not implement IMessageStoreViewer", storeName)), HttpStatusCode.NotFound);

                    case (MessageStoreViewerModelError.StoreMessageViewerGetException):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unable to retrieve detail for store {0}", storeName)), HttpStatusCode.InternalServerError);

                    case (MessageStoreViewerModelError.GetActivationStateFromConfigError):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Mis-configured Message Viewer, unable to retrieve detail for store {0}", storeName)), HttpStatusCode.InternalServerError);
                    default:
                        throw new Exception("Code can't reach here");
                }
            });

            Get("/search/{storeName}/{searchTerm}", parameters =>
            {
                string messageStoreName = parameters.storeName;
                string searchTerm = parameters.searchTerm;

                ViewModelRetrieverResult<MessageListModel, MessageListModelError> searchModelResult = messageSearchListItemRetriever.Filter(messageStoreName, searchTerm);
                if (!searchModelResult.IsError)
                {
                    return Response.AsJson(searchModelResult.Result);
                }
                switch (searchModelResult.Error)
                {
                    case (MessageListModelError.StoreNotFound):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unknown store {0}", messageStoreName)), HttpStatusCode.NotFound);

                    case (MessageListModelError.StoreMessageViewerNotImplemented):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Found store {0} does not implement IMessageStoreViewer", messageStoreName)), HttpStatusCode.NotFound);

                    case (MessageListModelError.StoreMessageViewerGetException):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unable to retrieve messages for store {0}", messageStoreName)), HttpStatusCode.InternalServerError);
                    default:
                        throw new Exception("Code can't reach here");
                }
            });
        }
示例#9
0
        public StoresNancyModule(
            IMessageStoreActivationStateListViewModelRetriever messageStoreActivationStateListViewModelRetriever,
            IMessageStoreViewerModelRetriever messageStoreViewerModelRetriever,
            IMessageListViewModelRetriever messageSearchListItemRetriever)
            : base("/stores")
        {
            Get("/", x =>
            {
                var result = messageStoreActivationStateListViewModelRetriever.Get();
                if (!result.IsError)
                {
                    return(Response.AsJson(result.Result));
                }
                switch (result.Error)
                {
                case (MessageStoreActivationStateListModelError.GetActivationStateFromConfigError):
                    return(Response.AsJson(new MessageViewerError("Mis-configured message viewer - unable to read config store"), HttpStatusCode.InternalServerError));

                default:
                    throw new Exception("Code can't reach here");
                }
            });

            Get("/{name}", parameters =>
            {
                string storeName = parameters.Name;

                var result = messageStoreViewerModelRetriever.Get(storeName);
                if (!result.IsError)
                {
                    return(Response.AsJson(result.Result));
                }
                switch (result.Error)
                {
                case (MessageStoreViewerModelError.StoreNotFound):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unknown store {0}", storeName)), HttpStatusCode.NotFound));

                case (MessageStoreViewerModelError.StoreMessageViewerNotImplemented):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Found store {0} does not implement IMessageStoreViewer", storeName)), HttpStatusCode.NotFound));

                case (MessageStoreViewerModelError.StoreMessageViewerGetException):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unable to retrieve detail for store {0}", storeName)), HttpStatusCode.InternalServerError));

                case (MessageStoreViewerModelError.GetActivationStateFromConfigError):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Mis-configured Message Viewer, unable to retrieve detail for store {0}", storeName)), HttpStatusCode.InternalServerError));

                default:
                    throw new Exception("Code can't reach here");
                }
            });

            Get("/search/{storeName}/{searchTerm}", parameters =>
            {
                string messageStoreName = parameters.storeName;
                string searchTerm       = parameters.searchTerm;

                ViewModelRetrieverResult <MessageListModel, MessageListModelError> searchModelResult = messageSearchListItemRetriever.Filter(messageStoreName, searchTerm);
                if (!searchModelResult.IsError)
                {
                    return(Response.AsJson(searchModelResult.Result));
                }
                switch (searchModelResult.Error)
                {
                case (MessageListModelError.StoreNotFound):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unknown store {0}", messageStoreName)), HttpStatusCode.NotFound));

                case (MessageListModelError.StoreMessageViewerNotImplemented):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Found store {0} does not implement IMessageStoreViewer", messageStoreName)), HttpStatusCode.NotFound));

                case (MessageListModelError.StoreMessageViewerGetException):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unable to retrieve messages for store {0}", messageStoreName)), HttpStatusCode.InternalServerError));

                default:
                    throw new Exception("Code can't reach here");
                }
            });
        }
示例#10
0
        public StoresNancyModule(
            IMessageStoreActivationStateListViewModelRetriever messageStoreActivationStateListViewModelRetriever,
            IMessageStoreViewerModelRetriever messageStoreViewerModelRetriever,
            IMessageListViewModelRetriever messageSearchListItemRetriever)
            : base("/stores")
        {
            _logger = LogProvider.GetLogger("StoresNancyModule");

            Get["/"] = x =>
            {
                _logger.Log(LogLevel.Debug, () => "GET on stores");

                var result = messageStoreActivationStateListViewModelRetriever.Get();
                if (!result.IsError)
                {
                    return Response.AsJson(result.Result);
                }
                switch (result.Error)
                {
                    case (MessageStoreActivationStateListModelError.GetActivationStateFromConfigError):
                        return Response.AsJson(new MessageViewerError("Misconfigured message viewer - unable to read config store"), HttpStatusCode.InternalServerError);
                    default:
                        throw new SystemException("Code can't reach here");
                }
            };
            
            Get["/{name}"] = parameters =>
            {
                string storeName = parameters.Name;
                _logger.Log(LogLevel.Debug, () => "GET store " + storeName);

                var result = messageStoreViewerModelRetriever.Get(storeName);
                if (!result.IsError)
                {
                    return Response.AsJson(result.Result);
                }
                switch (result.Error)
                {
                    case (MessageStoreViewerModelError.StoreNotFound):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unknown store {0}", storeName)), HttpStatusCode.NotFound);

                    case (MessageStoreViewerModelError.StoreMessageViewerNotImplemented):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Found store {0} does not implement IMessageStoreViewer", storeName)), HttpStatusCode.NotFound);

                    case (MessageStoreViewerModelError.StoreMessageViewerGetException):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unable to retrieve detail for store {0}", storeName)), HttpStatusCode.InternalServerError);

                    case (MessageStoreViewerModelError.GetActivationStateFromConfigError):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Misconfigured Message Viewer, unable to retrieve detail for store {0}", storeName)), HttpStatusCode.InternalServerError);
                    default:
                        throw new SystemException("Code can't reach here");
                }
            };

            Get["/search/{storeName}/{searchTerm}"] = parameters =>
            {
                string messageStoreName = parameters.storeName;
                string searchTerm = parameters.searchTerm;
                _logger.Log(LogLevel.Debug, () => string.Format("SEARCH store {0} with '{1}'", messageStoreName, searchTerm));

                var searchModelResult = messageSearchListItemRetriever.Filter(messageStoreName, searchTerm);
                if (!searchModelResult.IsError)
                {
                    return Response.AsJson(searchModelResult.Result);
                }
                switch (searchModelResult.Error)
                {
                    case (MessageListModelError.StoreNotFound):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unknown store {0}", messageStoreName)), HttpStatusCode.NotFound);

                    case (MessageListModelError.StoreMessageViewerNotImplemented):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Found store {0} does not implement IMessageStoreViewer", messageStoreName)), HttpStatusCode.NotFound);

                    case (MessageListModelError.StoreMessageViewerGetException):
                        return Response.AsJson(new MessageViewerError(
                            string.Format("Unable to retrieve messages for store {0}", messageStoreName)), HttpStatusCode.InternalServerError);
                    default:
                        throw new SystemException("Code can't reach here");
                }
            };
        }
 public static void MessagesModule(
     this ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator config,
     IMessageListViewModelRetriever messageListViewModelRetriever)
 {
     config.MessagesModule(messageListViewModelRetriever, new FakeHandlerFactory());
 }
 public static void MessagesModule(
     this ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator config,
     IMessageListViewModelRetriever messageListViewModelRetriever)
 {
     config.MessagesModule(messageListViewModelRetriever, new FakeHandlerFactory());
 }