/// <summary> /// Sends a service request to delete additional information of a /// certain category /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripButtonDeleteCategoryInfo_Click(object sender, EventArgs e) { Safir.Dob.Typesystem.EntityId entityId = new Safir.Dob.Typesystem.EntityId(); if (m_vehicleEntityListHandler.GetSelectedEntityId(out entityId)) { Capabilities.Vehicles.Vehicle vehicle = new Capabilities.Vehicles.Vehicle(); try { // Get data from Dob and fill dialog using (Safir.Dob.EntityProxy entityProxy = m_secDobConnection.Read(entityId)) { vehicle = (Capabilities.Vehicles.Vehicle)entityProxy.Entity; } } catch { // The specified instance of the entity does not exist statusStrip.Items["toolStripStatus"].Text = "Data was not found in database"; } if (!vehicle.VehicleCategory.IsNull()) { Capabilities.Vehicles.DeleteVehicleCategoryService req = new Capabilities.Vehicles.DeleteVehicleCategoryService(); req.VehicleCategory.Val = vehicle.VehicleCategory.Val; m_secDobConnection.ServiceRequest(req, new Safir.Dob.Typesystem.HandlerId(), this); statusStrip.Items["toolStripStatus"].Text = "OK"; } } else { statusStrip.Items["toolStripStatus"].Text = "No vehicle selected."; } }
/// <summary> /// Open dialog to update a vehicle /// </summary> public bool UpdateVehicle(Safir.Dob.Typesystem.EntityId entityId) { this.Text = "Update vehicle"; ClearAllControls(); textBoxIdentification.ReadOnly = true; // Not allowed to change identification comboBoxCategory.Focus(); m_create = false; try { using (Safir.Dob.EntityProxy entityProxy = m_secDobConnection.Read(entityId)) { m_vehicle = (Capabilities.Vehicles.Vehicle)entityProxy.Entity; } } catch (Safir.Dob.NotFoundException) { // The specified instance of the entity does not exist return(false); } if (!m_vehicle.Identification.IsNull()) { textBoxIdentification.Text = m_vehicle.Identification.Val.ToString(); } if (!m_vehicle.VehicleCategory.IsNull()) { comboBoxCategory.SelectedItem = m_vehicle.VehicleCategory.Val.ToString(); } if (!m_vehicle.Speed.IsNull()) { textBoxSpeed.Text = m_vehicle.Speed.Val.ToString(); } else { textBoxSpeed.Text = ""; } if (!m_vehicle.Position.IsNull()) { // Position (latitude) if (!m_vehicle.Position.Obj.Latitude.IsNull()) { textBoxPosLat.Text = m_vehicle.Position.Obj.Latitude.Val.ToString(); } // Position (longitude) if (!m_vehicle.Position.Obj.Longitude.IsNull()) { textBoxPosLong.Text = m_vehicle.Position.Obj.Longitude.Val.ToString(); } } this.Show(); return(true); }
// // The following methods are derived from Safir.Dob.EntityHandlerInjection. // public void OnCreateRequest( Safir.Dob.EntityRequestProxy entityRequestProxy, Safir.Dob.ResponseSender responseSender) { bool bOk = false; Safir.Dob.Typesystem.InstanceId instanceId; Safir.Dob.Typesystem.EntityId entityId = new Safir.Dob.Typesystem.EntityId(); // Cast to known type, the vehicle entity. Capabilities.Vehicles.Vehicle vehicle = (Capabilities.Vehicles.Vehicle)entityRequestProxy.Request; // Identification is a mandatory member. if (!vehicle.Identification.IsNull()) { // Generate instance number from unique value. instanceId = new Safir.Dob.Typesystem.InstanceId(vehicle.Identification.Val); // Check if entity with given value already exist. entityId.TypeId = Capabilities.Vehicles.Vehicle.ClassTypeId; entityId.InstanceId = instanceId; if (!m_connection.IsCreated(entityId)) { // Store object in the Dob. m_connection.SetAll( vehicle, instanceId, new Safir.Dob.Typesystem.HandlerId()); bOk = true; m_iNumberOfCreatedVehicles++; } } if (bOk) { // Inform requestor about the instance. Safir.Dob.EntityIdResponse entIdResponse = new Safir.Dob.EntityIdResponse(); entIdResponse.Assigned.Val = entityId; responseSender.Send(entIdResponse); // Send notification message when the number of created vehicles // has reached the limit. if (m_iNumberOfCreatedVehicles == Capabilities.Vehicles.VehicleParameters.VehicleLimit) { MessageSender.Instance.SendMaxNofVehicleMsg(); } } else { Safir.Dob.ErrorResponse errorResponse = new Safir.Dob.ErrorResponse(); errorResponse.Code.Val = Safir.Dob.ResponseGeneralErrorCodes.SafirReqErr; responseSender.Send(errorResponse); } }
/// <summary> /// Update row in listview with new data /// </summary> public void OnUpdatedEntity(Safir.Dob.EntityProxy entityProxy) { Capabilities.Vehicles.Vehicle vehicle = (Capabilities.Vehicles.Vehicle)entityProxy.Entity; int index = m_ListView.Items.IndexOfKey(entityProxy.EntityId.InstanceId.ToString()); ListViewItem item = m_ListView.Items[index]; // Identification if (!vehicle.Identification.IsNull()) { item.SubItems[c_iColumnIdentification].Text = vehicle.Identification.Val.ToString(); } else { item.SubItems[c_iColumnIdentification].Text = "-"; } // Category if (!vehicle.VehicleCategory.IsNull()) { item.SubItems[c_iColumnCategory].Text = vehicle.VehicleCategory.Val.ToString(); } else { item.SubItems[c_iColumnCategory].Text = "-"; } //StartRemoveInExercise4 // Speed if (!vehicle.Speed.IsNull()) { item.SubItems[c_iColumnSpeed].Text = vehicle.Speed.Val.ToString(); } else { item.SubItems[c_iColumnSpeed].Text = "-"; } //StopRemoveInExercise4 // Position item.SubItems[3].Text = "-"; item.SubItems[4].Text = "-"; if (!vehicle.Position.IsNull()) { // Position (latitude) if (!vehicle.Position.Obj.Latitude.IsNull()) { item.SubItems[3].Text = vehicle.Position.Obj.Latitude.Val.ToString(); } // Position (longitude) if (!vehicle.Position.Obj.Longitude.IsNull()) { item.SubItems[4].Text = vehicle.Position.Obj.Longitude.Val.ToString(); } } }
/// <summary> /// Opens dialog for category information /// </summary> public bool Open(Safir.Dob.Typesystem.EntityId entityId) { ClearAllControls(); try { // Get data from Dob and fill dialog using (Safir.Dob.EntityProxy entityProxy = m_secDobConnection.Read(entityId)) { m_vehicle = (Capabilities.Vehicles.Vehicle)entityProxy.Entity; } } catch { // The specified instance of the entity does not exist return(false); } if (!m_vehicle.VehicleCategory.IsNull()) { textBoxCategoryCode.Text = m_vehicle.VehicleCategory.Val.ToString(); Capabilities.Vehicles.GetVehicleCategoryService req = new Capabilities.Vehicles.GetVehicleCategoryService(); req.VehicleCategory.Val = m_vehicle.VehicleCategory.Val; try { // Send service request m_secDobConnection.ServiceRequest(req, new Safir.Dob.Typesystem.HandlerId(), this); statusStrip.Items["toolStripStatus"].Text = "OK"; } catch (Safir.Dob.OverflowException) { statusStrip.Items["toolStripStatus"].Text = "Overflow when sending, please wait!"; } this.Show(); return(true); } return(false); }
/// <summary> /// Opens dialog to calculate speed difference /// </summary> public bool Open(Safir.Dob.Typesystem.EntityId entityId) { textBoxIdentification.Text = ""; textBoxCurrentSpeed.Text = ""; textboxNewSpeed.Text = ""; textboxSpeedDiff.Text = ""; statusStrip.Items["toolStripStatus"].Text = "OK"; // Get data from Dob and fill dialog try { using (Safir.Dob.EntityProxy entityProxy = m_secDobConnection.Read(entityId)) { m_vehicle = (Capabilities.Vehicles.Vehicle)entityProxy.Entity; } } catch { // The specified instance of the entity does not exist return(false); } if (!m_vehicle.Identification.IsNull()) { textBoxIdentification.Text = m_vehicle.Identification.Val.ToString(); } if (!m_vehicle.Speed.IsNull()) { textBoxCurrentSpeed.Text = m_vehicle.Speed.Val.ToString(); } else { statusStrip.Items["toolStripStatus"].Text = "Current speed must exist."; } this.Show(); return(true); }
public void OnUpdateRequest( Safir.Dob.EntityRequestProxy entityRequestProxy, Safir.Dob.ResponseSender responseSender) { bool bOk = false; // Cast to known type, the vehicle entity. Capabilities.Vehicles.Vehicle receivedVehicle = (Capabilities.Vehicles.Vehicle)entityRequestProxy.Request; if (m_connection.IsCreated(entityRequestProxy.EntityId)) { // Don't allow the identification to be updated. if (!receivedVehicle.Identification.IsChanged()) { // Update the stored vehicle with the received one. m_connection.SetChanges( receivedVehicle, entityRequestProxy.InstanceId, new Safir.Dob.Typesystem.HandlerId()); bOk = true; } } if (bOk) { responseSender.Send(new Safir.Dob.SuccessResponse()); } else { Safir.Dob.ErrorResponse errorResponse = new Safir.Dob.ErrorResponse(); errorResponse.Code.Val = Safir.Dob.ResponseGeneralErrorCodes.SafirReqErr; responseSender.Send(errorResponse); } }
/// <summary> /// Send a create request for Vehicle /// </summary> private void SendCreateRequest() { Capabilities.Vehicles.Vehicle vehicle = new Capabilities.Vehicles.Vehicle(); // Identification if (textBoxIdentification.Text == "") { statusStrip.Items["toolStripStatus"].Text = "Identification must be given."; return; } else { vehicle.Identification.Val = textBoxIdentification.Text; } // Category int sel = comboBoxCategory.SelectedIndex; if (sel == -1) { vehicle.VehicleCategory.SetNull(); } else { vehicle.VehicleCategory.Val = (Capabilities.Vehicles.VehicleCategoryCode.Enumeration)sel; } //StartRemoveInExercise5 // Speed if (textBoxSpeed.Text == "") { vehicle.Speed.SetNull(); } else { try { vehicle.Speed.Val = float.Parse(textBoxSpeed.Text); } catch { statusStrip.Items["toolStripStatus"].Text = "Illegal speed format!"; } } //StopRemoveInExercise5 // Position Safir.Geodesy.Position pos = new Safir.Geodesy.Position(); try { if (textBoxPosLat.Text == "" || textBoxPosLong.Text == "") { vehicle.Position.SetNull(); } else { pos.Latitude.Val = float.Parse(textBoxPosLat.Text); pos.Longitude.Val = float.Parse(textBoxPosLong.Text); pos.Altitude.Val = Safir.Geodesy.Position.DummyAltitude; vehicle.Position.Obj = pos; } } catch (System.FormatException) { statusStrip.Items["toolStripStatus"].Text = "Position must be a float"; return; } //StartRemoveInExercise5 try { m_secDobConnection.CreateRequest(vehicle, new Safir.Dob.Typesystem.HandlerId(), this); } catch (Safir.Dob.OverflowException) { statusStrip.Items["toolStripStatus"].Text = "Overflow when sending, please wait!"; return; } //StopRemoveInExercise5 }