protected override void ProcessRecord() { try { if (String.IsNullOrEmpty(AppId)) { AppId = InputHelper.GetUserInput(this, "AppId"); } if (String.IsNullOrEmpty(SecretKey)) { SecretKey = InputHelper.GetUserInput(this, "SecretKey"); } if (String.IsNullOrEmpty(Token)) { Token = InputHelper.GetUserInput(this, "Token"); } Latch latch = new Latch(AppId, SecretKey); WriteObject(latch.Pair(Token), true); } catch (Exception ex) { InvokeCommand.InvokeScript(String.Format("Write-Host Error: \"{0}\"", ex.Message)); } }
public UmbracoLatchResponse Pair(string token, int userId) { var application = GetApplication(); var latch = new Latch(application.ApplicationId, application.Secret); var response = latch.Pair(token); if (response.Error != null) { var errorMessage = GetPairingResponseMessage("error" + response.Error.Code); return(new UmbracoLatchResponse(false, errorMessage)); } if (response.Data == null || !response.Data.ContainsKey("accountId")) { var errorMessage = GetPairingResponseMessage("pairError"); return(new UmbracoLatchResponse(false, errorMessage)); } var pairedAccount = new LatchPairedAccount { UserId = userId, AccountId = response.Data["accountId"] as string }; latchRepo.AddPairedAccount(pairedAccount); var successMessage = GetPairingResponseMessage("pairSuccess"); return(new UmbracoLatchResponse(true, successMessage)); }
private void btnPair_Click(object sender, EventArgs e) { Latch latch = new Latch(tbApplicationID.Text, tbSecret.Text); LatchResponse response = latch.Pair(tbToken.Text); if (response.Data != null) { if (response.Data["accountId"] != null) { tbAccountID.Text = response.Data["accountId"].ToString(); lblLog.Text = "Pairing successful!"; StoreCredentials(); } } else { MessageBox.Show(response.Error.Message + " (" + response.Error.Code + ")"); } }
private void buttonAccept_Click(object sender, EventArgs e) { if (textBoxPairCode.Text == "") { string captionE = "Pair code empty"; string messageE = "You must enter a pair code"; MessageBox.Show(messageE, captionE, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Form wait = new Forms.Wait(); wait.Show(); LatchResponse pair = null; try { pair = latch.Pair(textBoxPairCode.Text); } catch { wait.Close(); string message = "You do not have internet connection"; string caption = "Problem with internet connection"; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (pair.Error != null && pair.Error.Message != "") { wait.Close(); string message = pair.Error.Message; string caption = "Latch connection: " + pair.Error.Code; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { wait.Close(); accountId = pair.Data["accountId"].ToString(); this.Close(); } } }