示例#1
0
 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";
    // CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
 }
示例#2
0
 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();
 }
示例#3
0
        public static async Task<ObservableCollection<MemberItemTrackingStatus>> getTrackingItemStatus(long trackingitemid)
        {
            ObservableCollection<MemberItemTrackingStatus> ritemstatuscollection = new ObservableCollection<MemberItemTrackingStatus>();
            methodLibrary mlb = new methodLibrary();
            string userclass = await mlb.readSerializedUserClass();
            RootObjectUsers rusers = new RootObjectUsers();
            rusers = Users.usersDataDeserializer(userclass);

            Library_APICall apiLibrary = new Library_APICall();
            string resp = await apiLibrary.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/tracked_item_statuses/search?tracked_item_id=" + trackingitemid);
            RootObjectTrackingItemStatus ritemstatus = trackingStatusDataDeserializer(resp);

            Dictionary<string, int> rstatus_items_data_ht = new Dictionary<string, int>();
            for (int i = 0; i < ritemstatus.collection.items[0].data.Count; i++)
            {
                if (!rstatus_items_data_ht.ContainsKey(ritemstatus.collection.items[0].data[i].name))
                {
                    rstatus_items_data_ht.Add(ritemstatus.collection.items[0].data[i].name, i);
                }
            }
            ritemstatuscollection.Clear();
            for (int i = 0; i < ritemstatus.collection.items.Count; i++)
            {
                MemberItemTrackingStatus robj = new MemberItemTrackingStatus();
                robj.object_id = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["id"]].value;
                robj.trackingitemid = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["tracked_item_id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["tracked_item_id"]].value;
                robj.status = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status"]].value == null ? "" : (string)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status"]].value;
                robj.member_id = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["member_id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["member_id"]].value;
                robj.status_code = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status_code"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status_code"]].value;
                CollectionUsersTeamMembers rmember = new CollectionUsersTeamMembers();
                rmember = mlb.getMemberInfoFromFile(rusers, robj.member_id);
                robj.member_name = rmember.fullname;
                ritemstatuscollection.Add(robj);
            }
            
            return ritemstatuscollection;
        }
示例#4
0
 public static string usersDataSerializer(RootObjectUsers rusers)
 {
     string response = JsonConvert.SerializeObject(rusers);
     return response;
 }
