Beispiel #1
0
 /// <summary>
 /// Uses DOM parsing to constitute an Event data object given the xml returned from facebook
 /// </summary>
 internal static FacebookEvent ParseEvent(XmlNode node)
 {
     FacebookEvent ev = new FacebookEvent();
     if (node != null)
     {
         ev.EventId = XmlHelper.GetNodeText(node, "eid");
         ev.Name = XmlHelper.GetNodeText(node, "name");
         ev.TagLine = XmlHelper.GetNodeText(node, "tagline");
         ev.NetworkId = XmlHelper.GetNodeText(node, "nid");
         ev.Host = XmlHelper.GetNodeText(node, "host");
         ev.Description = XmlHelper.GetNodeText(node, "description");
         ev.Type = XmlHelper.GetNodeText(node, "event_type");
         ev.SubType = XmlHelper.GetNodeText(node, "event_subtype");
         ev.Location = XmlHelper.GetNodeText(node, "location");
         ev.Creator = XmlHelper.GetNodeText(node, "creator");
         if (!String.IsNullOrEmpty(XmlHelper.GetNodeText(node, "pic")))
         {
             ev.PictureUrl = new Uri(XmlHelper.GetNodeText(node, "pic"));
         }
         if (!String.IsNullOrEmpty(XmlHelper.GetNodeText(node, "update_time")))
         {
             ev.UpdateDate = DateHelper.ConvertDoubleToDate(double.Parse(XmlHelper.GetNodeText(node, "update_time"), CultureInfo.InvariantCulture));
         }
         if (!String.IsNullOrEmpty(XmlHelper.GetNodeText(node, "start_time")))
         {
             ev.StartDate = DateHelper.ConvertDoubleToDate(double.Parse(XmlHelper.GetNodeText(node, "start_time"), CultureInfo.InvariantCulture));
         }
         if (!String.IsNullOrEmpty(XmlHelper.GetNodeText(node, "end_time")))
         {
             ev.EndDate = DateHelper.ConvertDoubleToDate(double.Parse(XmlHelper.GetNodeText(node, "end_time"), CultureInfo.InvariantCulture));
         }
         ev.Venue = LocationParser.ParseLocation(((XmlElement)node).GetElementsByTagName("venue")[0]);
     }
     return ev;
 }
Beispiel #2
0
 private void LoadEvent(FacebookEvent facebookEvent)
 {
     pbEventPicture.Image = facebookEvent.Picture;
     lblEvent.Text = facebookEvent.Name;
     lblHostedBy.Text = facebookEvent.Host;
     lblType.Text = facebookEvent.Type;
     lblWhere.Text = facebookEvent.Location;
     lblWhen.Text = facebookEvent.StartDate.ToString();
 }
Beispiel #3
0
 private void LoadEvent(FacebookEvent facebookEvent)
 {
     pbEventPicture.Image = facebookEvent.Picture;
     lblEvent.Text        = facebookEvent.Name;
     lblHostedBy.Text     = facebookEvent.Host;
     lblType.Text         = facebookEvent.Type;
     lblWhere.Text        = facebookEvent.Location;
     lblWhen.Text         = facebookEvent.StartDate.ToString();
 }
Beispiel #4
0
        private ListViewItem createEventItem(FacebookEvent i_Event, ImageList i_EventsImageList)
        {
            string imageKey = i_Event.Name;
            if (!i_EventsImageList.Images.ContainsKey(imageKey))
            {
                i_EventsImageList.Images.Add(imageKey, i_Event.ImageSmall);
            }

            ListViewItem eventItem = new ListViewItem { ImageKey = imageKey };
            eventItem.SubItems.Add(i_Event.Name);
            eventItem.Tag = i_Event;

            return eventItem;
        }
Beispiel #5
0
        public DroidFacebookButton()
        {
            MainActivity.callbackManager = CallbackManagerFactory.Create();

            LoginManager.Instance.RegisterCallback(MainActivity.callbackManager, new FacebookCallback <LoginResult> {
                HandleSuccess = (result) => {
                    var expires    = result.AccessToken.Expires;
                    var epoch      = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    var expiration = epoch.AddMilliseconds(expires.Time);

                    if (callback != null)
                    {
                        FacebookEvent data = new FacebookEvent()
                        {
                            AccessToken     = result.AccessToken.Token,
                            TokenExpiration = expiration,
                            UserId          = result.AccessToken.UserId
                        };
                        callback(data);
                    }
                    else
                    {
                        throw new Exception("Login callback is not defined");
                    }
                },
                HandleCancel = () => {
                    if (callback != null)
                    {
                        callback(default(FacebookEvent));
                    }
                    else
                    {
                        throw new Exception("Login callback is not defined");
                    }
                },
                HandleError = (error) => {
                    if (callback != null)
                    {
                        callback(default(FacebookEvent));
                    }
                    else
                    {
                        throw new Exception("Login callback is not defined");
                    }
                }
            });
        }
        public async void MakeRequestForFacebookEvent()
        {
            var credentials = TestSettings.GetToken <Facebook, OAuth2Credentials>();

            if (credentials.IsTokenExpired)
            {
                throw new Exception("Expired credentials!!!");
            }

            var request = new FacebookEvent()
            {
                Since = DateTime.Today.Subtract(TimeSpan.FromDays(500)),
                Until = DateTime.Today,
                Limit = 3
            };
            var response = await new OAuthRequester(credentials)
                           .MakeOAuthRequestAsync <FacebookEvent, FacebookEventResponse>(request)
                           .ConfigureAwait(false);

            Assert.NotNull(response);
        }
