Beispiel #1
0
        private void GetItemsFromDB()
        {
            this.itemsInDBValue.Items.Clear();
            this._itemList.Clear();

            if (ConnectedToDB)
            {
                MongoCursor <BsonDocument> result = null;
                if (string.IsNullOrEmpty(filterValue.Text))
                {
                    result = MongoUtils.MongoData.GetCollection("World", "Items").FindAllAs <BsonDocument>();
                }
                else
                {
                    if (filterTypeValue.Text == "_id")
                    {
                        result = MongoUtils.MongoData.GetCollection("World", "Items").FindAs <BsonDocument>(Query.EQ(filterTypeValue.Text, ObjectId.Parse(filterValue.Text)));
                    }
                    else
                    {
                        result = MongoUtils.MongoData.GetCollection("World", "Items").FindAs <BsonDocument>(Query.EQ(filterTypeValue.Text, filterValue.Text));
                    }
                }

                if (result != null)
                {
                    _itemList = result.ToList <BsonDocument>();
                }

                foreach (BsonDocument doc in result)
                {
                    this.itemsInDBValue.Items.Add(doc["Name"].AsString);
                }
            }
        }
Beispiel #2
0
        private void DodajSmestajForm_Load(object sender, EventArgs e)
        {
            if (azuriranje != null)
            {
                txtTip.Text        = azuriranje.Tip;
                txtNaziv.Text      = azuriranje.Naziv;
                txtAdresa.Text     = azuriranje.Adresa;
                txtBroj.Text       = azuriranje.BrojZvezdica;
                cbxOpstina.Enabled = false;
                //cbxOpstina.Text = azuriranje.Opstina.ToString();
            }

            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var database         = server.GetDatabase("TouristGuide");

            var collection = database.GetCollection <Entities.Opstina>("opstine");


            MongoCursor <Entities.Opstina> opstine = collection.FindAll();


            foreach (Entities.Opstina o in opstine.ToList <Entities.Opstina>())
            {
                cbxOpstina.Items.Add(o.Naziv);
            }
        }
Beispiel #3
0
        private void DodajFakultetForm_Load(object sender, EventArgs e)
        {
            if (azuriranje != null)
            {
                txtNaziv.Text      = azuriranje.Naziv;
                txtAdresa.Text     = azuriranje.Adresa;
                cbxOpstina.Enabled = false;
                comboBox1.Enabled  = false;
                //cbxOpstina.Text = azuriranje.Opstina.ToString();
            }

            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var database         = server.GetDatabase("TouristGuide");

            var collection = database.GetCollection <Entities.Opstina>("opstine");

            var facultyCollection = database.GetCollection <Univerzitet>("univerziteti");

            MongoCursor <Univerzitet> univerziteti = facultyCollection.FindAll();

            MongoCursor <Entities.Opstina> opstine = collection.FindAll();


            foreach (Entities.Opstina o in opstine.ToList <Entities.Opstina>())
            {
                cbxOpstina.Items.Add(o.Naziv);
            }

            foreach (Univerzitet u in univerziteti.ToList <Univerzitet>())
            {
                comboBox1.Items.Add(u.Naziv);
            }
        }
