コード例 #1
0
        private FacebookApiEventArgs GetApiEventArgs(AsyncCompletedEventArgs e, string json, out HttpMethod httpMethod)
        {
            var state = (WebClientStateContainer)e.UserState;

            httpMethod = state.Method;

            var cancelled = e.Cancelled;
            var userState = state.UserState;
            var error     = e.Error;

            // Check for Graph Exception
            var webException = error as WebExceptionWrapper;

            if (webException != null)
            {
                error = ExceptionFactory.GetGraphException(webException) ?? (Exception)webException.ActualWebException;
            }

            if (error == null)
            {
                var jsonObj = JsonSerializer.Current.DeserializeObject(json);

                // we need to check for graph exception here again coz fb return 200ok
                // for https://graph.facebook.com/i_dont_exist
                error = ExceptionFactory.GetGraphException(jsonObj) ??
                        ExceptionFactory.CheckForRestException(DomainMaps, state.RequestUri, jsonObj);
            }

            var args = new FacebookApiEventArgs(error, cancelled, userState, json, state.IsBatchRequest);

            return(args);
        }
コード例 #2
0
ファイル: RegisterPage.xaml.cs プロジェクト: poedja/SpaceTrek
        void client_GetCompleted(object sender, FacebookApiEventArgs e)
        {
            if (e.Error != null)
            {
                Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                return;
            }
            else
            {
                //SocialAccount account = new SocialAccount(
                //var result = (IDictionary<string, object>)e.GetResultData();
                //var id = (string)result["id"];
                FBUser userAccount = JsonConvert.DeserializeObject<FBUser>(e.GetResultData().ToString());
                
                SocialAccount socialAccount = new SocialAccount(userAccount.id,client.AccessToken,userAccount.username,null);
                SettingHelper.SetKeyValue<SocialAccount>("SocialAccount",socialAccount);

                Dispatcher.BeginInvoke(() =>
                {

                    FacebookWebBrowser.Visibility = System.Windows.Visibility.Collapsed;
                    StackPanelHeader.Visibility = System.Windows.Visibility.Visible;
                    ContentPanel.Visibility = System.Windows.Visibility.Visible;
                });
            }
           
        }
コード例 #3
0
 protected void OnGetCompleted(FacebookApiEventArgs args)
 {
     if (GetCompleted != null)
     {
         GetCompleted(this, args);
     }
 }
コード例 #4
0
        void RFBClient_PostCompleted(object sender, FacebookApiEventArgs e)
        {
            RFBClient.PostCompleted -= new EventHandler<FacebookApiEventArgs>(RFBClient_PostCompleted);
            if (e.Error == null)
            {
#if !DEBUG
                Stopwatch OStop = new Stopwatch();
                Console.WriteLine("Friends Fetching Started ..");
                OStop.Start();
#endif
                var result = (IDictionary<string, object>)e.GetResultData();
                //if (Verifier.Verify(ResultsObject, "data"))
                //    ResultsArray = ResultsObject["data"] as JsonArray;
                var id = result["id"] as string;

                OnNewEventCreated(id);
#if !DEBUG
                Console.WriteLine("Friends Fetching Finished in " + OStop.ElapsedMilliseconds);
                OStop.Stop();
#endif

                //FinishedEvents.NotifyFriendsDataFinished(true, FriendList);
            }
            else
            {
                //FinishedEvents.NotifyFriendsDataFinished(false, null);
            }
        }
コード例 #5
0
        /// <summary>
        /// Raise OnDeletedCompleted event handler.
        /// </summary>
        /// <param name="args">The <see cref="FacebookApiEventArgs"/>.</param>
#if FLUENTHTTP_CORE_TPL
        //[Obsolete]
        //[SuppressMessage("Microsoft.Design", "CA1041:ProvideObsoleteAttributeMessage")]
#endif
        protected virtual void OnDeleteCompleted(FacebookApiEventArgs args)
        {
            if (DeleteCompleted != null)
            {
                DeleteCompleted(this, args);
            }
        }
コード例 #6
0
        /// <summary>
        /// Raise OnPostCompleted event handler.
        /// </summary>
        /// <param name="args">The <see cref="FacebookApiEventArgs"/>.</param>
#if FLUENTHTTP_CORE_TPL
        //[Obsolete]
        //[SuppressMessage("Microsoft.Design", "CA1041:ProvideObsoleteAttributeMessage")]
#endif
        protected virtual void OnPostCompleted(FacebookApiEventArgs args)
        {
            if (PostCompleted != null)
            {
                PostCompleted(this, args);
            }
        }
