Example #1
0
 private dynamic ResolvePlaceHolderImageForDocumentType(IEnvironmentPathProvider pathProvider, dynamic doc)
 {
     if (doc is Cd)
     {
         return Response.AsFile(Path.Combine(pathProvider.GetPlaceHolderImagesPath(), "Cd.png"));
     }
     if (doc is Book)
     {
         return Response.AsFile(Path.Combine(pathProvider.GetPlaceHolderImagesPath(), "Book.png"));
     }
     if (doc is Film)
     {
         return Response.AsFile(Path.Combine(pathProvider.GetPlaceHolderImagesPath(), "Film.png"));
     }
     if (doc is SheetMusic)
     {
         return Response.AsFile(Path.Combine(pathProvider.GetPlaceHolderImagesPath(), "SheetMusic.png"));
     }
     if (doc is Journal)
     {
         return Response.AsFile(Path.Combine(pathProvider.GetPlaceHolderImagesPath(), "Journal.png"));
     }
     if (doc is Game)
     {
         return Response.AsFile(Path.Combine(pathProvider.GetPlaceHolderImagesPath(), "Game.png"));
     }
     if (doc is AudioBook)
     {
         return Response.AsFile(Path.Combine(pathProvider.GetPlaceHolderImagesPath(), "AudioBook.png"));
     }
     return Response.AsFile(Path.Combine(pathProvider.GetPlaceHolderImagesPath(), "Document.png"));
 }
Example #2
0
        public ListModule(ILibraryListRepository lists, IRepository documents, IImageRepository images, IEnvironmentPathProvider pathProvider)
            : base("/lists")
        {
            _documents = documents;
            
            Get["/"] = _ =>
            {
                var results = lists.GetAll().Select(doc => DtoMaps.Map(doc));
                return Response.AsJson(results).AsCacheable(DateTime.Now.AddDays(1)); // f***s up CORS... ?
            };

            Get["/{id}"] = args =>
            {
                LibrarylistDto dto = DtoMaps.Map(lists.Get(args.id), _documents);
                return Response.AsJson(dto).AsCacheable(DateTime.Now.AddDays(1));
            };

            Get["/{id}/thumbnail"] = args =>
            {
                LibraryList list = lists.Get(args.id);

                foreach (var docNo in list.DocumentNumbers.Keys)
                {
                    var img = images.GetDocumentImage(docNo);

                    if (String.IsNullOrEmpty(img)) continue;

                    return Response.AsFile(Path.Combine(pathProvider.GetImageCachePath(), img));
                }

                return TextResponse.NoBody; // todo: placeholder img
            };
        }
        public LibraryListXmlRepository(IRepository repository, IImageRepository imageRepository, IEnvironmentPathProvider environment)
        {
            _repository = repository;
            _imageRepository = imageRepository;

            var folderPath = environment.GetXmlListPath();
            _folderPath = string.IsNullOrEmpty(folderPath) ? StdFolderPath : folderPath;
        }
        public InformationRepositoryXml(IEnvironmentPathProvider environment)
        {
            var filePathOpening = environment.GetOpeningInfoAsXmlPath();
            var filePathContact = environment.GetContactInfoAsXmlPath();

            _filePathOpening = string.IsNullOrEmpty(filePathOpening) ? StdFilePathOpening : filePathOpening;
            _filePathContact = string.IsNullOrEmpty(filePathContact) ? StdFilePathContact : filePathContact;
        }
        public LibraryListDynamicRepository(IRepository documentRepository, IImageRepository imageRepository, IEnvironmentPathProvider environment)
        {
            this._documentRepository = documentRepository;
            this._imageRepository = imageRepository;

            var xmlFilePath = environment.GetXmlFilePath();
            _xmlFolderPath = string.IsNullOrEmpty(xmlFilePath) ? StdFolderPath : xmlFilePath;
        }
Example #6
0
        public DocumentModule(IRepository documents, IImageRepository images, IRatingRepository ratings, IReviewRepository reviews, IFavoritesRepository favorites, IEnvironmentPathProvider pathProvider)
            : base("/documents")
        {
            Get["/{id}/thumbnail"] = args =>
            {
                var doc = documents.GetDocument(args.id, true);
                string img = images.GetDocumentImage(args.id);

                if (String.IsNullOrEmpty(img))
                {
                    return ResolvePlaceHolderImageForDocumentType(pathProvider, doc);
                }

                return Response.AsFile(Path.Combine(pathProvider.GetImageCachePath(), img));
            };

            Get["/{id}"] = args =>
            {
                Document document = documents.GetDocument(args.id, false);
                return Response.AsJson(DtoMaps.Map(document, favorites, Context.GetUserInfo()));
            };
            
            Get["/{id}/rating"] = args =>
            {
                try
                {
                    DocumentRating rating = ratings.GetDocumentRating(args.id);

                    return Response.AsJson(new DocumentRatingDto
                    {
                        MaxScore = rating.MaxScore,
                        Score = rating.Score,
                        Source = rating.Source,
                        SourceUrl = rating.SourceUrl,
                        HasRating = true
                    }).AsCacheable(DateTime.Now.AddDays(1));
                }
                catch
                {
                    return new DocumentRatingDto {Success = true, HasRating = false};
                }
            };

            Get["/{id}/review"] = args =>
            {
                string review = reviews.GetDocumentReview(args.id);
                return Response.AsJson(new DocumentReviewDto{ Review = review, Url = "" }).AsCacheable(DateTime.Now.AddDays(1));
            };

            Get["/search"] = _ =>
            {
                string query = Request.Query.query.HasValue ? Request.Query.query : null;

                if (null == query) throw new InvalidOperationException("Ingenting å søke etter.");

                return Response.AsJson(documents.Search(query).Select(doc => DtoMaps.Map(doc, favorites, Context.GetUserInfo())).ToArray()).AsCacheable(DateTime.Now.AddHours(12));
            };
        }