Beispiel #4
0
        public string PricingPlanFinished(PricingPlan plan)
        {
            string result = "";

            try
            {
                MongoDBHelper <PricingPlan> mongo_plan = new MongoDBHelper <PricingPlan>();
                QueryDocument query = new QueryDocument();
                query.Add("MeterNo", plan.MeterNo);
                MongoCursor <PricingPlan> mongoCursor = mongo_plan.Query(CollectionNameDefine.MeterPricingPlan, query);
                var dataList = mongoCursor.ToList();
                if (dataList != null && dataList.Count >= 1)
                {
                    //删除老计划
                    List <string> list = new List <string>();
                    foreach (PricingPlan p in dataList)
                    {
                        list.Add(p._id.ToString());
                    }

                    var iDelete = new QueryDocument();
                    iDelete.Add("MeterNo", plan.MeterNo);

                    mongo_plan.Delete(CollectionNameDefine.MeterPricingPlan, iDelete);
                }
            }
            catch (Exception e)
            {
                result = e.Message;
            }

            return(result);
        }
        /// <summary>
        /// 分页查询 指定索引最后项-PageSize模式
        /// </summary>
        /// <typeparam name="T">所需查询的数据的实体类型</typeparam>
        /// <param name="query">查询的条件 没有可以为null</param>
        /// <param name="indexName">索引名称</param>
        /// <param name="lastKeyValue">最后索引的值</param>
        /// <param name="pageSize">分页的尺寸</param>
        /// <param name="sortType">排序类型 1升序 -1降序 仅仅针对该索引</param>
        /// <param name="collectionName">指定的集合名称</param>
        /// <returns>返回一个List列表数据</returns>
        public List <T> Find <T>(IMongoQuery query, string indexName, object lastKeyValue, int pageSize, int sortType, string collectionName)
        {
            MongoCollection <T> mc          = this._db.GetCollection <T>(collectionName);
            MongoCursor <T>     mongoCursor = null;

            query = this.InitQuery(query);
            //判断升降序后进行查询
            if (sortType > 0)
            {
                //升序
                if (lastKeyValue != null)
                {
                    //有上一个主键的值传进来时才添加上一个主键的值的条件
                    query = Query.And(query, Query.GT(indexName, BsonValue.Create(lastKeyValue)));
                }
                //先按条件查询 再排序 再取数
                mongoCursor = mc.Find(query).SetSortOrder(new SortByDocument(indexName, 1)).SetLimit(pageSize);
            }
            else
            {
                //降序
                if (lastKeyValue != null)
                {
                    query = Query.And(query, Query.LT(indexName, BsonValue.Create(lastKeyValue)));
                }
                mongoCursor = mc.Find(query).SetSortOrder(new SortByDocument(indexName, -1)).SetLimit(pageSize);
            }
            return(mongoCursor.ToList <T>());
        }
Beispiel #6
0
        public List <T> GetCustomeAll(string action1, string action2)
        {
            var             query  = Query.EQ(action1, action2);
            MongoCursor <T> cursor = _collection.Find(query);

            return(cursor.ToList());
        }
Beispiel #7
0
        public List <Info> Read <Info>() where Info : class, IModel, new()
        {
            List <Info> itemList = new List <Info>();
            MongoCursor <BsonDocument> cursor  = GetCollection <Info>().FindAllAs <BsonDocument>();
            List <BsonDocument>        docList = cursor.ToList <BsonDocument>();

            foreach (BsonDocument doc in docList)
            {
                Info item = new Info();
                foreach (string name in doc.Names)
                {
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        continue;
                    }
                    var _name = name.ToLower();
                    if (_name == "_id" || _name == "id")
                    {
                        item.SetPropertyValue("Id", doc[name].ToString());
                    }
                    else if (doc[name].IsBsonBinaryData)
                    {
                        item.SetPropertyValue(name, doc[name].AsByteArray);
                    }
                    else
                    {
                        item.SetPropertyValue(name, doc[name].ToString());
                    }
                }
                itemList.Add(item);
            }
            return(itemList);
        }
