public TennisDataItem(String uniqueId, String title, String subtitle, String imagePath, String description, String content, TennisDataGroup group) : base(uniqueId, title, subtitle, imagePath, description) { this._content = content; this._group = group; }
public async void PopulateData() { string[] theName = null; string[] theImage = null; string[] theDescription = null; string[,] theTitlesCountComparation = null; string[,] theTimeBetweenComparation = null; string[,] theWinningYearsComparation = null; string[,] theTitlesValueComparation = null; string[,] theFinalResultComparation = null; int[] theTitles = null; DateTime australianOpen = new DateTime(DateTime.Now.Year+1, 2, 7); //For tasting change with: DateTime.Now.Year+1 DateTime frenchOpen = new DateTime(DateTime.Now.Year+1, 6, 19); //For tasting change with: DateTime.Now.Year+1 DateTime winbledon = new DateTime(DateTime.Now.Year+1, 7, 17); //For tasting change with: DateTime.Now.Year+1 DateTime usOpen = new DateTime(DateTime.Now.Year+1, 9, 18); //For tasting change with: DateTime.Now.Year+1 StorageFile dateFile = null; var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; try { dateFile = await localFolder.GetFileAsync("date.txt"); } catch (Exception ex) { } DateTime? overwriteDate = null; if (dateFile != null) { var result = await Windows.Storage.FileIO.ReadTextAsync(dateFile); overwriteDate = DateTime.Parse(result); } DateTime[] tournaments = new DateTime[] { australianOpen, frenchOpen, winbledon, usOpen, }; if (overwriteDate != null && !this.OverwriteInfo(overwriteDate)) { var namesStr = await this.ReadDataFromLocalFolder("names"); var descriptionStr = await this.ReadDataFromLocalFolder("desc"); var imageStr = await this.ReadDataFromLocalFolder("img"); var titlesStr = await this.ReadDataFromLocalFolder("title"); var titlesCountStr = await this.ReadDataFromLocalFolder("titleCount"); var timeBetweenStr = await this.ReadDataFromLocalFolder("timeBetween"); var winningYearsStr = await this.ReadDataFromLocalFolder("winningYears"); var titlesValueStr = await this.ReadDataFromLocalFolder("titlesValue"); var finalResultStr = await this.ReadDataFromLocalFolder("finalResult"); theName = JsonConvert.DeserializeObject<string[]>(namesStr); theDescription = JsonConvert.DeserializeObject<string[]>(descriptionStr); theImage = JsonConvert.DeserializeObject<string[]>(imageStr); theTitles = JsonConvert.DeserializeObject<int[]>(titlesStr); theTitlesCountComparation = JsonConvert.DeserializeObject<string[,]>(titlesCountStr); theTimeBetweenComparation = JsonConvert.DeserializeObject<string[,]>(timeBetweenStr); theWinningYearsComparation = JsonConvert.DeserializeObject<string[,]>(winningYearsStr); theTitlesValueComparation = JsonConvert.DeserializeObject<string[,]>(titlesValueStr); theFinalResultComparation = JsonConvert.DeserializeObject<string[,]>(finalResultStr); //If uncoment next rows and start the application the local storage will be cleaned and the next starting of //application wiil be near 10 seconds because will be extracting the data from internet //var stFileToCheck = await localFolder.GetFileAsync("names.txt"); //await stFileToCheck.DeleteAsync(); //stFileToCheck = await localFolder.GetFileAsync("desc.txt"); //await stFileToCheck.DeleteAsync(); //stFileToCheck = await localFolder.GetFileAsync("img.txt"); //await stFileToCheck.DeleteAsync(); //stFileToCheck = await localFolder.GetFileAsync("title.txt"); //await stFileToCheck.DeleteAsync(); //stFileToCheck = await localFolder.GetFileAsync("titleCount.txt"); //await stFileToCheck.DeleteAsync(); //stFileToCheck = await localFolder.GetFileAsync("timeBetween.txt"); //await stFileToCheck.DeleteAsync(); //stFileToCheck = await localFolder.GetFileAsync("winningYears.txt"); //await stFileToCheck.DeleteAsync(); //stFileToCheck = await localFolder.GetFileAsync("titlesValue.txt"); //await stFileToCheck.DeleteAsync(); //stFileToCheck = await localFolder.GetFileAsync("finalResult.txt"); //await stFileToCheck.DeleteAsync(); //await dateFile.DeleteAsync(); } else { { //SERVICES CONSUMING //http://04servicesofwhichtenisistisbigger.apphb.com/ var please = MakeAsyncRequest("http://04servicesofwhichtenisistisbigger.apphb.com/api/Name"); string namesStr = please.Result; theName = JsonConvert.DeserializeObject<string[]>(namesStr); this.WriteToLocalFolder("names", namesStr); please = MakeAsyncRequest("http://04servicesofwhichtenisistisbigger.apphb.com/api/Description"); string descriptionStr = please.Result; theDescription = JsonConvert.DeserializeObject<string[]>(descriptionStr); this.WriteToLocalFolder("desc", descriptionStr); please = MakeAsyncRequest("http://04servicesofwhichtenisistisbigger.apphb.com/api/Image"); string imageStr = please.Result; theImage = JsonConvert.DeserializeObject<string[]>(imageStr); this.WriteToLocalFolder("img", imageStr); please = MakeAsyncRequest("http://04servicesofwhichtenisistisbigger.apphb.com/api/Titles"); string titlesStr = please.Result; theTitles = JsonConvert.DeserializeObject<int[]>(titlesStr); this.WriteToLocalFolder("title", titlesStr); please = MakeAsyncRequest("http://04servicesofwhichtenisistisbigger.apphb.com/api/TitlesCount"); string titlesCountStr = please.Result; theTitlesCountComparation = JsonConvert.DeserializeObject<string[,]>(titlesCountStr); this.WriteToLocalFolder("titleCount", titlesCountStr); please = MakeAsyncRequest("http://04servicesofwhichtenisistisbigger.apphb.com/api/TimeBetween"); string timeBetweenStr = please.Result; theTimeBetweenComparation = JsonConvert.DeserializeObject<string[,]>(timeBetweenStr); this.WriteToLocalFolder("timeBetween", timeBetweenStr); please = MakeAsyncRequest("http://04servicesofwhichtenisistisbigger.apphb.com/api/WinningYears"); string winningYearsStr = please.Result; theWinningYearsComparation = JsonConvert.DeserializeObject<string[,]>(winningYearsStr); this.WriteToLocalFolder("winningYears", winningYearsStr); please = MakeAsyncRequest("http://04servicesofwhichtenisistisbigger.apphb.com/api/TitlesValue"); string titlesValueStr = please.Result; theTitlesValueComparation = JsonConvert.DeserializeObject<string[,]>(titlesValueStr); this.WriteToLocalFolder("titlesValue", titlesValueStr); please = MakeAsyncRequest("http://04servicesofwhichtenisistisbigger.apphb.com/api/FinalResult"); string finalResultStr = please.Result; theFinalResultComparation = JsonConvert.DeserializeObject<string[,]>(finalResultStr); this.WriteToLocalFolder("finalResult", finalResultStr); var date = this.CheckNearestDate(tournaments, overwriteDate); this.WriteToLocalFolder("date", date.ToString()); } } // data populations TennisDataGroup[] group = new TennisDataGroup[15]; for (int i = 0; i < 15; i++) { group[i] = new TennisDataGroup("Group-" + (i + 1), theName[i], theName[i] + " Grand Slam titles: " + theTitles[i], theImage[i], theDescription[i]); for (int j = 0; j < 15; j++) { if (i != j) { group[i].Items.Add(new TennisDataItem("Group-" + (i + 1) + "-Item-" + (j + 1), theName[j], theName[j] + " Grand Slam titles: " + theTitles[i], theImage[j], theDescription[j], theTitlesCountComparation[i, j] + theTimeBetweenComparation[i, j] + theWinningYearsComparation[i, j] + theTitlesValueComparation[i, j] + theFinalResultComparation[i, j], group[i])); } } this.AllGroups.Add(group[i]); } }