コード例 #7
0
        private void OnGetFriendsCompleted(object sender, FacebookApiEventArgs e)
        {
            RFBClient.GetCompleted -= new EventHandler<FacebookApiEventArgs>(OnGetFriendsCompleted);

            if (e.Error == null)
            {
#if !DEBUG
                Stopwatch OStop = new Stopwatch();
                Console.WriteLine("Friends Fetching Started ..");
                OStop.Start();
#endif
                var result = (IDictionary<string, object>)e.GetResultData();

                //JsonArray ResultsArray = null;
                //JsonObject ResultsObject = e.GetResultData() as JsonObject;
                ObservableCollection<ProfileInfo> FriendList = new ObservableCollection<ProfileInfo>();
                List<string> ids = new List<string>();

                //if (Verifier.Verify(ResultsObject, "data"))
                //    ResultsArray = ResultsObject["data"] as JsonArray;
                var dataItem = (JsonArray)result["data"];
                foreach (JsonObject item in dataItem)
                {
                    FriendList.Add(new ProfileInfo(item));
                }
                foreach (var item in FriendList)
                {
                    ids.Add(item.ID);
                }

                OnFriendListUpdated(FriendList);


#if !DEBUG
                Console.WriteLine("Friends Fetching Finished in " + OStop.ElapsedMilliseconds);
                OStop.Stop();
#endif

                App.MManager.PublishMessageByType<FriendListMessage>(new FriendListMessage()
                {
                    FriendIDList = ids
                });
            }
            else
            {
            }

        }
コード例 #8
0
        //[Obsolete]
        //[SuppressMessage("Microsoft.Design", "CA1041:ProvideObsoleteAttributeMessage")]
#endif
        private void OnCompleted(HttpMethod httpMethod, FacebookApiEventArgs args)
        {
            switch (httpMethod)
            {
            case HttpMethod.Get:
                OnGetCompleted(args);
                break;

            case HttpMethod.Post:
                OnPostCompleted(args);
                break;

            case HttpMethod.Delete:
                OnDeleteCompleted(args);
                break;

            default:
                throw new ArgumentOutOfRangeException("httpMethod");
            }
        }
コード例 #9
0
 void fbClient_PostCompleted(object sender, FacebookApiEventArgs e)
 {
     if(e.Error!=null)
     {
         if (e.Error is FacebookOAuthException)
         {
             Dispatcher.BeginInvoke(() => MessageBox.Show("Error de Autorizacion, favor re-logearse"));
             //se elimina el actual token de registro
             guardarTokenRegistro(null);
             fbClient.AccessToken = null;
         }
         else
         {
             Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
         }
     }
     else
     {
         Dispatcher.BeginInvoke(() => MessageBox.Show("Mensaje Posteado con exito"));
     }
 }
コード例 #10
0
        public void fb_PostCompleted(object sender, FacebookApiEventArgs e)
        {
            if (e.Cancelled)
            {
                MessageBox.Show("Upload cancelled");
            }
            else if (e.Error == null)
            {
                // upload successful.
                MessageBox.Show(e.GetResultData().ToString());
            }
            else
            {
                // upload failed
                //MessageBox.Show(e.Error.Message);
            }

            progressBar1.BeginInvoke(new MethodInvoker(() =>
            {
                progressBar1.Value = 0;
            }));
        }
コード例 #11
0
        private void OnGetEventsCompleted(object sender, FacebookApiEventArgs e)
        {
            RFBClient.GetCompleted -= new EventHandler<FacebookApiEventArgs>(OnGetEventsCompleted);

            if (e.Error == null)
            {
#if !DEBUG
                Stopwatch OStop = new Stopwatch();
                Console.WriteLine("Friends Fetching Started ..");
                OStop.Start();
#endif
                var result = (IDictionary<string, object>)e.GetResultData();

                ObservableCollection<Event> FriendList = new ObservableCollection<Event>();

                //if (Verifier.Verify(ResultsObject, "data"))
                //    ResultsArray = ResultsObject["data"] as JsonArray;
                var dataItem = (JsonArray)result["data"];
                foreach (JsonObject item in dataItem)
                {
                    FriendList.Add(new Event(item));
                }

                OnEventListUpdated(FriendList);
#if !DEBUG
                Console.WriteLine("Friends Fetching Finished in " + OStop.ElapsedMilliseconds);
                OStop.Stop();
#endif

                //FinishedEvents.NotifyFriendsDataFinished(true, FriendList);
            }
            else
            {
                //FinishedEvents.NotifyFriendsDataFinished(false, null);
            }

        }
