Exemplo n.º 1
0
        public async void LogSeasonChanged(Season season)
        {
            LogEntry entry = new LogEntry();
            entry.Function = Function.Click.ToString();
            entry.Operation = Operation.Season.ToString();
            entry.Error = null;
            entry.Method = "SeasonChanged";
            entry.ErrorLevel = ErrorLevel.Info.ToString();

            entry.AttributesDictionary = new Dictionary<string, object>();
            entry.AttributesDictionary.Add("Method", "SeasonChanged");
            entry.AttributesDictionary.Add("Season", season.seasonId);
            entry.AttributesDictionary.Add("Year", season.year);
            entry.AttributesDictionary.Add("ClickedOn", DateTime.Now);

            entry.Attributes = JsonConvert.SerializeObject(entry.AttributesDictionary);
            entry.AttributesDictionary = null;

            ServiceAccessor.MakeApiCallLog(ServiceAccessor.URL_SERVICE_LOG, JsonConvert.SerializeObject(entry));
        }
Exemplo n.º 2
0
        public async Task DownloadPlaylists(List<Playlist> playlists, Season seasonAndGame)//list of playlists,  season(with game)
        {
            currentlyDownloadingPlaylists = playlists;
            backgroundDownloader = new BackgroundDownloader();
            Downloading = true;
            TotalBytes = 0;
            ClipsComplete = 0;
            CurrentDownloadedBytes = 0;
            TotalClips = 0;
            var httpClient = new System.Net.Http.HttpClient();
            
            foreach (Playlist cut in playlists)
            {
                foreach (Clip c in cut.clips)
                {
                    foreach (Angle angle in c.angles)
                    {
                        TotalBytes += angle.fileSize;
                        TotalClips++;
                    }
                }
            }
            long playlistSize = 0;
            var userFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync(AppDataAccessor.GetUsername(), Windows.Storage.CreationCollisionOption.OpenIfExists);
            foreach (Playlist pl in playlists)
            {
                // Log download playlist begin
                Logger.Instance.LogPlaylistDownloadStart(pl);

                playlistSize = 0;
                var fileFolder = await userFolder.CreateFolderAsync(pl.playlistId, Windows.Storage.CreationCollisionOption.OpenIfExists);
                //save thumbnail
                var sourceThumb = new Uri(pl.thumbnailLocation);
                var destinationFileThumb = await fileFolder.CreateFileAsync("Thumbnail.jpg", CreationCollisionOption.ReplaceExisting);
                var downloaderThumb = new BackgroundDownloader();
                var downloadThumb = downloaderThumb.CreateDownload(sourceThumb, destinationFileThumb);
                var downloadOperationThumb = await downloadThumb.StartAsync();
                var fileThumb = (StorageFile)downloadOperationThumb.ResultFile;
                pl.downloadedThumbnailLocation = fileThumb.Path.Replace("\\", "/");
                var files = await fileFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName);
                foreach (Clip c in pl.clips)
                {
                    foreach (Angle angle in c.angles)
                    {
                        try
                        {
                            var source = new Uri(angle.fileLocation);
                            var file = files.FirstOrDefault(x => x.Name.Equals(angle.clipAngleId.ToString()));

                            if (file == null)
                            {
                                //PlaylistId-ClipId-ClipAngleId
                                var destinationFile = await fileFolder.CreateFileAsync(pl.playlistId + "-" + c.clipId + "-" + angle.clipAngleId, CreationCollisionOption.ReplaceExisting);
                                Download = backgroundDownloader.CreateDownload(source, destinationFile);
                                file = await StartDownloadAsync(Download);
                                //BasicProperties prop = await file.GetBasicPropertiesAsync();
                                long newBytesDownloaded = diskSpaceFromDownloads.totalBytes + angle.fileSize;
                                playlistSize += angle.fileSize;
                                diskSpaceFromDownloads = new DiskSpaceResponse { totalBytes = newBytesDownloaded, formattedSize = FormatBytes(newBytesDownloaded) };
                                angle.preloadFile = file.Path;
                                angle.isPreloaded = true;
                                ClipsComplete++;
                            }
                        }
                        catch (Exception e)
                        {
                            RemoveDownload(pl);
                            return;
                        }
                    }
                }
                pl.totalFilesSize = playlistSize;
                StorageFile downloadModel = await fileFolder.CreateFileAsync("DownloadsModel", Windows.Storage.CreationCollisionOption.OpenIfExists);
                pl.downloadedDate = DateTime.Now;
                string updatedModel = JsonConvert.SerializeObject(pl);
                await Windows.Storage.FileIO.WriteTextAsync(downloadModel, updatedModel);
                downloadedPlaylists.Add(pl);

                // Log download complete
                Logger.Instance.LogPlaylistDownloadComplete(pl);
            }
            Game selectedGame = seasonAndGame.games.FirstOrDefault();
            Game newGameWithOnlyDownloads = new Game { date = selectedGame.date, gameId = selectedGame.gameId, opponent = selectedGame.opponent, categories = new BindableCollection<Category>() };
            foreach (Category c in selectedGame.categories)
            {
                foreach (Playlist plFromSelectedGame in c.playlists)
                {
                    foreach (Playlist plFromParameter in playlists)
                    {
                        if (plFromSelectedGame.playlistId == plFromParameter.playlistId)
                        {
                            Category foundCat = newGameWithOnlyDownloads.categories.Where(u => u.categoryId == c.categoryId).FirstOrDefault();
                            if (foundCat == null)
                            {
                                newGameWithOnlyDownloads.categories.Add(new Category { categoryId = c.categoryId, name = c.name, playlists = c.playlists });
                            }
                            break;
                        }
                    }
                }
            }

            foreach (Category c in newGameWithOnlyDownloads.categories)
            {
                BindableCollection<Playlist> newPlaylists = new BindableCollection<Playlist>();
                foreach (Playlist pl in c.playlists)
                {
                    Playlist found = playlists.Where(u => u.playlistId == pl.playlistId).FirstOrDefault();
                    if (found != null)
                    {
                        newPlaylists.Add(found);
                    }
                }
                c.playlists = newPlaylists;
            }
            seasonAndGame.games[0] = newGameWithOnlyDownloads;//model to be saved
            seasonAndGame.owningTeam.seasons = null;

            BindableCollection<Season> currentDownloadsCompleteModel = await GetDownloadsModel();
            bool seasonFound = false;
            foreach (Season s in currentDownloadsCompleteModel)
            {
                if (s.seasonId == seasonAndGame.seasonId)//found the season we need to merge
                {
                    seasonFound = true;
                    Game g = s.games.Where(u => u.gameId == newGameWithOnlyDownloads.gameId).FirstOrDefault();
                    if (g != null)
                    {
                        BindableCollection<Category> newCategories = g.categories;
                        foreach (Category newCat in newGameWithOnlyDownloads.categories)//gameToBeAdded could have multiple new categories and playlists
                        {
                            Category fromCurrent = g.categories.Where(u => u.categoryId == newCat.categoryId).FirstOrDefault();
                            if (fromCurrent == null)
                            {
                                g.categories.Add(newCat);
                            }
                            else
                            {
                                foreach (Playlist p in newCat.playlists)
                                {
                                    fromCurrent.playlists.Add(p);
                                }
                            }
                        }

                    }
                    else
                    {
                        s.games.Add(newGameWithOnlyDownloads);
                    }
                }
            }
            if (!seasonFound)
            {
                currentDownloadsCompleteModel.Add(seasonAndGame);
            }

            StorageFile completeModelFile = await userFolder.CreateFileAsync("CompleteModel", Windows.Storage.CreationCollisionOption.OpenIfExists);
            string complete = JsonConvert.SerializeObject(currentDownloadsCompleteModel);
            await Windows.Storage.FileIO.WriteTextAsync(completeModelFile, complete);

 
            DownloadComplete_Notification();
            Downloading = false;
            CurrentDownloadedBytes = 0;
            TotalBytes = 0;
            currentlyDownloadingPlaylists = new List<Playlist>();
        }
