private async void Users_Load(object sender, EventArgs e) { try { PopulateRoles(); string credentials = Program.identity.ToString() + "." + Program.securityToken.ToString(); //Send Data ClientSDK clientSDK = new ClientSDK(); string uriString = Program.serverURL + "/User"; var jsonResult = await clientSDK.Read(uriString, credentials); var objectResult = JsonConvert.DeserializeObject <List <Models.User> >(jsonResult); for (int i = 0; i < objectResult.Count; i++) { ListViewItem listViewItem = new ListViewItem(objectResult[i].Id.ToString()); listViewItem.SubItems.Add(objectResult[i].FirstName); listViewItem.SubItems.Add(objectResult[i].LastName); listViewItem.SubItems.Add(objectResult[i].Description); if (objectResult[i].Role == 1) { listViewItem.SubItems.Add("Writer"); } else { listViewItem.SubItems.Add("Reader"); } listViewUsers.Items.Add(listViewItem); } } catch (Exception ex) { if (ex.Message == "404") { //No data returned } else if (ex.Message == "401") { MessageBox.Show("The email address or password you entered is either incorrect or this user doesn't exist in the system", "Error"); } else if (ex.Message == "An error occurred while sending the request.") { MessageBox.Show("The Moab Platform is unreachable.", "Network Error"); } else { MessageBox.Show(ex.Message); } } finally { } }
private async void btnDelete_Click(object sender, EventArgs e) { try { string credentials = Program.identity.ToString() + "." + Program.securityToken.ToString(); //Send Data ClientSDK clientSDK = new ClientSDK(); string uriString = Program.serverURL + "/DigitalTwin"; string id = string.Empty; string name = string.Empty; string desc = string.Empty; if (listViewTwins.Items.Count > 0) { foreach (ListViewItem viewItem in listViewTwins.SelectedItems) { //Get Selected Group id = viewItem.SubItems[0].Text; name = viewItem.SubItems[1].Text; desc = viewItem.SubItems[2].Text; var jsonResult = await clientSDK.Delete(uriString + "/" + id, credentials); var objectResult = JsonConvert.DeserializeObject <Models.Response>(jsonResult); if (objectResult.Status == "success") { viewItem.Remove(); } } } } catch (Exception ex) { if (ex.Message == "404") { //No data returned } else if (ex.Message == "401") { MessageBox.Show("The email address or password you entered is either incorrect or this user doesn't exist in the system", "Error"); } else if (ex.Message == "An error occurred while sending the request.") { MessageBox.Show("The Moab Platform is unreachable.", "Network Error"); } else { MessageBox.Show(ex.Message); } } finally { } }
private void DigitalTwins_Load(object sender, EventArgs e) { string credentials = Program.identity.ToString() + "." + Program.securityToken.ToString(); ClientSDK clientSDK = new ClientSDK(); RetrieveGroups(credentials, clientSDK); RetrieveModels(credentials, clientSDK); RetrieveTwins(credentials, clientSDK); }
private async void btnSend_Click(object sender, EventArgs e) { try { if (txtIdentity.Text != "" && txtSecurityToken.Text != "" && txtPayload.Text != "") { //Capture Credentials string credentials = txtIdentity.Text.Trim() + "." + txtSecurityToken.Text.Trim(); //Capture Data Payload var jsonString = txtPayload.Text.Trim(); //Send Data ClientSDK clientSDK = new ClientSDK(); string uriString = Program.serverURL + "/Telemetry"; var jsonResult = await clientSDK.Create(uriString, jsonString, credentials); var objectResult = JsonConvert.DeserializeObject <Models.Response>(jsonResult); MessageBox.Show("Telemetry successfully saved in Moab"); } else { MessageBox.Show("All fields must be properly filled-in.", "Information"); } } catch (Exception ex) { if (ex.Message == "404") { //No data returned } else if (ex.Message == "401") { MessageBox.Show("The provided credentials are either incorrect or this entity doesn't exist in the system", "Error"); } else if (ex.Message == "400") { MessageBox.Show("The URL may be incorrect or the JSON is improperly formatted", "Error"); } else if (ex.Message == "An error occurred while sending the request.") { MessageBox.Show("The Moab Platform is unreachable.", "Network Error"); } else { MessageBox.Show(ex.Message); } } finally { } }
private async void DigitalTwinStaticProperties_Load(object sender, EventArgs e) { try { string credentials = Program.identity.ToString() + "." + Program.securityToken.ToString(); //Send Data ClientSDK clientSDK = new ClientSDK(); string uriString = Program.serverURL + "/DigitalTwinStaticProperty/" + twinId; var jsonResult = await clientSDK.Read(uriString, credentials); var objectResult = JsonConvert.DeserializeObject <List <Models.DigitalTwinStaticProperty> >(jsonResult); for (int i = 0; i < objectResult.Count; i++) { ListViewItem listViewItem = new ListViewItem(objectResult[i].Id.ToString()); listViewItem.SubItems.Add(objectResult[i].Name); listViewItem.SubItems.Add(objectResult[i].Value); listViewProperties.Items.Add(listViewItem); } } catch (Exception ex) { if (ex.Message == "404") { //No data returned } else if (ex.Message == "401") { MessageBox.Show("The email address or password you entered is either incorrect or this user doesn't exist in the system", "Error"); } else if (ex.Message == "An error occurred while sending the request.") { MessageBox.Show("The Moab Platform is unreachable.", "Network Error"); } else { MessageBox.Show(ex.Message); } } finally { } textBoxDigitalTwin.Text = twinName; }
private async void RetrieveTwins(string credentials, ClientSDK clientSDK) { try { //Send Data string uriString = Program.serverURL + "/DigitalTwin"; var jsonResult = await clientSDK.Read(uriString, credentials); var objectResult = JsonConvert.DeserializeObject <List <Models.DigitalTwin> >(jsonResult); for (int i = 0; i < objectResult.Count; i++) { ListViewItem listViewItem = new ListViewItem(objectResult[i].Id.ToString()); listViewItem.SubItems.Add(objectResult[i].Name); listViewItem.SubItems.Add(objectResult[i].Description); listViewTwins.Items.Add(listViewItem); } } catch (Exception ex) { if (ex.Message == "404") { //No data returned } else if (ex.Message == "401") { MessageBox.Show("The email address or password you entered is either incorrect or this user doesn't exist in the system", "Error"); } else if (ex.Message == "An error occurred while sending the request.") { MessageBox.Show("The Moab Platform is unreachable.", "Network Error"); } else { MessageBox.Show(ex.Message); } } finally { } }
private async void RetrieveModels(string credentials, ClientSDK clientSDK) { try { //Send Data string uriString = Program.serverURL + "/DigitalTwinModel"; var jsonResult = await clientSDK.Read(uriString, credentials); var objectResult = JsonConvert.DeserializeObject <List <Models.DigitalTwinModel> >(jsonResult); comboBoxDigitalTwinModel.DisplayMember = "Name"; comboBoxDigitalTwinModel.ValueMember = "Id"; comboBoxDigitalTwinModel.DataSource = objectResult; } catch (Exception ex) { if (ex.Message == "404") { //No data returned } else if (ex.Message == "401") { MessageBox.Show("The email address or password you entered is either incorrect or this user doesn't exist in the system", "Error"); } else if (ex.Message == "An error occurred while sending the request.") { MessageBox.Show("The Moab Platform is unreachable.", "Network Error"); } else { MessageBox.Show(ex.Message); } } finally { } }
private async void btnCreateUser_Click(object sender, EventArgs e) { try { if (txtFirstName.Text != "" && txtLastName.Text != "" && txtDescription.Text != "" && txtEmailAddress.Text != "" && txtPassword.Text != "" && txtPasswordRetype.Text != "") { if (txtPassword.Text.Trim() == txtPasswordRetype.Text.Trim()) { //Capture Values Models.UserRequest userRequest = new Models.UserRequest(); userRequest.FirstName = txtFirstName.Text.Trim(); userRequest.LastName = txtLastName.Text.Trim(); userRequest.Description = txtDescription.Text.Trim(); userRequest.EmailAddress = txtEmailAddress.Text.Trim(); userRequest.Password = txtPassword.Text.Trim(); userRequest.Role = (comboBoxRole.SelectedItem as Models.Role).Id; userRequest.CreatedBy = Program.identity; //Create JSON Document var jsonString = JsonConvert.SerializeObject(userRequest); //Clear Values txtFirstName.Clear(); txtLastName.Clear(); txtDescription.Clear(); txtEmailAddress.Clear(); txtPassword.Clear(); txtPasswordRetype.Clear(); string credentials = Program.identity.ToString() + "." + Program.securityToken.ToString(); //Send Data ClientSDK clientSDK = new ClientSDK(); string uriString = Program.serverURL + "/User"; var jsonResult = await clientSDK.Create(uriString, jsonString, credentials); var objectResult = JsonConvert.DeserializeObject <Models.UserResponse>(jsonResult); //Add to User List ListViewItem listViewItem = new ListViewItem(objectResult.Id.ToString()); listViewItem.SubItems.Add(userRequest.FirstName); listViewItem.SubItems.Add(userRequest.LastName); listViewItem.SubItems.Add(userRequest.Description); if (userRequest.Role == 1) { listViewItem.SubItems.Add("Writer"); } else { listViewItem.SubItems.Add("Reader"); } listViewUsers.Items.Add(listViewItem); } else { MessageBox.Show("The Password fields must match.", "Information"); } } else { MessageBox.Show("All fields must be properly filled-in.", "Information"); } } catch (Exception ex) { if (ex.Message == "404") { //No data returned } else if (ex.Message == "401") { MessageBox.Show("The email address or password you entered is either incorrect or this user doesn't exist in the system", "Error"); } else if (ex.Message == "An error occurred while sending the request.") { MessageBox.Show("The Moab Platform is unreachable.", "Network Error"); } else { MessageBox.Show(ex.Message); } } finally { } }
private async void btnCreateGroup_Click(object sender, EventArgs e) { try { if (txtGroupName.Text != "" && txtGroupDescription.Text != "") { //Capture Values Models.GroupRequest groupRequest = new Models.GroupRequest(); groupRequest.Name = txtGroupName.Text.Trim(); groupRequest.Description = txtGroupDescription.Text.Trim(); //Create JSON Document var jsonString = JsonConvert.SerializeObject(groupRequest); //Clear Values txtGroupName.Clear(); txtGroupDescription.Clear(); string credentials = Program.identity.ToString() + "." + Program.securityToken.ToString(); //Send Data ClientSDK clientSDK = new ClientSDK(); string uriString = Program.serverURL + "/Group"; var jsonResult = await clientSDK.Create(uriString, jsonString, credentials); var objectResult = JsonConvert.DeserializeObject <Models.Response>(jsonResult); //Add to Group List ListViewItem listViewItem = new ListViewItem(objectResult.Id.ToString()); listViewItem.SubItems.Add(groupRequest.Name); listViewItem.SubItems.Add(groupRequest.Description); listViewGroups.Items.Add(listViewItem); } else { MessageBox.Show("All fields must be properly filled-in.", "Information"); } } catch (Exception ex) { if (ex.Message == "404") { //No data returned } else if (ex.Message == "401") { MessageBox.Show("The email address or password you entered is either incorrect or this user doesn't exist in the system", "Error"); } else if (ex.Message == "An error occurred while sending the request.") { MessageBox.Show("The Moab Platform is unreachable.", "Network Error"); } else { MessageBox.Show(ex.Message); } } finally { } }