示例#5
0
        private async void AddNewEmail_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                teamid_temp = (long)ApplicationData.Current.LocalSettings.Values["currentTeamID"];
                //teamid_temp = 1521479;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            if (parameterPresent == false)
            {
                string userclass = await mlb.readSerializedUserClass();
                ruser = Users.usersDataDeserializer(userclass);

                mselectrecipient.Clear();
                for (int i = 0; i < (ruser.teams).Count; i++)
                {
                    if (ruser.teams[i].id == teamid_temp)
                    {
                        for (int j = 0; j < ruser.teams[i].members.Count; j++)
                        {
                            CollectionUsersTeamMembers msr = new CollectionUsersTeamMembers();
                            msr.member_id = ruser.teams[i].members[j].member_id;
                            msr.fullname = ruser.teams[i].members[j].fullname;
                            mselectrecipient.Add(msr);
                        }
                        memberid = ruser.teams[i].members[0].member_id;
                    }
                }
            }
            else
            {
                mselectrecipient.Clear();
                teamid_temp = rcem.team_id;
                var rcemMember = rcem.memberAvailable;
                foreach (var val in rcemMember)
                {
                    CollectionUsersTeamMembers msr = new CollectionUsersTeamMembers();
                    msr.member_id = val.member_id;
                    msr.fullname = val.member_name;
                    mselectrecipient.Add(msr);
                }
            }
        }
        private async void PostTopic_Click(object sender, RoutedEventArgs e)
        {
            RootObjectForumTopics rftopics = new RootObjectForumTopics();
            CollectionForumTopicsTemplate rfttemplate = new CollectionForumTopicsTemplate();
            RootObjectUsers ruser = new RootObjectUsers();
            RootObjectForumPosts rfposts = new RootObjectForumPosts();
            CollectionForumPostsTemplate rfptemplate = new CollectionForumPostsTemplate();
            if (Subject.Text == "" || Message.Text == "")
            {

            } 
            else
            {
                try
                {
                    /// filling out the template for Forum Topics
                    string forumtopic = await mlibrary.readFile("forum_topics");
                    rftopics = forum_topics.forumtopicsDataDeserializer(forumtopic);
                    rfttemplate = rftopics.collection.template;
                    Hashtable rfttemplate_ht = new Hashtable();
                    for (int i = 0; i < rfttemplate.data.Count; i++)
                    {
                        rfttemplate_ht.Add(rfttemplate.data[i].name, i);
                    }
                    rfttemplate.data[(int)rfttemplate_ht["title"]].value = Subject.Text;
                    if (broadcast_to_team.IsChecked == true)
                    {
                        rfttemplate.data[(int)rfttemplate_ht["is_announcement"]].value = true;
                    }
                    else
                    {
                        rfttemplate.data[(int)rfttemplate_ht["is_announcement"]].value = false;
                    }
                    rfttemplate.data[(int)rfttemplate_ht["team_id"]].value = teamid.ToString();
                    rfttemplate.data[(int)rfttemplate_ht["type"]].value = "forum_topic";
                    string rftresponse = forum_topics.forumTopicsTemplateSerializer(rfttemplate);
                    rftresponse = "{\"template\":" + rftresponse + "}";
                    Debug.WriteLine(rftresponse);
                    // make POST to forum_topic
                    await APILibrary.apiPOST((string)ApplicationData.Current.LocalSettings.Values["Tokens"], rftresponse, rftopics.collection.href);

                    // read POST response to fetch message id.
                    string postresp = await mlibrary.readFile("POSTresponse");
                    rftopics = forum_topics.forumtopicsDataDeserializer(postresp);

                    string userclass = await mlibrary.readSerializedUserClass();
                    Debug.WriteLine(userclass);
                    ruser = Users.usersDataDeserializer(userclass);
                    Debug.WriteLine(ruser.items[0].id);
                    /// filling out the template for forum posts
                    string forumposts = await mlibrary.readFile("forum_posts");
                    rfposts = forum_posts.forumpostsDataDeserializer(forumposts);
                    rfptemplate = rfposts.collection.template;
                    Hashtable rfptemplate_ht = new Hashtable();
                    for(int i=0; i < rfptemplate.data.Count; i++)
                    {
                        rfptemplate_ht.Add(rfptemplate.data[i].name, i);
                    }
                    long teammember_id = 0;
                    for (int i = 0; i < ruser.teams.Count; i++)
                    {
                        if (ruser.teams[i].id == (long)ApplicationData.Current.LocalSettings.Values["currentTeamID"])
                        {
                            teammember_id = ruser.teams[i].loggedInUsersmemberID;
                        }
                    }
                    rfptemplate.data[(int)rfptemplate_ht["forum_topic_id"]].value = rftopics.collection.items[0].data[0].value;
                    rfptemplate.data[(int)rfptemplate_ht["member_id"]].value = teammember_id;
                    rfptemplate.data[(int)rfptemplate_ht["message"]].value = Message.Text;
                    rfptemplate.data[(int)rfptemplate_ht["broadcast_to_team"]].value = rfttemplate.data[(int)rfttemplate_ht["is_announcement"]].value;
                    rfptemplate.data[(int)rfptemplate_ht["type"]].value = "forum_post";

                    string rfpresponse = forum_posts.forumpostsTemplateSerializer(rfptemplate);
                    rfpresponse = "{\"template\":" + rfpresponse + "}";
                    string remove = "{\"name\":\"division_member_id\",\"value\":null},";
                    int index = rfpresponse.IndexOf(remove);
                    rfpresponse = (index < 0) ? rfpresponse : rfpresponse.Remove(index, remove.Length);

                    Debug.WriteLine(rfpresponse);
                    await APILibrary.apiPOST((string)ApplicationData.Current.LocalSettings.Values["Tokens"], rfpresponse, rfposts.collection.href);
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(Forums), teamid);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception returned in AddNewForumTopic.xaml.cs : " + ex);
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(Forums), teamid);
                }
            }
        }
