Exemplo n.º 1
0
 public Dashboard()
 {
     this.InitializeComponent();           
     userInfo = new ObservableCollection<CollectionUsersTeam>();
     userFunction = new Users();
     LibraryMethods = new methodLibrary();
     LibraryAuth = new Library_TokenAuth();
     feedbackLaunchLimit = 25;
     this.NavigationCacheMode = NavigationCacheMode.Required;            
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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;
        }