コード例 #12
0
        public void fb_PostCompleted(object sender, FacebookApiEventArgs e)
        {
            picStatus.Visible = false;

            btnUpload.Tag = 0;
            btnUpload.Text = GlobalSetting.LangPack.Items["frmFacebook.btnUpload._Upload"];

            if (e.Cancelled)
            {
                lblStatus.Text = GlobalSetting.LangPack.Items["frmFacebook._StatusCancel"];
            }
            else if (e.Error == null)
            {
                // upload successful.
                lblStatus.Text = GlobalSetting.LangPack.Items["frmFacebook._StatusSuccessful"];
                btnUpload.Tag = e.GetResultData().ToString().Substring(7, 15);//Get Post ID
                btnUpload.Text = GlobalSetting.LangPack.Items["frmFacebook.btnUpload._ViewImage"];
            }
            else
            {
                // upload failed
                lblStatus.Text = e.Error.Message;
            }
        }
コード例 #13
0
 protected virtual void OnDeleteCompleted(FacebookApiEventArgs args)
 {
     if (DeleteCompleted != null)
         DeleteCompleted(this, args);
 }
コード例 #14
0
 protected virtual void OnPostCompleted(FacebookApiEventArgs args)
 {
     if (PostCompleted != null)
         PostCompleted(this, args);
 }
コード例 #15
0
        /// <summary>
        /// will be called when the data is ready from facebook
        /// <summary>
        void _fbClient_GetCompleted(object sender, FacebookApiEventArgs e)
        {
            IDictionary<string, object> result = (IDictionary<string, object>)e.GetResultData();

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                (e.UserState as Action<IDictionary<string, object>>)(result);
            });
        }
コード例 #16
0
 void client_PostCompleted(object sender, FacebookApiEventArgs e)
 {
     if (e.Error == null)
     {
         //Success
         ExecuteBatch();
     }
     else
     {
         //Error
         if (ShareLink_Complete != null)
             ShareLink_Complete.Invoke(this, new ShareLinkEventArgs(false, e.Error));
     }
 }
コード例 #17
0
 private void client_GetCompleted(object sender, FacebookApiEventArgs e)
 {
     dynamic items = dataGridFriendsEvents.ItemsSource ?? new List<GamingEvent>();
     dynamic result = e.GetResultData();
     Event eEvent = (Event)e.UserState;
     GamingEvent gEvent  = new GamingEvent();
     gEvent.Event = eEvent;
     if(result.description != null)
         gEvent.Description = result.description.ToString();
     if(result.end_time != null)
         gEvent.EndTime = DateTime.Parse(result.end_time.ToString());
     if (result.start_time != null)
         gEvent.StartTime = DateTime.Parse(result.start_time.ToString());
     if (result.name != null)
         gEvent.Name = result.name.ToString();
     if (result.location != null)
         gEvent.Location = result.location.ToString();
     items.Add(gEvent);
     dataGridFriendsEvents.ItemsSource = items;
 }
コード例 #18
0
        private void Facebook_PostComplete(object sender, FacebookApiEventArgs args)
        {
            //Checking for errors
            if (args.Error != null)
            {
                //Authorization error
                if (args.Error is FacebookOAuthException)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show("Authorization Error"));
                    //Remove the actual token since it doesn't work anymore.
                    FacebookClientHelpers.SaveToken(null);
                    client.AccessToken = null;
                }
                else
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message));
                }
            }
            else
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("Message posted successfully");
                    NavigationService.GoBack();
                });
            }

            Dispatcher.BeginInvoke(() => IsCalculating = false);
        }
コード例 #19
0
        private void facebookClient_PostCompleted(object sender, FacebookApiEventArgs e)
        {
            Logger.Info("Called");

            if (e.Cancelled)
            {
                Logger.Info("Cancelled");
                PublishWorkerResult = PublishWorkerResults.Cancelled;
            }
            else if (e.Error != null)
            {
                Logger.Error("Error uploading: " + e.Error);
                ErrorMessage = e.Error.ToString();
                PublishWorkerResult = PublishWorkerResults.UnableToShare;
            }
            else
            {
                /* format:
                {
                    "id": "xxxxx19208xxxxx"
                }
                 */
                string jsonResponse = e.GetResultData().ToString();

                Logger.Info("Response from Facebook: " + jsonResponse);

                var structuredResponse = (FacebookJSONResponse)facebookClient.DeserializeJson(jsonResponse, typeof(FacebookJSONResponse));

                /* This works, but it requires extra assemblies
                var ser = new DataContractJsonSerializer(typeof(FacebookJSONResponse));
                var stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonResponse));
                var structuredResponse = (FacebookJSONResponse)ser.ReadObject(stream);
                stream.Close();
                 */

                Logger.Info("FacebookActivityId = " + structuredResponse.id);

                HighlightObject.FacebookActivityId = structuredResponse.id;

                PublishWorkerResult = PublishWorkerResults.Success;
            }

            uploadCompleted = true;
        }
