public async Task<bool> apiPOST(string access_token, string response, string href) { mlibrary = new methodLibrary(); HttpClient httpClient = new HttpClient(); try { httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("Bearer", access_token); httpClient.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json")); var httpResponseMessage = await httpClient.PostAsync(new Uri(href), new HttpStringContent(response)); string resp = await httpResponseMessage.Content.ReadAsStringAsync(); await mlibrary.writeFile("POSTresponse", resp); Debug.WriteLine(resp); ApplicationData.Current.LocalSettings.Values["POSTCallMade"] = true; } catch(Exception ex) { Debug.WriteLine("Caught exception : " + ex); return false; } return true; }
public AddNewForumTopic() { this.InitializeComponent(); mlibrary = new methodLibrary(); APILibrary = new Library_APICall(); this.NavigationCacheMode = NavigationCacheMode.Required; }
public filesView() { this.InitializeComponent(); mlibrary = new methodLibrary(); apiLibrary = new Library_APICall(); photosCollection = new ObservableCollection<Photos>(); }
public MediaFolders() { this.InitializeComponent(); teamid = 0; mLibrary = new methodLibrary(); apiLibrary = new Library_APICall(); rteamMedia = new RootObjectTeamMedia(); photoCollectionFolder = new ObservableCollection<PhotoCollectionFolder>(); }
public CalendarPage() { this.InitializeComponent(); networkproblems = false; calendarfound = false; mlibrary = new methodLibrary(); cal = new ObservableCollection<Calendar>(); calAllEvents = new ObservableCollection<Calendar>(); }
public PaymentsPage() { this.InitializeComponent(); APILibrary = new Library_APICall(); mlibrary = new methodLibrary(); rteamFeeAPI = new RootObjectTeamFeeAPI(); rMemberPaymentAPI = new RootObjectMemberPaymentAPI(); rpaymentcollection = new ObservableCollection<TeamFeeItems>(); rpayment = new RootPaymentCollection(); }
public Dashboard() { this.InitializeComponent(); userInfo = new ObservableCollection<CollectionUsersTeam>(); userFunction = new Users(); LibraryMethods = new methodLibrary(); LibraryAuth = new Library_TokenAuth(); feedbackLaunchLimit = 10; this.Loaded += Dashboard_Loaded; this.NavigationCacheMode = NavigationCacheMode.Required; }
public ForumPostsPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; rftopic = new ForumsTopic(); mlibrary = new methodLibrary(); APILibrary = new Library_APICall(); rfpost = new ObservableCollection<ForumsPost>(); /*ReplyToPostBox.MaxHeight = ReplyToPostBox.Height; replybutton.MaxHeight = ReplyToPostBox.MaxHeight; replybutton.Height = ReplyToPostBox.Height;*/ }
public signin() { this.InitializeComponent(); LibraryAuth = new Library_TokenAuth(); LibraryAPI = new Library_APICall(); lib = new methodLibrary(); rme = new RootObjectMe(); rmembers = new RootObjectMembers(); rteams = new RootObjectTeams(); rusers = new RootObjectUsers(); meAPI = "https://api.teamsnap.com/v3/me"; tokenflag = false; }
public AddNewEmail() { mlb = new methodLibrary(); APILibrary = new Library_APICall(); mselectrecipient = new ObservableCollection<CollectionUsersTeamMembers>(); ruser = new RootObjectUsers(); teamid_temp = 0; memberid = 0; parameterPresent = false; recipient_ids = null; recipient_names = null; rcem = new CollectionEventAvailabilityMembers(); this.Loaded += AddNewEmail_Loaded; this.InitializeComponent(); }
public Forums() { this.InitializeComponent(); APILibrary = new Library_APICall(); mlibrary = new methodLibrary(); rforumposts = new RootObjectForumPosts(); rforumtopics = new RootObjectForumTopics(); rforumdata = new RootObjectForumsData(); remails = new RootObjectEmails(); remaildata = new RootEmailData(); ftopic = new ObservableCollection<ForumsTopic>(); etopic = new ObservableCollection<EmailTopics>(); DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait; this.NavigationCacheMode = NavigationCacheMode.Required; //rforumdatatopic = new ForumsTopic(); //this.NavigationCacheMode = NavigationCacheMode.Required; teamid = 0; }
public CalendarPageDetail() { this.InitializeComponent(); caldata = new ObservableCollection<Calendar>(); mapIconAddress = ""; mlibrary = new methodLibrary(); rmemGoing = new ObservableCollection<MemberAvailabilityStatus>(); rmemMaybe = new ObservableCollection<MemberAvailabilityStatus>(); rmemNotGoing = new ObservableCollection<MemberAvailabilityStatus>(); rmemUnknown = new ObservableCollection<MemberAvailabilityStatus>(); reventavail = new RootObjectEventAvailability(); status_code = -1; eventMemberAvailability_pos = 0; memberAvailable_pos = 0; teamid = 0; eventid = 0; hrefForAvailabilityRequest = null; currentUserMemberID = 0; }
public async Task<bool> getUserCollection(ObservableCollection<CollectionUsersTeam> teamData) { try { libMethods = new methodLibrary(); //await libMethods.writeToLogFile((DateTime.UtcNow).ToString() + ": in getUserCollection method"); string resp = await libMethods.readSerializedUserClass(); var rootuser = usersDataDeserializer(resp); var teamsobject = rootuser.teams; teamData.Clear(); foreach (var teams in teamsobject) { teamData.Add(teams); } } catch (Exception ex) { //await libMethods.writeToLogFile((DateTime.UtcNow).ToString() + ": Exception in getUserCollection"); return false; } return true; }
public MainPage() { mlibrary = new methodLibrary(); this.Loaded += MainPage_Loaded; }
/// <summary> /// Download an image from a URL and store it to app local store. /// </summary> /// <param name="url"></param> /// <param name="filename"></param> /// <returns></returns> public static async Task<bool> downloadImage(string url, string filename) { Uri uri = new Uri(url); //string fname = member_id + ".png"; methodLibrary mlb = new methodLibrary(); var bitmapImage = new BitmapImage(); var httpClient = new HttpClient(); var httpResponse = await httpClient.GetAsync(uri); byte[] b = await httpResponse.Content.ReadAsByteArrayAsync(); try { // create a new in memory stream and datawriter using (var stream = new InMemoryRandomAccessStream()) { using (DataWriter dw = new DataWriter(stream)) { // write the raw bytes and store dw.WriteBytes(b); await dw.StoreAsync(); // set the image source stream.Seek(0); bitmapImage.SetSource(stream); var storageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync( filename +".png", CreationCollisionOption.OpenIfExists); using (var storageStream = await storageFile.OpenAsync(FileAccessMode.ReadWrite)) { await RandomAccessStream.CopyAndCloseAsync(stream.GetInputStreamAt(0), storageStream.GetOutputStreamAt(0)); } } } await mlb.scaleImage(filename); } catch (Exception ex) { Debug.WriteLine("Exception in downloading image : " + ex); await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": download image exception", false); return false; } return true; }
public async Task<bool> doWhatSignInDoes() { string access_token = null; string meAPIRespone = null; string teamAPIResponse = null; bool writeserializeduserclass = false; //string memberAPIResponse = null; LibraryAuth = new Library_TokenAuth(); methodLibrary mlb = new methodLibrary(); Library_APICall LibraryAPI = new Library_APICall(); RootObjectMe rme = new RootObjectMe(); //RootObjectMembers rmembers = new RootObjectMembers(); RootObjectTeams rteams = new RootObjectTeams(); RootObjectUsers ru = new RootObjectUsers(); Debug.WriteLine("doWhatSignInDoes : Checking if token is valid"); string meAPI = (string)ApplicationData.Current.LocalSettings.Values["meAPI"]; if (await LibraryAuth.tokenIsValid()) { access_token = (string)ApplicationData.Current.LocalSettings.Values["Tokens"]; //call Me API //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Token is valid."); meAPIRespone = await LibraryAPI.apiCall(access_token, meAPI); if (meAPIRespone == "fail") { //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Call to Me API failed"); return false; } //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Call to Me API succeeded."); Debug.WriteLine(meAPIRespone); // deserialize meAPIResponse //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Deserializaing Me API response."); rme = Me.MeDataDeserializer(meAPIRespone); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": me API response deserialization complete."); Dictionary<string, int> links_ht = new Dictionary<string, int>(); int id = 0; while (id < rme.collection.items[0].links.Count) { if (!links_ht.ContainsKey(rme.collection.items[0].links[id].rel)) { links_ht.Add(rme.collection.items[0].links[id].rel, id); } id++; } ApplicationData.Current.LocalSettings.Values["TeamsAPI"] = rme.collection.items[0].links[(int)links_ht["active_teams"]].href; string teamAPI = (string)ApplicationData.Current.LocalSettings.Values["TeamsAPI"]; Debug.WriteLine(rme.collection.items[0].data[0].value); teamAPIResponse = await LibraryAPI.apiCall(access_token, teamAPI); if (teamAPIResponse == "fail") { //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Call to Teams API failed."); return false; } //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Call to Teams API succeded."); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Deserializing Teams API Response."); rteams = Teams.teamDataDeserializer(teamAPIResponse); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Deserialization of Teams API Response completed successfully."); ////await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Writing Me Response to file."); await writeFile("meAPIResponse", meAPIRespone); await writeFile("teamAPIResponse", teamAPIResponse); var rtemplate = rteams.collection.template; writeFile("teamTemplate", Teams.teamTemplateSerializer(rtemplate)); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Updating the User Class."); rusers = await methodLibrary.updateUser(); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": User class updated"); string resp = Users.usersDataSerializer(rusers); Debug.WriteLine(resp); writeserializeduserclass = await writeSerializedUserClass(resp); resp = await readSerializedUserClass(); //return true; } else { Debug.WriteLine("Network problems"); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Network connectivity problems."); return false; } return writeserializeduserclass; }
public async Task<bool> writeFile(string filename, string response) { methodLibrary mlb = new methodLibrary(); using (await m_lock.LockAsync()) { //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Writing to file " + filename); var applicationData = Windows.Storage.ApplicationData.Current; var localFolder = applicationData.LocalFolder; Debug.WriteLine("In writeFile : " + filename); try { //Debug.WriteLine("In try of write."); StorageFile sampleFile = await localFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(sampleFile, response); } catch (System.UnauthorizedAccessException e) { Debug.WriteLine("in write to file : " + filename + " : " + e); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": SystemUnauthorizedException in writing to file " + filename); return false; } } return true; }
public async Task<string> readFile(string filename) { methodLibrary mlb = new methodLibrary(); using (await m_lock.LockAsync()) { //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Reading file " + filename); var applicationData = Windows.Storage.ApplicationData.Current; var localFolder = applicationData.LocalFolder; string response = null; try { // Debug.WriteLine("in try of read"); StorageFile sampleFile = await localFolder.GetFileAsync(filename); response = await FileIO.ReadTextAsync(sampleFile); } catch (Exception e) { Debug.WriteLine("In read file : " + e); await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Exception in reading file " + filename, true); } return response; } }
/// <summary> /// Scales an image down. Not a very good algo, but good enough. /// </summary> /// <param name="filename"></param> /// <returns></returns> public async Task<bool> scaleImage(string filename) { var applicationData = Windows.Storage.ApplicationData.Current; methodLibrary mlb = new methodLibrary(); Image image = new Image(); int height = 0; int scaledHeight = 80 ; int scaledWidth = 80; int width = 0; var localFolder = applicationData.LocalFolder; try { StorageFile sourceFile= await localFolder.GetFileAsync(filename + ".png"); IRandomAccessStreamWithContentType stream = await sourceFile.OpenReadAsync(); ImageProperties properties = await sourceFile.Properties.GetImagePropertiesAsync(); height = (int)properties.Height; width = (int)properties.Width; double scaleBy = 0; for (int scale = 10; scale > 0; scale--) { if (((height * scale *0.1) <= 80) || ((width * scale *0.1) <= 80)) { scaleBy = scale + 1; break; } } if (height != 0) { scaledHeight = (int)(height * scaleBy * 0.1); } if (width != 0) { scaledWidth = (int)(width * scaleBy * 0.1); } if(scaleBy == 0) { scaledHeight = (int)(height * 0.1); scaledWidth = (int)(width * 0.1); } StorageFile destinationFile = await localFolder.CreateFileAsync(filename + "_scaled.png", CreationCollisionOption.ReplaceExisting); using (var sourceStream = await sourceFile.OpenAsync(FileAccessMode.Read)) { BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceStream); BitmapTransform transform = new BitmapTransform() { ScaledHeight = (uint)scaledHeight, ScaledWidth = (uint)scaledWidth }; PixelDataProvider pixelData = await decoder.GetPixelDataAsync(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.DoNotColorManage); Debug.WriteLine("Actual height : " + height + " Scaled height : " + scaledHeight); Debug.WriteLine("Actual width : " + width+ " Scaled width : " + scaledWidth); using (var destinationStream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite)) { BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, destinationStream); encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, (uint)scaledWidth, (uint)scaledHeight, 96, 96, pixelData.DetachPixelData()); await encoder.FlushAsync(); } } } catch (Exception ex) { Debug.WriteLine("Exception in scaling image assets : " + ex); await mlb.writeToLogFile(DateTime.UtcNow.ToString() + "Exception in scaling image assets", false); return false; } return true; }
/// <summary> /// update User Information. /// </summary> /// <returns></returns> public static async Task<RootObjectUsers> updateUser() { mlb = new methodLibrary(); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": in updateUser method"); string meAPIResponse = await mlb.readFile("meAPIResponse"); RootObjectMe rme = new RootObjectMe(); rme = Me.MeDataDeserializer(meAPIResponse); string teamAPIResponse = await mlb.readFile("teamAPIResponse"); RootObjectTeams rteams = new RootObjectTeams(); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Deserializing teams response"); rteams = Teams.teamDataDeserializer(teamAPIResponse); // start with rme and store data about the user itemCollection = new CollectionUsersItem(); LibraryAPI = new Library_APICall(); //teamsCollection = new CollectionUsersTeam(); rusers = new RootObjectUsers(); rusers.items = new List<CollectionUsersItem>(); rusers.teams = new List<CollectionUsersTeam>(); rsports = new RootObjectSports(); RootObjectMembers rmembers = new RootObjectMembers(); Dictionary<string, int> rme_ht = new Dictionary<string, int>(); Dictionary<string, int> rteam_ht = new Dictionary<string, int>(); Dictionary<string, int> rteamlinks_ht = new Dictionary<string, int>(); string memberAPIResponse = null; int id = 0; /** Populate a hashtable to get sportname quickly. Also write results of sportsAPI call to a file.**/ string sportres = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/sports"); rsports = Sports.usersDataDeserializer(sportres); Dictionary<object, long> rsports_ht = new Dictionary<object, long>(); for (int i = 0; i < rsports.collection.items.Count; i++) { if (!rsports_ht.ContainsKey(rsports.collection.items[i].data[0].value)) { rsports_ht.Add(rsports.collection.items[i].data[0].value, i); } } mlb.makeAPICallandWriteToFile("sportsName", "https://api.teamsnap.com/v3/sports"); /************/ while(id < rme.collection.items[0].data.Count) { if (!rme_ht.ContainsKey(rme.collection.items[0].data[id].name)) { rme_ht.Add(rme.collection.items[0].data[id].name, id); } id++; } await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Updating itemcollections", false); itemCollection.id = rme.collection.items[0].data[(int)rme_ht["id"]].value == null ? 0:(long)rme.collection.items[0].data[(int)rme_ht["id"]].value; itemCollection.type = rme.collection.items[0].data[(int)rme_ht["type"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["type"]].value; itemCollection.address_country = rme.collection.items[0].data[(int)rme_ht["address_country"]].value == null ? "" : (string)rme.collection.items[0].data[(int)rme_ht["address_country"]].value; itemCollection.address_state = rme.collection.items[0].data[(int)rme_ht["address_state"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["address_state"]].value; itemCollection.birthday = rme.collection.items[0].data[(int)rme_ht["birthday"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["birthday"]].value; itemCollection.email = rme.collection.items[0].data[(int)rme_ht["email"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["email"]].value; itemCollection.first_name = rme.collection.items[0].data[(int)rme_ht["first_name"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["first_name"]].value; itemCollection.last_name = rme.collection.items[0].data[(int)rme_ht["last_name"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["last_name"]].value; //itemCollection.teams_count = rme.collection.items[0].data[(int)rme_ht["teams_count"]].value == null ? 0:(long)rme.collection.items[0].data[(int)rme_ht["teams_count"]].value; try { itemCollection.teams_count = (int)rteams.collection.items.Count; } catch (Exception ex) { await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Exception in setting team count", true); } await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": itemcollection has been updated", false); rusers.items.Add(itemCollection); Debug.WriteLine("MethodLibrary : End rME. Start rTeam."); // now use rteams to store data about the teams the user is a member of. for(int i=0; i < rusers.items[0].teams_count; i++) { id = 0; try { while (id < rteams.collection.items[i].data.Count) { if (!rteam_ht.ContainsKey(rteams.collection.items[i].data[id].name)) { rteam_ht.Add(rteams.collection.items[i].data[id].name, id); } id++; } id = 0; while (id < rteams.collection.items[i].links.Count) { if (!rteamlinks_ht.ContainsKey(rteams.collection.items[i].links[id].rel)) { rteamlinks_ht.Add(rteams.collection.items[i].links[id].rel, id); } id++; } } catch (Exception ex) { Debug.WriteLine("Exception in setting rteam_ht and rteamlinks_ht :" + ex); await mlb.writeToLogFile((DateTime.UtcNow).ToString() + "Exception in setting rteam_ht and rteamlinks_ht: " + ex, true); } teamsCollection = new CollectionUsersTeam(); teamsCollection.members = new List<CollectionUsersTeamMembers>(); teamsCollection.id = rteams.collection.items[i].data[(int)rteam_ht["id"]].value == null ? 0:(long)rteams.collection.items[i].data[(int)rteam_ht["id"]].value; teamsCollection.eventsLink = rteams.collection.items[i].links[(int)rteamlinks_ht["events"]].href == null ? "":(string)rteams.collection.items[i].links[(int)rteamlinks_ht["events"]].href; /** Writing API call results of Opponents, Events and Locations to file. Speed up stuff ahead**/ string flname = "events_" + (teamsCollection.id).ToString(); await mlb.makeAPICallandWriteToFile(flname, teamsCollection.eventsLink); flname = "opponents_" + (teamsCollection.id).ToString(); mlb.makeAPICallandWriteToFile(flname, (string)rteams.collection.items[i].links[(int)rteamlinks_ht["opponents"]].href); flname = "locations_" + (teamsCollection.id).ToString(); mlb.makeAPICallandWriteToFile(flname, (string)rteams.collection.items[i].links[(int)rteamlinks_ht["locations"]].href); /**Done**/ //string tempres = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], teamsCollection.eventsLink); teamsCollection.locationsLink = rteams.collection.items[i].links[(int)rteamlinks_ht["locations"]].href == null ? "":(string)rteams.collection.items[i].links[(int)rteamlinks_ht["locations"]].href; string memberslink = rteams.collection.items[i].links[(int)rteamlinks_ht["members"]].href == null ? "":(string)rteams.collection.items[i].links[(int)rteamlinks_ht["members"]].href; teamsCollection.type = rteams.collection.items[i].data[(int)rteam_ht["type"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["type"]].value; teamsCollection.division_name = rteams.collection.items[i].data[(int)rteam_ht["division_name"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["division_name"]].value; teamsCollection.is_archived_season = rteams.collection.items[i].data[(int)rteam_ht["is_archived_season"]].value == null ? false : (bool)rteams.collection.items[i].data[(int)rteam_ht["is_archived_season"]].value; teamsCollection.is_retired = rteams.collection.items[i].data[(int)rteam_ht["is_retired"]].value == null ? false : (bool)rteams.collection.items[i].data[(int)rteam_ht["is_retired"]].value; teamsCollection.league_name = rteams.collection.items[i].data[(int)rteam_ht["league_name"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["league_name"]].value; teamsCollection.league_url = rteams.collection.items[i].data[(int)rteam_ht["league_url"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["league_url"]].value; teamsCollection.is_in_league = rteams.collection.items[i].data[(int)rteam_ht["is_in_league"]].value == null ? false : (bool)rteams.collection.items[i].data[(int)rteam_ht["is_in_league"]].value; teamsCollection.location_country = rteams.collection.items[i].data[(int)rteam_ht["location_country"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["location_country"]].value; teamsCollection.location_postal_code = rteams.collection.items[i].data[(int)rteam_ht["location_postal_code"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["location_postal_code"]].value; teamsCollection.location_latitude = rteams.collection.items[i].data[(int)rteam_ht["location_latitude"]].value == null ? "38.8951100" :(string)rteams.collection.items[i].data[(int)rteam_ht["location_latitude"]].value; ApplicationData.Current.LocalSettings.Values["team_latitude_" + teamsCollection.id] = (string)teamsCollection.location_latitude; teamsCollection.location_longitude = rteams.collection.items[i].data[(int)rteam_ht["location_longitude"]].value == null ? "-77.0363700" : (string)rteams.collection.items[i].data[(int)rteam_ht["location_longitude"]].value; ApplicationData.Current.LocalSettings.Values["team_longitude_" + teamsCollection.id] = (string)teamsCollection.location_longitude; teamsCollection.name = rteams.collection.items[i].data[(int)rteam_ht["name"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["name"]].value; teamsCollection.plan_id = rteams.collection.items[i].data[(int)rteam_ht["plan_id"]].value == null ? 0:(long)rteams.collection.items[i].data[(int)rteam_ht["plan_id"]].value; teamsCollection.season_name = rteams.collection.items[i].data[(int)rteam_ht["season_name"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["season_name"]].value; teamsCollection.sport_id = rteams.collection.items[i].data[(int)rteam_ht["sport_id"]].value == null ? 0:(long)rteams.collection.items[i].data[(int)rteam_ht["sport_id"]].value; teamsCollection.sport_name = getSportName(teamsCollection.sport_id, rsports_ht); teamsCollection.pathToSportLogo = "images/" + teamsCollection.sport_id + ".png"; //teamsCollection.teamOwner = itemCollection.first_name + " " + itemCollection.last_name; mlb.writeToLogFile("Calling TeamAvailability API", false); mlb.makeAPICallandWriteToFile("teamAvailabilityAPI" + teamsCollection.id, (string)rteams.collection.items[i].links[(int)rteamlinks_ht["availabilities"]].href); mlb.writeToLogFile("Done calling TeamAvailability API and updating the availabilityfile", false); // make API call to fetch members for that particular team memberAPIResponse = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], memberslink); if (memberAPIResponse != "fail") { //deserialize the response rmembers = Members.membersDataDeserializer(memberAPIResponse); Dictionary<string, int> rmember_ht = new Dictionary<string, int>(); // use rmembers to store data about the members the team has for (int j = 0; j < rmembers.collection.items.Count; j++) { int idm = 0; // Debug.WriteLine("Adding values to rmember_ht"); while (idm < rmembers.collection.items[j].data.Count) { //Debug.WriteLine("Inside the while loop that adds values to rmember_ht"); try { if (!rmember_ht.ContainsKey(rmembers.collection.items[j].data[idm].name)) { rmember_ht.Add(rmembers.collection.items[j].data[idm].name, idm); } idm++; } catch (Exception ex) { Debug.WriteLine(ex); await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": rmember_ht exception", true); } } teammembers = new CollectionUsersTeamMembers(); await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Updating teammember", false); teammembers.address_city = rmembers.collection.items[j].data[(int)rmember_ht["address_city"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_city"]].value; teammembers.address_state = rmembers.collection.items[j].data[(int)rmember_ht["address_state"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_state"]].value; teammembers.address_street1 = rmembers.collection.items[j].data[(int)rmember_ht["address_street1"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_street1"]].value; teammembers.address_street2 = rmembers.collection.items[j].data[(int)rmember_ht["address_street2"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_street2"]].value; teammembers.address_zip = rmembers.collection.items[j].data[(int)rmember_ht["address_zip"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_zip"]].value; teammembers.birthday = rmembers.collection.items[j].data[(int)rmember_ht["birthday"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["birthday"]].value; teammembers.member_id = rmembers.collection.items[j].data[(int)rmember_ht["id"]].value == null ? 0 : (long)rmembers.collection.items[j].data[(int)rmember_ht["id"]].value; //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": member id " + teammembers.member_id); teammembers.first_name = rmembers.collection.items[j].data[(int)rmember_ht["first_name"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["first_name"]].value; teammembers.gender = rmembers.collection.items[j].data[(int)rmember_ht["gender"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["gender"]].value; teammembers.is_address_hidden = rmembers.collection.items[j].data[(int)rmember_ht["is_address_hidden"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["hide_address"]].value; teammembers.is_age_hidden = rmembers.collection.items[j].data[(int)rmember_ht["is_age_hidden"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["hide_age"]].value; teammembers.is_manager = rmembers.collection.items[j].data[(int)rmember_ht["is_manager"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["is_manager"]].value; teammembers.is_non_player = rmembers.collection.items[j].data[(int)rmember_ht["is_non_player"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["is_non_player"]].value; teammembers.jersey_number = rmembers.collection.items[j].data[(int)rmember_ht["jersey_number"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["jersey_number"]].value; //Debug.WriteLine("Jersey Number : " + ((bool)string.IsNullOrEmpty((string)rmembers.collection.items[j].data[24].value)) ? true : false ); teammembers.last_name = rmembers.collection.items[j].data[(int)rmember_ht["last_name"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["last_name"]].value; teammembers.position = rmembers.collection.items[j].data[(int)rmember_ht["position"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["position"]].value; teammembers.team_id = rmembers.collection.items[j].data[(int)rmember_ht["team_id"]].value == null ? 0:(long)rmembers.collection.items[j].data[(int)rmember_ht["team_id"]].value; teammembers.user_id = rmembers.collection.items[j].data[(int)rmember_ht["user_id"]].value == null ? 0 : (long)rmembers.collection.items[j].data[(int)rmember_ht["user_id"]].value; bool is_owner = rmembers.collection.items[j].data[(int)rmember_ht["is_owner"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["is_owner"]].value; /// if the current member is also the logged-in user, store that id in a separate object if (teammembers.user_id == rusers.items[0].id) { teamsCollection.loggedInUsersmemberID = teammembers.member_id; } if (is_owner == true) { teamsCollection.teamOwner = teammembers.first_name + " " + teammembers.last_name; teamsCollection.teamOwnerMemberId = teammembers.member_id; } bool is_manager = rmembers.collection.items[j].data[(int)rmember_ht["is_owner"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["is_manager"]].value; if (is_manager == true) { teamsCollection.teamManagerName = teammembers.first_name + " " + teammembers.last_name; teamsCollection.teamManagerMemberId = teammembers.member_id; } //teammembers.updated_at = rmembers.collection.items[j].data[(int)rmember_ht["updated_at"]].value == null ? DateTime.MinValue : (DateTime)rmembers.collection.items[j].data[(int)rmember_ht["updated_at"]].value; /* Fetching Family Member Information */ //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": ****Calling Contacts, Contacts Phone and Contacts Email API for member : " + teammembers.member_id + "****", false); //string family_contacts_res = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/contacts/search?member_id=" + teammembers.member_id); //RootObjectMemberContacts rmemcontacts = new RootObjectMemberContacts(); //if (teammembers.first_name == "User1") //{ // Debug.WriteLine(family_contacts_res); //} //rmemcontacts = MemberContacts.membercontactsDataDeserializer(family_contacts_res); //try //{ // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rmemcontacts.collection.items == null ? ": No items in rmemcontacts" : ": rmemcontact has " + rmemcontacts.collection.items.Count + " values"), false); // if (rmemcontacts.collection.items != null) // { // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Inside if (rmemcontacts.collection.items != null)", false); // teammembers.family_members = new List<FamilyMemberContacts>(); // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": GET Phone API", false); // string family_contacts_phone_res = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/contact_phone_numbers/search?member_id=" + teammembers.member_id); // if (teammembers.first_name == "User1") // { // Debug.WriteLine(family_contacts_phone_res); // } // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": GET Email API", false); // string family_contacts_email_res = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/contact_email_addresses/search?member_id=" + teammembers.member_id); ; // if (teammembers.first_name == "User1") // { // Debug.WriteLine(family_contacts_email_res); // } // RootObjectContactPhone rcontactphone = new RootObjectContactPhone(); // RootObjectContactEmailAddress rcontactemailaddress = new RootObjectContactEmailAddress(); // rcontactemailaddress = MemberContactEmailAddress.contactEmailAddressDataDeserializer(family_contacts_email_res); // Dictionary<string, int> rcontactemail_items_ht = new Dictionary<string, int>(); // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Finished deserializing Email API response", false); // rcontactphone = MemberContactsPhoneNumbers.contactPhoneDataDeserializer(family_contacts_phone_res); // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Finished deserializing Phone API response", false); // Dictionary<string, int> rmemcontacts_ht = new Dictionary<string, int>(); // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Hashtable has been populated.", false); // for (int ind = 0; ind < rmemcontacts.collection.items.Count; ind++) // { // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Creating Hashtable.", false); // for (int ind1 = 0; ind1 < rmemcontacts.collection.items[ind].data.Count; ind1++) // { // rmemcontacts_ht.Add(rmemcontacts.collection.items[ind].data[ind1].name, ind1); // } // FamilyMemberContacts rfammemcontacts = new FamilyMemberContacts(); // rfammemcontacts.id = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["id"]].value == null ? 0 : (long)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["id"]].value; // rfammemcontacts.address_city = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_city"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_city"]].value; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_city from TeamSnap.", false); // rfammemcontacts.address_country = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_country"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_country"]].value; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_country from TeamSnap.", false); // rfammemcontacts.address_state = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_state"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_state"]].value; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_state from TeamSnap.", false); // rfammemcontacts.address_street1 = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_street1"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_street1"]].value; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_street1 from TeamSnap.", false); // rfammemcontacts.address_street2 = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_street2"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_street2"]].value; ; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_street2 from TeamSnap.", false); // rfammemcontacts.address_zip = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_zip"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_zip"]].value; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_zip from TeamSnap.", false); // rfammemcontacts.first_name = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["first_name"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["first_name"]].value; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched first_name from TeamSnap.", false); // rfammemcontacts.label = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["label"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["label"]].value; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched label from TeamSnap.", false); // rfammemcontacts.last_name = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["last_name"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["last_name"]].value; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched last_name from TeamSnap.", false); // rfammemcontacts.full_name = rfammemcontacts.first_name + " " + rfammemcontacts.last_name; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched full_name from TeamSnap.", false); // rfammemcontacts.nameAndLabel = rfammemcontacts.full_name + " (" + rfammemcontacts.label + ")"; // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched label from TeamSnap.", false); // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rcontactphone.collection.items == null ? ": No items in rcontactphone" : ": rcontactphone has " + rcontactphone.collection.items.Count + " values"), false); // if (rcontactphone.collection.items != null) // { // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rcontactphone.collection.items[ind] == null ? ": rcontactphone.collection.items[ind] is null" : ": rcontactphone.collection.items[ind] is not null"), false); // Dictionary<string, int> rfamcontactphone_ht = new Dictionary<string, int>(); // rfammemcontacts.phonenum = new System.Collections.ObjectModel.ObservableCollection<FamilyMemberContactsPhones>(); // for (int k = 0; k < rcontactphone.collection.items[0].data.Count; k++) // { // rfamcontactphone_ht.Add(rcontactphone.collection.items[0].data[k].name, k); // } // for (int k = 0; k < rcontactphone.collection.items.Count; k++) // { // Debug.WriteLine((int)rfamcontactphone_ht["contact_id"]); // Debug.WriteLine((long)rcontactphone.collection.items[k].data[(int)rfamcontactphone_ht["contact_id"]].value); // if ((long)rcontactphone.collection.items[k].data[(int)rfamcontactphone_ht["contact_id"]].value == rfammemcontacts.id) // { // FamilyMemberContactsPhones rfamcontactphone = new FamilyMemberContactsPhones(); // rfamcontactphone.phone_number = rcontactphone.collection.items[k].data[(int)rfamcontactphone_ht["phone_number"]].value == null ? null : (string)rcontactphone.collection.items[k].data[(int)rfamcontactphone_ht["phone_number"]].value; // rfammemcontacts.phonenum.Add(rfamcontactphone); // } // } // rfamcontactphone_ht.Clear(); // } // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rcontactemailaddress.collection.items == null ? ": No items in rcontactphone" : ": rcontactphone has " + rcontactemailaddress.collection.items.Count + " values"), false); // if (rcontactemailaddress.collection.items != null) // { // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rcontactemailaddress.collection.items[ind] == null ? ": rcontactemailaddress.collection.items[ind] is null" : ": rcontactemailaddress.collection.items[ind] is not null"), false); // Dictionary<string, int> rfamcontactemail_ht = new Dictionary<string, int>(); // rfammemcontacts.emailAdd = new System.Collections.ObjectModel.ObservableCollection<FamilyMemberContactsEmail>(); // for (int k = 0; k < rcontactemailaddress.collection.items[0].data.Count; k++) // { // // if (rcontactemailaddress.collection.items[0].data[k].name != "sms_gateway_id") // //{ // rfamcontactemail_ht.Add(rcontactemailaddress.collection.items[0].data[k].name, k); // //} // } // for (int k = 0; k < rcontactemailaddress.collection.items.Count; k++) // { // if ((long)rcontactemailaddress.collection.items[k].data[(int)rfamcontactemail_ht["contact_id"]].value == rfammemcontacts.id) // { // FamilyMemberContactsEmail rfamcontactemail = new FamilyMemberContactsEmail(); // Debug.WriteLine((int)rfamcontactemail_ht["email"]); // Debug.WriteLine((string)rcontactemailaddress.collection.items[k].data[(int)rfamcontactemail_ht["email"]].value); // rfamcontactemail.email_address = rcontactemailaddress.collection.items[k].data[(int)rfamcontactemail_ht["email"]].value == null ? null : (string)rcontactemailaddress.collection.items[k].data[(int)rfamcontactemail_ht["email"]].value; // rfammemcontacts.emailAdd.Add(rfamcontactemail); // } // } // rfamcontactemail_ht.Clear(); // //if (rcontactemailaddress.collection.items[ind] != null) // //{ // // for (int index = 0; index < rcontactemailaddress.collection.items[ind].data.Count; index++) // // { // // if (rcontactemailaddress.collection.items[ind].data[index].name == "email") // // { // // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetching email_address.", false); // // rfammemcontacts.email_address = rcontactemailaddress.collection.items[ind].data[index].value == null ? null : (string)rcontactemailaddress.collection.items[ind].data[index].value; // // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched email_address.", false); // // } // // } // //} // } // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Addsing rfamemcontacts to teammebers.family_members.", false); // teammembers.family_members.Add(rfammemcontacts); // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Clearing the hashtable.", false); // rmemcontacts_ht.Clear(); // } // } //} //catch (Exception ex) //{ // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Exception in Calling Contacts, Contacts Phone and Contacts Email API " + ex, true); //} //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": ****Finished calling Contacts, Contacts Phone and Contacts Email API****", false); ///* //Family Member Information Section over //*/ //string emailres = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/member_email_addresses/search?member_id=" + teammembers.member_id); //RootObjectMemberEmail rmemberemail = MemberEmail.memberemailDataDeserializer(emailres); //if (rmemberemail.collection.items != null) //{ // for (int emaili = 0; emaili < rmemberemail.collection.items[0].data.Count; emaili++) // { // if (rmemberemail.collection.items[0].data[emaili].name == "email") // { // teammembers.email_address = (string)rmemberemail.collection.items[0].data[emaili].value; // Debug.WriteLine(teammembers.member_id); // break; // } // } //} //else //{ // teammembers.email_address = null; //} //string phoneres = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/member_phone_numbers/search?member_id=" + teammembers.member_id); //RootObjectMemberPhone rmemberphone = MemberPhone.memberPhoneDataDeserializer(phoneres); //if (rmemberphone.collection.items != null) //{ // for (int phonei = 0; phonei < rmemberphone.collection.items[0].data.Count; phonei++) // { // if (rmemberphone.collection.items[0].data[phonei].name == "phone_number") // { // Debug.WriteLine(teammembers.first_name + " " + teammembers.last_name + " of team " + teamsCollection.name + " has a phone number : " + (string)rmemberphone.collection.items[0].data[phonei].value); // teammembers.phone_number = (string)rmemberphone.collection.items[0].data[phonei].value; // break; // } // } //} //else //{ // Debug.WriteLine(teammembers.first_name + " " + teammembers.last_name + " of team " + teamsCollection.name + " doesn't have a phone number"); // teammembers.phone_number = null; //} teammembers.fullname = teammembers.first_name + (teammembers.last_name == null ? "" : (" " + teammembers.last_name)); Debug.WriteLine("Member ID : " + teammembers.member_id); await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Updating member_photos", false); //teammembers.member_photo = "images/member_photo.png"; bool memberPhotofound = false; Debug.WriteLine("Running through all the links to find rel member_photo"); for (int m = 0; m < rmembers.collection.items[j].links.Count; m++) { //Debug.WriteLine("rel : " + rmembers.collection.items[j].links[m].rel); //Debug.WriteLine("m : " + m); if (rmembers.collection.items[j].links[m].rel == "member_photo") { memberPhotofound = true; //Debug.WriteLine("Member Photo Exists"); Debug.WriteLine(rmembers.collection.items[j].links[m].href); string teammembers_member_photo = (string)rmembers.collection.items[j].links[m].href; //string flname = (teammembers.member_id).ToString() if (await checkIfFileExists("fileUserClass.txt")) { //teammembers.member_photo = "images/member_photo.jpg"; RootObjectUsers rtempuser = new RootObjectUsers(); string re = await mlb.readSerializedUserClass(); try { rtempuser = Users.usersDataDeserializer(re); } catch (Exception ex) { Debug.WriteLine("failed to deserialize data"); await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Failed to deserialize data", true); } for (int h = 0; h < rtempuser.teams.Count; h++) { if (rtempuser.teams[h].id == teamsCollection.id) { for (int ih = 0; ih < rtempuser.teams[h].members.Count; ih++) { if (rtempuser.teams[h].members[ih].member_id == teammembers.member_id) { ///////////////Future bug here. teammembers.updated_at has min value if (DateTime.Compare(rtempuser.teams[h].members[ih].updated_at, teammembers.updated_at) < 0) { try { await downloadImage(teammembers_member_photo, "member" + (teammembers.member_id).ToString()); teammembers.member_photo = "ms-appdata:///local/member" + (teammembers.member_id).ToString() + "_scaled.png"; teammembers.member_photo_notscaled = "ms-appdata:///local/member" + (teammembers.member_id).ToString() + ".png"; } catch (Exception ex) { Debug.WriteLine("Failed to download images"); teammembers.member_photo = "images/member_photo.png"; teammembers.member_photo_notscaled = "images/member_photo.png"; await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Failed to download image", false); } } else { if (await checkIfFileExists("member" + (teammembers.member_id).ToString() + "_scaled.png")) { teammembers.member_photo = "ms-appdata:///local/member" + (teammembers.member_id).ToString() + "_scaled.png"; teammembers.member_photo_notscaled = "ms-appdata:///local/member" + (teammembers.member_id).ToString() + ".png"; } else { teammembers.member_photo = "images/member_photo.png"; teammembers.member_photo_notscaled = "images/member_photo.png"; } } } } } } } else { try { Debug.WriteLine("teammembers_member_photo : " + teammembers_member_photo); await downloadImage(teammembers_member_photo, "member" + (teammembers.member_id).ToString()); teammembers.member_photo = "ms-appdata:///local/member" + (teammembers.member_id).ToString() + "_scaled.png"; teammembers.member_photo_notscaled = "ms-appdata:///local/member" + (teammembers.member_id).ToString() + ".png"; } catch (Exception ex) { Debug.WriteLine("Failed to download image"); teammembers.member_photo = "images/member_photo.png"; teammembers.member_photo_notscaled = "images/member_photo.png"; await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Failed to download image", false); } } } } Debug.WriteLine("Photo Found : " + memberPhotofound); if(memberPhotofound == false) { Debug.WriteLine("Adding default photos to the teammembers link"); teammembers.member_photo = "images/member_photo.png"; teammembers.member_photo_notscaled = "images/member_photo.png"; Debug.WriteLine("Finished adding default photos to the teammembers link"); } //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": All member photos have been updated"); Debug.WriteLine("Adding members to teamcollection"); teamsCollection.members.Add(teammembers); rmember_ht.Clear(); } } Debug.WriteLine("Adding teamCollection to rusers"); rusers.teams.Add(teamsCollection); //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": teamCollection added to userClass"); rteam_ht.Clear(); rteamlinks_ht.Clear(); Debug.WriteLine("Done adding teamcollection to rusers"); //rsports_ht.Clear(); } await updateAvailability(rusers); Debug.WriteLine("MethodLibrary : End rTeam."); rsports_ht.Clear(); Debug.WriteLine("returning users"); return rusers; }
public static async Task<bool> updateAvailability(RootObjectUsers rusers) { methodLibrary mlib = new methodLibrary(); Dictionary<long, int> rteams_ht = new Dictionary<long, int>(); if (rusers.teams != null) { for (int i = 0; i < rusers.teams.Count; i++) { if (!rteams_ht.ContainsKey(rusers.teams[i].id)) { rteams_ht.Add(rusers.teams[i].id, i); } } } RootObjectEventAvailability reventavailability = new RootObjectEventAvailability(); for (int teami = 0; teami < rusers.teams.Count; teami++) { try { string response = await mlib.readFile("teamAvailabilityAPI" + rusers.teams[teami].id); long manager_memberid = 0; long owner_memberid = 0; RootObjectAvailabilityAPI ravailbilityAPI = AvailabilityAPI.availabilityAPIDataDeserializer(response); RootObjectEventAvailability reventavail = new RootObjectEventAvailability(); reventavail.eventMemberAvailability = new ObservableCollection<CollectionEventAvailabilityMembers>(); if (ravailbilityAPI.collection.items != null) //meaning there is some availability defined in there { Dictionary<string, int> ravailibityAPI_items_ht = new Dictionary<string, int>(); for (int i = 0; i < ravailbilityAPI.collection.items[0].data.Count; i++) { if (!ravailibityAPI_items_ht.ContainsKey(ravailbilityAPI.collection.items[0].data[i].name)) { ravailibityAPI_items_ht.Add(ravailbilityAPI.collection.items[0].data[i].name, i); } } Dictionary<object, int> ravailabilityAPI_events_ht = new Dictionary<object, int>(); int pos = 0; for (int i = 0; i < ravailbilityAPI.collection.items.Count; i++) { if (!ravailabilityAPI_events_ht.ContainsKey(ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value)) { if(!ravailabilityAPI_events_ht.ContainsKey(ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value)) { ravailabilityAPI_events_ht.Add(ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value, pos); } CollectionEventAvailabilityMembers reventavailmembers = new CollectionEventAvailabilityMembers(); //reventavailmembers.hrefForThisEvent = ravailbilityAPI.collection.items[i].href; reventavailmembers.eventid = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value == null ? 0 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value; reventavailmembers.team_id = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["team_id"]].value == null ? 0 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["team_id"]].value; reventavailmembers.manager_memberID = rusers.teams[(int)rteams_ht[reventavailmembers.team_id]].teamManagerMemberId; manager_memberid = reventavailmembers.manager_memberID; reventavailmembers.owner_memberID = rusers.teams[(int)rteams_ht[reventavailmembers.team_id]].teamOwnerMemberId; owner_memberid = reventavailmembers.owner_memberID; reventavailmembers.currentUser_memberID = rusers.teams[(int)rteams_ht[reventavailmembers.team_id]].loggedInUsersmemberID; reventavail.eventMemberAvailability.Add(reventavailmembers); pos++; } MemberAvailabilityStatus rmemstatus = new MemberAvailabilityStatus(); try { rmemstatus.updateMemberAvailabilityhref = ravailbilityAPI.collection.items[i].href; } catch (Exception ex) { Debug.WriteLine("Exception in storing the availability API of a member : " + ex); await mlb.writeToLogFile("xception in storing the availability API of a member : " + ex, false); } rmemstatus.member_id = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["member_id"]].value == null ? 0 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["member_id"]].value; rmemstatus.notes = (string)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["notes"]].value; rmemstatus.notes_author_member_id = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["notes_author_member_id"]].value == null ? -1 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["notes_author_member_id"]].value; rmemstatus.status_code = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["status_code"]].value == null ? -1 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["status_code"]].value; rmemstatus.status_string = (string)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["status"]].value; if (rmemstatus.member_id == manager_memberid) { rmemstatus.is_teammamager = true; } else { rmemstatus.is_teammamager = false; } if (rmemstatus.member_id == owner_memberid) { rmemstatus.is_teamowner = true; } else { rmemstatus.is_teamowner = false; } int event_pos = (int)ravailabilityAPI_events_ht[ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value]; if (reventavail.eventMemberAvailability[event_pos].memberAvailable == null) { reventavail.eventMemberAvailability[event_pos].memberAvailable = new ObservableCollection<MemberAvailabilityStatus>(); } reventavail.eventMemberAvailability[event_pos].memberAvailable.Add(rmemstatus); } ravailabilityAPI_events_ht.Clear(); ravailibityAPI_items_ht.Clear(); } for (int i = 0; i < reventavail.eventMemberAvailability.Count; i++) { if (rteams_ht.ContainsKey(reventavail.eventMemberAvailability[i].team_id)) { var teams = rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]]; Dictionary<object, int> rteamMember_ht = new Dictionary<object, int>(); int numOfMembersInTeam = rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]].members.Count; for (int j = 0; j < numOfMembersInTeam; j++) { rteamMember_ht.Add(rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]].members[j].member_id, j); } for (int j = 0; j < reventavail.eventMemberAvailability[i].memberAvailable.Count; j++) { if (rteamMember_ht.ContainsKey(reventavail.eventMemberAvailability[i].memberAvailable[j].member_id)) { // int event_member_pos = (int)reventavail.eventMemberAvailability[i].memberAvailable[j].member_id; // bool tr = rteamMember_ht.Contains(event_member_pos); int member_pos = (int)rteamMember_ht[reventavail.eventMemberAvailability[i].memberAvailable[j].member_id]; reventavail.eventMemberAvailability[i].memberAvailable[j].member_name = teams.members[member_pos].fullname; reventavail.eventMemberAvailability[i].memberAvailable[j].member_photo = teams.members[member_pos].member_photo; } } rteamMember_ht.Clear(); } } string res = AvailabilityAPI.eventAvailabilityDataSerializer(reventavail); await mlib.writeFile("EventsMemberAvailability" + rusers.teams[teami].id, res); Debug.WriteLine(res); } catch (Exception ex) { await mlib.writeToLogFile("Exception in updateAvailability() : " + ex, true); } } rteams_ht.Clear(); return true; }
public static async Task<RootPaymentCollection> createPaymentCollection(RootObjectTeamFeeAPI rteamFee, RootObjectMemberPaymentAPI rteamMemberPayment) { Library_APICall APILibrary = new Library_APICall(); RootPaymentCollection rpayment = new RootPaymentCollection(); methodLibrary mlb = new methodLibrary(); List<CollectionUsersTeamMembers> ctrmList = new List<CollectionUsersTeamMembers>(); Dictionary<long, int> teamfeeId_ListPos = new Dictionary<long, int>(); // Keeps track of position of each team id in the team_fees list. /*Extracting the list of members for the current team from FileUserClass.txt*/ Dictionary<long, int> memberid_ListPos = new Dictionary<long, int>(); //Keeps track of the position in list based on the member id. Will be useful later. string fileuserclass = await mlb.readSerializedUserClass(); RootObjectUsers ruser = Users.usersDataDeserializer(fileuserclass); for (int i = 0; i < ruser.teams.Count; i++) { if (ruser.teams[i].id == (long)ApplicationData.Current.LocalSettings.Values["currentTeamID"]) { for (int j = 0; j < ruser.teams[i].members.Count; j++) { CollectionUsersTeamMembers ctm = new CollectionUsersTeamMembers(); ctm = ruser.teams[i].members[j]; ctrmList.Add(ctm); // Keep in mind that all this stuff is being done for just one team. A single team will have all unique member_ids if (ctrmList.Count > 0) { memberid_ListPos.Add(ruser.teams[i].members[j].member_id, ctrmList.Count - 1); } } } } /****************************/ /*Working on the TeamFee */ rpayment.team_fees = new List<TeamFeeItems>(); Dictionary<string, int> rteamfee_ht = new Dictionary<string, int>(); // Adding the data items to a hashtable so that I can compare and add stuff to the right place for (int i = 0; i < rteamFee.collection.items[0].data.Count; i++) { rteamfee_ht.Add(rteamFee.collection.items[0].data[i].name, i); } // Run through array of items and add it to and object of type TeamFeeItems for (int i = 0; i < rteamFee.collection.items.Count; i++) { TeamFeeItems rtfitems = new TeamFeeItems(); rtfitems.team_fee_id = rteamFee.collection.items[i].data[(int)rteamfee_ht["id"]].value == null ? 0 : (long)rteamFee.collection.items[i].data[(int)rteamfee_ht["id"]].value; if (!teamfeeId_ListPos.ContainsKey(rtfitems.team_fee_id)) { teamfeeId_ListPos.Add(rtfitems.team_fee_id, i); } rtfitems.team_fee_description = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["description"]].value; rtfitems.team_fee_amount = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["amount"]].value; rtfitems.team_fee_notes = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["notes"]].value; rtfitems.team_fee_balance = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["balance"]].value; rtfitems.team_member = new List<Team_Member>(); rpayment.team_fees.Add(rtfitems); } /*************************/ /*Working on member payments now*/ //Run through memberPayments and for each matching team_fee_id, add the data to rpayment.team_fees[i].team_member Dictionary<string, int> rteamMemberPayment_ht = new Dictionary<string, int>(); for (int i = 0; i < rteamMemberPayment.collection.items[0].data.Count; i++) { rteamMemberPayment_ht.Add(rteamMemberPayment.collection.items[0].data[i].name, i); } for (int i = 0; i < rteamMemberPayment.collection.items.Count; i++) { // read the team_fee_id long member_team_fee_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["team_fee_id"]].value; // check if it matches an existing team_fee_id in teamfeeId_ListPos if (teamfeeId_ListPos.ContainsKey(member_team_fee_id)) { TeamFeeItems rtfitems = new TeamFeeItems(); rtfitems = rpayment.team_fees[(int)teamfeeId_ListPos[member_team_fee_id]]; Team_Member rteammember = new Team_Member(); rteammember.tickmark = new TeamMemberTickMarkVisibility(); rteammember.team_fee_id = member_team_fee_id; rteammember.team_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["team_id"]].value; rteammember.amount_paid = (string)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["amount_paid"]].value; rteammember.amount_due = (string)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["amount_due"]].value; rteammember.is_applicable = rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["is_applicable"]].value == null ? false : (bool)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["is_applicable"]].value; rteammember.member_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["member_id"]].value; rteammember.tickmark.is_applicable = rteammember.is_applicable; rteammember.tickmark.amount_due = rteammember.amount_due; //Check if memberid_ListPos contains this team_fee_member_id. If it does, fetch member info from there long team_fee_member_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["member_id"]].value; if (memberid_ListPos.ContainsKey(team_fee_member_id)) { int pos = (int)memberid_ListPos[team_fee_member_id]; rteammember.member_name = ctrmList[pos].first_name + (String.IsNullOrEmpty(ctrmList[pos].last_name) ? "" : " " + ctrmList[pos].last_name); rteammember.member_photo = ctrmList[pos].member_photo; rteammember.member_photo = ctrmList[pos].member_photo_notscaled; rteammember.email_address = ctrmList[pos].email_address; rteammember.is_non_player = ctrmList[pos].is_non_player; } rpayment.team_fees[(int)teamfeeId_ListPos[member_team_fee_id]].team_member.Add(rteammember); // Adding rteammember under the right TeamFeeItems } } return rpayment; }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { cal.Clear(); calAllEvents.Clear(); pivotSchedule.SelectedIndex = 0; UpcomingRectangle.Visibility = Visibility.Visible; CollectionUsersTeam ruserteam = new CollectionUsersTeam(); if (e.Parameter != null) { ruserteam = (CollectionUsersTeam)e.Parameter; string response = Users.collectionUsersTeamDataSerializer(ruserteam); await mlibrary.writeFile("CollectionUsersTeam", response); } else { string response = await mlibrary.readFile("CollectionUsersTeam"); ruserteam = Users.collectionUsersTeamDataDeserializer(response); } //updateAvailability(); teamid = ruserteam.id; ruserteam.calendar = new List<Calendar>(); string eventsLink = (string)ruserteam.eventsLink; // myProgressRing.IsActive = true; Library_APICall apic = new Library_APICall(); Debug.WriteLine(eventsLink); string flname = "events_" + ruserteam.id; Debug.WriteLine(flname); string res = await mlibrary.readFile(flname); try { if (res == "fail") { Debug.WriteLine("Network Problems"); networkproblems = true; } else { methodLibrary ml = new methodLibrary(); RootObjectEvents revents = Events.eventsDataDeserializer(res); if (revents.collection.items != null) { //YesCalendarPage.Visibility = Visibility.Visible; //AddNewEvent.Visibility = Visibility.Visible; //temp NoCalendarPage.Visibility = Visibility.Collapsed; calendarfound = true; Dictionary<string,int> revent_ht = new Dictionary<string, int>(); for (int i = 0; i < revents.collection.items.Count; i++) { for (int j = 0; j < revents.collection.items[i].data.Count; j++) { revent_ht.Add(revents.collection.items[i].data[j].name, j); } Calendar revent_item = new Calendar(); long locationid = (long)revents.collection.items[i].data[(int)revent_ht["location_id"]].value; string locationAPI = "https://api.teamsnap.com/v3/locations/" + locationid.ToString(); //string locationres = await apic.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], locationAPI); string locationres = await mlibrary.readFile("locations_" + ruserteam.id); RootObjectLocation rlocation = locations.locationDataDeserializer(locationres); int pos = 0; for (int m = 0; m < rlocation.collection.items.Count; m++) { if (rlocation.collection.items[m].href == locationAPI) { pos = m; break; } } Dictionary<string, int> location_ht = new Dictionary<string, int>(); for (int l = 0; l < rlocation.collection.items[pos].data.Count; l++) { location_ht.Add(rlocation.collection.items[pos].data[l].name, l); } revent_item.locationAddress = (string)rlocation.collection.items[pos].data[(int)location_ht["address"]].value; revent_item.locationName = (string)rlocation.collection.items[pos].data[(int)location_ht["name"]].value; revent_item.locationNotes = (string)rlocation.collection.items[pos].data[(int)location_ht["notes"]].value; revent_item.locationPhone = (string)rlocation.collection.items[pos].data[(int)location_ht["phone"]].value; revent_item.name = (string)revents.collection.items[i].data[(int)revent_ht["name"]].value; revent_item.team_id = teamid; revent_item.game_type = revents.collection.items[i].data[(int)revent_ht["game_type"]].value == null ? null : (string)revents.collection.items[i].data[(int)revent_ht["game_type"]].value; revent_item.uniform = revents.collection.items[i].data[(int)revent_ht["uniform"]].value == null ? null : (string)revents.collection.items[i].data[(int)revent_ht["uniform"]].value; if (revents.collection.items[i].data[(int)revent_ht["opponent_id"]].value == null) { revent_item.opponent_id = null; } else { revent_item.opponent_id = (revents.collection.items[i].data[(int)revent_ht["opponent_id"]].value).ToString(); //string opponentres = await apic.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/opponents/" + revent_item.opponent_id); string opponentres = await mlibrary.readFile("opponents_" + ruserteam.id); RootObjectOpponent ropponent = Opponent.opponentDataDeserializer(opponentres); // Use opponent ID to find opponent name pos = 0; for (int m = 0; m < ropponent.collection.items.Count; m++) { if (ropponent.collection.items[m].href == ("https://api.teamsnap.com/v3/opponents/" + revent_item.opponent_id)) { pos = m; break; } } Debug.WriteLine(pos); for (int len = 0; len < ropponent.collection.items[pos].data.Count; len++) { if (ropponent.collection.items[pos].data[len].name == "name") { revent_item.game_title = "vs " + (string)ropponent.collection.items[pos].data[len].value; break; } } } // done //revent_item.opponent_id = (string)(revents.collection.items[i].data[(int)revent_ht["opponent_id"]].value).ToString(); revent_item.id = (long)revents.collection.items[i].data[(int)revent_ht["id"]].value; revent_item.additional_location_details = (string)revents.collection.items[i].data[(int)revent_ht["additional_location_details"]].value; revent_item.arrival_date = revents.collection.items[i].data[(int)revent_ht["arrival_date"]].value == null ? DateTime.MinValue : ((DateTime)revents.collection.items[i].data[(int)revent_ht["arrival_date"]].value).ToLocalTime(); revent_item.arrival_time = revent_item.arrival_date.ToString("hh:mm tt"); revent_item.division_location_id = (string)revents.collection.items[i].data[(int)revent_ht["division_location_id"]].value; revent_item.duration_in_minutes = revents.collection.items[i].data[(int)revent_ht["duration_in_minutes"]].value == null ? 0 : (long)revents.collection.items[i].data[(int)revent_ht["duration_in_minutes"]].value; //revent_item.end_Date = (DateTime)revents.collection.items[i].data[(int)revent_ht["end_date"]].value; if (revents.collection.items[i].data[(int)revent_ht["end_date"]].value != null) { revent_item.end_Date = ((DateTime)revents.collection.items[i].data[(int)revent_ht["end_date"]].value).ToLocalTime(); } else { revent_item.end_Date = DateTime.MinValue; } revent_item.formatted_results = (string)revents.collection.items[i].data[(int)revent_ht["formatted_results"]].value; revent_item.game_type = (string)revents.collection.items[i].data[(int)revent_ht["game_type"]].value; revent_item.is_game = revents.collection.items[i].data[(int)revent_ht["is_game"]].value == null ? false : (bool)revents.collection.items[i].data[(int)revent_ht["is_game"]].value; revent_item.is_tbd = revents.collection.items[i].data[(int)revent_ht["is_tbd"]].value == null ? false : (bool)revents.collection.items[i].data[(int)revent_ht["is_tbd"]].value; revent_item.label = (string)revents.collection.items[i].data[(int)revent_ht["label"]].value; revent_item.location_id = revents.collection.items[i].data[(int)revent_ht["location_id"]].value == null ? 0 : (long)revents.collection.items[i].data[(int)revent_ht["location_id"]].value; revent_item.minutes_to_arrive_early = revents.collection.items[i].data[(int)revent_ht["minutes_to_arrive_early"]].value == null ? 0 : (long)revents.collection.items[i].data[(int)revent_ht["minutes_to_arrive_early"]].value; revent_item.name = (string)revents.collection.items[i].data[(int)revent_ht["name"]].value; revent_item.notes = (string)revents.collection.items[i].data[(int)revent_ht["notes"]].value; revent_item.start_date = revents.collection.items[i].data[(int)revent_ht["start_date"]].value == null ? DateTime.MinValue : ((DateTime)revents.collection.items[i].data[(int)revent_ht["start_date"]].value).ToLocalTime(); revent_item.time_zone = (string)revents.collection.items[i].data[(int)revent_ht["time_zone"]].value; revent_item.updated_at = revents.collection.items[i].data[(int)revent_ht["updated_at"]].value == null ? DateTime.MinValue : (DateTime)revents.collection.items[i].data[(int)revent_ht["updated_at"]].value; revent_item.eventDay = revent_item.start_date.ToString("dd"); revent_item.eventMonth = revent_item.start_date.ToString("MMMM"); revent_item.dddFormat = (revent_item.start_date.ToString("ddd")).ToUpper(); revent_item.eventTime = revent_item.start_date.ToString("hh:mm tt");//revent_item.start_date.Hour.ToString() + ":" + revent_item.start_date.Minute.ToString() + " " + revent_item.start_date.ToString("tt"); revent_ht.Clear(); location_ht.Clear(); if (DateTime.Compare(revent_item.start_date, (DateTime.Now).AddDays(-3)) > 0) // if there is a start date and no end date { cal.Add(revent_item); } calAllEvents.Add(revent_item); } if (cal.Count < 1) { //Meaning no future events, but there are past events scheduleView.Visibility = Visibility.Visible; PivotHeaderGrid.Visibility = Visibility.Visible; noUpcomingEvents.Visibility = Visibility.Visible; noEvents.Visibility = Visibility.Collapsed; } else { MyCalendarListViewUpcomingEvents.Visibility = Visibility.Visible; scheduleView.Visibility = Visibility.Visible; PivotHeaderGrid.Visibility = Visibility.Visible; noUpcomingEvents.Visibility = Visibility.Collapsed; noEvents.Visibility = Visibility.Collapsed; } } else { //tempYesCalendarPage.Visibility = Visibility.Collapsed; //AddNewEvent.Visibility = Visibility.Collapsed; //temp NoCalendarPage.Visibility = Visibility.Visible; //temp noCalendarFlipViewButtons.Visibility = Visibility.Collapsed; //temp MyCalendarListViewAllEventsNoCalendar.Visibility = Visibility.Collapsed; scheduleView.Visibility = Visibility.Collapsed; PivotHeaderGrid.Visibility = Visibility.Collapsed; noEvents.Visibility = Visibility.Visible; calendarfound = false; } ApplicationData.Current.LocalSettings.Values["eventTemplateFile"] = "eventTemplate.txt"; await mlibrary.writeFile((string)ApplicationData.Current.LocalSettings.Values["eventTemplateFile"], res); } } catch (Exception ex) { Debug.WriteLine(ex); } //myProgressRing.IsActive = false; if (calendarfound == false) { //temp YesCalendarPage.Visibility = Visibility.Collapsed; //temp NoCalendarPage.Visibility = Visibility.Visible; //temp noCalendarFlipViewButtons.Visibility = Visibility.Collapsed; //temp MyCalendarListViewAllEventsNoCalendar.Visibility = Visibility.Collapsed; } Debug.WriteLine(cal.Count); Debug.WriteLine(calAllEvents.Count); MyCalendarListViewAllEvents.DataContext = this; MyCalendarListViewUpcomingEvents.DataContext = this; //temp Debug.WriteLine("MyCalendarListView Visibility : " + (MyCalendarListView.Visibility).ToString()); //temp MyCalendarListView.DataContext = this; //temp MyCalendarListViewAllEvents.DataContext = this; }
public static async Task<ObservableCollection<Comments>> createCollection(string response) { methodLibrary mlb = new methodLibrary(); string userclass = await mlb.readSerializedUserClass(); RootObjectUsers rusers = Users.usersDataDeserializer(userclass); ObservableCollection<Comments> rphotocomments = new ObservableCollection<Comments>(); try { RootObjectMediaComments rmediacom = mediaCommentsDataDeserializer(response); if (rmediacom.collection.items != null) { Dictionary<string, int> rmediacom_itemdata_ht = new Dictionary<string, int>(); for (int i = 0; i < rmediacom.collection.items[0].data.Count; i++) { if (!rmediacom_itemdata_ht.ContainsKey(rmediacom.collection.items[0].data[i].name)) { rmediacom_itemdata_ht.Add(rmediacom.collection.items[0].data[i].name, i); } } for (int i = 0; i < rmediacom.collection.items.Count; i++) { Comments cm = new Comments(); CollectionUsersTeamMembers rmembers = new CollectionUsersTeamMembers(); cm.comment = (string)rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["comment"]].value; cm.memberid = rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["member_id"]].value == null ? 0 : (long)rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["member_id"]].value; cm.mediaid = rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["team_medium_id"]].value == null ? 0 : (long)rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["team_medium_id"]].value; rmembers = mlb.getMemberInfoFromFile(rusers, cm.memberid); cm.membername = rmembers.first_name + " " + rmembers.last_name; // cm.memberphoto = rmembers.member_thumbnail_uri; DateTime lastupdatetime = rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["updated_at"]].value == null ? DateTime.MinValue : (DateTime)rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["updated_at"]].value; if (lastupdatetime.CompareTo(DateTime.MinValue) > 0) { if (lastupdatetime.CompareTo(DateTime.UtcNow.AddDays(-1)) > 0) { TimeSpan ts = DateTime.Now.Subtract(lastupdatetime); if (ts.Hours == 0) { if (ts.Minutes == 0) { cm.lastupdatedat = "A few seconds ago"; } else if (ts.Minutes < 5 && ts.Minutes > 0) { cm.lastupdatedat = "A few min ago"; } else { cm.lastupdatedat = ts.Minutes + " min ago"; } } else { if (ts.Hours == 1) { cm.lastupdatedat = "An hour ago"; } else { cm.lastupdatedat = ts.Hours + " hours ago"; } } } else { DateTime localtime = lastupdatetime.ToLocalTime(); cm.lastupdatedat = String.Format("{0:ddd, MMM dd, yyyy}", localtime); } } rphotocomments.Add(cm); } } } catch (Exception ex) { } return rphotocomments; }