Exemplo n.º 1
6
 public IActionResult RemoveClient(string clientID)
 {
     IActionResult result;
     Guid clientIDGuid;
     if (StringUtils.GuidTryDecode(clientID, out clientIDGuid))
     {
         Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
         if (client != null)
         {
             BusinessLogicFactory.Clients.DeleteClient(client);
             result = new NoContentResult();
         }
         else
         {
             result = new NotFoundResult();
         }
     }
     else
     {
         result = new NotFoundResult();
     }
     return result;
 }
Exemplo n.º 2
0
        public void HttpNotFoundResult_InitializesStatusCode()
        {
            // Arrange & act
            var notFound = new NotFoundResult();

            // Assert
            Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode);
        }
 public IActionResult GetBootstrapConfiguration()
 {
     IActionResult result;
     Model.BootstrapServer bootstrapServer = BusinessLogicFactory.Configuration.GetBootstrapServer(User.GetOrganisationID());
     if (bootstrapServer == null)
         result = new NotFoundResult();
     else
     {
         ServiceModels.Bootstrap response = new ServiceModels.Bootstrap(bootstrapServer);
         result = Request.GetObjectResult(response);
     }
     return result;
 }
 public IActionResult GetAccessKey(string key)
 {
     IActionResult result;
     Model.AccessKey accessKey = BusinessLogicFactory.AccessKeys.GetAccessKey(key);
     if (accessKey == null)
         result = new NotFoundResult();
     else
     {
         ServiceModels.AccessKey response = new ServiceModels.AccessKey(accessKey);
         string rootUrl = Request.GetRootUrl();
         response.AddSelfLink(string.Concat(rootUrl, "/accesskeys/", response.Key), true, true);
         result = Request.GetObjectResult(response);
     }
     return result;
 }
Exemplo n.º 5
0
 public IActionResult GetObjectType(string clientID, string definitionID)
 {
     IActionResult result = new NotFoundResult();
     Guid clientIDGuid;
     Guid definitionIDGuid;
     if (StringUtils.GuidTryDecode(clientID, out clientIDGuid) && StringUtils.GuidTryDecode(definitionID, out definitionIDGuid))
     {
         Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
         if ((client != null) && (client.SupportedTypes != null))
         {
             Model.ObjectDefinition definition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(User.GetOrganisationID(), definitionIDGuid);
             if (definition != null)
             {
                 Model.ObjectType objectType = client.SupportedTypes.GetObjectType(int.Parse(definition.ObjectID));
                 if (objectType != null)
                 {
                     ServiceModels.ObjectType response = new ServiceModels.ObjectType(objectType);
                     string rootUrl = Request.GetRootUrl();
                     response.AddSelfLink(string.Concat(rootUrl, "/clients/", clientID, "/objecttypes/", definitionID), false, false);
                     response.AddLink<ObjectDefinition>(Request, "definition", string.Concat(rootUrl, "/objecttypes/definitions/", definitionID));
                     response.AddLink("instances", string.Concat(rootUrl, "/clients/", clientID, "/objecttypes/", definitionID, "/instances"), Request.GetContentType(definition.MIMEType));
                     result = Request.GetObjectResult(response);
                 }
             }
         }
     }
     else
     {
         result = new BadRequestResult();
     }
     return result;
 }