コード例 #20
0
        void client_GetCompleted(object sender, FacebookApiEventArgs e)
        {
            UserInfoStruct UserInfo = new UserInfoStruct();

            if (e.Error == null)
            {
                //Success
                JsonArray ResultsArray = (JsonArray)e.GetResultData();
                UserInfo = ParseResults(ResultsArray);

                //Event
                if (GetUserInfo_Complete != null)
                    GetUserInfo_Complete.Invoke(this, new GetUserInfoEventArgs(UserInfo, true, null));
            }
            else
            {
                //Error, Event
                if (GetUserInfo_Complete != null)
                    GetUserInfo_Complete.Invoke(this, new GetUserInfoEventArgs(UserInfo, false, e.Error));
            }
        }
コード例 #21
0
        private FacebookApiEventArgs GetApiEventArgs(AsyncCompletedEventArgs e, string json, out HttpMethod httpMethod)
        {
            var state = (WebClientStateContainer)e.UserState;
            httpMethod = state.Method;

            var cancelled = e.Cancelled;
            var userState = state.UserState;
            var error = e.Error;

            // Check for Graph Exception
            var webException = error as WebExceptionWrapper;
            if (webException != null)
            {
                error = ExceptionFactory.GetGraphException(webException);
            }

            if (error == null)
            {
                error = ExceptionFactory.CheckForRestException(DomainMaps, state.RequestUri, json) ?? error;
            }

            var args = new FacebookApiEventArgs(error, cancelled, userState, json);
            return args;
        }
コード例 #22
0
        void client_GetCompleted(object sender, FacebookApiEventArgs e)
        {
            if (e.Error == null)
            {
                resultsRecieved++;
                UpdateProgress();
                //Success
                JsonArray results = e.GetResultData<JsonArray>();

                ParseResults(results);

                //If we need another page the run it, continue
                if (resultsRecieved >= pageTotal)
                {
            #if DEBUG
                    RunMetrics();
            #endif
                    TimeSpan duration = DateTime.Now - StartTime;
                    core.Analytics.SendMetric(core.Analytics.Metric.MapTime, duration.Seconds);
                    core.Analytics.SendMetric(core.Analytics.Metric.MaxReturnFQL, MaxFqlReturnSize);
                    core.Analytics.SendMetric(core.Analytics.Metric.Edges, EdgeNum);
                    ApiComplete(FriendsMap);
                }
            }
            else
            {
                //Error
                Debug.WriteLine(e.Error.Message);
                throw e.Error;
            }
        }
コード例 #23
0
        /// <summary>
        /// called when the pictured is posted
        /// <summary>
        void _fbClient_PostCompleted(object sender, FacebookApiEventArgs e)
        {
            // when the picture is not posted successfully it returns here
            if (e.Cancelled || e.Error != null)
            {
                return;
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                (e.UserState as Action)();
            });
        }
コード例 #24
0
 private void OnCompleted(HttpMethod httpMethod, FacebookApiEventArgs args)
 {
     switch (httpMethod)
     {
         case HttpMethod.Get:
             OnGetCompleted(args);
             break;
         case HttpMethod.Post:
             OnPostCompleted(args);
             break;
         case HttpMethod.Delete:
             OnDeleteCompleted(args);
             break;
         default:
             throw new ArgumentOutOfRangeException("httpMethod");
     }
 }
