예제 #1
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            using (var db = new PicturePlaceDb())
            {
                db.Database.Migrate();
            }
        }
예제 #2
0
 /*Deletes everything from the database
  */
 private void DeleteFromDB()
 {
     using (var db = new PicturePlaceDb())
     {
         foreach (var item in db.data)
         {
             db.data.Remove(item);
         }
         db.SaveChanges();
     }
 }
예제 #3
0
        /*Method stores pics in the local database
         */
        private void StorePicture(Datum pic, PicturePlaceDb db)
        {
            var picInfo = new FbPicInfo
            {
                city      = pic.place.location.city,
                country   = pic.place.location.country,
                latitude  = pic.place.location.latitude,
                longitude = pic.place.location.longitude,
                id        = pic.id,
                name      = pic.place.name,
                source    = pic.source
            };

            db.Add(picInfo);
            db.SaveChanges();
        }
예제 #4
0
        /*Checks to see if there are any new pics in the results returned from facebook, if yes, they are added to the database, otherwise return true "All Pics Added"
         */
        private Boolean SortPictures(PicturePlaceObject results, PicturePlaceDb db)
        {
            Boolean addedAllPics = true;

            foreach (var pic in results.data)                        //loop through all the Pics in results.data
            {
                if (pic.place != null && pic.place.location != null) //Only add Pics that have a place/location from results
                {
                    var placeId = db.data.Select(id => id.id);       //COLLECTION OF ALL THE IDS IN THE DATABASE
                    //check to see if the collection of ids already contains the new id, if not a new pic is found etc.
                    if (!placeId.Contains(pic.id))
                    {
                        addedAllPics = false;
                        StorePicture(pic, db);
                    }
                }
            }
            return(addedAllPics);
        }
예제 #5
0
        /*Method takes in the Database object and creates a temporary list which is then looped through and passed into   AddPinToMap() to paint the pin to map
         */
        private async void PaintPins(PicturePlaceDb db)
        {
            var tempList = db.data.AsEnumerable().Select(pic => new FbPicInfo
            {
                longitude = pic.longitude,
                latitude  = pic.latitude,
                source    = pic.source,
                name      = pic.name,
                country   = pic.country,
                city      = pic.city
            }).ToList();

            foreach (var pic in tempList)//loop through all the Pics in tempList
            {
                AddPinToMap(DesignPin(pic), CreateBasicGeoPosition(pic));
            }
            if (tempList.Count == 0)
            {
                var dialog = new MessageDialog("You are not currently not tagged in any facebook pictures with locations.\nPlease Tag youself in a picture on facebook and give it a location and run the app again");
                dialog.Title = "No Tagged Photos Found With Locations";
                await dialog.ShowAsync();
            }
        }
예제 #6
0
        /*On Successful login, send GET request to FB endpoint with params and DeserializeJson the results into objects/Dictonary
         */
        private async void OnSuccessLogin()
        {
            string endpoint = "/me/photos";//where the url starts from

            PropertySet parameters = new PropertySet();

            parameters.Add("fields", "source,place");                                                      //Required fields needed

            FBSingleValue value       = new FBSingleValue(endpoint, parameters, DeserializeJson.FromJson); //send the request and get back a JSON responce
            FBResult      graphResult = await value.GetAsync();

            if (graphResult.Succeeded)//check to see if the Request Succeeded
            {
                PicturePlaceObject results = graphResult.Object as PicturePlaceObject;

                var db = new PicturePlaceDb();
                GetAllFbPic(results, parameters, endpoint, db);
            }
            else
            {
                MessageDialog dialog = new MessageDialog("Try Again Later!");
                await dialog.ShowAsync();
            }
        }
예제 #7
0
        /*Method keeps sending get requets to facebook api using paging, untill all pictures have been added
         */
        private async void GetAllFbPic(PicturePlaceObject results, PropertySet parameters, string endpoint, PicturePlaceDb db)
        {
            Boolean addedAllPics = false;

            do                                            //only do this while there is a next page and all pics have not been added
            {
                addedAllPics = SortPictures(results, db); //Add Results to a list

                if (addedAllPics == false)
                {
                    parameters.Remove("after");                                                                    //Remove previous parameters
                    parameters.Add("after", results.paging.cursors.after);                                         //the next page to send the request too

                    FBSingleValue value       = new FBSingleValue(endpoint, parameters, DeserializeJson.FromJson); //send the request and get back a JSON responce
                    FBResult      graphResult = await value.GetAsync();                                            //check to see if the Requets Succeeded

                    results = graphResult.Object as PicturePlaceObject;
                }
            } while ((results.paging != null || results.data.Count() != 0) && addedAllPics == false);
            PaintPins(db);
        }