Exemplo n.º 6
0
        public IActionResult GetObjectInstances(string clientID, string definitionID)
        {
            IActionResult result;

            Guid definitionIDGuid, clientIDGuid;
            if (StringUtils.GuidTryDecode(definitionID, out definitionIDGuid) && StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                int organisationID = User.GetOrganisationID();
                Model.ObjectDefinition definition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, definitionIDGuid);
                if (definition != null)
                {
                    Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
                    if (client != null)
                    {
                        List<Model.Object> instances = BusinessLogicFactory.Clients.GetObjects(client, definition.ObjectDefinitionID);
                        if (instances != null)
                        {
                            ObjectInstances response = new ObjectInstances(definition);
                            string rootUrl = Request.GetRootUrl();
                            string instancesUrl = string.Concat(rootUrl, "/clients/", clientID, "/objecttypes/", StringUtils.GuidEncode(definition.ObjectDefinitionID), "/instances");

                            response.AddLink("add", instancesUrl, "");

                            response.PageInfo = Request.GetPageInfo(instances.Count);
                            int endIndex = response.PageInfo.StartIndex + response.PageInfo.ItemsCount;
                            for (int index = response.PageInfo.StartIndex; index < endIndex; index++)
                            {
                                ObjectInstance instance = new ObjectInstance(definition, instances[index]);
                                string instanceUrl = string.Concat(instancesUrl, "/", instances[index].InstanceID);
                                AddObjectInstanceLinks(Request, definition, instance, instanceUrl);
                                response.Add(instance);
                            }
                            result = response.GetAction();
                        }
                        else
                        {
                            result = new NotFoundResult();
                        }
                    }
                    else
                    {
                        result = new NotFoundResult();
                    }
                }
                else
                {
                    result = new NotFoundResult();
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return result;
        }
Exemplo n.º 7
0
        public IActionResult GetObjectInstance(string clientID, string definitionID, string instanceID)
        {
            IActionResult result;

            Guid definitionIDGuid, clientIDGuid;
            if (StringUtils.GuidTryDecode(definitionID, out definitionIDGuid) && StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                int organisationID = User.GetOrganisationID();
                Model.ObjectDefinition definition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, definitionIDGuid);
                if (definition != null)
                {
                    Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
                    if (client != null)
                    {
                        Model.Object instance = BusinessLogicFactory.Clients.GetObject(client, definition.ObjectDefinitionID, instanceID);
                        if (instance != null)
                        {
                            ServiceModels.ObjectInstance response = new ServiceModels.ObjectInstance(definition, instance);
                            string rootUrl = Request.GetRootUrl();
                            string instanceUrl = string.Concat(rootUrl, "/clients/", clientID, "/objecttypes/", StringUtils.GuidEncode(definition.ObjectDefinitionID), "/instances/", instanceID);

                            AddObjectInstanceLinks(Request, definition, response, instanceUrl);
                            result = response.GetAction();
                        }
                        else
                        {
                            result = new NotFoundResult();
                        }
                    }
                    else
                    {
                        result = new NotFoundResult();
                    }
                }
                else
                {
                    result = new NotFoundResult();
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return result;
        }
Exemplo n.º 8
0
 public IActionResult GetClient(string clientID)
 {
     IActionResult result;
     Guid clientIDGuid;
     if (StringUtils.GuidTryDecode(clientID, out clientIDGuid))
     {
         Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
         if (client != null)
         {
             ServiceModels.Client response = new ServiceModels.Client(client);
             string clientUrl = string.Concat(Request.GetRootUrl(), "/clients/", StringUtils.GuidEncode(client.ClientID));
             response.AddSelfLink(clientUrl, false, true);
             response.AddLink<ObjectTypes>(Request, "objecttypes", string.Concat(clientUrl, "/objecttypes"));
             response.AddLink<ServiceModels.Subscriptions>(Request, "subscriptions", string.Concat(clientUrl, "/subscriptions"));
             response.AddLink<ServiceModels.Metrics>(Request, "metrics", string.Concat(clientUrl, "/metrics"));
             result = Request.GetObjectResult(response);
         }
         else
         {
             result = new NotFoundResult();
         }
     }
     else
     {
         result = new NotFoundResult();
     }
     return result;
 }
        public IActionResult UpdateSubscription(string subscriptionID, [FromBody] ServiceModels.Subscription subscription)
        {
            IActionResult result;
            Guid subscriptionIDGuid;
            if (StringUtils.GuidTryDecode(subscriptionID, out subscriptionIDGuid))
            {
                Model.Subscription subscriptionToUpdate = BusinessLogicFactory.Subscriptions.GetSubscription(subscriptionIDGuid);
                if (subscriptionToUpdate == null)
                    result = new NotFoundResult();
                else
                {
                    subscription.UpdateModel(subscriptionToUpdate);

                    if (!ExistingSubscriptionMatches(subscriptionToUpdate))
                    {
                        BusinessLogicFactory.Subscriptions.SaveSubscription(subscriptionToUpdate, TObjectState.Update);
                        result = new NoContentResult();
                    }
                    else
                    {
                        result = new StatusCodeResult((int)System.Net.HttpStatusCode.Conflict);
                    }
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return result;
        }
 public IActionResult RemoveSubscription(string subscriptionID)
 {
     IActionResult result;
     Guid subscriptionIDGuid;
     if (StringUtils.GuidTryDecode(subscriptionID, out subscriptionIDGuid))
     {
         Model.Subscription subscription = BusinessLogicFactory.Subscriptions.GetSubscription(subscriptionIDGuid);
         if (subscription == null)
             result = new NotFoundResult();
         else
         {
             BusinessLogicFactory.Subscriptions.SaveSubscription(subscription, TObjectState.Delete);
             result = new NoContentResult();
         }
     }
     else
     {
         result = new BadRequestResult();
     }
     return result;
 }
Exemplo n.º 11
0
 public IActionResult UpdateAccessKey(string key, [FromBody] ServiceModels.AccessKey accessKey)
 {
     IActionResult result;
     Model.AccessKey existingAccessKey = BusinessLogicFactory.AccessKeys.GetAccessKey(key);
     if (existingAccessKey == null)
         result = new NotFoundResult();
     else
     {
         existingAccessKey.Name = accessKey.Name;
         BusinessLogicFactory.AccessKeys.SaveAccessKey(existingAccessKey, Model.TObjectState.Update);
         result = new NoContentResult();
     }
     return result;
 }
Exemplo n.º 12
0
        public IActionResult RemoveObjectInstance(string clientID, string definitionID, string instanceID)
        {
            IActionResult result;

            Guid definitionIDGuid, clientIDGuid;
            if (StringUtils.GuidTryDecode(definitionID, out definitionIDGuid) && StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                int organisationID = User.GetOrganisationID();
                Model.ObjectDefinition definition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, definitionIDGuid);
                if (definition != null)
                {
                    Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
                    if (client != null)
                    {
                        Model.Object instance = BusinessLogicFactory.Clients.GetObject(client, definition.ObjectDefinitionID, instanceID);
                        if (instance != null)
                        {
                            BusinessLogicFactory.Clients.SaveObject(client, instance, Model.TObjectState.Delete);
                            result = new NoContentResult();
                        }
                        else
                        {
                            result = new NotFoundResult();
                        }
                    }
                    else
                    {
                        result = new NotFoundResult();
                    }
                }
                else
                {
                    result = new NotFoundResult();
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return result;
        }
 public IActionResult GetObjectDefinition(string id)
 {
     IActionResult result;
     Guid objectDefinitionID;
     if (StringUtils.GuidTryDecode(id, out objectDefinitionID))
     {
         int organisationID = User.GetOrganisationID();
         Model.ObjectDefinition objectDefinition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, objectDefinitionID);
         if (objectDefinition == null)
             result = new NotFoundResult();
         else
         {
             ServiceModels.ObjectDefinition response = new ServiceModels.ObjectDefinition(objectDefinition);
             string rootUrl = Request.GetRootUrl();
             if (organisationID == 0)
                 response.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", response.ObjectDefinitionID), true, true);
             else
                 response.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", response.ObjectDefinitionID), objectDefinition.OrganisationID.HasValue, objectDefinition.OrganisationID.HasValue);
             result = Request.GetObjectResult(response);
         }
     }
     else
         result = new BadRequestResult();
     return result;
 }
 public IActionResult UpdateObjectDefinition(string id, [FromBody] ServiceModels.ObjectDefinition objectDefinition)
 {
     IActionResult result;
     Guid objectDefinitionID;
     if (StringUtils.GuidTryDecode(id, out objectDefinitionID))
     {
         int organisationID = User.GetOrganisationID();
         Model.ObjectDefinition existingObjectDefinition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, objectDefinitionID);
         if (existingObjectDefinition == null)
             result = new NotFoundResult();
         else
         {
             if (!existingObjectDefinition.OrganisationID.HasValue && (organisationID != 0))
                 result = new StatusCodeResult((int)System.Net.HttpStatusCode.Forbidden);
             else
             {
                 Model.ObjectDefinition updatedObjectDefinition = objectDefinition.ToModel();
                 updatedObjectDefinition.OrganisationID = User.GetOrganisationID();
                 BusinessLogicFactory.ObjectDefinitions.SaveObjectDefinition(updatedObjectDefinition, Model.TObjectState.Update);
                 result = new NoContentResult();
             }
         }
     }
     else
         result = new BadRequestResult();
     return result;
 }
 public IActionResult RemoveObjectDefinition(string id)
 {
     IActionResult result;
     Guid objectDefinitionID;
     if (StringUtils.GuidTryDecode(id, out objectDefinitionID))
     {
         int organisationID = User.GetOrganisationID();
         Model.ObjectDefinition objectDefinition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, objectDefinitionID);
         if (objectDefinition == null)
             result = new NotFoundResult();
         else
         {
             if (!objectDefinition.OrganisationID.HasValue && (organisationID != 0))
                 result = new StatusCodeResult((int)System.Net.HttpStatusCode.Forbidden);
             else
             {
                 BusinessLogicFactory.ObjectDefinitions.SaveObjectDefinition(objectDefinition, Model.TObjectState.Delete);
                 result = new NoContentResult();
             }
         }
     }
     else
         result = new BadRequestResult();
     return result;
 }
Exemplo n.º 16
0
        public IActionResult GetObjectTypes(string clientID)
        {
            IActionResult result;
            Guid clientIDGuid;
            if (StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
                if (client != null)
                {
                    ServiceModels.ObjectTypes response = new ServiceModels.ObjectTypes();
                    string rootUrl = Request.GetRootUrl();

                    if (client.SupportedTypes != null)
                    {
                        Model.ObjectDefinitionLookups definitions = BusinessLogicFactory.ObjectDefinitions.GetLookups();

                        response.PageInfo = Request.GetPageInfo(client.SupportedTypes.Count);
                        int endIndex = response.PageInfo.StartIndex + response.PageInfo.ItemsCount;
                        for (int index = response.PageInfo.StartIndex; index < endIndex; index++)
                        {
                            ServiceModels.ObjectType objectType = new ServiceModels.ObjectType(client.SupportedTypes[index]);
                            if (definitions != null)
                            {
                                Model.ObjectDefinition definition = definitions.GetObjectDefinition(User.GetOrganisationID(), objectType.ObjectTypeID);
                                if (definition != null)
                                {
                                    objectType.AddSelfLink(string.Concat(rootUrl, "/clients/", clientID, "/objecttypes/", StringUtils.GuidEncode(definition.ObjectDefinitionID)), false, false);
                                    objectType.AddLink<ObjectDefinition>(Request, "definition", string.Concat(rootUrl, "/objecttypes/definitions/", StringUtils.GuidEncode(definition.ObjectDefinitionID)));
                                    objectType.AddLink("instances", string.Concat(rootUrl, "/clients/", clientID, "/objecttypes/", StringUtils.GuidEncode(definition.ObjectDefinitionID), "/instances"), Request.GetContentType(definition.MIMEType));
                                }
                            }
                            response.Add(objectType);
                        }
                    }
                    result = Request.GetObjectResult(response);
                }
                else
                {
                    result = new NotFoundResult();
                }
            }
            else
            {
                result = new BadRequestResult();
            }

            return result;
        }
Exemplo n.º 17
0
 public IActionResult RemovePSKIdentity(string identity)
 {
     IActionResult result;
     Model.PSKIdentity pskIdentity = BusinessLogicFactory.Identities.GetPSKIdentity(identity);
     if (pskIdentity == null)
         result = new NotFoundResult();
     else
     {
         BusinessLogicFactory.Identities.SavePSKIdentity(pskIdentity, Model.TObjectState.Delete);
         result = new NoContentResult();
     }
     return result;
 }
 public IActionResult GetSubscription(string subscriptionID)
 {
     IActionResult result;
     Guid subscriptionIDGuid;
     if (StringUtils.GuidTryDecode(subscriptionID, out subscriptionIDGuid))
     {
         Model.Subscription subscription = BusinessLogicFactory.Subscriptions.GetSubscription(subscriptionIDGuid);
         if (subscription == null)
             result = new NotFoundResult();
         else
         {
             ServiceModels.Subscription response = new ServiceModels.Subscription(subscription);
             string rootUrl = Request.GetRootUrl();
             response.AddSelfLink(string.Concat(rootUrl, "/subscriptions/", StringUtils.GuidEncode(subscription.SubscriptionID)), true, true);
             result = Request.GetObjectResult(response);
         }
     }
     else
     {
         result = new BadRequestResult();
     }
     return result;
 }
Exemplo n.º 19
0
 public IActionResult RemoveAccessKey(string key)
 {
     IActionResult result;
     Model.AccessKey accessKey = BusinessLogicFactory.AccessKeys.GetAccessKey(key);
     if (accessKey == null)
         result = new NotFoundResult();
     else
     {
         BusinessLogicFactory.AccessKeys.SaveAccessKey(accessKey, Model.TObjectState.Delete);
         result = new NoContentResult();
     }
     return result;
 }
        public IActionResult GetSubscriptions(string clientID, string definitionID, string instanceID)
        {
            Guid clientIDGuid = Guid.Empty;
            Guid definitionIDGuid = Guid.Empty;
            IActionResult result = null;

            if (clientID != null && !StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                result = new BadRequestResult();
            }
            else if (clientID != null && BusinessLogicFactory.Clients.GetClient(clientIDGuid) == null)
            {
                result = new NotFoundResult();
            }
            else if (definitionID != null && !StringUtils.GuidTryDecode(definitionID, out definitionIDGuid))
            {
                result = new BadRequestResult();
            }
            else if (definitionID != null && BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(User.GetOrganisationID(), definitionIDGuid) == null)
            {
                result = new NotFoundResult();
            }
            else
            {
                string rootUrl = Request.GetRootUrl();
                if (clientID != null)
                    rootUrl = string.Concat(rootUrl, "/clients/", clientID);
                if (definitionID != null)
                    rootUrl = string.Concat(rootUrl, "/objecttypes/", definitionID);
                if (instanceID != null)
                    rootUrl = string.Concat(rootUrl, "/instances/", instanceID);

                ServiceModels.Subscriptions response = new ServiceModels.Subscriptions();
                response.AddLink("add", string.Concat(rootUrl, "/subscriptions"), null);

                List<Model.Subscription> subscriptions = null;
                if (clientID == null)
                {
                    int organisationID = User.GetOrganisationID();
                    subscriptions = BusinessLogicFactory.Subscriptions.GetSubscriptions(organisationID);
                }
                else
                {
                    List<Model.Subscription> unfilteredSubscriptions = BusinessLogicFactory.Subscriptions.GetSubscriptions(clientIDGuid);

                    if (definitionID != null)
                    {
                        subscriptions = new List<Model.Subscription>();

                        foreach (Model.Subscription subscription in unfilteredSubscriptions)
                        {
                            if (definitionID == null || definitionIDGuid == subscription.ObjectDefinitionID)
                            {
                                if (instanceID == null || instanceID.Equals(subscription.ObjectID))
                                {
                                    subscriptions.Add(subscription);
                                }
                            }
                        }
                    }
                    else
                    {
                        subscriptions = unfilteredSubscriptions;
                    }
                }

                response.PageInfo = Request.GetPageInfo(subscriptions.Count);
                int endIndex = response.PageInfo.StartIndex + response.PageInfo.ItemsCount;
                for (int index = response.PageInfo.StartIndex; index < endIndex; index++)
                {
                    ServiceModels.Subscription subscription = new ServiceModels.Subscription(subscriptions[index]);
                    subscription.AddSelfLink(string.Concat(Request.GetRootUrl(), "/subscriptions/", StringUtils.GuidEncode(subscriptions[index].SubscriptionID)), true, true);
                    response.Add(subscription);
                }
                result = Request.GetObjectResult(response);
            }
            return result;
        }
Exemplo n.º 21
0
 public IActionResult GetPSKIdentity(string identity)
 {
     IActionResult result;
     Model.PSKIdentity pskIdentity = BusinessLogicFactory.Identities.GetPSKIdentity(identity);
     if (pskIdentity == null)
         result = new NotFoundResult();
     else
     {
         ServiceModels.PSKIdentity response = new ServiceModels.PSKIdentity(pskIdentity);
         string rootUrl = Request.GetRootUrl();
         response.AddSelfLink(string.Concat(rootUrl, "/identities/psk/", response.Identity), false, true);
         result = Request.GetObjectResult(response);
     }
     return result;
 }