Exemplo n.º 1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "categories")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            CosmosGraphClient cosmosGraphClient = new CosmosGraphClient();

            string cloud_id = req.Query["cloud_id"];


            string projectStr = cosmosGraphClient.BuildProjectString(new List <string> {
                "id", "label", "name"
            });
            string q;

            if (cloud_id != null)
            {
                q = String.Format("g.V('{0}').in('source_cloud')", cloud_id);
            }
            else
            {
                q = "g.V().hasLabel('category')";
            }
            q += projectStr;

            var records = cosmosGraphClient.Query(q);

            return(new OkObjectResult(records));
        }
Exemplo n.º 2
0
 public CosmosDBConfig()
 {
     _graphClient = new Lazy <ICosmosGraphClient>(
         () =>
     {
         return(CosmosGraphClient.GetCosmosClient(Account, Database, Collection, AuthKey));
     });
 }
Exemplo n.º 3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "services/{service_id?}")] HttpRequest req,
            string service_id,
            ILogger log)
        {
            CosmosGraphClient cosmosGraphClient = new CosmosGraphClient();

            string cloud_id    = req.Query["cloud_id"];
            string category_id = req.Query["category_id"];


            string q;
            string projectStr = cosmosGraphClient.BuildProjectString(new List <string> {
                "id", "label", "name", "short_description", "long_description", "uri", "icon_uri"
            });


            if (service_id != null)
            {
                q = String.Format(@"g.V('{0}')
                        .project(
                            'id', 'label', 'name', 'shortDescription',
                            'longDescription', 'uri', 'iconUri', 'relatedServices'
                        ).by('id').by('label').by('name').by('short_description')
                        .by('long_description').by('uri').by('icon_uri')
                        .by(coalesce(
                            out('related_service').project('id', 'name').by('id').by('name'),
                            constant([]))
                        )", service_id);
            }
            else if (category_id != null)
            {
                q = String.Format("g.V('{0}').in('belongs_to'){1}", category_id, projectStr);
            }
            else if (cloud_id != null)
            {
                var cloudIdRes = cosmosGraphClient.Query(String.Format("g.V('{0}').values('abbreviation')", cloud_id));
                if (cloudIdRes.Count == 1)
                {
                    q = String.Format("g.V().hasLabel('{0}_category').in('belongs_to'){1}", cloudIdRes[0], projectStr);
                }
                else
                {
                    return(new BadRequestObjectResult(String.Format("Invalid cloud_id parameter. {0} does not exist", cloud_id)));
                }
            }
            else
            {
                return(new BadRequestObjectResult("You must supply one of cloud_id, category_id or service_id"));
            }

            var records = cosmosGraphClient.Query(q);

            return(new OkObjectResult(records));
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "clouds")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string            q = "g.V().hasLabel('cloud').project('id', 'name', 'abbreviation').by('id').by('name').by('abbreviation')";
            CosmosGraphClient cosmosGraphClient = new CosmosGraphClient();
            var records = cosmosGraphClient.Query(q);

            return(new OkObjectResult(records));
        }
Exemplo n.º 5
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "gremlin")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            CosmosGraphClient cosmosGraphClient = new CosmosGraphClient();

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);
            string  query       = data?.query;

            ActionResult res;

            if (query == null || query.Contains("drop") || query.Contains("add"))
            {
                res = new BadRequestObjectResult("Please pass a valid gremlin traversal query. Queries that add, update or delete vertices or edges are not allowed.");
            }
            else
            {
                var records = cosmosGraphClient.Query(query);
                res = new OkObjectResult(records);
            }
            return(res);
        }