Example #1
0
        public Subscription(Model.Subscription item)
        {
            SubscriptionType = item.SubscriptionType.ToString();

            if (item.ObjectDefinitionID != null && item.PropertyDefinitionID != null)
            {
                Model.ObjectDefinition objectDefinition = DataAccessFactory.ObjectDefinitions.GetLookups().GetObjectDefinition(item.ObjectDefinitionID);
                if (objectDefinition != null)
                {
                    Model.PropertyDefinition propertyDefinition = objectDefinition.GetProperty(item.PropertyDefinitionID);
                    if (propertyDefinition != null)
                    {
                        Property = propertyDefinition.SerialisationName;
                    }
                }
            }
            Url = item.Url;
            AcceptContentType = item.AcceptContentType;

            if (item.NotificationParameters != null)
            {
                Attributes             = new SubscriptionAttributes();
                Attributes.Pmin        = item.NotificationParameters.MinimumPeriod;
                Attributes.Pmax        = item.NotificationParameters.MaximumPeriod;
                Attributes.Step        = item.NotificationParameters.Step;
                Attributes.LessThan    = item.NotificationParameters.LessThan;
                Attributes.GreaterThan = item.NotificationParameters.GreaterThan;
            }
        }
Example #2
0
        public IActionResult UpdateObjectInstance(string clientID, string definitionID, string instanceID)
        {
            IActionResult result;

            Guid definitionIDGuid, clientIDGuid;

            if (StringUtils.GuidTryDecode(definitionID, out definitionIDGuid) && StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                Model.Client           client         = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
                int                    organisationID = User.GetOrganisationID();
                Model.ObjectDefinition definition     = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, definitionIDGuid);
                if (definition != null)
                {
                    // TODO: add error handling around deserialisation.
                    List <Model.Property> executeProperties = new List <Model.Property>();
                    Model.Object          lwm2mObject       = new ServiceModels.ObjectInstance(definition, Request).Resource;
                    lwm2mObject.InstanceID = instanceID;
                    int index = 0;
                    while (index < lwm2mObject.Properties.Count)
                    {
                        Model.PropertyDefinition propertyDefinition = definition.GetProperty(lwm2mObject.Properties[index].PropertyDefinitionID);
                        if (propertyDefinition.Access == Model.TAccessRight.Execute)
                        {
                            executeProperties.Add(lwm2mObject.Properties[index]);
                            lwm2mObject.Properties.RemoveAt(index);
                        }
                        else
                        {
                            index++;
                        }
                    }
                    if (lwm2mObject.Properties.Count > 0)
                    {
                        BusinessLogicFactory.Clients.SaveObject(client, lwm2mObject, Model.TObjectState.Update);
                    }
                    if (executeProperties.Count > 0)
                    {
                        BusinessLogicFactory.Clients.Execute(client, lwm2mObject, executeProperties);
                    }
                    result = new NoContentResult();
                }
                else
                {
                    result = new BadRequestResult();
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return(result);
        }