예제 #1
0
        private void client_UploadPictureCompleted(object sender, RequestCompletedEventArgs e)
        {
            // unregister previous event handler
            App.MetrocamService.UploadPictureCompleted -= client_UploadPictureCompleted;

            // extract response
            PictureURL result = e.Data as PictureURL;

            // create new picture
            MobileClientLibrary.Models.Picture data = new MobileClientLibrary.Models.Picture();

            Dispatcher.BeginInvoke(() =>
            {
                data.Caption = this.captionBox.Text;

                if (Settings.locationService.Value)
                {
                    data.Latitude  = Convert.ToDecimal(MainPage.lat);
                    data.Longitude = Convert.ToDecimal(MainPage.lng);
                }
                else
                {
                    data.Latitude  = Convert.ToDecimal(0.00);
                    data.Longitude = Convert.ToDecimal(0.00);
                }

                data.LargeURL  = result.LargeURL;
                data.MediumURL = result.MediumURL;
                data.SmallURL  = result.SmallURL;

                // upload the picture object
                App.MetrocamService.CreatePictureCompleted += new RequestCompletedEventHandler(client_CreatePictureCompleted);
                App.MetrocamService.CreatePicture(data);
            });
        }
        private void client_UploadPictureCompleted(object sender, RequestCompletedEventArgs e)
        {
            // unregister previous event handler
            App.MetrocamService.UploadPictureCompleted -= client_UploadPictureCompleted;

            // extract response
            PictureURL result = e.Data as PictureURL;

            // create new picture
            MobileClientLibrary.Models.Picture data = new MobileClientLibrary.Models.Picture();

            Dispatcher.BeginInvoke(() =>
            {
                data.Caption = this.captionBox.Text;

                if (Settings.locationService.Value)
                {
                    data.Latitude = Convert.ToDecimal(MainPage.lat);
                    data.Longitude = Convert.ToDecimal(MainPage.lng);
                }
                else
                {
                    data.Latitude = Convert.ToDecimal(0.00);
                    data.Longitude = Convert.ToDecimal(0.00);
                }

                data.LargeURL = result.LargeURL;
                data.MediumURL = result.MediumURL;
                data.SmallURL = result.SmallURL;

                // upload the picture object
                App.MetrocamService.CreatePictureCompleted += new RequestCompletedEventHandler(client_CreatePictureCompleted);
                App.MetrocamService.CreatePicture(data);
            });
        }
예제 #3
0
        private void client_CreatePictureCompleted(object sender, RequestCompletedEventArgs e)
        {
            if (GlobalLoading.Instance.IsLoading)
            {
                GlobalLoading.Instance.IsLoading = false;
            }

            isUploading = false;

            MobileClientLibrary.Models.Picture data = e.Data as MobileClientLibrary.Models.Picture;

            // unregister previous event handler
            App.MetrocamService.CreatePictureCompleted -= client_CreatePictureCompleted;

            if (twitterSwitch.IsChecked == true)
            {
                TwitterService t = new TwitterService(TwitterSettings.ConsumerKey, TwitterSettings.ConsumerKeySecret, MainPage.TwitterToken, MainPage.TwitterSecret);
                t.SendTweet(data.Caption + " " + "http://metrocam.cloudapp.net/p/" + data.ID, (status, response) =>
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        // YAY
                    }
                });

                //    var _credentials = new OAuthCredentials
                //    {
                //        Type = OAuthType.AccessToken,
                //        SignatureMethod = OAuthSignatureMethod.HmacSha1,
                //        ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                //        ConsumerKey = TwitterSettings.ConsumerKey,
                //        ConsumerSecret = TwitterSettings.ConsumerKeySecret,
                //        Token = MainPage.TwitterToken,
                //        TokenSecret = MainPage.TwitterSecret,
                //        Version = TwitterSettings.OAuthVersion,
                //    };

                //    var client = new RestClient
                //    {
                //        Authority = "https://upload.twitter.com",
                //        HasElevatedPermissions = true
                //    };

                //    var requestPath = "/1/statuses/update_with_media.xml";
                //    var request = new RestRequest
                //    {
                //        Credentials = _credentials,
                //        Path = requestPath,
                //        Method = WebMethod.Post
                //    };

                //    request.AddParameter("status", data.Caption);
                //    request.AddFile("media[]", "TweetPhoto.jpg", ms, "image/jpeg");
                //    client.BeginRequest(request, new RestCallback(PhotoTweetCompleted));
            }

            Dispatcher.BeginInvoke(() =>
            {
                // This flag is needed for MainPage to clear back stack
                App.isFromUploadPage = true;

                NavigationService.Navigate(new Uri("/MainPage.xaml?from=upload", UriKind.Relative));
            });
        }