Beispiel #7
0
 public EventSelectedEventArgs(FacebookEvent facebookEvent)
 {
     _facebookEvent = facebookEvent;
 }
Beispiel #8
0
 public EventListItem(FacebookEvent facebookEvent)
     : this()
 {
     _facebookEvent = facebookEvent;
     LoadEvent(facebookEvent);
 }
Beispiel #9
0
 public EventItemSelectedEventArgs(FacebookEvent facebookEvent)
 {
     _facebookEvent = facebookEvent;
 }
Beispiel #10
0
 private void LoadEventBasedControls(FacebookEvent facebookEvent)
 {
     inviteeList1.FacebookEvent = facebookEvent;
     inviteeList1.Invitees = facebookService1.GetEventMembers(facebookEvent.EventId);
 }
Beispiel #11
0
 private void displayEventData(FacebookEvent i_EventData)
 {
     facebookEventBindingSource.DataSource = i_EventData;
 }
Beispiel #12
0
        // TODO: Implement "AsGroup"

        /// <summary>
        /// Gets the profile as a Facebook event.
        /// </summary>
        /// <returns>An instance of <see cref="FacebookEvent"/>.</returns>
        public FacebookEvent AsEvent()
        {
            return(FacebookEvent.Parse(JObject));
        }
Beispiel #13
0
        public static FacebookEvent Event(long id, JToken json)
        {
            FacebookEvent fb;
            if ((fb = Data.FacebookEvents.FirstOrDefault(x => x.Id == id)) == null)
            {
                fb = new FacebookEvent
                {
                    Id = id,
                    Name = json.TryGetValue<string>("name")
                };
                if (fb.Name == default(string))
                    return null;
                Data.FacebookEvents.InsertOnSubmit(fb);
            }
            if (!json.Any())
                return fb;

            fb.Name = json.TryGetValue<string>("name");
            fb.Description = json.TryGetValue<string>("description");
            fb.TimeStart = json.TryGetValue<DateTime>("start_time");
            fb.TimeEnd = json.TryGetValue<DateTime>("end_time");
            if (fb.TimeEnd == default(DateTime))
                fb.TimeEnd = null;
            fb.TimeUpdated = json.TryGetValue<DateTime>("updated_time");
            if (fb.TimeUpdated == default(DateTime))
                fb.TimeUpdated = null;
            fb.Response = json.TryGetValue<string>("rsvp_status");

            try
            {
                Data.SubmitChanges();
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("There was an error saving the event: {0} {1}", id, fb.Name), ex);
                return null;
            }

            var fromId = json["owner"].TryGetValue<long?>("id");
            if (fromId != null)
            {
                var contact = Contact(fromId.Value, json["owner"]);
                if (contact != null)
                    fb.Contact = contact.Id;
                try
                {
                    Data.SubmitChanges();
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("There was an error saving the event: {0} {1}", id, fb.Name), ex);
                }
            }

            var locationId = json.TryGetValue<long?>("id");
            if (locationId != null)
            {
                var location = Place(locationId.Value, json["venue"]);
                if (location != null)
                    fb.Place = location.Id;
                try
                {
                    Data.SubmitChanges();
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("There was an error saving the event: {0} {1}", id, fb.Name), ex);
                }
            }

            var comments = json.TryGetValue<JObject>("comments");
            if (comments != null)
            {
                Message(id, json);
            }

            return fb;
        }
Beispiel #14
0
 public EventListItem(FacebookEvent facebookEvent)
     : this()
 {
     _facebookEvent = facebookEvent;
     LoadEvent(facebookEvent);
 }
Beispiel #15
0
        // See https://developers.facebook.com/docs/graph-api/reference/user/events
        public async Task<string> PublishEvent(IdentityUser user, FacebookEvent ev)
        {
            var accessToken = GetAccessToken(user);
            var client = new FacebookClient(accessToken);

            var eventdata = new Dictionary<string, object>();
            eventdata.AddIfNotNull("name", ev.Name);
            eventdata.AddIfNotNull("description", ev.Description);
            eventdata.AddIfNotNull("start_time", "2014-04-30"); // Use DateTimeConverter To.... here
            eventdata.AddIfNotNull("location", "Lincoln, NE");
            eventdata.AddIfNotNull("privacy_type", "OPEN");

            var result = await client.PostTaskAsync(string.Format("me/events"), eventdata);

            var settings = new JsonSerializerSettings
            {
                MissingMemberHandling = MissingMemberHandling.Ignore,
                NullValueHandling = NullValueHandling.Ignore
            };
            var id = JsonConvert.DeserializeObject<FacebookIdentity>(result.ToString(), settings);

            Log.InfoFormat("Published a Facebook event.  UserId={0} CreatedId={1} Name={2}", user.Id, id.Id, ev.Name);

            return id.Id;
        }