Example #7
0
        public AlephRepository(IEnvironmentPathProvider environment)
        {
            var pathToImageCache = environment.GetImageCachePath();
            var pathToRulesFolder = environment.GetRulesPath();

            _storageHelper = new StorageHelper(pathToImageCache);
            _imageRepository = new ImageRepository(null, environment);
            if (pathToRulesFolder != null)
                _rulesRepository = new RulesRepository(pathToRulesFolder);

        }
Example #8
0
        public SlideConfigModule(IEnvironmentPathProvider pathProvider) : base("/slides")
        {
            _pathProvider = pathProvider;

            Get["/{id}"] = args =>
                {
                    var slideConfigs = GetSlideConfigurationsFromFile();
                    if (slideConfigs.ContainsKey(args.id))
                    {
                        return Response.AsJson(slideConfigs[(string)args.id]).AsCacheable(DateTime.Now.AddMinutes(20));
                    }

                    return slideConfigs.ContainsKey("default") ? Response.AsJson(slideConfigs["default"]).AsCacheable(DateTime.Now.AddMinutes(20)) : 404;
                };
        }
        public DocumentModuleTests()
        {
            _documentRepository = A.Fake<IRepository>();
            _imageRepository = A.Fake<IImageRepository>();
            _ratingRepository = A.Fake<IRatingRepository>();
            _reviewRepository = A.Fake<IReviewRepository>();
            _pathProvider = A.Fake<IEnvironmentPathProvider>();

            _browser = new Browser(with =>
            {
                with.Module<DocumentModule>();
                with.Dependency(_documentRepository);
                with.Dependency(_imageRepository);
                with.Dependency(_ratingRepository);
                with.Dependency(_reviewRepository);
                with.Dependency(_pathProvider);
                with.Dependency(A.Fake<IFavoritesRepository>());
            });
        }
Example #10
0
        public LuceneRepository(IEnvironmentPathProvider environment, IRepository documentRepository = null)
        {
            var indexPath = environment.GetDictionaryIndexPath();
            var suggestionPath = environment.GetSuggestionListPath();

            _pathToSuggestionsDict = string.IsNullOrEmpty(suggestionPath)
                ? @"App_Data\ordlister\ord_forslag.txt" : suggestionPath;
            
            if (!File.Exists(_pathToSuggestionsDict)) File.Create(_pathToSuggestionsDict); 
            
            _pathToDictDir = string.IsNullOrEmpty(indexPath)
                ? @"App_Data\ordlister_index" : indexPath;

            _suggestionList = new HashSet<string>();

            _documentRepository = documentRepository;


        }
Example #11
0
        public EventModule(IEnvironmentPathProvider env) : base("/events")
        {
            var events = new List<EventDto>();

            var client = new WebClient();
            client.Encoding = Encoding.UTF8;

            var organizerId = ConfigurationManager.AppSettings["TicketCoOrganizerId"];
            var apiToken = ConfigurationManager.AppSettings["TicketCoApiToken"];

            var eventsJson = client.DownloadString(new Uri(
                String.Format("https://ticketco.no/api/public/v1/events?organizer_id={0}&token={1}", organizerId,
                    apiToken)));

            var serializer = new JsonSerializer();
            serializer.Culture = new CultureInfo("nb-no");

            var ticketCoEvents = serializer.Deserialize<TicketCoResult>(new JsonTextReader(new StringReader(eventsJson)));

            foreach (var element in ticketCoEvents.events)
            {
                var ev = new EventDto();
                events.Add(ev);

                ev.Id = element.mobile_link.GetHashCode();
                ev.Name = element.title;
                ev.Description = element.description;
                ev.ImageUrl = element.image.iphone2x.url;
                ev.Location = element.location_name;
                ev.Start = element.start_at;
                ev.End = element.end_at;
                ev.TicketPrice = element.ticket_price;
                ev.TicketUrl = element.mobile_link;
            }

            // todo: implement after new events integration in place
            Get["/"] = _ => events.OrderBy(ev => ev.Start).ToArray();

            Get["/{id}"] = args => events.FirstOrDefault(ev => ev.Id == args.id);
        }
Example #12
0
        public ImageRepository(IRepository documentRepository, IEnvironmentPathProvider environment)
        {
            var pathToImageCache = environment.GetImageCachePath();

            _documentRepository = documentRepository;

            _pathToImageCache = string.IsNullOrEmpty(pathToImageCache)
    ? @"App_Data\"+Properties.Settings.Default.ImageCacheFolder : pathToImageCache;

            _storageHelper = new StorageHelper(_pathToImageCache);


            _serveruri = Properties.Settings.Default.BokBasenServerUri;
            _serverSystem = Properties.Settings.Default.BokBasenSystem;

            _xmluri = _serveruri;

            foreach (var param in _trueParams)
                _xmluri += param + "=true&";

            _xmluri += "SYSTEM=" + _serverSystem;
        }
 public FavoritesRepository(IRepository documents, IEnvironmentPathProvider pathProvider)
 {
     _documents = documents;
     _pathProvider = pathProvider;
 }
Example #14
0
 public BlogRepository(IEnvironmentPathProvider environment)
 {
     var folderPath = environment.GetBlogFeedPath();
     _folderPath = string.IsNullOrEmpty(folderPath) ? StdFolderPath : folderPath;
 }