Exemplo n.º 1
0
        /// <summary>
        /// Opens Microsoft Login page using live sdk
        /// </summary>
        private void MicrosoftLogin()
        {
            try
            {
                var auth = new LiveAuthClient(Entity.Models.Constant.LiveSdkClientIdWP);
                this.Dispatcher.BeginInvoke(async () =>
                {
                    LiveLoginResult result = await auth.InitializeAsync(new string[] { "wl.basic", "wl.signin" });
                    if (result.Status != LiveConnectSessionStatus.Connected)
                    {
                        try
                        {
                            result = await auth.LoginAsync(new string[] { "wl.basic", "wl.signin" });
                        }
                        catch (Exception)
                        {
                            App.ViewModel.CommentViewModel.IsDataLoading = false;
                            (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                            (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                            txtComment.IsEnabled = true;
                        }
                    }
                    if (result.Status == LiveConnectSessionStatus.Connected)
                    {
                        LiveConnectClient liveClient = new LiveConnectClient(result.Session);
                        var userDetails = await liveClient.GetAsync("me");
                        var userName = userDetails.Result["name"];
                        //auth.Logout();
                        CommentData commentData = new CommentData();
                        commentData.Author = userName.ToString();
                        commentData.CityName = this.city;
                        commentData.ReportName = this.dataSetName;
                        commentData.Id = this.compositeKey;
                        commentData.CommentPublishAt = DateTime.Now.ToUniversalTime();
                        commentData.CommentTitle = "";
                        commentData.CommentMessage = this.txtComment.Text.Trim();
                        App.ViewModel.CommentViewModel.AddComment(commentData);

                        App.ViewModel.CommentViewModel.CommentList.Add(commentData);
                        this.tbkNoResult.Visibility = Visibility.Collapsed;
                        IncreaseCommentsCount();
                        txtComment.Text = "";
                    }
                    App.ViewModel.CommentViewModel.IsDataLoading = false;
                    (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                    (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                    txtComment.IsEnabled = true;
                });
            }
            catch (LiveAuthException)
            {
                App.ViewModel.CommentViewModel.IsDataLoading = false;
                (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                txtComment.IsEnabled = true;
            }
        }
Exemplo n.º 2
0
        private void SocrataLogin(string username, string password)
        {
            try
            {
                socrataLoginCredentials = new NetworkCredential(username, password);
                string httpBase = Constant.SocrataLoginHttpBase;
                string appToken = Constant.SocrataLoginAppToken;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(httpBase + Constant.SocrataUserDetailUrl);
                //request.PreAuthenticate = true;
                request.Credentials = socrataLoginCredentials;
                request.Headers["X-App-Token"] = appToken;
                request.Headers["Authorization"] = getAuthorization();
                                
                string temp = null;
                int count = 0;
                byte[] buffer;
                StringBuilder sb = new StringBuilder();
                request.BeginGetResponse(delegate(IAsyncResult responseData)
                {
                    try
                    {
                        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(responseData);
                        using (var stream = response.GetResponseStream())
                        {
                            buffer = new byte[stream.Length];
                            // Read to the end of the response
                            do
                            {
                                count = stream.Read(buffer, 0, buffer.Length);
                                if (count != 0)
                                {
                                    temp = Encoding.UTF8.GetString(buffer, 0, count);
                                    sb.Append(temp);
                                }
                            } while (count > 0);
                        }
                        socrataUserDetails = Newtonsoft.Json.JsonConvert.DeserializeObject<SocrataUserDetail>(sb.ToString());

                        if (socrataUserDetails != null)
                        {
                            this.Dispatcher.BeginInvoke(() =>
                            {
                                CommentData commentData = new CommentData();
                                commentData.Author = socrataUserDetails.displayName;
                                commentData.CityName = this.city;
                                commentData.ReportName = this.dataSetName;
                                commentData.Id = this.compositeKey;
                                commentData.CommentPublishAt = DateTime.Now.ToUniversalTime();
                                commentData.CommentTitle = "";
                                commentData.CommentMessage = this.txtComment.Text.Trim();

                                App.ViewModel.CommentViewModel.AddComment(commentData);

                                App.ViewModel.CommentViewModel.CommentList.Add(commentData);
                                this.tbkNoResult.Visibility = Visibility.Collapsed;
                                IncreaseCommentsCount();
                                txtComment.Text = "";

                                this.popUpSocrataLogin.IsOpen = false;
                                this.ApplicationBar.IsVisible = true;
                                App.ViewModel.CommentViewModel.IsDataLoading = false;
                                (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                                (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                                txtComment.IsEnabled = true;
                                IsSocrataLoginRemember = true;
                                socrataUserName = username;
                                socrataPassword = password;
                            });
                        }
                        else
                        {
                            MessageBox.Show(AppResources.SocrataLoginErrorMessageText, AppResources.LoginErrorMessageTitle, MessageBoxButton.OK);
                            App.ViewModel.CommentViewModel.IsDataLoading = false;
                            (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                            (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                            txtComment.IsEnabled = true;
                        }
                    }
                    catch (Exception)
                    {
                        this.Dispatcher.BeginInvoke(() =>
                            {
                                MessageBox.Show(AppResources.SocrataLoginErrorMessageText, AppResources.LoginErrorMessageTitle, MessageBoxButton.OK);
                                App.ViewModel.CommentViewModel.IsDataLoading = false;
                                (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                                (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                                txtComment.IsEnabled = true;
                            });
                    }
                }, null);

            }
            catch (Exception)
            {
                MessageBox.Show(AppResources.SocrataLoginErrorMessageText, AppResources.LoginErrorMessageTitle, MessageBoxButton.OK);
                App.ViewModel.CommentViewModel.IsDataLoading = false;
                (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                txtComment.IsEnabled = true;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds comment.
        /// </summary>
        async public void AddComment(CommentData requestData)
        {
            try
            {
                this.IsDataLoading = true;
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    var results = JSON_Helper.Serialize<CommentData>(requestData);
                    HttpContent content = new StringContent(results);

                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    var response = await client.PostAsync(string.Format(Constant.AzureServiceURL, Constant.CommentsAzureServiceKey), content);
                    this.IsDataLoading = false;
                }
                else
                {
                    this.MessageDialog = "Internet connection required. Please check your internet connection and try again.";
                    this.IsDataLoading = false;
                }
            }
            catch (Exception)
            {
                this.MessageDialog = "There is some problem on connecting to server. Please check your internet connection and try again.";
                this.IsDataLoading = false;
            }
        }