コード例 #25
0
        protected virtual void ApiAsync(HttpMethod httpMethod, string path, object parameters, Type resultType, object userState)
        {
            Stream input;
            bool containsEtag;
            IList<int> batchEtags = null;
            var httpHelper = PrepareRequest(httpMethod, path, parameters, resultType, out input, out containsEtag, out batchEtags);
            _httpWebRequest = httpHelper.HttpWebRequest;

#if FLUENTHTTP_CORE_TPL
            if (HttpWebRequestWrapperCreated != null)
                HttpWebRequestWrapperCreated(this, new HttpWebRequestCreatedEventArgs(userState, httpHelper.HttpWebRequest));
#endif

            var uploadProgressChanged = UploadProgressChanged;
            bool notifyUploadProgressChanged = uploadProgressChanged != null && httpHelper.HttpWebRequest.Method == "POST";

            httpHelper.OpenReadCompleted +=
                (o, e) =>
                {
                    FacebookApiEventArgs args;
                    if (e.Cancelled)
                    {
                        args = new FacebookApiEventArgs(e.Error, true, userState, null);
                    }
                    else if (e.Error == null)
                    {
                        string responseString = null;

                        try
                        {
                            using (var stream = e.Result)
                            {
#if NETFX_CORE
                                bool compressed = false;
                                
                                var contentEncoding = httpHelper.HttpWebResponse.Headers.AllKeys.Contains("Content-Encoding") ? httpHelper.HttpWebResponse.Headers["Content-Encoding"] : null;
                                if (contentEncoding != null)
                                {
                                    if (contentEncoding.IndexOf("gzip") != -1)
                                    {
                                        using (var uncompressedStream = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Decompress))
                                        {
                                            using (var reader = new StreamReader(uncompressedStream))
                                            {
                                                responseString = reader.ReadToEnd();
                                            }
                                        }

                                        compressed = true;
                                    }
                                    else if (contentEncoding.IndexOf("deflate") != -1)
                                    {
                                        using (var uncompressedStream = new System.IO.Compression.DeflateStream(stream, System.IO.Compression.CompressionMode.Decompress))
                                        {
                                            using (var reader = new StreamReader(uncompressedStream))
                                            {
                                                responseString = reader.ReadToEnd();
                                            }
                                        }

                                        compressed = true;
                                    }
                                }

                                if (!compressed)
                                {
                                    using (var reader = new StreamReader(stream))
                                    {
                                        responseString = reader.ReadToEnd();
                                    }
                                }
#else
                                var response = httpHelper.HttpWebResponse;
                                if (response != null && response.StatusCode == HttpStatusCode.NotModified)
                                {
                                    var jsonObject = new JsonObject();
                                    var headers = new JsonObject();

                                    foreach (var headerName in response.Headers.AllKeys)
                                        headers[headerName] = response.Headers[headerName];

                                    jsonObject["headers"] = headers;
                                    args = new FacebookApiEventArgs(null, false, userState, jsonObject);
                                    OnCompleted(httpMethod, args);
                                    return;
                                }

                                using (var reader = new StreamReader(stream))
                                {
                                    responseString = reader.ReadToEnd();
                                }
#endif
                            }

                            try
                            {
                                object result = ProcessResponse(httpHelper, responseString, resultType, containsEtag, batchEtags);
                                args = new FacebookApiEventArgs(null, false, userState, result);
                            }
                            catch (Exception ex)
                            {
                                args = new FacebookApiEventArgs(ex, false, userState, null);
                            }
                        }
                        catch (Exception ex)
                        {
                            args = httpHelper.HttpWebRequest.IsCancelled ? new FacebookApiEventArgs(ex, true, userState, null) : new FacebookApiEventArgs(ex, false, userState, null);
                        }
                    }
                    else
                    {
                        var webEx = e.Error as WebExceptionWrapper;
                        if (webEx == null)
                        {
                            args = new FacebookApiEventArgs(e.Error, httpHelper.HttpWebRequest.IsCancelled, userState, null);
                        }
                        else
                        {
                            if (webEx.GetResponse() == null)
                            {
                                args = new FacebookApiEventArgs(webEx, false, userState, null);
                            }
                            else
                            {
                                var response = httpHelper.HttpWebResponse;
                                if (response.StatusCode == HttpStatusCode.NotModified)
                                {
                                    var jsonObject = new JsonObject();
                                    var headers = new JsonObject();

                                    foreach (var headerName in response.Headers.AllKeys)
                                        headers[headerName] = response.Headers[headerName];

                                    jsonObject["headers"] = headers;
                                    args = new FacebookApiEventArgs(null, false, userState, jsonObject);
                                }
                                else
                                {
                                    httpHelper.OpenReadAsync();
                                    return;
                                }
                            }
                        }
                    }

                    OnCompleted(httpMethod, args);
                };

            if (input == null)
            {
                httpHelper.OpenReadAsync();
            }
            else
            {
                // we have a request body so write
                httpHelper.OpenWriteCompleted +=
                    (o, e) =>
                    {
                        FacebookApiEventArgs args;
                        if (e.Cancelled)
                        {
                            input.Dispose();
                            args = new FacebookApiEventArgs(e.Error, true, userState, null);
                        }
                        else if (e.Error == null)
                        {
                            try
                            {
                                using (var stream = e.Result)
                                {
                                    // write input to requestStream
                                    var buffer = new byte[BufferSize];
                                    int nread;

                                    if (notifyUploadProgressChanged)
                                    {
                                        long totalBytesToSend = input.Length;
                                        long bytesSent = 0;

                                        while ((nread = input.Read(buffer, 0, buffer.Length)) != 0)
                                        {
                                            stream.Write(buffer, 0, nread);
                                            stream.Flush();

                                            // notify upload progress changed
                                            bytesSent += nread;
                                            OnUploadProgressChanged(new FacebookUploadProgressChangedEventArgs(0, 0, bytesSent, totalBytesToSend, ((int)(bytesSent * 100 / totalBytesToSend)), userState));
                                        }
                                    }
                                    else
                                    {
                                        while ((nread = input.Read(buffer, 0, buffer.Length)) != 0)
                                        {
                                            stream.Write(buffer, 0, nread);
                                            stream.Flush();
                                        }
                                    }
                                }

                                httpHelper.OpenReadAsync();
                                return;
                            }
                            catch (Exception ex)
                            {
                                args = new FacebookApiEventArgs(ex, httpHelper.HttpWebRequest.IsCancelled, userState, null);
                            }
                            finally
                            {
                                input.Dispose();
                            }
                        }
                        else
                        {
                            input.Dispose();
                            var webExceptionWrapper = e.Error as WebExceptionWrapper;
                            if (webExceptionWrapper != null)
                            {
                                var ex = webExceptionWrapper;
                                if (ex.GetResponse() != null)
                                {
                                    httpHelper.OpenReadAsync();
                                    return;
                                }
                            }

                            args = new FacebookApiEventArgs(e.Error, false, userState, null);
                        }

                        OnCompleted(httpMethod, args);
                    };

                httpHelper.OpenWriteAsync();
            }
        }
