コード例 #1
0
        // POST: api/Tags
        public async Task <IHttpActionResult> Post([FromBody] HTKLibrary.Classes.MDW.Tag value)
        {
            _client   = new MongoClient(connectionString);
            _database = _client.GetDatabase("mdw+service");
            var _collection = _database.GetCollection <HTKLibrary.Classes.MDW.Tag>("tags");

            _collection.InsertOne(value);
            return(Ok());
        }
コード例 #2
0
        // GET: api/Tags/5
        public IEnumerable <HTKLibrary.Classes.MDW.Tag> Get(string from)
        {
            List <HTKLibrary.Classes.MDW.Tag> TagList = new List <HTKLibrary.Classes.MDW.Tag>();

            //if (LocalIP.Get() == server)
            //{
            _client   = new MongoClient(connectionString);
            _database = _client.GetDatabase("mdw+service");
            var _collection = _database.GetCollection <BsonDocument>("tags");
            var filter      = Builders <BsonDocument> .Filter.Gt("timestamp", from);

            var found = _collection.Find(filter).Sort(Builders <BsonDocument> .Sort.Ascending("timestamp")).ToList();

            foreach (BsonDocument item in found)
            {
                HTKLibrary.Classes.MDW.Tag tag = new HTKLibrary.Classes.MDW.Tag();
                if (item.Contains("epc"))
                {
                    tag.epc = item.GetElement("epc").Value.AsString;
                }

                if (item.Contains("direction"))
                {
                    tag.direction = item.GetElement("direction").Value.AsDouble;
                }

                if (item.Contains("erasetime"))
                {
                    tag.erasetime = item.GetElement("erasetime").Value.AsDouble;
                }

                if (item.Contains("ip"))
                {
                    tag.ip = item.GetElement("ip").Value.AsString;
                }

                if (item.Contains("rssi"))
                {
                    tag.rssi = item.GetElement("rssi").Value.AsDouble;
                }

                if (item.Contains("timestamp"))
                {
                    tag.timestamp = item.GetElement("timestamp").Value.AsString;
                }

                TagList.Add(tag);
            }
            return(TagList);
        }