Beispiel #1
0
        /// <summary>
        /// Get a developer authentication Access Token obtained from Azure Data Market.
        /// Used to identify the third-party application using the Xbox Music RESTful API.
        /// </summary>
        /// <param name="clientId"></param>
        /// <param name="clientSecret"></param>
        /// <returns></returns>
        public async Task <Authenication> GetAccessToken(string clientId, string clientSecret, string refreshToken)
        {
            Authenication authenication = new Authenication();

            const string service   = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13";
            const string scope     = "http://music.xboxlive.com";
            const string grantType = "client_credentials";

            using (HttpClient proxy = new HttpClient())
            {
                var postData = new Dictionary <string, string>();
                postData["client_id"]     = clientId;
                postData["client_secret"] = clientSecret;
                postData["scope"]         = scope;
                postData["grant_type"]    = grantType;
                if (!string.IsNullOrEmpty(refreshToken))
                {
                    postData["accessToken"] = refreshToken;
                }

                HttpContent content = new FormUrlEncodedContent(postData);

                // Authentication Request
                HttpResponseMessage response = await proxy.PostAsync(new Uri(service), content);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    // Parsing content to extract the token
                    authenication = JsonConvert.DeserializeObject <Authenication>(responseContent);
                }
                else
                {
                    // Triggers Failed Event
                    Music error = Music.PopulateObject(responseContent);
                    OnFailed(new ErrorEventArgs(error.Error));
                }
            }

            return(authenication);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetAllWellHeaders();
            }

            //if (!Page.IsPostBack)
            //{

            //Call Stored procedure
            //try
            //{
            //     Return ID Intentity of Inserted Record
            //    Int32? refint = 1;
            //    WellProfileDataContext dc = new WellProfileDataContext();
            //    dc.proc_WellXMeterHistoryInsert(ref refint, 14, 37896, "", "", 8, "", 1011, "", "", "", System.DateTime.Now, "", System.DateTime.Now);
            //    dc.SubmitChanges();
            //}
            //catch
            //{

            //}

            try
            {
                string currentuser = Authenication.GetCurrentUserWindowsLogin();
            }
            catch
            {
            }


            bindGridView();

            //}
            ///
            //MessageLabel.Text = FormView1.CurrentMode.ToString();
            //SqlDataSource1 = " SELECT [MeterID],[Manufacturer], [ModelID], [RTUSN], [SecurityCode], [MeterComIDAddress], [PrimaryMeasDevice], [BTUBase], [CreatedBy], [CreateDate], [LastModifiedBy], [LastModifiedDate], [Metername], [MeterDescription], [MeterField], [MeterType], [Filter], [Rank], [Route], [Connect], [ConnectString], [NRI], [CSLink], [Choke], [MeterStatus], [Area], [Formation], [ResponsibleParty1], [SalesPoint], [Reports], [ActiveChoke], [AccountingID], [PC_Outsideoperatedflag], [UnitAddress], [GroupAddress], [MeterAddress], [MeterID] FROM [Meter]";
            //SqlDataSource1=
        }
        protected void UpdateButton_Click(Object sender, EventArgs e)
        {
            try
            {
                //Use the UpdateItem method to programmatically update
                //the current record in the FormView control.

                String key = FormView1.DataKey.Value.ToString();

                //Calendar cl = new Calendar();
                //cl= (Calendar)FormView1.FindControl("createdate");

                //cl.SelectedDate = Convert.ToDateTime("12/10/2013");

                TextBox txtTextBoxValue = new TextBox();
                txtTextBoxValue = (TextBox)FormView1.FindControl("MeternameTextBox");

                TextBox txtTextBoxValue1 = new TextBox();
                txtTextBoxValue1 = (TextBox)FormView1.FindControl("Meterid");

                //TODO
                //,[CreatedBy]
                //,[CreateDate]
                //,[LastModifiedBy]
                //,[LastModifiedDate]

                if (FormView1.CurrentMode == FormViewMode.Edit)
                {
                    TextBox txtTextBoxCreatedBy = new TextBox();
                    txtTextBoxCreatedBy      = (TextBox)FormView1.FindControl("Createdby");
                    txtTextBoxCreatedBy.Text = Authenication.GetCurrentUserWindowsLogin();
                }

                //Hidden fiels- must be bound to update
                TextBox txtTextBoxSecurity = new TextBox();
                txtTextBoxSecurity = (TextBox)FormView1.FindControl("SecurityCodeTextBox");

                TextBox txtTextBoxSecurityEnc = new TextBox();
                txtTextBoxSecurityEnc = (TextBox)FormView1.FindControl("Security");

                try
                {
                    txtTextBoxSecurityEnc.Text = Encryption.Encrypt(txtTextBoxSecurity.Text, "NoPass123456789");
                }
                catch
                {
                }
                //End Hidden



                //TextBox txtTextBoxValue2 = new TextBox();
                //txtTextBoxValue2 = (TextBox)FormView1.FindControl("ManufacturerTextBox");
                //txtTextBoxValue2.Text = "Eagle";

                //Response.Write(txtTextBoxValue.Text);

                try
                {
                    FormView1.UpdateItem(true);
                    FormView1.ChangeMode(FormViewMode.Edit);
                }
                catch (Exception ex)
                {
                    MessageLabel.Text = "Error Inserting";
                }
            }
            catch (HttpException ex)
            {
                //MessageLabel.Text = "The FormView control must be in edit mode to update a record.";
            }
        }