Beispiel #8
0
        private void LoadGrid()
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var database         = server.GetDatabase("TouristGuide");

            var collection = database.GetCollection <Entities.Smestaj>("smestaji");

            MongoCursor <Entities.Smestaj> smestaji = collection.FindAll();

            List <Smestaj> sm = new List <Smestaj>();

            foreach (Smestaj o in smestaji.ToList <Smestaj>())
            {
                sm.Add(o);
            }

            dataGridView1.DataSource = sm;
            foreach (DataGridViewColumn s in dataGridView1.Columns)
            {
                s.Visible = true;
                if (s.HeaderText == "Id")
                {
                    s.Visible = false;
                }
                if (s.HeaderText == "Opstina")
                {
                    s.Visible = false;
                }
            }
        }
        public ActionResult <DeveloperResponses> FetchAll()
        {
            try
            {
                //prepare responses
                DeveloperResponses      responses = new DeveloperResponses();
                MongoCursor <Developer> results   = context.Developer.FindAll();

                //test for emptiness
                if (results.Count() == 0)
                {
                    return(NotFound(new { Message = Constants.Empty_List }));
                }
                responses.Status = true;

                //return data
                responses.Data = results.ToList();
                return(Ok(responses));
            }
            catch (Exception ex)
            {
                Log.LogError(ex);
                return(StatusCode(500, ex.ToString()));
            }
        }
Beispiel #10
0
        public ActionResult <DeveloperResponses> FetchByStack(int stack)
        {
            try
            {
                //initialize response
                DeveloperResponses responses = new DeveloperResponses();
                IMongoQuery        query     = Query <Developer> .EQ(d => (int)d.Stack, stack);

                MongoCursor <Developer> listed = context.Developer.Find(query);
                if (listed.Count() == 0)
                {
                    return(NotFound(new { Message = Constants.Non_Exist }));
                }

                responses.Data = listed.ToList();

                //prepare response
                responses.Status = true;
                return(Ok(responses));
            }
            catch (Exception ex)
            {
                Log.LogError(ex);
                return(StatusCode(500, ex.ToString()));
            }
        }
Beispiel #11
0
        private void LoadGrid()
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var database         = server.GetDatabase("TouristGuide");

            var collection = database.GetCollection <Entities.Banka>("banke");

            MongoCursor <Entities.Banka> banke = collection.FindAll();

            List <Entities.Banka> bankice = new List <Entities.Banka>();

            foreach (Entities.Banka o in banke.ToList <Entities.Banka>())
            {
                bankice.Add(o);
            }

            dataGridView1.DataSource = bankice;
            foreach (DataGridViewColumn s in dataGridView1.Columns)
            {
                if (s.HeaderText == "Id")
                {
                    s.Visible = false;
                }
                if (s.HeaderText == "Opstina")
                {
                    s.Visible = false;
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// 获取列表top几
        /// </summary>
        /// <param name="sortByMap"> var sort = new SortByDocument { { "_id", -1 } }; ->这里1为ASC, -1为DESC</param>
        /// <returns></returns>
        public List <T> List(Expression <Func <T, bool> > filter, Dictionary <string, sbyte> sortByMap = null, int?top = null)
        {
            MongoCursor <T> cursor = null;

            if (null != filter)
            {
                var findQuery = Query <T> .Where(filter);

                cursor = this._mongoCollection.Find(findQuery);
            }
            else
            {
                cursor = this._mongoCollection.FindAll();
            }

            if (null != sortByMap)
            {
                var orderByQuery = new SortByDocument(sortByMap);
                cursor = cursor.SetSortOrder(orderByQuery);
            }

            if (top.HasValue)
            {
                List <T> list = cursor.SetLimit(top.Value).ToList();
                return(list);
            }
            return(cursor.ToList());
        }
Beispiel #13
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            MongoDBHelper <CY.IoTM.Common.Business.Task> mongo = new MongoDBHelper <CY.IoTM.Common.Business.Task>();
            List <CY.IoTM.Common.Business.Task>          list  = new List <CY.IoTM.Common.Business.Task>();

            QueryDocument query = new QueryDocument();

            if (this.comboBox1.Text != "全部")
            {
                if (this.comboBox1.Text == "等待")
                {
                    query.Add("TaskState", 0);
                }
                else if (this.comboBox1.Text == "撤销")
                {
                    query.Add("TaskState", 1);
                }
                else if (this.comboBox1.Text == "已完成")
                {
                    query.Add("TaskState", 2);
                }
                else if (this.comboBox1.Text == "失败")
                {
                    query.Add("TaskState", 3);
                }
            }
            MongoCursor <CY.IoTM.Common.Business.Task> mongoCursor = mongo.Query("Task", query);

            if (mongoCursor != null)
            {
                var dataList = mongoCursor.ToList();

                this.bindingSource1.DataSource = dataList;
            }
        }
Beispiel #14
0
        public static List <T> Find <T>(string connectionName, string database, string collection, MongoQueryWarpper querys, int pageindex, int pagesize, string[] fields, MongoSortWarpper sorts)
        {
            var mongoquery      = querys == null ? Query.Null : querys.MongoQuery;
            var mongocollection = GetCollecion <T>(connectionName, database, collection);
            var mongosortby     = (sorts == null || sorts.MongoSortBy == SortBy.Null) ? SortBy.Null : sorts.MongoSortBy;
            int skip            = (pageindex - 1) * pagesize;

            MongoCursor <T> mongocursor = null;

            if (mongosortby != SortBy.Null)
            {
                mongocursor = mongocollection.FindAs <T>(mongoquery).SetSkip(skip).SetLimit(pagesize).SetSortOrder(mongosortby);
            }
            else
            {
                mongocursor = mongocollection.FindAs <T>(mongoquery).SetSkip(skip).SetLimit(pagesize);
            }

            if (fields != null && fields.Length > 0)
            {
                mongocursor = mongocursor.SetFields(fields);
            }

            List <T> list = mongocursor.ToList();

            return(list);
        }
Beispiel #15
0
        private void LoadGrid()
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var database         = server.GetDatabase("TouristGuide");

            var collection = database.GetCollection <Entities.Nasledje>("nasledja");

            MongoCursor <Entities.Nasledje> nasledja = collection.FindAll();

            List <Nasledje> nasl = new List <Nasledje>();

            foreach (Nasledje o in nasledja.ToList <Nasledje>())
            {
                nasl.Add(o);
            }

            dataGridView1.DataSource = nasl;
            foreach (DataGridViewColumn s in dataGridView1.Columns)
            {
                s.Visible = true;
                if (s.HeaderText == "Id")
                {
                    s.Visible = false;
                }
                if (s.HeaderText == "Opstina")
                {
                    s.Visible = false;
                }
            }
        }
