コード例 #1
0
        public Models.Response CreateDigitalTwinModelStaticProperty(Models.DigitalTwinModelStaticPropertyRequest value, Guid organization)
        {
            Models.Response response = new Models.Response();

            try
            {
                //SQL Statement
                var sqlString = "INSERT INTO digital_twin_model_static_properties (id, name, value, digital_twin_model, organization, created, created_by) " +
                                "VALUES (@id, @name, @value, @digital_twin_model, @organization, @created, @created_by)";

                //Create a new Id UUID
                Guid idGuid = Guid.NewGuid();

                using (var connection = new NpgsqlConnection(connectionString))
                {
                    connection.Open();

                    using (var command = new NpgsqlCommand(sqlString, connection))
                    {
                        command.Parameters.AddWithValue("@id", NpgsqlTypes.NpgsqlDbType.Uuid, idGuid);
                        command.Parameters.AddWithValue("@name", NpgsqlTypes.NpgsqlDbType.Text, value.Name);
                        command.Parameters.AddWithValue("@value", NpgsqlTypes.NpgsqlDbType.Text, value.Value);
                        command.Parameters.AddWithValue("@digital_twin_model", NpgsqlTypes.NpgsqlDbType.Uuid, value.DigitalTwinModel);
                        command.Parameters.AddWithValue("@organization", NpgsqlTypes.NpgsqlDbType.Uuid, organization);
                        command.Parameters.AddWithValue("@created", NpgsqlTypes.NpgsqlDbType.TimestampTz, DateTime.UtcNow);
                        command.Parameters.AddWithValue("@created_by", NpgsqlTypes.NpgsqlDbType.Uuid, value.CreatedBy);
                        command.Prepare();
                        command.ExecuteNonQuery();

                        //Log Success
                        response.Status  = "success";
                        response.Message = "Digital Twin Model Static Property created";
                        response.Id      = idGuid;
                        return(response);
                    }
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                _logger.LogError(ex, "Digital Twin Model Static Property creation failed");
                response.Status  = "error";
                response.Message = "Digital Twin Model Static Property creation failed";
                response.Id      = errorGuid;
                return(response);
            }
        }
コード例 #2
0
        private async void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.Text != "" && txtValue.Text != "")
                {
                    //Capture Values
                    Models.DigitalTwinModelStaticPropertyRequest staticPropertyRequest = new Models.DigitalTwinModelStaticPropertyRequest();
                    staticPropertyRequest.Name             = txtName.Text.Trim();
                    staticPropertyRequest.Value            = txtValue.Text.Trim();
                    staticPropertyRequest.DigitalTwinModel = modelId;
                    staticPropertyRequest.CreatedBy        = Program.identity;

                    //Create JSON Document
                    var jsonString = JsonConvert.SerializeObject(staticPropertyRequest);

                    //Clear Values
                    txtName.Clear();
                    txtValue.Clear();

                    string credentials = Program.identity.ToString() + "." + Program.securityToken.ToString();

                    //Send Data
                    ClientSDK clientSDK  = new ClientSDK();
                    string    uriString  = Program.serverURL + "/DigitalTwinModelStaticProperty";
                    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(staticPropertyRequest.Name);
                    listViewItem.SubItems.Add(staticPropertyRequest.Value);
                    listViewProperties.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
            {
            }
        }