Exemplo n.º 1
0
        public static void injectRecord(RecordObject rec)
        {
            try
            {
                BsonDocument doc = new BsonDocument
                {
                    { "Time", rec.Time },
                    { "Operation", rec.Operation },
                    { "Key", rec.KeyWord },
                    { "Window", rec.Window }
                };

                MongoDBUtils.RecordsCollection.InsertOne(doc);
            }
            catch
            {
                MongoDBUtils.Connect();
            }
        }
Exemplo n.º 2
0
        public async static Task <List <RecordObject> > RetriveRecordsAfter(long time)
        {
            List <RecordObject> recordsToReturn = new List <RecordObject>();

            MongoDBUtils.RecordsCollection = Database.GetCollection <BsonDocument>("Records");
            var    builder = Builders <BsonDocument> .Filter;
            var    filter = builder.Gt("Time", time);
            long   timeO = 0;
            string operation = string.Empty, key = string.Empty, window = string.Empty;
            var    sort = Builders <BsonDocument> .Sort.Ascending("Time");

            var result = await MongoDBUtils.RecordsCollection.Find(filter).Sort(sort).ToListAsync();

            foreach (BsonDocument res in result)
            {
                foreach (BsonElement el in res)
                {
                    if (el.Name.Equals("Time"))
                    {
                        timeO = (long)el.Value;
                    }
                    else if (el.Name.Equals("Operation"))
                    {
                        operation = (string)el.Value;
                    }
                    else if (el.Name.Equals("Key"))
                    {
                        key = (string)el.Value;
                    }
                    else if (el.Name.Equals("Window"))
                    {
                        window = (string)el.Value;
                    }
                }

                RecordObject obj = new RecordObject(timeO, operation, key, window);
                recordsToReturn.Add(obj);
            }
            return(recordsToReturn);
        }
Exemplo n.º 3
0
        public void insertRecord(RecordObject record)
        {
            //using (SqlConnection conn = new SqlConnection(sqlCon))
            //{
            //    if (conn.State == ConnectionState.Closed)
            //    {
            //        conn.Open();
            //        SqlCommand command =
            //            new SqlCommand("INSERT INTO Records " +
            //                           "VALUES(" +
            //                           record.Time + ", " +
            //                           record.Operation + ", " +
            //                           record.KeyWord + ", " +
            //                           record.Window + ");",
            //                           conn);

            //        command.ExecuteReader();
            //    }
            //}

            MongoDBUtils.injectRecord(record);
        }