コード例 #26
0
        void fbApp_PostCompleted(object sender, FacebookApiEventArgs e)
        {
            bool fail = e.Cancelled || e.Error != null;
            //if (fail) SettingsProvider.Delete(FACEBOOK_SETTING_KEY);  // In the case of OAuth key is invalidated or access revoked!

            UploadFinished(!fail, SocialNetwork.FACEBOOK);

            Dispatcher.BeginInvoke(() =>
            {
                loading.IsIndeterminate = false;
                if (fail)
                {
                    MessageBox.Show("Photo upload failed. Please try again later.", "Error", MessageBoxButton.OK);
                }
                else
                {
                    MessageBox.Show("You have succesfully posted photo to your Facebook profile.", "Tip", MessageBoxButton.OK);
                }

            });
        }
コード例 #27
0
 void client_GetCompleted(object sender, FacebookApiEventArgs e)
 {
 }
コード例 #28
0
        private void onMessageSentCompletion(object sender, FacebookApiEventArgs e)
        {
            try
            {
                var a = App.Current as App;
                if (e.Error == null)
                {
                    var result = (IDictionary<string, object>)e.GetResultData();
                    var model = new List<Place>();
                    foreach (var place in (JsonArray)result["data"])
                        model.Add(new Place()
                        {
                            Id = (string)(((JsonObject)place)["id"]),
                            Name = (string)(((JsonObject)place)["name"])
                        });

                    FacebookClient fb = new FacebookClient(_facebookToken);

                    var param = new Dictionary<string, object> { { "message", "I am in danger at :" },
                                                            { "place", model.FirstOrDefault().Id },
                                                            {"acess_token",_facebookToken},
                                                            {"privacy", new Dictionary<string, object>{{"value", "ALL_FRIENDS"}}}};
                    // Posting status on facebook
                    fb.PostTaskAsync("me/feed", param, new System.Threading.CancellationToken());

                    // Calling  method to send sms
                    SMSUtils smsmUtil = new SMSUtils();
                    smsmUtil.SendText(GetSavedNumbers(), "I am in danger at :" + model.FirstOrDefault().Name);

                }
                else
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("Error ocurred in sending messages " + e.Error.Message);
                    });
                }
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("Internet connection is not working : " + ex.Message);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error while posting status in facebook : " + ex.Message);
            }
        }
コード例 #29
0
        void fbApp_PostCompleted(object sender, FacebookApiEventArgs e)
        {
            Dispatcher.BeginInvoke(() =>
            {
                shellProgress.IsVisible = false;
                MessageBox.Show("You have succesfully posted link to your profile.");

                browserAuth.Navigated -= FacebookLoginBrowser_Navigated;
            });
        }
コード例 #30
0
        void client_GetCompleted(object sender, FacebookApiEventArgs e)
        {
            List<long> FriendsList = new List<long>();
            Dictionary<long, FriendsInfoStruct> FriendsInfo = new Dictionary<long,FriendsInfoStruct>();

            if (e.Error == null)
            {
                //Success
                JsonArray ResultsArray = (JsonArray)e.GetResultData();
                FriendsInfo = ParseResults(ResultsArray);

                foreach (KeyValuePair<long, FriendsInfoStruct> kvp in FriendsInfo)
                {
                    FriendsList.Add(kvp.Key);
                }

                //Event
                if (GetFriendsInfo_Complete != null)
                    GetFriendsInfo_Complete.Invoke(this, new GetFriendsInfoEventArgs(FriendsList, FriendsInfo, true, null));
            }
            else
            {
                //Error, Event
                if (GetFriendsInfo_Complete != null)
                    GetFriendsInfo_Complete.Invoke(this, new GetFriendsInfoEventArgs(FriendsList, FriendsInfo, false, e.Error));
            }
        }
