Esempio n. 1
0
        public Task <TabPerson> ToPerson()
        {
            if (person != null)
            {
                return(person.Task);
            }

            person = new TaskCompletionSource <TabPerson> ();
            var recipientQuery = new ParseQuery("Person");

            recipientQuery.SetCachePolicy(ParseQuery.CachePolicy.CacheElseNetwork);
            if (Emails.Any())
            {
                recipientQuery.WhereContainedIn("emails", Emails.Select(TabPerson.MD5Hash).ToArray());
            }
            else
            {
                recipientQuery.WhereEqualTo("displayName", DisplayName);
            }

            ParseObject recipient       = null;
            TabPerson   recipientPerson = null;

            recipientQuery.GetFirstInBackground(new TabGetCallback((o, e) => {
                if (o != null)
                {
                    recipient       = o;
                    recipientPerson = TabPerson.FromParse(recipient);
                    // TODO: add the emails that are in Emails and not in recipientPerson.Emails
                    person.SetResult(recipientPerson);
                }
                else
                {
                    recipientPerson = new TabPerson {
                        DisplayName = DisplayName,
                        Emails      = Emails,
                    };
                    recipient = recipientPerson.ToParse();
                    recipient.SaveInBackground(new TabSaveCallback(ex => {
                        if (ex == null)
                        {
                            person.SetResult(recipientPerson);
                        }
                        else
                        {
                            Android.Util.Log.Error("PersonCreator", ex.ToString());
                            person.SetException(ex);
                        }
                    }));
                    recipientQuery.ClearCachedResult();
                }
            }));

            return(person.Task);
        }
Esempio n. 2
0
        static TabPlace FromParse(ParseObject obj)
        {
            var geoPoint = obj.GetParseGeoPoint("latLng");

            return(new TabPlace(obj)
            {
                PlaceName = obj.GetString("placeName"),
                LatLng = Tuple.Create(geoPoint.Latitude, geoPoint.Longitude),
                Person = TabPerson.FromParse(obj.GetParseObject("person"))
            });
        }
Esempio n. 3
0
 public static TabObject FromParse(ParseObject parseObject)
 {
     return(new TabObject {
         Originator = TabPerson.FromParse(parseObject.GetParseObject("originator")),
         Recipient = TabPerson.FromParse(parseObject.GetParseObject("recipient")),
         Direction = (TabDirection)parseObject.GetInt("direction"),
         Type = TabType.FromParse(parseObject.GetParseObject("tabType")),
         LatLng = GeopointToTuple(parseObject.GetParseGeoPoint("location")),
         LocationDesc = parseObject.GetString("locationDesc"),
         Time = JavaDateToDateTime(parseObject.GetDate("time")),
         parseData = parseObject
     });
 }
Esempio n. 4
0
        internal void LaunchApp(Activity ctx, ParseUser withUser, Action uiCallback)
        {
            // Fetch the person corresponding to the user
            Task.Factory.StartNew(() => {
                var query = new ParseQuery("Person");
                query.SetCachePolicy(ParseQuery.CachePolicy.CacheElseNetwork);
                query.WhereEqualTo("parseUser", withUser);
                query.Include("parseUser");
                ParseObject self = null;
                try {
                    self = query.First;
                } catch (ParseException ex) {
                    // We may have a stall result from a previous registration
                    if (query.HasCachedResult)
                    {
                        query.ClearCachedResult();
                        try {
                            self = query.First;
                        } catch {
                            Android.Util.Log.Error("Landing", "Error when trying to retrieve user 2. Normal if empty. {0}", ex.ToString());
                        }
                    }
                    Android.Util.Log.Error("Landing", "Error when trying to retrieve user. Normal if empty. {0}", ex.ToString());
                }
                // First time ever, fill the info
                if (self == null)
                {
                    TabPerson person = null;
                    // Check if our TabPerson wasn't created indirectly by another user
                    query = new ParseQuery("Person");
                    query.WhereEqualTo("emails", TabPerson.MD5Hash(withUser.Email));
                    try {
                        person = TabPerson.FromParse(query.First);
                        person.AssociatedUser = withUser;
                    } catch {
                        // We use the main address email we got by parseUser
                        // and we will fill the rest lazily later from profile
                        // idem for the display name
                        person = new TabPerson {
                            AssociatedUser = withUser,
                            Emails         = new string[] { withUser.Email }
                        };
                    }
                    return(person);
                }
                else
                {
                    TabPerson.CurrentPerson = TabPerson.FromParse(self);
                    return(null);
                }
            }).ContinueWith(t => {
                ctx.RunOnUiThread(() => {
                    // If the user was created, we setup a CursorLoader to query the information we need
                    if (t.Result != null)
                    {
                        var person         = t.Result;
                        person.DisplayName = string.IsNullOrEmpty(profile.DisplayName) ? MakeNameFromEmail(withUser.Email) : profile.DisplayName;
                        person.Emails      = profile.Emails.Union(person.Emails);
                        person.ToParse().SaveEventually();
                        TabPerson.CurrentPerson = person;
                    }

                    if (uiCallback != null)
                    {
                        uiCallback();
                    }
                    ctx.Finish();
                    ctx.StartActivity(typeof(MainActivity));
                });
            });
        }