Beispiel #16
0
        public string NewPricingPlan(PricingPlan plan)
        {
            string result = "";

            try
            {
                MongoDBHelper <PricingPlan> mongo_plan = new MongoDBHelper <PricingPlan>();
                QueryDocument query = new QueryDocument();
                query.Add("MeterNo", plan.MeterNo);
                MongoCursor <PricingPlan> mongoCursor = mongo_plan.Query(CollectionNameDefine.MeterPricingPlan, query);
                var dataList = mongoCursor.ToList();
                if (dataList != null && dataList.Count >= 1)
                {
                    var iDelete = new QueryDocument();
                    iDelete.Add("MeterNo", plan.MeterNo);

                    //删除老计划
                    mongo_plan.Delete(CollectionNameDefine.MeterPricingPlan, iDelete);
                }

                mongo_plan.Insert(CollectionNameDefine.MeterPricingPlan, plan);
            }
            catch (Exception e) {
                result = e.Message;
            }
            return(result);
        }
Beispiel #17
0
        public List <Task> GetTaskList(string mac)
        {
            List <Task> list = new List <Task> ();

            try
            {
                MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
                QueryDocument        query = new QueryDocument();
                query.Add("MeterMac", mac);
                query.Add("TaskState", 0);
                MongoCursor <Task> mongoCursor = mongo.Query(CollectionNameDefine.TaskCollectionName, query);
                var dataList = mongoCursor.ToList();
                foreach (Task task in dataList)
                {
                    if (task.TaskType != TaskType.TaskType_校准)
                    {
                        task.CommandList.AddRange(CommandDA.QueryCommandList(task.TaskID));
                        list.Add(task);
                    }
                }
            }
            catch (Exception e)
            {
                //记录日志
                Console.WriteLine(e.Message);
            }
            return(list);
        }
