Example #1
0
        public void ProcessRoutes(IProgressListener listener, ITransactionDataAccess dataAccess, Dictionary <MediaDto, string> mediaToFilePath)
        {
            fetchedMedia = mediaDataFetcher.CombineMediasAndFiles(dataAccess, mediaToFilePath);

            ProcessUpdatedRoutes(listener, dataAccess);
            ProcessNewRoutes(listener, dataAccess);
        }
        private void ProcessUpdatedExhibits(IProgressListener listener, FetchedMediaData fetchedMedia, ITransactionDataAccess dataAccess)
        {
            var exhibits = dataAccess.Exhibits().GetExhibits().ToDictionary(x => x.IdForRestApi);

            foreach (var exhibitDto in updatedExhibits)
            {
                var dbExhibit = exhibits[exhibitDto.Id];

                ExhibitConverter.Convert(exhibitDto, dbExhibit);

                AddImageToExhibit(dbExhibit, exhibitDto.Image, fetchedMedia);
                //TODO: Check if exhibit was already downloaded
                //if(dbExhibit.DetailsDataLoaded)
                //{
                //    IoCManager.Resolve<INewDataCenter>().AddExhibitToBeUpdated(dbExhibit);
                //}

                var removedPages = dbExhibit.Pages.Where(x => !exhibitDto.Pages.Contains(x.IdForRestApi));
                foreach (var page in removedPages)
                {
                    dbExhibit.Pages.Remove(page);
                }

                listener.ProgressOneStep();
            }
        }
        private void ProcessNewExhibits(IProgressListener listener, FetchedMediaData fetchedMedia, ITransactionDataAccess dataAccess)
        {
            foreach (var exhibitDto in newExhibits)
            {
                var dbExhibit = ExhibitConverter.Convert(exhibitDto);

                AddImageToExhibit(dbExhibit, exhibitDto.Image, fetchedMedia);
                dataAccess.Exhibits().AddExhibit(dbExhibit);
                listener.ProgressOneStep();
            }
        }
Example #4
0
        private void AddContentToPage(Page dbPage, PageDto pageDto, FetchedMediaData fetchedMedia)
        {
            if (pageDto != null && dbPage != null)
            {
                PageConverter.Convert(pageDto, dbPage);

                switch (dbPage)
                {
                case ImagePage imagePage:
                    var image = fetchedMedia.Images.SingleOrDefault(x => x.IdForRestApi == pageDto.Image);
                    imagePage.Image = image ?? BackupData.BackupImage;
                    break;

                case TextPage textPage:
                    break;

                case TimeSliderPage timeSliderPage:
                    var fetchedImages = fetchedMedia.Images;

                    if (fetchedImages.Count > 0)
                    {
                        Debug2.Assert(timeSliderPage.SliderImages.Count == pageDto.Images.Count);
                        for (var i = 0; i < timeSliderPage.SliderImages.Count; i++)
                        {
                            var imageId = pageDto.Images[i].Image;
                            var dbImage = fetchedImages.FirstOrDefault(img => img.IdForRestApi == imageId);
                            timeSliderPage.SliderImages[i].Image = dbImage;
                        }
                    }
                    else
                    {
                        timeSliderPage.SliderImages.Add(new TimeSliderPageImage
                        {
                            Page  = timeSliderPage,
                            Image = BackupData.BackupImage
                        });
                    }

                    break;
                }

                var audio = fetchedMedia.Audios.SingleOrDefault(x => x.IdForRestApi == pageDto.Audio);

                if (audio != null)
                {
                    dbPage.Audio = audio;
                }
            }
        }
Example #5
0
        private void AddImageToRoute(Route dbRoute, int?mediaId, FetchedMediaData fetchedMediaData)
        {
            if (mediaId.HasValue)
            {
                var image = fetchedMediaData.Images.SingleOrDefault(x => x.IdForRestApi == mediaId);

                if (image != null)
                {
                    dbRoute.Image = image;
                }
            }
            else
            {
                dbRoute.Image = BackupData.BackupImage;
            }
        }
Example #6
0
        private void AddAudioToRoute(Route dbRoute, int?mediaId, FetchedMediaData fetchedMediaData)
        {
            if (!mediaId.HasValue)
            {
                return;
            }

            var audio = fetchedMediaData.Audios.SingleOrDefault(x => x.IdForRestApi == mediaId);

            if (audio == null)
            {
                return;
            }

            dbRoute.Audio = audio;
        }
Example #7
0
        public FetchedMediaData CombineMediasAndFiles(ITransactionDataAccess dataAccess, Dictionary <MediaDto, string> mediaToFilePath)
        {
            var fetchedData = new FetchedMediaData
            {
                Audios = new List <Audio>(),
                Images = new List <Image>()
            };

            if (fetchedMedias == null)
            {
                return(fetchedData);
            }

            foreach (var mediaDto in fetchedMedias)
            {
                var isAudio =
                    mediaDto.Type == MediaTypeDto.Audio ? true :
                    mediaDto.Type == MediaTypeDto.Image ? false :
                    throw new ArgumentOutOfRangeException("Unsupported media type");

                var dbMedia = isAudio
                    ? audioConverter.ConvertReplacingExisting(mediaDto, mediaDto.Id.ToString(), dataAccess)
                    : imageConverter.ConvertReplacingExisting(mediaDto, mediaDto.Id.ToString(), dataAccess) as Media;

                dbMedia.DataPath = mediaToFilePath.TryGetValueOrDefault(mediaDto) ??
                                   throw new NullReferenceException($"No file path for image {mediaDto.Id}");

                if (isAudio)
                {
                    fetchedData.Audios.Add((Audio)dbMedia);
                }
                else
                {
                    fetchedData.Images.Add((Image)dbMedia);
                }
            }

            return(fetchedData);
        }
Example #8
0
        private void AddTagsToRoute(Route dbRoute, RouteDto routeDto, FetchedMediaData fetchedMediaData)
        {
            if (routeDto.Tags != null && routeDto.Tags.Any())
            {
                foreach (var tagId in routeDto.Tags)
                {
                    var tagDto = routeTags.SingleOrDefault(x => x.Id == tagId);

                    if (tagDto != null)
                    {
                        RouteTag dbTag = dbRoute.Tags.SingleOrDefault(x => x.IdForRestApi == tagId);

                        if (dbTag != null)
                        {
                            TagConverter.Convert(tagDto, dbTag);
                        }
                        else
                        {
                            dbTag = TagConverter.Convert(tagDto);
                            dbRoute.Tags.Add(dbTag);
                        }

                        if (tagDto.Image.HasValue)
                        {
                            var tagImage = fetchedMediaData.Images.SingleOrDefault(x => x.IdForRestApi == tagDto.Image);
                            if (tagImage != null)
                            {
                                dbTag.Image = tagImage;
                            }
                        }
                        else
                        {
                            dbTag.Image = BackupData.BackupImageTag;
                        }
                    }
                }
            }
        }