示例#1
0
        public void SetUp()
        {
            var configure = new MongoConfigurationBuilder();

            configure.ConnectionStringAppSettingKey("mongoserver");
            config = configure.BuildConfiguration();
        }
        public void SetUp()
        {
            var configure = new MongoConfigurationBuilder();

            configure.ConnectionStringAppSettingKey("mongoserver");
            config = configure.BuildConfiguration();
            SessionStateItemCollection  sessionItemsCollection  = new SessionStateItemCollection();
            HttpStaticObjectsCollection staticObjectsCollection = new HttpStaticObjectsCollection();

            item = new SessionStateStoreData(sessionItemsCollection, staticObjectsCollection, 1);
        }
示例#3
0
        private static MongoConfiguration GetConfiguration <T>() where T : class
        {
            var config = new MongoConfigurationBuilder();

            config.Mapping(mapping =>
            {
                mapping.DefaultProfile(d => d.SubClassesAre(s => s.IsSubclassOf(typeof(T))));
                mapping.Map <T>();
            });

            config.ConnectionString(Resources.ConnectionString);

            return(config.BuildConfiguration());
        }
示例#4
0
        //  为Mongo 提供 MongoConfiguration
        public MongoConfiguration InitMongoBuilder(string ConnString)
        {
            var config = new MongoConfigurationBuilder();

            //加入连接字符串
            config.ConnectionString(ConnString);
            //映射公共类
            BaseMapping mapping = new BaseMapping();

            //向映射公共类注册自己定义映射
            mapping.AddMapping(new MyMapping().Mapping);
            //传入公共类的执行方法
            config.Mapping(mapping.ForeachMapping);
            return(config.BuildConfiguration());
        }
示例#5
0
        private Mongo GetMongo()
        {
            var config = new MongoConfigurationBuilder();

            config.Mapping(mapping =>
            {
                mapping.DefaultProfile(profile =>
                {
                    profile.SubClassesAre(t => t.IsSubclassOf(typeof(T)));
                });
                mapping.Map <T>();
            });
            config.ConnectionString(connectionString);
            return(new Mongo(config.BuildConfiguration()));
        }
示例#6
0
        private static MongoConfiguration BuildMongoConfiguration(ITypeCatalog snapshotTypeCatalog, string connectionString)
        {
            var configurationBuilder = new MongoConfigurationBuilder();

            configurationBuilder.ConnectionString(connectionString);
            configurationBuilder.Mapping(mapping =>
            {
                mapping.DefaultProfile(profile => profile.SubClassesAre(type => type.IsSubclassOf(typeof(Snapshot))));
                snapshotTypeCatalog
                .GetDerivedTypes(typeof(Snapshot))
                .ToList()
                .ForEach(type => MapEventType(type, mapping));
            });

            return(configurationBuilder.BuildConfiguration());
        }
示例#7
0
        /// <summary>
        ///     连接到数据库,只需执行一次
        /// </summary>
        public override bool ConnectDB()
        {
            ConnectionString = GetConnectString();
            var config = new MongoConfigurationBuilder();

            config.ConnectionString(ConnectionString);
            //定义Mongo服务
            Mongo     = new Mongo(config.BuildConfiguration());
            IsUseable = Mongo.TryConnect();
            if (IsUseable != true)
            {
                return(IsUseable);
            }
            // todo
            // update = new Document {["$inc"] = new Document(AutoIndexName, 1)};
            DB = Mongo.GetDatabase(DBName);
            return(IsUseable);
        }
示例#8
0
        static void Main(string[] args)
        {
            OptionSet options = new OptionSet()
            {
                { "i|inspect_sessions", i => InspectSessions() },
                { "fe|flush_expired", fe => FlushExpiredSession() },
                { "aix|add_indexes", aix => AddIndexes() },
                { "?|h|help", h => ShowHelp() }
            };

            try
            {
                var configure = new MongoConfigurationBuilder();
                configure.ConnectionStringAppSettingKey("mongoserver");
                var config = configure.BuildConfiguration();
                options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                return;
            }
        }
示例#9
0
        public static void Main(string[] args)
        {
            var config = new MongoConfigurationBuilder();

            // COMMENT OUT FROM HERE
            config.Mapping(mapping =>
            {
                mapping.DefaultProfile(profile =>
                {
                    profile.SubClassesAre(t => t.IsSubclassOf(typeof(MyClass)));
                });
                mapping.Map <MyClass>();
                mapping.Map <SubClass>();
            });
            // TO HERE

            config.ConnectionString("Server=127.0.0.1");

            using (Mongo mongo = new Mongo(config.BuildConfiguration()))
            {
                mongo.Connect();
                try
                {
                    var db         = mongo.GetDatabase("TestDb");
                    var collection = db.GetCollection <MyClass>();

                    MyClass square = new MyClass()
                    {
                        Corners = 4,
                        Name    = "Square"
                    };

                    MyClass circle = new MyClass()
                    {
                        Corners = 0,
                        Name    = "Circle"
                    };

                    SubClass sub = new SubClass()
                    {
                        Name    = "SubClass",
                        Corners = 6,
                        Ratio   = 3.43
                    };

                    collection.Save(square);
                    collection.Save(circle);
                    collection.Save(sub);

                    var superclass = (from item in db.GetCollection <MyClass>("MyClass").Linq()
                                      where item.Corners > 1
                                      select item.Corners).ToList();

                    var subclass = (from item in db.GetCollection <SubClass>("MyClass").Linq()
                                    where item.Ratio > 1
                                    select item.Corners).ToList();

                    Console.WriteLine("Count by LINQ on typed collection: {0}", collection.Linq().Count(x => x.Corners > 1));
                    Console.WriteLine("Count by LINQ on typed collection2: {0}", db.GetCollection <SubClass>().Linq().Count(x => x.Corners > 1));
                    //Console.WriteLine("Count by LINQ on typed collection3: {0}", db.GetCollection<SubClass>().Count(new { Corners = Op.GreaterThan(1) }));
                    Console.WriteLine("Count on typed collection: {0}", collection.Count(new { Corners = Op.GreaterThan(1) }));

                    var coll  = db.GetCollection("MyClass");
                    var count = coll.Count(new Document("Corners", Op.GreaterThan(1)));
                    Console.WriteLine("Count: {0}", count);
                    Console.ReadKey();
                }
                finally
                {
                    mongo.Disconnect();
                }
            }

            //var main = new MainClass();
            //main.Setup();
            //main.Run();
        }
示例#10
0
        public static List <DEALERSHIP> GetDealerships(string ParserType)
        {
            List <DEALERSHIP> retval = null;

            using (Mongo mongo = new Mongo(config.BuildConfiguration()))
            {
                mongo.Connect();
                var db = mongo.GetDatabase(VehicleRecords.VEHICLE_DB.DataBaseName);

                IMongoCollection <Document> collDealers = db.GetCollection <Document>(DEALERSHIP.TableName);

                Document qDealer = new Document();
                qDealer["PARSER_TYPE"]  = ParserType;
                qDealer["COLLECT_DATA"] = "YES";

                DEALERSHIP[] founddealers = DEALERSHIP.GetDEALERSHIPsFromQueryDocument(collDealers, qDealer);

                if (founddealers != null && founddealers.Count <DEALERSHIP>() > 0)
                {
                    retval = founddealers.ToList <DEALERSHIP>();
                }
                mongo.Disconnect();
            }

            return(retval);
        }
 private SessionStore()
 {
     configure = new MongoConfigurationBuilder();
     configure.ConnectionStringAppSettingKey("mongoserver");
     config = configure.BuildConfiguration();
 }