Beispiel #18
0
        public static List <Trening> SviTreninzi()
        {
            MongoCollection <Trening> treninziCollection = Connection <Trening> .getCollection("treninzi");

            MongoCursor <Trening> treninzi = treninziCollection.FindAll();

            return(treninzi.ToList <Trening>());
        }
Beispiel #19
0
        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="bsonElements"></param>
        /// <returns></returns>
        public List <T> QueryDatas <T>(string field, string value)
        {
            var query = Query.Matches(field, new BsonRegularExpression(new Regex(value, RegexOptions.IgnoreCase)));

            MongoCursor <T> mc = mongoCollection.FindAs <T>(query);

            return(mc.ToList());
        }
Beispiel #20
0
        public static List <Vezba> SveVezbe()
        {
            MongoCollection <Vezba> vezbeCollection = Connection <Vezba> .getCollection("vezbe");

            MongoCursor <Vezba> vezbe = vezbeCollection.FindAll();

            return(vezbe.ToList <Vezba>());
        }
        /// <summary>
        /// 查询一个集合中的所有数据
        /// </summary>
        /// <typeparam name="T">该集合数据的所属类型</typeparam>
        /// <param name="collectionName">指定集合的名称</param>
        /// <returns>返回一个List列表</returns>
        public List <T> FindAll <T>(string collectionName)
        {
            MongoCollection <T> mc = this._db.GetCollection <T>(collectionName);
            //以实体方式取出其数据集合
            MongoCursor <T> mongoCursor = mc.FindAll();

            //直接转化为List返回
            return(mongoCursor.ToList <T>());
        }
        public List <T> getAll <T>()
        {
            var             db         = server.GetDatabase(instanceName);
            var             collection = db.GetCollection <T>("Game");
            MongoCursor <T> cursor     = collection.FindAll();
            List <T>        entities   = cursor.ToList();

            return(entities);
        }
        /// <summary>
        /// 根据指定条件查询集合中的数据
        /// </summary>
        /// <typeparam name="T">该集合数据的所属类型</typeparam>
        /// <param name="query">指定的查询条件 比如Query.And(Query.EQ("username","admin"),Query.EQ("password":"******"))</param>
        /// <param name="collectionName">指定的集合的名称</param>
        /// <returns>返回一个List列表</returns>
        public List <T> Find <T>(IMongoQuery query, string collectionName)
        {
            MongoCollection <T> mc = this._db.GetCollection <T>(collectionName);

            query = this.InitQuery(query);
            MongoCursor <T> mongoCursor = mc.Find(query);

            return(mongoCursor.ToList <T>());
        }
Beispiel #24
0
 private List <IPerson> LoadRecords(MongoCursor <IPerson> records)
 {
     if (allrecords == null)
     {
         Trace.WriteLine("Loading Data...");
         allrecords = records.ToList <IPerson>();
     }
     return(allrecords);
 }
        public List <IUserAuthDetails> GetUserAuthDetails(string userAuthId)
        {
            IMongoQuery query = Query.EQ("UserAuthId", int.Parse(userAuthId));

            var collection = mongoDatabase.GetCollection <UserAuthDetails>(UserOAuthProvider_Col);
            MongoCursor <UserAuthDetails> queryResult = collection.Find(query);

            return(queryResult.ToList().Cast <IUserAuthDetails>().ToList());
        }
Beispiel #26
0
        public List <Company> GetCompanies()
        {
            List <Company> lstCompanies = new List <Company>();

            MongoCursor <Company> cursor = Companies.FindAll();

            lstCompanies = cursor.ToList <Company>();

            return(lstCompanies);
        }