Exemplo n.º 3
0
 internal static Season DeepCopy(Season seasonAndGame)
 {
     Season returnSeason = new Season {name = seasonAndGame.name, seasonId = seasonAndGame.seasonId, owningTeam = seasonAndGame.owningTeam, year = seasonAndGame.year };
     foreach (Game g in seasonAndGame.games)
     {
         Game newGame = new Game { date = g.date, gameId = g.gameId, opponent = g.opponent };
         foreach (Category c in g.categories)
         {
             Category newCategory = new Category { categoryId = c.categoryId, name = c.name };
             foreach (Playlist p in c.playlists)
             {
                 newCategory.playlists.Add(Playlist.Copy(p));
             }
             newGame.categories.Add(newCategory);
         }
         returnSeason.games.Add(newGame);
     }
     return returnSeason;
 }
Exemplo n.º 4
0
        public async void GameSelected(ItemClickEventArgs eventArgs)
        {
            PageIsEnabled = false;
            ProgressRingIsActive = true;
            ProgressRingVisibility = Visibility.Visible;

            GameViewModel gameViewModel = (GameViewModel)eventArgs.ClickedItem;
            Season seasonToPass = new Season() { name=selectedSeason.name, owningTeam = selectedSeason.owningTeam, seasonId = selectedSeason.seasonId, year = selectedSeason.year, games = new BindableCollection<Game>() }; //Because we're changing the games in this season, we need to make a copy.
            seasonToPass.games.Add(gameViewModel.GameModel);

            if (!gameViewModel.IsLastViewed)
            {
                try
                {
                    await gameViewModel.FetchPlaylists;
                    navigationService.NavigateToViewModel<SectionViewModel>(new PageParameter { season = seasonToPass, hubGroups = Groups, playlist = new Playlist() });

                    if (gameViewModel.IsNextGame)
                    {
                        Logger.Instance.LogGameSelected(gameViewModel.GameModel, Logger.LOG_GAME_NEXT);
                    }
                    else if (gameViewModel.IsPreviousGame)
                    {
                        Logger.Instance.LogGameSelected(gameViewModel.GameModel, Logger.LOG_GAME_PREVIOUS);
                    }
                    else
                    {
                        Logger.Instance.LogGameSelected(gameViewModel.GameModel);
                    }
                }
                catch
                {
                    navigationService.NavigateToViewModel<ErrorViewModel>();
                }
            }
            else
            {
                Playlist downloadedPlaylist = DownloadAccessor.Instance.downloadedPlaylists.Where(u => u.playlistId == gameViewModel.GameModel.gameId).FirstOrDefault();
                if (downloadedPlaylist != null)
                {
                    navigationService.NavigateToViewModel<VideoPlayerViewModel>(new PageParameter { season = seasonToPass, hubGroups = Groups, playlist = downloadedPlaylist });
                    Logger.Instance.LogLastViewedClick(downloadedPlaylist);
                }
                else
                {
                    ClipResponse response = await ServiceAccessor.GetPlaylistClipsAndHeaders(gameViewModel.GameModel.gameId);
                    Playlist lastViewedPlaylist = new Playlist { playlistId = gameViewModel.GameModel.gameId, name = gameViewModel.GameModel.opponent, thumbnailLocation = gameViewModel.Thumbnail, clips = response.clips, displayColumns = response.DisplayColumns, clipCount = response.clips.Count };
                    navigationService.NavigateToViewModel<VideoPlayerViewModel>(new PageParameter { season = seasonToPass, hubGroups = Groups, playlist = lastViewedPlaylist });
                    Logger.Instance.LogLastViewedClick(lastViewedPlaylist);
                }
            }
            
        }
Exemplo n.º 5
0
 public static Season FromDTO(SeasonDTO seasonDTO, Team team)
 {
     Season s = new Season();
     s.owningTeam = team;
     s.name = seasonDTO.Name;
     s.seasonId = seasonDTO.SeasonId;
     s.year = seasonDTO.Year;
     return s;
 }