示例#7
0
        public async Task<bool> doWhatSignInDoes()
        {
            string access_token = null;
            string meAPIResponse = 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.");
                //meAPIResponse = await LibraryAPI.apiCall(access_token, meAPI);
                string refreshclicked = (string)ApplicationData.Current.LocalSettings.Values["RefreshClicked"];
                // if (await checkIfFileExists(("family_contacts_phone_res" + teammembers.member_id)) && (String.IsNullOrEmpty(refreshclicked) || refreshclicked.Equals("false")))
                if (await checkIfFileExists("meAPIResponse") && (String.IsNullOrEmpty(refreshclicked) || refreshclicked.Equals("false")))
                {
                    meAPIResponse = await readFile("meAPIResponse");
                    if (String.IsNullOrEmpty(meAPIResponse))
                    {
                        meAPIResponse = await LibraryAPI.apiCall(access_token, meAPI);
                    }
                }
                else
                {
                    meAPIResponse = await LibraryAPI.apiCall(access_token, meAPI);
                }
                if (meAPIResponse == "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(meAPIResponse);

                // deserialize meAPIResponse
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Deserializaing Me API response.");
                rme = Me.MeDataDeserializer(meAPIResponse);
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": me API response deserialization complete.");
                Hashtable links_ht = new Hashtable();
                int id = 0;
                while (id < rme.collection.items[0].links.Count)
                {
                    if (!links_ht.Contains(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", meAPIResponse);
                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;
        }
示例#8
0
        /// <summary>
        /// update User Information.
        /// </summary>
        /// <returns></returns>
        public static async Task<RootObjectUsers> updateUser()
        {
            //await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
            //    () =>
            //    {
            //        // UI stuff here
                     
            //    });
            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();
            
            Hashtable rme_ht = new Hashtable();
            Hashtable rteam_ht = new Hashtable();
            Hashtable rteamlinks_ht = new Hashtable();
            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);
            Hashtable rsports_ht = new Hashtable();
            for (int i = 0; i < rsports.collection.items.Count; i++)
            {
                if (!rsports_ht.Contains(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.Contains(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;
            updatePlanInfo(itemCollection.email);
            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.Contains(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.Contains(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);

                ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Updating Team";
                /**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";
                ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Updating Team " + teamsCollection.name;
                //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);
                    Hashtable rmember_ht = new Hashtable();
                    // 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.Contains(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);
                                var tc = new TelemetryClient();
                                await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": rmember_ht exception", true);
                                tc.TrackEvent("rmember_ht exception : " + ex);
                            }
                        }
                        ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Updating Team Members";
                        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;
                        ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Updating " + teammembers.first_name + " information";
                        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
                         */
                        ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Looking for " + teammembers.first_name + "'s family information";
                        await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": ****Calling Contacts, Contacts Phone and Contacts Email API for member : " + teammembers.member_id +  "****", false);
                      
                        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.jpg";
                        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_thumbnail")
                            {
                                teammembers.member_thumbnail_uri = (string)rmembers.collection.items[j].links[m].href;
                            }
                            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;
                                
                                try
                                {
                                    ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Looking for changes to " + teammembers.first_name + "'s profile photo.";
                                    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";
                                    if (String.IsNullOrEmpty(teammembers_member_photo))
                                    {
                                        teammembers.member_photo_imagex_path = "images/member_photo.jpg";
                                        teammembers.member_photo_imagex_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                                    }
                                    else
                                    {
                                        //teammembers.member_photo_imagex_path = "ms-appdata:///temp/ImageCache/" + methodLibrary.BuildFileName(new Uri(teammembers_member_photo));
                                        teammembers.member_photo_imagex_uri = teammembers_member_photo;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine("Failed to download image");
                                    teammembers.member_photo = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                                    teammembers.member_photo_imagex_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                                    teammembers.member_thumbnail_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                                    teammembers.member_photo_notscaled = "images/member_photo.jpg";
                                    teammembers.member_photo_imagex_path = "images/member_photo.jpg";
                                    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 = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                            teammembers.member_photo_imagex_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                            teammembers.member_thumbnail_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.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;
        }
示例#9
0
 public CollectionUsersTeamMembers getMemberInfoFromFile(RootObjectUsers ruser, long memberid)
  {
      CollectionUsersTeamMembers rmember = new CollectionUsersTeamMembers();
      long teamid = Constants.CurrentTeamID;
      foreach (var item in ruser.teams)
      {
          if (item.id == teamid)
          {
              foreach (var memberlist in item.members)
              {
                  if (memberlist.member_id == memberid)
                  {
                      rmember = memberlist;
                      break;
                  }
              }
          }
      }
      return rmember;
  }
示例#10
0
        public static async Task<bool> updateAvailability(RootObjectUsers rusers)
        {
            methodLibrary mlib = new methodLibrary();
            Hashtable rteams_ht = new Hashtable();
            if (rusers.teams != null)
            {
                for (int i = 0; i < rusers.teams.Count; i++)
                {
                    if (!rteams_ht.Contains(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
                    {
                        Hashtable ravailibityAPI_items_ht = new Hashtable();
                        for (int i = 0; i < ravailbilityAPI.collection.items[0].data.Count; i++)
                        {
                            if (!ravailibityAPI_items_ht.Contains(ravailbilityAPI.collection.items[0].data[i].name))
                            {
                                ravailibityAPI_items_ht.Add(ravailbilityAPI.collection.items[0].data[i].name, i);
                            }
                        }
                        Hashtable ravailabilityAPI_events_ht = new Hashtable();
                        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))
                            {
                                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.Contains(reventavail.eventMemberAvailability[i].team_id))
                        {
                            var teams = rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]];
                            Hashtable rteamMember_ht = new Hashtable();
                            int numOfMembersInTeam = rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]].members.Count;
                            for (int j = 0; j < numOfMembersInTeam; j++)
                            {
                                if (!rteamMember_ht.Contains(rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]].members[j].member_id))
                                {
                                    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.Contains(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;
        }