Beispiel #27
0
//        static void Main(string[] args)
//        {
//            //连接信息
//            string conn = "mongodb://192.168.1.2:27017";
//            string database = "IoTMeter";
//            string collection = "CommLog";
//            MongoServerSettings msSettings = new MongoServerSettings();
//            MongoClient mongoClient = new MongoClient(conn);
//            //mongoClient.Settings.Server = new MongoServerAddress("192.168.1.2", 27017);
//            //mongoClient.Settings.SocketTimeout = new TimeSpan(0, 0, (int)(1000 / 1000));

//            MongoServer mongodb = mongoClient.GetServer();// MongoServer.Create(conn);//连接数据库new MongoServer(msSettings); //
//            MongoDB.Driver.MongoDatabase mongoDataBase = mongodb.GetDatabase(database);//选择数据库名
//            if(!mongoDataBase.CollectionExists(collection))
//                mongoDataBase.CreateCollection(collection);

//            MongoDB.Driver.MongoCollection mongoCollection = mongoDataBase.GetCollection(collection);//选择集合,相当于表

//            mongodb.Connect();

//            //BsonDocument bsonDocumnet = new BsonDocument();
//            //bsonDocumnet.Add("Name", "武");
//            //List<BsonValue> list = new List<BsonValue> ();
//            //list.Add ("武宜波");
//            MongoCursor<Person> cursor = mongoCollection.FindAs<Person>(Query.EQ("Name","武宜波"));

//            var dataList = cursor.ToList();// cursor.Where<Person>(p1 => p1.Name == "武宜波");
//            foreach (Person doc in dataList)
//            {
//                Console.WriteLine("{0}", doc.ToJson());

//            }



//            /*---------------------------------------------
//* sql : SELECT * FROM table
//*---------------------------------------------
//*/
//            MongoCursor<Person> p = mongoCollection.FindAllAs<Person>();
//            long perCount = p.Count();
//            Console.WriteLine("{0}", perCount);

//            //普通插入
//            var o = new { Uid = 15, Name = "武宜波", PassWord = "******" };
//            mongoCollection.Insert(o);

//            //对象插入
//            Person person = new Person { Uid = 102, Name = "IoTMeter", PassWord = "******", Car = new Car { _id = ObjectId.GenerateNewId(), Name="baoma",arge=40} };
//            mongoCollection.Insert(person);

//            //BsonDocument 插入
//            MongoDB.Bson.BsonDocument b = new MongoDB.Bson.BsonDocument();
//            b.Add("Uid", 125);
//            b.Add("Name", "郑州创源");
//            b.Add("PassWord", "333333");
//            mongoCollection.Insert(b);


//            /*---------------------------------------------
//             * sql : SELECT * FROM table WHERE Uid > 10 AND Uid < 20
//             *---------------------------------------------
//             */
//            QueryDocument query = new QueryDocument();
//            b = new BsonDocument();
//            b.Add("$gt", 10);
//            b.Add("$lt", 20);
//            query.Add("Uid", b);


//            MongoCursor<Person> m = mongoCollection.FindAs<Person>(query);
//            Print(m);

//            /*-----------------------------------------------
//             * sql : SELECT COUNT(*) FROM table WHERE Uid > 10 AND Uid < 20
//             *-----------------------------------------------
//             */
//            long c = mongoCollection.Count(query);

//            /*-----------------------------------------------
//            * sql : SELECT Name FROM table WHERE Uid > 10 AND Uid < 20
//            *-----------------------------------------------
//            */
//            query = new QueryDocument();
//            b = new BsonDocument();
//            b.Add("$gt", 20);
//            b.Add("$lt", 200);
//            query.Add("Uid", b);
//            FieldsDocument f = new FieldsDocument();
//            f.Add("Name", 1);

//            m = mongoCollection.FindAs<Person>(query).SetFields(f);
//            Print(m);

//            /*-----------------------------------------------
//            * sql : SELECT * FROM table ORDER BY Uid DESC LIMIT 10,10
//            *-----------------------------------------------
//            */
//            query = new QueryDocument();
//            SortByDocument s = new SortByDocument();
//            s.Add("Uid", -1);//-1=DESC

