public static bool?CheckOperationStatus(string operationId) { if (LatchHandler.IsPaired && !string.IsNullOrEmpty(operationId)) { try { LatchResponse latchResponse = LatchHandler.LatchSDK.OperationStatus(Configuration.GetConfig().AccountId, operationId); if (latchResponse.Data != null && latchResponse.Data.ContainsKey("operations")) { Dictionary <string, object> dictionary = (Dictionary <string, object>)latchResponse.Data["operations"]; if (dictionary.ContainsKey(operationId)) { Dictionary <string, object> dictionary2 = (Dictionary <string, object>)dictionary[operationId]; if (dictionary2.ContainsKey("status")) { string text = dictionary2["status"].ToString(); return(new bool?(text.Equals("on", StringComparison.InvariantCultureIgnoreCase))); } } } } catch (Exception) { } } return(null); }
public Boolean getLatchStatus(Latch latch) { LatchResponse statusResponse = null; try { statusResponse = latch.Status(accountId); } catch (Exception es) { string message = "You do not have internet connection"; string caption = "Problem with internet connection"; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (statusResponse.Error != null && statusResponse.Error.Message != "") { string message = statusResponse.Error.Message; string caption = "Latch connection: " + statusResponse.Error.Code; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } else { Dictionary <string, object> op = (Dictionary <string, object>)statusResponse.Data["operations"]; Dictionary <string, object> st = (Dictionary <string, object>)op[global::LockifiApp.Properties.Settings.Default.latch_appid]; return(st["status"].ToString() == "on"); } }
public BooleanResult AuthorizeUser(SessionProperties properties) { UserInformation userInfo = properties.GetTrackedSingle <UserInformation>(); if (!ReferenceEquals(null, Settings.ApplicationID) && !ReferenceEquals(null, Settings.Secret)) { string applicationID = Util.GetSettingsString((string)Settings.ApplicationID); string secret = Util.GetSettingsString((string)Settings.Secret); string accountID = Util.GetSettingsString((string)Settings.AccountID); //m_logger.InfoFormat("ApplicationID: {0}", applicationID); //m_logger.InfoFormat("Secret: {0}", secret); //m_logger.InfoFormat("AccountID: {0}", accountID); Latch latch = new Latch(applicationID, secret); LatchResponse response = latch.Status(accountID); // One of the ugliest lines of codes I ever wrote, but quickest way to access the object without using json serialization try { Dictionary <string, object> operations = ((Dictionary <string, object>)response.Data["operations"]); Dictionary <string, object> appSettings = ((Dictionary <string, object>)operations[(applicationID)]); string status = ((string)appSettings["status"]); m_logger.InfoFormat("Latch status is {0}", status); if (status == "on") { return new BooleanResult() { Success = true, Message = "Ready to go!" } } ; else { return new BooleanResult() { Success = false, Message = "Latch is protecting this account!" } }; } catch (Exception) { return(new BooleanResult() { Success = true, Message = "Something went wrong, letting you in because I don't want to lock you out!" }); } } else { return(new BooleanResult() { Success = false, Message = "Latch is not correctly configured." }); } }
/// <summary> /// Unpairs the specified account ID /// </summary> /// <param name="accountId">The account ID of the user</param> /// <returns>If everything goes well, an empty response</returns> public bool Unpair(string accountId) { if (string.IsNullOrEmpty(accountId)) { return(false); } LatchResponse l = HttpPerformRequest(API_UNPAIR_URL + "/" + UrlEncode(accountId)); return(l != null && (l.Error == null || (l.Error != null && l.Error.Code == 201))); }
private Boolean Fill_dataGridViewUsers() { dataGridViewUsers.Rows.Clear(); if (global::LockifiApp.Properties.Settings.Default.latch_appid == "" || global::LockifiApp.Properties.Settings.Default.latch_seckey == "" || global::LockifiApp.Properties.Settings.Default.latch_appid == "*" || global::LockifiApp.Properties.Settings.Default.latch_seckey == "*") { string message = "You must configure Latch"; string caption = "Latch is not configured"; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (users.Count > 0) { LatchResponse statusC = null; try { statusC = latch.Status(users[0].accountId); }catch (Exception e) { string message = "You do not have internet connection"; string caption = "Problem with internet connection"; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (statusC.Error != null && statusC.Error.Code == 102) { string message = "Latch configuration is wrong"; string caption = "Problem with Latch configuration"; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } else { dataGridViewUsers.ColumnCount = 3; dataGridViewUsers.Columns[0].Name = "accountId"; dataGridViewUsers.Columns[1].Name = "User"; dataGridViewUsers.Columns[2].Name = "Status"; dataGridViewUsers.Columns[0].Visible = false; foreach (User user in users) { user.status = user.getLatchStatus(latch); String[] dataGrid_data = { user.accountId, user.name, user.status.ToString() };; dataGridViewUsers.Rows.Add(dataGrid_data); } dataGridViewUsers.ClearSelection(); return(true); } } } return(false); }
private void btnCheckStatus_Click(object sender, EventArgs e) { Latch latch = new Latch(tbApplicationID.Text, tbSecret.Text); LatchResponse response = latch.Status(tbAccountID.Text); if (response.Data != null) { Dictionary <string, object> operations = ((Dictionary <string, object>)response.Data["operations"]); Dictionary <string, object> appSettings = ((Dictionary <string, object>)operations[(tbApplicationID.Text)]); string status = ((string)appSettings["status"]); lblLog.Text = "Latch account status is " + status; } }
/// <summary> /// Performs an HTTP request to an URL using the specified method and data, returning the response as a string /// </summary> LatchResponse HttpPerformRequest(string url, HttpMethod method = HttpMethod.GET, IDictionary <string, string> data = null) { try { IDictionary <string, string> authHeaders = AuthenticationHeaders(method.ToString(), url, null, data); string json = HttpPerformRequest(API_HOST + url, method, authHeaders, data); LatchResponse r = JsonHelper.Deserialize <LatchResponse>(json); // , new JsonSerializerSettings() //{ // Converters = new List<JsonConverter> { new StatusConverter() } //}); return(r); } catch { } return(null); }
public static void Pair(string pairingToken) { if (!LatchHandler.IsPaired && !string.IsNullOrWhiteSpace(pairingToken)) { LatchResponse latchResponse = LatchHandler.LatchSDK.Pair(pairingToken); if (latchResponse.Data != null && latchResponse.Data.ContainsKey("accountId")) { Configuration.GetConfig().AccountId = latchResponse.Data["accountId"].ToString(); Configuration.Save(); return; } if (latchResponse.Error != null) { throw new ApplicationException(latchResponse.Error.Message); } } }
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(); } } }
private void btnCheckLatchConf_Click(object sender, EventArgs e) { lblLog.Text = ""; if (tbApplicationID.Text == null || tbSecret.Text == null) { lblLog.Text = "Application ID and Secret must be set"; return; } // This is the simpliest way I found to check if the details are correct. Hope they add a Validate() method to the API Latch latch = new Latch(tbApplicationID.Text, tbSecret.Text); LatchResponse response = latch.Status("TestingUserDoNotHateMePalako"); if (response.Error.Code == 202) { lblLog.Text = "Application ID and Secret are valid."; } else { MessageBox.Show(response.Error.Message + " (" + response.Error.Code + ")"); } }
/// <summary> /// Requests the status of the specified account ID /// </summary> /// <param name="accountId">The account ID of the user</param> /// <returns>If everything goes well, a <code>LatchResponse</code> object containing the status of the account</returns> public bool Status(string accountId) { LatchResponse l = HttpPerformRequest(API_CHECK_STATUS_URL + "/" + UrlEncode(accountId)); return(l != null && l.Data != null && l.Data.status != null && l.Data.status.ToLower() == "on"); }
/// <summary> /// Pairs an account using a token /// </summary> /// <param name="token">Pairing token obtained by the user from the mobile application</param> /// <returns>If everything goes well, a <code>LatchResponse</code> object containing the AccountID</returns> public string Pair(string token) { LatchResponse r = HttpPerformRequest(API_PAIR_URL + "/" + UrlEncode(token)); return(r != null && r.Data != null ? r.Data.accountId : null); }