// // 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); } }
public void OnDeleteRequest( Safir.Dob.EntityRequestProxy entityRequestProxy, Safir.Dob.ResponseSender responseSender) { if (m_connection.IsCreated(entityRequestProxy.EntityId)) { m_connection.Delete( entityRequestProxy.EntityId, new Safir.Dob.Typesystem.HandlerId()); m_iNumberOfCreatedVehicles--; } responseSender.Send(new Safir.Dob.SuccessResponse()); }
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); } }
public void OnDeleteRequest(Safir.Dob.EntityRequestProxy entityRequestProxy, Safir.Dob.ResponseSender responseSender) { responseSender.Send(Safir.Dob.ErrorResponse.CreateErrorResponse(Safir.Dob.ResponseGeneralErrorCodes.SafirNoPermission, "")); }
void Safir.Dob.ServiceRequestBase.OnServiceRequest(Safir.Dob.ServiceRequestProxy serviceRequestProxy, Safir.Dob.ResponseSender responseSender) { DoseTest.DumpResult result = new DoseTest.DumpResult(); result.Result.Val = Logger.Instance.ToString(); Logger.Instance.Clear(); responseSender.Send(result); }
void Safir.Dob.EntityRequestBase.OnUpdateRequest(Safir.Dob.EntityRequestProxy entityRequestProxy, Safir.Dob.ResponseSender responseSender) { responseSender.Send(new Safir.Dob.ErrorResponse()); }
public void OnServiceRequest( Safir.Dob.ServiceRequestProxy serviceRequestProxy, Safir.Dob.ResponseSender responseSender) { float speed, speedProperty, speedDiff; bool bOk = false, bPropertyOk = true; Safir.Dob.Entity ent; Capabilities.CalculateSpeedDifferenceResponse serviceResponse = new Capabilities.CalculateSpeedDifferenceResponse(); // Cast to known type, the CalculateSpeedDiff service. Capabilities.CalculateSpeedDifference receivedService = (Capabilities.CalculateSpeedDifference)serviceRequestProxy.Request; if (!receivedService.ObjectWithSpeed.IsNull() || !receivedService.Speed.IsNull()) { // Retrieve the values. speed = receivedService.Speed.Val; ent = receivedService.ObjectWithSpeed.Obj; // Use the property mechanism to obtain the value from the // ObjectWithSpeed member. Be sure to check the mapping first. // Note, that this is just an example of how to use properties // and it has nothing to do with the service mechanism. if (Capabilities.SpeedObjectProperty.HasProperty(ent)) { // Check Speed property. if (!Capabilities.SpeedObjectProperty.IsNullSpeedMember(ent)) { // Retrieve the value from the entity by using the property. speedProperty = Capabilities.SpeedObjectProperty.GetSpeedMember(ent); speedDiff = speedProperty - speed; serviceResponse.SpeedDifference.Val = speedDiff; bOk = true; } else { bPropertyOk = false; } } else { bPropertyOk = false; } } // Send response. if (bOk) { responseSender.Send(serviceResponse); } else if (!bPropertyOk) { // Respond with an error list that points out the member ObjectWithSpeed // as erroneous. This is to examplify usage of an error list. Safir.Dob.ErrorListResponse errorListResponse = new Safir.Dob.ErrorListResponse(); // Insert only one error in the list. errorListResponse.NumberOfErrors.Val = 1; // The error to be inserted in the error list. Safir.Dob.ResponseErrorInfo error = new Safir.Dob.ResponseErrorInfo(); error.Member.Val = Capabilities.CalculateSpeedDifference.ObjectWithSpeedMemberIndex; error.Code.Val = Safir.Dob.ResponseGeneralErrorCodes.SafirReqErr; // Insert error in list. errorListResponse.Error[0].Obj = error; responseSender.Send(errorListResponse); } else { // Respond with a general error. Safir.Dob.ErrorResponse errorResponse = new Safir.Dob.ErrorResponse(); errorResponse.Code.Val = Safir.Dob.ResponseGeneralErrorCodes.SafirReqErr; responseSender.Send(errorResponse); } }