//            m = mongoCollection.FindAllAs<Person>().SetSortOrder(s).SetSkip(10).SetLimit(10);
//            Print(m);

//            Console.ReadLine();
//        }
        static void Print(MongoCursor <Person> persons)
        {
            //Console.WriteLine(persons.ToJson());
            var list = persons.ToList(); //<Person>();

            foreach (var p in list)
            {
                Console.WriteLine(p.ToJson());
            }
        }
Beispiel #28
0
        /// <summary>
        /// Search for documents containing the searched value, that is a field of an object in array of objects array e.g. { contacts: [{name: "john", id: 1}, {name: "sarah", id: 2}, {name: "matt", id=3}] }
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public List <T> SearchObjectArray <T>(string arrayName, string key, string value) where T : class, new()
        {
            string command = "{ \"" + arrayName + "\" : { $elemMatch : { \"" + key + "\": \"" + value + "\" } } }";
            var    bsonDoc = BsonSerializer.Deserialize <BsonDocument>(command);
            var    query   = new QueryDocument(bsonDoc);

            MongoCursor <T> cursor = mongoDb.GetCollection <T>(GetTypeName(typeof(T))).Find(query);

            return(cursor.ToList());
        }
Beispiel #29
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var database         = server.GetDatabase("TouristGuide");

            var gradovi      = database.GetCollection <Grad>("gradovi");
            var opstine      = database.GetCollection <Opstina>("opstine");
            var univerziteti = database.GetCollection <Univerzitet>("univerziteti");

            MongoCursor <Grad>        grads        = gradovi.FindAll();
            MongoCursor <Opstina>     opstinas     = opstine.FindAll();
            MongoCursor <Univerzitet> univerzitets = univerziteti.FindAll();

            Grad g = new Grad {
                Ime = "Nis", BrojStanovnika = "200000"
            };

            if (grads.ToList <Grad>().Count == 0)
            {
                gradovi.Insert(g);
            }

            Opstina o1 = new Opstina {
                Naziv = "Palilula", BrojStanovnika = "30000"
            };
            Opstina o2 = new Opstina {
                Naziv = "Medijana", BrojStanovnika = "20000"
            };

            if (opstinas.ToList <Opstina>().Count == 0)
            {
                o1.Grad = new MongoDBRef("gradovi", g.Id);
                opstine.Insert(o1);
                g.Opstine.Add(new MongoDBRef("opstine", o1.Id));
                gradovi.Save(g);
                o2.Grad = new MongoDBRef("gradovi", g.Id);
                opstine.Insert(o2);
                g.Opstine.Add(new MongoDBRef("opstine", o2.Id));
                gradovi.Save(g);
            }


            Univerzitet u = new Univerzitet {
                Naziv = "Niski"
            };

            if (univerzitets.ToList <Univerzitet>().Count == 0)
            {
                u.Grad = new MongoDBRef("gradovi", g.Id);
                univerziteti.Insert(u);
                g.Univerziteti.Add(new MongoDBRef("univerziteti", u.Id));
                gradovi.Save(g);
            }
        }
Beispiel #30
0
        public List <Ustanova> vratiPrevoz()
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var db = server.GetDatabase("TouristGuide");

            var collection = db.GetCollection <Ustanova>("ustanove");
            MongoCursor <Ustanova> opstina = collection.FindAll();

            return(opstina.ToList <Ustanova>());
        }
Beispiel #31
0
        private void DataLoaded(MongoCursor<BsonDocument> data)
        {
            try
            {
                if (data == null)
                {
                    return;
                }

                bool alt = true;
                _nextItemId = 0;
                data.ToList().ForEach(item => { AddItems(item.ToArray(), 0, alt, null, item["_id"].AsBsonValue); alt = !alt; });
                _pager.PropertyChanged += PagerPropertyChanged;
            }
            catch (Exception ex)
            {
                Utilities.LogException(ex);
            }
            finally
            {
                if (BusyStateChanged != null) BusyStateChanged(false, null);
            }
        }