コード例 #31
0
 private static void HandleGetCompleted(object sender, FacebookApiEventArgs e)
 {
     var callback = e.UserState as FacebookDelegate;
     if (callback != null)
     {
         var result = new FBResult();
         if (e.Cancelled)
             result.Error = "Cancelled";
         else if (e.Error != null)
             result.Error = e.Error.Message;
         else
         {
             var obj = e.GetResultData();
             result.Text = obj.ToString();
             result.Json = obj as JsonObject;
         }
         Dispatcher.InvokeOnAppThread(() => { callback(result); });
     }
 }
コード例 #32
0
        //[Obsolete("Use ApiTaskAsync instead.")]
        //[EditorBrowsable(EditorBrowsableState.Never)]
#endif
        protected virtual void ApiAsync(HttpMethod httpMethod, string path, object parameters, Type resultType, object userState)
        {
            Stream      input;
            bool        containsEtag;
            IList <int> batchEtags = null;
            var         httpHelper = PrepareRequest(httpMethod, path, parameters, resultType, out input, out containsEtag, out batchEtags);

            _httpWebRequest = httpHelper.HttpWebRequest;

#if FLUENTHTTP_CORE_TPL
            if (HttpWebRequestWrapperCreated != null)
            {
                HttpWebRequestWrapperCreated(this, new HttpWebRequestCreatedEventArgs(userState, httpHelper.HttpWebRequest));
            }
#endif

            var  uploadProgressChanged       = UploadProgressChanged;
            bool notifyUploadProgressChanged = uploadProgressChanged != null && httpHelper.HttpWebRequest.Method == "POST";

            httpHelper.OpenReadCompleted +=
                (o, e) =>
            {
                FacebookApiEventArgs args;
                if (e.Cancelled)
                {
                    args = new FacebookApiEventArgs(e.Error, true, userState, null);
                }
                else if (e.Error == null)
                {
                    string responseString = null;

                    try
                    {
                        using (var stream = e.Result)
                        {
#if NETFX_CORE
                            bool compressed = false;

                            var contentEncoding = httpHelper.HttpWebResponse.Headers.AllKeys.Contains("Content-Encoding") ? httpHelper.HttpWebResponse.Headers["Content-Encoding"] : null;
                            if (contentEncoding != null)
                            {
                                if (contentEncoding.IndexOf("gzip") != -1)
                                {
                                    using (var uncompressedStream = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Decompress))
                                    {
                                        using (var reader = new StreamReader(uncompressedStream))
                                        {
                                            responseString = reader.ReadToEnd();
                                        }
                                    }

                                    compressed = true;
                                }
                                else if (contentEncoding.IndexOf("deflate") != -1)
                                {
                                    using (var uncompressedStream = new System.IO.Compression.DeflateStream(stream, System.IO.Compression.CompressionMode.Decompress))
                                    {
                                        using (var reader = new StreamReader(uncompressedStream))
                                        {
                                            responseString = reader.ReadToEnd();
                                        }
                                    }

                                    compressed = true;
                                }
                            }

                            if (!compressed)
                            {
                                using (var reader = new StreamReader(stream))
                                {
                                    responseString = reader.ReadToEnd();
                                }
                            }
#else
                            var response = httpHelper.HttpWebResponse;
                            if (response != null && response.StatusCode == HttpStatusCode.NotModified)
                            {
                                var jsonObject = new JsonObject();
                                var headers    = new JsonObject();

                                foreach (var headerName in response.Headers.AllKeys)
                                {
                                    headers[headerName] = response.Headers[headerName];
                                }

                                jsonObject["headers"] = headers;
                                args = new FacebookApiEventArgs(null, false, userState, jsonObject);
                                OnCompleted(httpMethod, args);
                                return;
                            }

                            using (var reader = new StreamReader(stream))
                            {
                                responseString = reader.ReadToEnd();
                            }
#endif
                        }

                        try
                        {
                            object result = ProcessResponse(httpHelper, responseString, resultType, containsEtag, batchEtags);
                            args = new FacebookApiEventArgs(null, false, userState, result);
                        }
                        catch (Exception ex)
                        {
                            args = new FacebookApiEventArgs(ex, false, userState, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        args = httpHelper.HttpWebRequest.IsCancelled ? new FacebookApiEventArgs(ex, true, userState, null) : new FacebookApiEventArgs(ex, false, userState, null);
                    }
                }
                else
                {
                    var webEx = e.Error as WebExceptionWrapper;
                    if (webEx == null)
                    {
                        args = new FacebookApiEventArgs(e.Error, httpHelper.HttpWebRequest.IsCancelled, userState, null);
                    }
                    else
                    {
                        if (webEx.GetResponse() == null)
                        {
                            args = new FacebookApiEventArgs(webEx, false, userState, null);
                        }
                        else
                        {
                            var response = httpHelper.HttpWebResponse;
                            if (response.StatusCode == HttpStatusCode.NotModified)
                            {
                                var jsonObject = new JsonObject();
                                var headers    = new JsonObject();

                                foreach (var headerName in response.Headers.AllKeys)
                                {
                                    headers[headerName] = response.Headers[headerName];
                                }

                                jsonObject["headers"] = headers;
                                args = new FacebookApiEventArgs(null, false, userState, jsonObject);
                            }
                            else
                            {
                                httpHelper.OpenReadAsync();
                                return;
                            }
                        }
                    }
                }

                OnCompleted(httpMethod, args);
            };

            if (input == null)
            {
                httpHelper.OpenReadAsync();
            }
            else
            {
                // we have a request body so write
                httpHelper.OpenWriteCompleted +=
                    (o, e) =>
                {
                    FacebookApiEventArgs args;
                    if (e.Cancelled)
                    {
                        input.Dispose();
                        args = new FacebookApiEventArgs(e.Error, true, userState, null);
                    }
                    else if (e.Error == null)
                    {
                        try
                        {
                            using (var stream = e.Result)
                            {
                                // write input to requestStream
                                var buffer = new byte[BufferSize];
                                int nread;

                                if (notifyUploadProgressChanged)
                                {
                                    long totalBytesToSend = input.Length;
                                    long bytesSent        = 0;

                                    while ((nread = input.Read(buffer, 0, buffer.Length)) != 0)
                                    {
                                        stream.Write(buffer, 0, nread);
                                        stream.Flush();

                                        // notify upload progress changed
                                        bytesSent += nread;
                                        OnUploadProgressChanged(new FacebookUploadProgressChangedEventArgs(0, 0, bytesSent, totalBytesToSend, ((int)(bytesSent * 100 / totalBytesToSend)), userState));
                                    }
                                }
                                else
                                {
                                    while ((nread = input.Read(buffer, 0, buffer.Length)) != 0)
                                    {
                                        stream.Write(buffer, 0, nread);
                                        stream.Flush();
                                    }
                                }
                            }

                            httpHelper.OpenReadAsync();
                            return;
                        }
                        catch (Exception ex)
                        {
                            args = new FacebookApiEventArgs(ex, httpHelper.HttpWebRequest.IsCancelled, userState, null);
                        }
                        finally
                        {
                            input.Dispose();
                        }
                    }
                    else
                    {
                        input.Dispose();
                        var webExceptionWrapper = e.Error as WebExceptionWrapper;
                        if (webExceptionWrapper != null)
                        {
                            var ex = webExceptionWrapper;
                            if (ex.GetResponse() != null)
                            {
                                httpHelper.OpenReadAsync();
                                return;
                            }
                        }

                        args = new FacebookApiEventArgs(e.Error, false, userState, null);
                    }

                    OnCompleted(httpMethod, args);
                };

                httpHelper.OpenWriteAsync();
            }
        }
コード例 #33
0
        void client_GetCompleted(object sender, FacebookApiEventArgs e)
        {
            if (e.Error == null)
            {
                //Success
                resultsList.Add(e.GetResultData<JsonArray>());

                UpdateProgress();

                if (Parameters.Count > 0)
                    ExecuteBatch();
                else
                {
                    List<FriendsEdgeStruct> EdgeList = ParseResults(resultsList, friendsList);
                    RemoveDuplicates(EdgeList);
                    //Done
                }
            }
            else
            {
                //Error
                Debug.WriteLine(e.Error.Message);
                throw e.Error;
            }
        }
コード例 #34
0
 private void OnFacebookPostCompleted(object sender, FacebookApiEventArgs e)
 {
     MessageBox.Show("成功張貼訊息!", "Facebook", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
 }
コード例 #35
0
ファイル: Form1.cs プロジェクト: admirhodzic/ClickShare
        private void fb_PostCompleted(object sender, FacebookApiEventArgs e)
        {
            if (e.Cancelled)    {
                var cancellationError = e.Error;
                MessageBox.Show("Upload cancelled");
            }
            else if (e.Error == null)
            {
                // upload successful.

                BeginInvoke(new MethodInvoker(() => { MessageBox.Show("Upload successful!"); this.Close(); }));
            }
            else
            {        // upload failed
                MessageBox.Show(e.Error.Message);
            }
        }
コード例 #36
0
ファイル: User.cs プロジェクト: PatriceS/Medienprogrammierung
        private void fb_PostCompleted(object sender, FacebookApiEventArgs e)
        {
            if (e.Cancelled)
            {
                var cancellationError = e.Error;
                MessageBox.Show("Upload unterbrochen");
            }
            else if (e.Error == null)
            {

                // upload successful.
                MessageBox.Show(e.GetResultData().ToString());
            }
            else
            {
                // upload failed
                MessageBox.Show(e.Error.Message);
            }
        }