Example #1
0
        public async void LogGameSelected(Game game, string description = "GameSelected")
        {
            LogEntry entry = new LogEntry();
            entry.Function = Function.Click.ToString();
            entry.Operation = Operation.Game.ToString();
            entry.Error = null;
            entry.Method = description;
            entry.ErrorLevel = ErrorLevel.Info.ToString();

            entry.AttributesDictionary = new Dictionary<string, object>();
            entry.AttributesDictionary.Add("Method", description);
            entry.AttributesDictionary.Add("Game", game.gameId);
            entry.AttributesDictionary.Add("ClickedOn", DateTime.Now);

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

            ServiceAccessor.MakeApiCallLog(ServiceAccessor.URL_SERVICE_LOG, JsonConvert.SerializeObject(entry));
        }
Example #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>();
        }
Example #3
0
 public GameViewModel(Game game, bool isLarge = false, bool isLastviewed = false, bool isNextGame = false, bool isPreviousGame = false)
 {
     GameModel = game;
     IsLargeView = isLarge;
     IsLastViewed = isLastviewed;
     IsNextGame = isNextGame;
     IsPreviousGame = isPreviousGame;
     Thumbnail = "ms-appx:///Assets/hudl-mark-gray.png";
     Stretch = "None";
 }
Example #4
0
        protected override void OnActivate()//called every page load
        {
            base.OnActivate();
            if (currentUserName != AppDataAccessor.GetUsername())
            {
                Groups = new BindableCollection<HubGroupViewModel>();//clears old page after logout
                OnInitialize();
            }
            SettingsPane.GetForCurrentView().CommandsRequested += CharmsData.SettingCharmManager_HubCommandsRequested;

            ProgressRingVisibility = Visibility.Collapsed;
            ProgressRingIsActive = false;

            PageIsEnabled = true;
            LastViewedResponse response = AppDataAccessor.GetLastViewed();
            if (response.ID != null && ServiceAccessor.ConnectedToInternet())
            {
                Game LastViewedGame = new Game { gameId = response.ID, opponent = response.name, date = DateTime.Parse(response.timeStamp) };//this is actually a playlist - not a game
                GameViewModel lastViewed = new GameViewModel(LastViewedGame, true, isLastviewed:true);
                lastViewed.Thumbnail = response.thumbnail;
                lastViewed.Stretch = "UniformToFill";
                LastViewedVM = new HubGroupViewModel() { Name = "Last Viewed", Games = new BindableCollection<GameViewModel>() };
                LastViewedVM.Games.Add(lastViewed);

                if (Groups.Count == 0 && (NoScheduleEntriesText == null || NoScheduleEntriesText == ""))
                {
                    ProgressRingVisibility = Visibility.Visible;
                    ProgressRingIsActive = true;
                }

                if (Groups.Count >= 3)
                {
                    
                    HubGroupViewModel oldLastViewed = Groups.Where(u => u.Name == "Last Viewed").FirstOrDefault();
                    if (oldLastViewed != null)
                    {
                        Groups[Groups.IndexOf(oldLastViewed)] = LastViewedVM;
                    }
                    else
                    {
                        Groups.Insert(1, LastViewedVM);
                    }
                }
            }
        }
Example #5
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;
 }
Example #6
0
        public static Game FromDTO(CategoryDTO gameDTO)
        {
            Game game = new Game();
            int c;
            int.TryParse(gameDTO.Classification, out c);
            game.Classification = c;
            string[] oppAndDate = gameDTO.Name.Split('-'); //in the call we're using to return this information, opponent and date are concatenated.
            game.gameId = gameDTO.CategoryId;

            //get the game's name
            if (gameDTO.Classification == "1")
            {
                game.opponent = "";

                for (int i = 0; i < oppAndDate.Length - 1; i++)
                {
                    game.opponent += oppAndDate[i];
                }

                string[] date = oppAndDate.Last().Split('/');
                int year;
                int month;
                int day;
                try
                {
                    int.TryParse(date[2], out year);
                    int.TryParse(date[1], out day);
                    int.TryParse(date[0], out month);
                    game.date = new DateTime(year, month, day);
                }
                catch (Exception e)
                {
                    game.date = new DateTime();
                }

            }
            else
            {
                game.opponent = gameDTO.Name;
            }
            foreach(CategoryDTO cat in gameDTO.SubCategories)
            {
                game.categories.Add(Category.FromDTO(cat));
            }
            return game;
        }