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); }
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"); } }); }
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"); } }); }
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"); } }; }