public BookRepository()
        {
            var mClient = new MongoClient(LibraryMongo.Properties.Settings.Default.LibraryConnectionString);

            mDb   = mClient.GetDatabase("Library");
            books = mDb.GetCollection <Books>("Books");
        }
        public CustomerService(ICustomerDatabaseSettings settings)
        {
            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.DatabaseName);

            _customers = database.GetCollection <Customer>(settings.CustomersCollectionName);
        }
 public DataModelsController()
 {
     MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient();
     _db               = client.GetDatabase(ConfigurationManager.AppSettings["dbname"]);
     _models           = _db.GetCollection <DataModel>("data_models");
     _entityController = new EntityModelsController();
 }
        public InformationService(IOptions <BoMayDatabaseSettings> setting)
        {
            _settings = setting.Value;
            var client   = new MongoClient(_settings.ConnectionString);
            var database = client.GetDatabase(_settings.DatabaseName);

            Informations = database.GetCollection <Information>(_settings.BoMaysCollectionName);
        }
        public UserService(IOptions <AppSettings> appSettings)
        {
            _appSettings = appSettings.Value;
            var client   = new MongoClient(_appSettings.ConnectionString);
            var database = client.GetDatabase(_appSettings.Database);

            _users = database.GetCollection <User>("Users");
        }
Beispiel #6
0
 public UserService()
 {
     try
     {
         var mClient = new MongoClient(FixedAsset_MVC.Properties.Settings.Default.FixedAssetsConnectionString);
         mDb   = mClient.GetDatabase("FIXED_ASSET");
         users = mDb.GetCollection <User>("users");
     }
     catch (Exception)
     {
         serverDown = true;
     }
 }
