Exemple #1
0
 //StartRemoveInExercise1
 /// <summary>
 /// Overrides Safir.Dob.Requestor. Response for sent request
 /// </summary>
 public void OnResponse(Safir.Dob.ResponseProxy responseProxy)
 {
     if (responseProxy.RequestTypeId == Capabilities.Vehicles.DeleteVehicleCategoryService.ClassTypeId)
     {
         if (responseProxy.IsSuccess)
         {
             statusStrip.Items["toolStripStatus"].Text = "Category info for the chosen object has succesfully been deleted";
         }
         else
         {
             statusStrip.Items["toolStripStatus"].Text = "Category info for the chosen object could not be deleted";
         }
     }
     else
     {
         if (responseProxy.IsSuccess)
         {
             statusStrip.Items["toolStripStatus"].Text = "OK";
         }
         else
         {
             Safir.Dob.ErrorResponse errorResponse = (Safir.Dob.ErrorResponse)responseProxy.Response;
             if (errorResponse.AdditionalInfo.IsNull())
             {
                 statusStrip.Items["toolStripStatus"].Text = "Error";
             }
             else
             {
                 statusStrip.Items["toolStripStatus"].Text = "Error: " + errorResponse.AdditionalInfo.Val;
             }
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// Overrides Safir.Dob.Requestor. Response for sent request.
 /// </summary>
 public void OnResponse(Safir.Dob.ResponseProxy responseProxy)
 {
     if (responseProxy.IsSuccess)
     {
         if (m_apply)
         {
             statusStrip.Items["toolStripStatus"].Text = "OK";
         }
         else
         {
             this.Hide();
         }
     }
     //StartRemoveInExercise6
     else
     {
         Safir.Dob.ErrorResponse errorResponse = (Safir.Dob.ErrorResponse)responseProxy.Response;
         //if (errorResponse.AdditionalInfo.IsNull())
         if (errorResponse.Code.IsNull())
         {
             // No error code.
             statusStrip.Items["toolStripStatus"].Text = "Unspecified error";
         }
         else
         {
             // Error code specified.
             if (errorResponse.Code.Val == Safir.Dob.ResponseGeneralErrorCodes.SafirReqErr)
             {
                 statusStrip.Items["toolStripStatus"].Text = "General request error";
             }
         }
     }
     //StopRemoveInExercise6
 }
        //
        // 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 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);
            }
        }
Exemple #5
0
        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);
            }
        }