PixelLocator.cs 1.48 KB
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AIAHTML5.API.Models
{
    public class PixelLocator
    {

        internal static dynamic GetBodyRegionsPixelData(string layerNumber, string bodyViewIndex, string systemNumber, string zoom)
        {
            var client = new MongoClient("mongodb://192.168.90.43:27017");
            var db = client.GetDatabase("aia");

            var col = db.GetCollection<BsonDocument>("DAImages");

            var pipeline = new BsonDocument[] 
            {
                new BsonDocument{{"$unwind", "$terms"}},
                new BsonDocument{ { "$match", new BsonDocument("terms.SystemNumbers",
                                                    Convert.ToInt32(systemNumber)).Add("bodyViewIndex", 
                                                    Convert.ToInt32(bodyViewIndex)).Add("layerNumber", 
                                                    Convert.ToInt32(layerNumber)).Add("zoom", 
                                                    Convert.ToInt32(zoom)) }},
                new BsonDocument { {"$project", new BsonDocument()
                    .Add("_id", 0)
                    .Add("terms", 1)
                    .Add("bodyRegionId", 1)
                    } }
            };


            var pixelData = col.Aggregate<BsonDocument>(pipeline).ToList();

            return pixelData.ToJson();
        }
}
}