private void listBox1_DoubleClick(object sender, EventArgs e) { // Instance <string> // Instance <number> string s = (string)this.listBox1.SelectedItem; Safir.Dob.Typesystem.EntityId entityId; try { Int64 instance = Int64.Parse(s); entityId = new Safir.Dob.Typesystem.EntityId(typeId, new Safir.Dob.Typesystem.InstanceId(instance)); } catch { string instanceStr = s; entityId = new Safir.Dob.Typesystem.EntityId(typeId, new Safir.Dob.Typesystem.InstanceId(instanceStr)); } try { using (Safir.Dob.EntityProxy entityProxy = MainForm.Instance.Dose.Read(entityId)) { EntityInfo entityInfo = new EntityInfo(); entityInfo.Obj = entityProxy.Entity; entityInfo.setHandlerId(entityProxy.OwnerWithStringRepresentation); entityInfo.setInstanceId(entityProxy.InstanceId); MainForm.Instance.AddTabPage(new ObjectEditTabPage(entityInfo)); } } catch { MessageBox.Show(entityId.InstanceId.ToString() + " does no longer exist."); } }
/// <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); } }
//For subscribe public MyListViewItem(Int64 typeId, Safir.Dob.Typesystem.EntityId entityId, Safir.Dob.Typesystem.ChannelId channelId, bool upd, bool restart) { this.Text = Safir.Dob.Typesystem.Operations.GetName(typeId); this.typeId = typeId; this.entityId = entityId; this.channelId = channelId; this.upd = upd; this.restartSubscription = restart; string infoStr; if (channelId == null) { if (entityId == null) { infoStr = ""; } else { infoStr = entityId.InstanceId.ToString(); } } else { infoStr = channelId.ToString(); } this.SubItems.Add(infoStr); string subscrStr = ""; bool slash = false; if (upd) { if (slash) { subscrStr += " / "; } subscrStr += "update"; slash = true; } if (restartSubscription) { if (slash) { subscrStr += " / "; } subscrStr += "restart"; slash = true; } this.SubItems.Add(subscrStr); }
public bool EntityIdExist(Safir.Dob.Typesystem.EntityId entityId) { int index = m_ListView.Items.IndexOfKey(entityId.InstanceId.ToString()); if (index == -1) { return(false); } else { return(true); } }
public int GetImageIndex(Safir.Dob.Typesystem.EntityId entityId, ImageType imageType) { return(ApplyImageType(ObjectDefault, imageType)); /* * if (oid.Instance >= 0) //object icon * { * return ApplyImageType(ObjectDefault, imageType); * } * else //class * { * return GetImageIndex(oid.TypeId, imageType); * } */ }
/// <summary> /// Removes selected vehicle /// </summary> private void toolStripButtonDelete_Click(object sender, EventArgs e) { Safir.Dob.Typesystem.EntityId entityId = new Safir.Dob.Typesystem.EntityId(); if (m_vehicleEntityListHandler.GetSelectedEntityId(out entityId)) { //StartRemoveInExercise7 m_secDobConnection.DeleteRequest(entityId, this); //StopRemoveInExercise7 statusStrip.Items["toolStripStatus"].Text = "OK"; } else { statusStrip.Items["toolStripStatus"].Text = "No vehicle selected."; } }
/// <summary> /// Get object id for the object being selected /// </summary> public bool GetSelectedEntityId(out Safir.Dob.Typesystem.EntityId entityId) { entityId = new Safir.Dob.Typesystem.EntityId(); entityId.TypeId = Capabilities.Vehicles.Vehicle.ClassTypeId; if (m_ListView.SelectedItems.Count > 0) { ListViewItem lastSelectedItem = m_ListView.SelectedItems[m_ListView.SelectedItems.Count - 1]; entityId.InstanceId = new Safir.Dob.Typesystem.InstanceId(Convert.ToInt64(lastSelectedItem.Name)); return(true); } else { return(false); } }
public Executor(string[] args) { m_instance = int.Parse(args[0]); m_instanceString = m_instance.ToString(); m_partnerEntityId = new Safir.Dob.Typesystem.EntityId(DoseTest.Partner.ClassTypeId, new Safir.Dob.Typesystem.InstanceId(m_instance)); m_controlConnectionName = m_identifier + "_control"; m_testConnectionName = "partner_test_connection"; m_callbackActions = new Dictionary <Safir.Dob.CallbackId.Enumeration, List <DoseTest.Action> >(); foreach (Safir.Dob.CallbackId.Enumeration cb in Enum.GetValues(typeof(Safir.Dob.CallbackId.Enumeration))) { m_callbackActions.Add(cb, new List <DoseTest.Action>()); } m_controlDispatcher = new ControlDispatcher(m_controlDispatchEvent); m_testDispatcher = new Dispatcher(m_testDispatchEvent); m_testStopHandler = new StopHandler(); m_actionReceiver = new ActionReceiver(m_instance, m_dataReceivedEvent); }
/// <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 OpenCategoryInfoDlg() { if (m_ListView.SelectedItems.Count > 0) { ListViewItem lastSelectedItem = m_ListView.SelectedItems[m_ListView.SelectedItems.Count - 1]; Safir.Dob.Typesystem.EntityId entityId = new Safir.Dob.Typesystem.EntityId (Capabilities.Vehicles.Vehicle.ClassTypeId, new Safir.Dob.Typesystem.InstanceId(Convert.ToInt64(lastSelectedItem.Name))); if (!m_CategoryInfoDlg.Open(entityId)) { m_frameStatusStrip.Text = "Vehicle could not be read from Dob"; } else { m_frameStatusStrip.Text = "OK"; } } else { m_frameStatusStrip.Text = "No vehicle selected."; } }
public EntityIdSerializeable(Safir.Dob.Typesystem.EntityId entityId) { m_typeId = entityId.TypeId; m_instanceIdSerializeable = new InstanceIdSerializeable(entityId.InstanceId); }
void HandleSequencerState(DoseTest.Sequencer sequencerState) { bool activate = sequencerState != null && sequencerState.Partners[m_instance].Val.Equals(m_identifier); //bool activate = true; if (activate == m_isActive) { //already active or not active return; } if (activate) { m_defaultContext = sequencerState.Context.Val; System.Console.WriteLine("Activating (default context is " + m_defaultContext + ")"); m_controlConnection.RegisterEntityHandler(m_partnerEntityId.TypeId, new Safir.Dob.Typesystem.HandlerId(m_instance), Safir.Dob.InstanceIdPolicy.Enumeration.HandlerDecidesInstanceId, this); m_controlConnection.RegisterServiceHandler(DoseTest.Dump.ClassTypeId, new Safir.Dob.Typesystem.HandlerId(m_instance), this); m_actionReceiver.Open(); DoseTest.Partner partner = new DoseTest.Partner(); partner.Identifier.Val = m_identifier; partner.Port.Val = m_actionReceiver.getPort(); try { Safir.Dob.Typesystem.InstanceId instance = new Safir.Dob.Typesystem.InstanceId(Safir.Dob.ThisNodeParameters.NodeNumber); Safir.Dob.Typesystem.EntityId eid = new Safir.Dob.Typesystem.EntityId(Safir.Dob.NodeInfo.ClassTypeId, instance); using (Safir.Dob.EntityProxy ep = m_controlConnection.Read(eid)) { partner.Address.Val = ((Safir.Dob.NodeInfo)ep.Entity).IpAddress.Val; } } catch (Safir.Dob.NotFoundException e) { System.Console.WriteLine("Not found exception: " + e); } m_controlConnection.SetAll(partner, m_partnerEntityId.InstanceId, new Safir.Dob.Typesystem.HandlerId(m_instance)); m_isActive = true; } else { System.Console.WriteLine("Deactivating"); m_actionReceiver.Close(); m_testConnection.Close(); m_controlConnection.Delete(m_partnerEntityId, new Safir.Dob.Typesystem.HandlerId(m_instance)); m_controlConnection.UnregisterHandler(m_partnerEntityId.TypeId, new Safir.Dob.Typesystem.HandlerId(m_instance)); m_controlConnection.UnregisterHandler(DoseTest.Dump.ClassTypeId, new Safir.Dob.Typesystem.HandlerId(m_instance)); m_isActive = false; } }