Beispiel #7
0
        /// <summary>
        /// For a given VHO #, add any new unique AltCodes into our member vho
        /// When completed a VHO, cache this in the DB
        /// </summary>
        /// <param name="vhoNumber"></param>
        public async Task <bool> AddUniqueFromVHOAsync(MongoDB.Driver.IMongoCollection <CatalogObject> collection)
        {
            Dictionary <string, CatalogObject> vho = new Dictionary <string, CatalogObject>();

            string path = GetTemplate(vhoNumber, "d:\\img\\img\\", new DateTime(2015, 7, 21));

            if (path != string.Empty)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Processing VHO : " + vhoNumber);
                Console.ForegroundColor = ConsoleColor.White;
                try
                {
                    String tempFile = Decompress(path);
                    using (StreamReader file = new System.IO.StreamReader(tempFile, Encoding.UTF8))
                    {
                        string line;
                        while ((line = await file.ReadLineAsync()) != null)
                        {
                            CatalogObject json = JsonConvert.DeserializeObject <CatalogObject>(line);

                            if ((json.AltCode == string.Empty))//blank AltCode, prob single screen
                            {
                                if (singleScreen)
                                {
                                    //Use the PID PAID since the AltCode is missing
                                    json.AltCode = json.ProviderID + ":" + json.ProviderAssetID.Substring(4);
                                    await AddMediaAsync(collection, json);
                                }
                            }
                            else if (multiScreen)
                            {
                                await AddMediaAsync(collection, json);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception caught opening file :" + ex.Message);
                }
            }
            //and Upsert the vho!
            //await collection.InsertManyAsync(vho.Values);
            return(true);
        }
Beispiel #8
0
        public UserRepository()
        {
            //var credential = MongoCredential.CreateMongoCRCredential("admin", "mongoAdmin", "$cR@m$H@1");
            //var settings = new MongoClientSettings
            //{
            //    Credentials = new[] { credential },
            //    Server = new MongoServerAddress("DEMO",4509)
            //};
            //var mClient = new MongoClient(settings);
            var mClient = new MongoClient(Settings.Default.LibraryConnectionString);

            mDb   = mClient.GetDatabase("Library");
            users = mDb.GetCollection <User>("Users");
            try
            {
                //var mServer=mClient.GetServer();
                //mServer.Ping();
            }
            catch (System.Exception ex)
            {
                serverDown = true;
            }
        }
Beispiel #9
0
        public MongoRepository(IDatabaseSettings settings)
        {
            var db = new MongoClient(settings.ConnectionString).GetDatabase(settings.DatabaseName);

            _collection = db.GetCollection <T>(GetCollectionName(typeof(T)));
        }
Beispiel #10
0
        static void MongoInsertFromAuthorities()
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();//开始计时
            //DataSet ds = MySQLHelper.Query("SELECT Zone,Host,Data,Type,TTL,Mbox,Serial,Refresh,Retry,Expire,Minimum FROM  authorities WHERE Zone IN (SELECT distinct Zone from zones WHERE NSState=1 ORDER BY Zone LIMIT 0,10000) ORDER BY Zone");
            //DataSet ds = MySQLHelper.Query("SELECT a.Zone,Host,Data,Type,TTL,Mbox,Serial,Refresh,Retry,Expire,Minimum,t.userid FROM (SELECT DISTINCT zone,userid from zonestemp where nsstate=1 and isload=1 order BY zone  LIMIT 0,500)as t inner join  authorities as a on t.zone=a.Zone");
            DataSet   ds    = MySQLHelper.Query("SELECT a.Zone,Host,Data,Type,TTL,Mbox,Serial,Refresh,Retry,Expire,Minimum,t.userid FROM (SELECT zone,userid,id from zonestemp where id in(1782993))as t inner join  authorities as a on t.id=a.Zoneid");
            long      q     = watch.ElapsedMilliseconds;
            DataTable dt    = ds.Tables[0];
            int       count = dt.Rows.Count;

            Console.WriteLine("query use time:" + q.ToString() + ";" + count + " rows data");
            int idx = 0;

            List <AuthoritiesSimple>[] ala = new List <AuthoritiesSimple>[16] {
                new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>()
            };

            List <AuthoritiesSimple> dl  = new List <AuthoritiesSimple>();
            List <DataRow>           drl = new List <DataRow>();
            string domain = "";

            while (idx < count)
            {
                domain = dt.Rows[idx][0].ToString().ToLower() + ".";
                string collectionname = StringHelper.CalculateMD5Hash(domain).ToLower().Substring(0, 1);
                drl.Add(dt.Rows[idx]);
                while (idx < (count - 1) && dt.Rows[idx][0].ToString() == dt.Rows[idx + 1][0].ToString())
                {
                    drl.Add(dt.Rows[idx + 1]);
                    idx++;
                }
                if (drl.Count > 1)
                {
                    dl = Row2Authorities(drl);
                }
                foreach (AuthoritiesSimple a in dl)
                {
                    ala[Int32.Parse(collectionname, System.Globalization.NumberStyles.HexNumber)].Add(a);
                }
                idx++;

                dl.Clear();
                drl.Clear();
                domain = "";
            }

            var client = DriverConfiguration.Client;
            var db     = client.GetDatabase(DriverConfiguration.DatabaseNamespace.DatabaseName);

            for (int i = 0; i < 16; i++)
            {
                MongoDB.Driver.IMongoCollection <AuthoritiesSimple> collection = db.GetCollection <AuthoritiesSimple>(i.ToString("x"));
                if (ala[i].Count > 0)
                {
                    collection.InsertMany(ala[i]);
                }
                Console.WriteLine("List " + i.ToString("x") + " obj count " + ala[i].Count);
            }
            Console.WriteLine("{0} row inserted;use time {1}", idx, watch.ElapsedMilliseconds);
            watch.Stop();//停止计时

            //Console.WriteLine("{0} row inserted;use time {1}", idx, watch.ElapsedMilliseconds);
            watch.Stop();//停止计时//305049  913076
        }
 public CourseRepository()
 {
     _context = ConnectionManager.GetContext().GetCollection <Course>("courses");
 }
Beispiel #12
0
        public async Task AddMediaAsync(MongoDB.Driver.IMongoCollection <CatalogObject> collection, CatalogObject json)
        {
            try
            {
                //var found = vho.TryGetValue(json.AltCode, out r);
                var filter = Builders <CatalogObject> .Filter.Eq("AltCode", json.AltCode);

                var found = await collection.Find(filter).ToListAsync();

                if (found.Count > 0)
                {
                    //check to see if its an exact copy, if it is then skip
                    var r = found[0];
                    if (r.GetHashCode() != json.GetHashCode())
                    {
                        if (json.IsHD)//only add values/updates from the HD version
                        {
                            //vho[json.AltCode] = json;
                            if (null != collection.Find(json.AltCode))
                            {
                                await collection.ReplaceOneAsync(x => x.AltCode == json.AltCode, json);
                            }
                            else
                            {
                                await collection.InsertOneAsync(json);
                            }
                            Compare(r, json);
                        }
                        else
                        {
                            //need to Add Avails data for nonHD here which requires making the private fields into a list of...
                        }
                    }
                }
                else
                {
                    //Not this is unusual and an error
                    //So possible outcome here is we have same content but first four chars dont match, but content is same
                    //var dict = vho.Where(kvp => json.ProviderAssetID.Substring(4)).SelectMany(kvp => kvp.Value);
                    //var dict = vho.SelectMany(m => m).Where(k => vho.Keys.Contains(json.ProviderAssetID.Substring(4)));

                    /*var selectValues = (from keyValuePair in vho
                     *                  where keyValuePair.Key.Contains(json.ProviderAssetID.Substring(4))
                     *                  select keyValuePair.Value).ToList();
                     * if (selectValues.Count > 1)
                     *  Console.WriteLine(vhoNumber + " : " + json.AltCode);
                     */
                    //vho[json.AltCode] = json;
                    if (null == collection.Find(json.AltCode))
                    {
                        await collection.ReplaceOneAsync(x => x.AltCode == json.AltCode, json);
                    }
                    else
                    {
                        await collection.InsertOneAsync(json);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #13
0
 public EntityModelsController()
 {
     MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient();
     _db     = client.GetDatabase(ConfigurationManager.AppSettings["dbname"]);
     _models = _db.GetCollection <EntityDefinition>("entity_definitions");
 }
Beispiel #14
0
 public AuthorRepository()
 {
     _context = ConnectionManager.GetContext().GetCollection <Author>("authors");
 }