예제 #1
0
 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;
 }
예제 #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";
     tokenflag = false;
 }
예제 #3
0
        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;
        }