コード例 #1
0
ファイル: InsertManyTest.cs プロジェクト: RavenZZ/MDRelation
 protected override void Execute(IMongoCollection<BsonDocument> collection, BsonDocument outcome, bool async)
 {
     if (async)
     {
         collection.InsertManyAsync(_documents).GetAwaiter().GetResult();
     }
     else
     {
         collection.InsertMany(_documents);
     }
 }
コード例 #2
0
        public void TestFixtureSetUp()
        {
            var client = DriverTestConfiguration.Client;
            var db = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName);
            db.DropCollection(DriverTestConfiguration.CollectionNamespace.CollectionName);
            _collection = db.GetCollection<ZipEntry>(DriverTestConfiguration.CollectionNamespace.CollectionName);

            // This is a subset of the data from the mongodb docs zip code aggregation examples
            _collection.InsertMany(new[]
            {
                new ZipEntry { Zip = "01053", City = "LEEDS", State = "MA", Population = 1350 },
                new ZipEntry { Zip = "01054", City = "LEVERETT", State = "MA", Population = 1748 },
                new ZipEntry { Zip = "01056", City = "LUDLOW", State = "MA", Population = 18820 },
                new ZipEntry { Zip = "01057", City = "MONSON", State = "MA", Population = 8194 },
                new ZipEntry { Zip = "36779", City = "SPROTT", State = "AL", Population = 1191 },
                new ZipEntry { Zip = "36782", City = "SWEET WATER", State = "AL", Population = 2444 },
                new ZipEntry { Zip = "36783", City = "THOMASTON", State = "AL", Population = 1527 },
                new ZipEntry { Zip = "36784", City = "THOMASVILLE", State = "AL", Population = 6229 },
            });
        }
コード例 #3
0
        static void RefreshNewColumn()
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();//开始计时

            List <ZonesSimple> dl = new List <ZonesSimple>();

            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 <DnsRecordsSimple>[] dla = new List <DnsRecordsSimple>[16] {
                new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>()
            };

            var client = DriverConfiguration.Client;
            var db     = client.GetDatabase(DriverConfiguration.DatabaseNamespace.DatabaseName);
            IMongoCollection <ZonesSimple> cz = db.GetCollection <ZonesSimple>("zones");

            DataTable dt = MySQLHelper.Query("SELECT z.id,z.zone,z.userid,CASE when d.maxfensheng<1 then 0 else 1 end as level,z.nsstate,z.active,z.forcestop from zones as z left join domainlevel as d on z.DomainLevel=d.levelvalue where z.userid<>348672 and (z.Active='N' or z.ForceStop='Y' ) ").Tables[0];

            DataTable dta = MySQLHelper.Query("select a.id,a.zone,host,data,type,ttl,mbox,serial,refresh,retry,expire,minimum ,t.userid,a.zoneid from authorities as a left join zones as t on a.ZoneID=t.id where t.userid<>348672 and (t.Active='N' or t.ForceStop='Y')").Tables[0];

            DataTable dtd = MySQLHelper.Query("select d.id,d.zoneid,d.zone,d.host,d.type,d.data,d.ttl,d.view,d.mx_priority,d.userid,d.active from dnsrecords as d left join zones as t on d.ZoneID=t.id where t.userid<>348672 and (t.Active='N' or t.ForceStop='Y')").Tables[0];

            Console.WriteLine("zones total count  " + dt.Rows.Count);
            Console.WriteLine("authorities total count  " + dta.Rows.Count);
            Console.WriteLine("dnsrecords total count  " + dtd.Rows.Count);

            List <zones> zonesList = DtToList <zones> .ConvertToModel(dt);

            int            deleteCount = 0;
            IList <string> zoneArry    = new List <string>();

            foreach (zones z in zonesList)
            {
                zoneArry.Add(z.zone + ".");

                ZonesSimple zs = Row2ZoneSimple(z);
                dl.Add(zs);
                if ((deleteCount > 0 && deleteCount % 200 == 0) || deleteCount == zonesList.Count)
                {
                    cz.DeleteMany(Builders <ZonesSimple> .Filter.In("domain", zoneArry));
                    string rrcol = StringHelper.CalculateMD5Hash(z.zone + ".").Substring(0, 1);
                    IMongoCollection <DnsRecordsSimple> cd = db.GetCollection <DnsRecordsSimple>(rrcol);
                    cd.DeleteMany(Builders <DnsRecordsSimple> .Filter.In("domain", zoneArry));

                    Console.WriteLine("delete count  " + deleteCount + " use time " + watch.ElapsedMilliseconds);

                    if (dl.Count > 0)
                    {
                        cz.InsertMany(dl);
                        Console.WriteLine("insert zones use time  " + watch.ElapsedMilliseconds);
                    }
                    zoneArry.Clear();
                    dl.Clear();
                }

                deleteCount++;
            }
            Console.WriteLine("delete complete use time " + watch.ElapsedMilliseconds);


            List <authorities> aList = DtToList <authorities> .ConvertToModel(dta);

            List <authorities> drl    = new List <authorities>();
            string             domain = "";

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

                drl.Clear();
                domain = "";
                idx++;
            }
            List <dnsrecords> rList = DtToList <dnsrecords> .ConvertToModel(dtd);

            List <dnsrecords> unList = new List <dnsrecords>();

            foreach (dnsrecords dr in rList)
            {
                if (CheckRecordHost(dr.host, dr.type) && CheckRecordData(dr.data, dr.type, dr.view, dr.host))
                {
                    DnsRecordsSimple d = Row2DnsRecords(dr);
                    string           collectionname = StringHelper.CalculateMD5Hash(d.domain).ToLower().Substring(0, 1);
                    int idx = Int32.Parse(collectionname, System.Globalization.NumberStyles.HexNumber);
                    dla[idx].Add(d);
                }
                else
                {
                    unList.Add(dr);
                }
            }

            Console.WriteLine("start insert use time " + watch.ElapsedMilliseconds);


            for (int i = 0; i < 16; i++)
            {
                IMongoCollection <DnsRecordsSimple> collection = db.GetCollection <DnsRecordsSimple>(i.ToString("x"));
                if (ala[i].Count > 0)
                {
                    collection.InsertMany(ala[i]);
                }
                if (dla[i].Count > 0)
                {
                    collection.InsertMany(dla[i]);
                }
            }
            if (unList.Count > 0)
            {
                Console.WriteLine("uninsert dnsrecords " + unList.Count);
            }
            Console.WriteLine("mission complete   use time " + watch.ElapsedMilliseconds);
        }
コード例 #4
0
        static void MongoInsertFromAuthorities()
        {
            try
            {
                List <TempZoneID> temp = DtToList <TempZoneID> .ConvertToModel(MySQLHelper.Query("select id as zoneid from Temp").Tables[0]);

                DataTable dtid = MySQLHelper.Query("select min(id),max(id) from zones").Tables[0];
                long      min  = Convert.ToInt32(dtid.Rows[0][0]);
                long      max  = Convert.ToInt32(dtid.Rows[0][1]);

                System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                watch.Start();//开始计时
                long index = min;
                do
                {
                    DataTable dt = MySQLHelper.Query("select a.id,a.zone,host,data,type,ttl,mbox,serial,refresh,retry,expire,minimum ,t.userid,a.zoneid from authorities as a left join zones as t on a.ZoneID=t.id where a.ZoneID BETWEEN " + index + " and " + (index + 20000) + " and t.userid<>348672  and t.id is not NULL and t.Active='Y' and t.ForceStop='N'  order by a.zone,a.type").Tables[0];
                    Console.WriteLine("getdatatabel from mysql             use time={0};", watch.ElapsedMilliseconds);
                    List <authorities> aListtemp = DtToList <authorities> .ConvertToModel(dt);

                    Console.WriteLine("datatable convert to modellist;     use time={0};", watch.ElapsedMilliseconds);
                    List <authorities> aList = new List <authorities>();
                    foreach (authorities a in aListtemp)
                    {
                        if (temp.FindAll(tz => tz.zoneid == a.zoneid).Count == 0)
                        {
                            aList.Add(a);
                        }
                    }
                    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 <authorities>       drl = new List <authorities>();
                    List <AuthoritiesSimple> dl  = new List <AuthoritiesSimple>();
                    string domain = "";
                    for (int idx = 0; idx < aList.Count;)
                    {
                        domain = aList[idx].zone.ToString().ToLower() + ".";
                        string collectionname = StringHelper.CalculateMD5Hash(domain).ToLower().Substring(0, 1);
                        drl.Add(aList[idx]);
                        while (idx < (aList.Count - 1) && aList[idx].zone == aList[idx + 1].zone)
                        {
                            drl.Add(aList[idx + 1]);
                            idx++;
                        }
                        if (drl.Count > 1)
                        {
                            foreach (AuthoritiesSimple a in Row2Authorities(drl))
                            {
                                ala[Int32.Parse(collectionname, System.Globalization.NumberStyles.HexNumber)].Add(a);
                            }
                        }

                        dl.Clear();
                        drl.Clear();
                        domain = "";
                        idx++;
                    }
                    Console.WriteLine("modellist convert;index={1};use time={0};", watch.ElapsedMilliseconds, index);
                    try
                    {
                        var client = DriverConfiguration.Client;
                        var db     = client.GetDatabase(DriverConfiguration.DatabaseNamespace.DatabaseName);
                        for (int i = 0; i < 16; i++)
                        {
                            IMongoCollection <AuthoritiesSimple> collection = db.GetCollection <AuthoritiesSimple>(i.ToString("x"));
                            if (ala[i].Count > 0)
                            {
                                collection.InsertMany(ala[i]);
                            }
                        }
                        Console.WriteLine("mongodb inserted;index={1};use time={0};", watch.ElapsedMilliseconds, index);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Insert Data" + ex.Message);
                    }

                    index = index + 20001;
                    Console.WriteLine("min={0};max={1};index={2};use time={3}", min, max, index, watch.ElapsedMilliseconds);
                    Console.WriteLine("==============================================");
                } while (index < max);
                Console.WriteLine("end min={0};max={1};index={2};use time {3}", min, max, index, watch.ElapsedMilliseconds);
                watch.Stop();//停止计时
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #5
0
        public AppCommandProcessor(IMongoCollection <AppData> apps, GridFSBucket files, RepositoryApi repository, DataTransferManager dataTransfer,
                                   IMongoCollection <ToDeleteRevision> toDelete, WorkDistributor <BuildRequest, BuildCompled> workDistributor, IActorRef changeTracker)
        {
            _apps = apps;

            CommandPhase1 <CreateAppCommand>("CreateApp", repository,
                                             (command, reporter) =>
            {
                reporter.Send(DeploymentMessages.RegisterRepository);
                return(new RegisterRepository(command.TargetRepo)
                {
                    IgnoreDuplicate = true
                });
            },
                                             (command, reporter, op) => new ContinueCreateApp(op, command, reporter));

            CommandPhase2 <ContinueCreateApp, CreateAppCommand, AppInfo>("CreateApp2", (command, result, reporter, data) =>
            {
                if (!result.Ok)
                {
                    if (reporter.IsCompled)
                    {
                        return(null);
                    }
                    reporter.Compled(OperationResult.Failure(result.Error ?? BuildErrorCodes.CommandErrorRegisterRepository));
                    return(null);
                }

                if (data != null)
                {
                    reporter.Compled(OperationResult.Failure(BuildErrorCodes.CommandDuplicateApp));
                    return(null);
                }

                var newData = new AppData(command.AppName, -1, DateTime.UtcNow, DateTime.MinValue, command.TargetRepo, command.ProjectName, ImmutableList <AppFileInfo> .Empty);

                apps.InsertOne(newData);
                var info = newData.ToInfo();

                changeTracker.Tell(info);
                return(info);
            });

            CommandPhase1 <PushVersionCommand>("PushVersion",
                                               (command, reporter) =>
            {
                var data = apps.AsQueryable().FirstOrDefault(ad => ad.Name == command.AppName);
                if (data == null)
                {
                    reporter.Compled(OperationResult.Failure(BuildErrorCodes.CommandAppNotFound));
                }
                else
                {
                    BuildRequest.SendWork(workDistributor, reporter, data, repository, BuildEnv.TempFiles.CreateFile())
                    .PipeTo(Self,
                            success: c => new ContinuePushNewVersion(OperationResult.Success(c), command, reporter),
                            failure: e => new ContinuePushNewVersion(OperationResult.Failure(e.Unwrap()?.Message ?? "Cancel"), command, reporter));
                }
            });

            CommandPhase2 <ContinuePushNewVersion, PushVersionCommand, AppBinary>("PushVersion2", (command, result, reporter, data) =>
            {
                if (data == null)
                {
                    if (!reporter.IsCompled)
                    {
                        reporter.Compled(OperationResult.Failure(BuildErrorCodes.CommandAppNotFound));
                    }
                    return(null);
                }

                if (!result.Ok)
                {
                    return(null);
                }

                using var transaction = apps.Database.Client.StartSession(new ClientSessionOptions { DefaultTransactionOptions = new TransactionOptions(writeConcern: WriteConcern.Acknowledged) });
                var dataFilter        = Builders <AppData> .Filter.Eq(ad => ad.Name, data.Name);

                var(commit, fileName) = ((string, ITempFile))result.Outcome !;

                using var targetStream = fileName;

                var newId = files.UploadFromStream(data.Name + ".zip", targetStream.Stream);

                var newBinary  = new AppFileInfo(newId, data.Last + 1, DateTime.UtcNow, false, commit);
                var newBinarys = data.Versions.Add(newBinary);

                var definition = Builders <AppData> .Update;
                var updates    = new List <UpdateDefinition <AppData> >
                {
                    definition.Set(ad => ad.Last, newBinary.Version),
                    definition.Set(ad => ad.Versions, newBinarys)
                };

                var deleteUpdates = new List <ToDeleteRevision>();

                if (data.Versions.Count(s => !s.Deleted) > 5)
                {
                    foreach (var info in newBinarys.OrderByDescending(i => i.CreationTime).Skip(5))
                    {
                        if (info.Deleted)
                        {
                            continue;
                        }
                        info.Deleted = true;
                        deleteUpdates.Add(new ToDeleteRevision(info.File.ToString()));
                    }
                }

                transaction.StartTransaction();

                if (deleteUpdates.Count != 0)
                {
                    toDelete.InsertMany(transaction, deleteUpdates);
                }
                if (!apps.UpdateOne(transaction, dataFilter, definition.Combine(updates)).IsAcknowledged)
                {
                    transaction.AbortTransaction();
                    reporter.Compled(OperationResult.Failure(BuildErrorCodes.DatabaseError));
                    return(null);
                }

                transaction.CommitTransaction();

                changeTracker.Tell(_apps.AsQueryable().FirstOrDefault(ad => ad.Name == command.AppName));
                return(new AppBinary(command.AppName, newBinary.Version, newBinary.CreationTime, false, newBinary.Commit, data.Repository));
            });
コード例 #6
0
 /* adicionar a partir de uma lista */
 public void AddFromList(List <Model> models)
 {
     modelColl.InsertMany(models);
 }
コード例 #7
0
ファイル: MongoService.cs プロジェクト: shi-tou/yezi_fang
        /// <summary>
        /// 插入多条数据
        /// </summary>
        /// <param name="list"></param>
        public void Insert <T>(List <T> list)
        {
            IMongoCollection <T> collection = MongoDatabase.GetCollection <T>(GetCollectionName(typeof(T)));

            collection.InsertMany(list);
        }
コード例 #8
0
 public void InsertMany(ICollection <TDocument> documents)
 {
     _collection.InsertMany(documents);
 }
コード例 #9
0
 public void Add(IEnumerable <TEntity> items)
 {
     _mongoCollection.InsertMany(items);
 }
コード例 #10
0
 public List <Book> Add(List <Book> books)
 {
     Collection.InsertMany(books);
     return(books);
 }
コード例 #11
0
 public void AddRange(IEnumerable <T> entities)
 {
     _context.InsertMany(entities);
 }
コード例 #12
0
ファイル: Repository.cs プロジェクト: xkissboss/exam
 public virtual List <TEntity> InsertList(List <TEntity> entityList)
 {
     mongoCollection.InsertMany(entityList);
     return(entityList);
 }
コード例 #13
0
        private void setupdata()
        {
            var list = new List <Game>()
            {
                new Game()
                {
                    DeadLine    = DateTime.Now,
                    Deleted     = false,
                    Description = "text",
                    GameId      = "a1",
                    Name        = "name",
                    Vochers     = new List <Vocher>()
                    {
                        new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b1",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }, new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b2",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }, new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b3",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }, new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b4",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }
                    }
                },
                new Game()
                {
                    DeadLine    = DateTime.Now,
                    Deleted     = false,
                    Description = "text",
                    GameId      = "a2",
                    Name        = "name",
                    Vochers     = new List <Vocher>()
                    {
                        new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b1",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }, new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b2",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }, new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b3",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }, new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b4",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }
                    }
                },
                new Game()
                {
                    DeadLine    = DateTime.Now,
                    Deleted     = false,
                    Description = "text",
                    GameId      = "a3",
                    Name        = "name",
                    Vochers     = new List <Vocher>()
                    {
                        new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b1",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }, new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b2",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }, new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b3",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }, new Vocher()
                        {
                            PerchesTime = DateTime.Now,
                            TicketId    = "b4",
                            Tickets     = new List <Ticket>()
                            {
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c1"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c2"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c3"
                                },
                                new Ticket()
                                {
                                    Price = 2, TicketId = "c4"
                                }
                            }
                        }
                    }
                }
            };

            _games.InsertMany(list);
        }
コード例 #14
0
 public void AddRange(IEnumerable <TModel> models)
 {
     mongoCollection.InsertMany(models);
 }
コード例 #15
0
 public virtual void InsertMany(ICollection <T> documents)
 {
     collection.InsertMany(documents);
 }
コード例 #16
0
 /// <summary>
 /// Insert entities
 /// </summary>
 /// <param name="entities">Entities</param>
 public virtual void Insert(IEnumerable <T> entities)
 {
     _collection.InsertMany(entities);
 }
コード例 #17
0
ファイル: GridFSTestBase.cs プロジェクト: RavenZZ/MDRelation
 private void InitializeCollection(IMongoCollection<BsonDocument> collection, List<BsonDocument> documents)
 {
     collection.DeleteMany(new BsonDocument());
     if (documents.Count > 0)
     {
         collection.InsertMany(documents);
     }
 }
コード例 #18
0
 public void CreateMany(List <Candidate> cand)
 {
     collection.InsertMany(cand);
 }
コード例 #19
0
 public static void InsertMany(IEnumerable <ParkDesign> entities)
 {
     parkCollection.InsertMany(entities);
 }
コード例 #20
0
 public Book CreateMany(List <Book> books)
 {
     _books.InsertMany(books);
     return(books[0]);
 }
コード例 #21
0
 public void InsertMany(IEnumerable <T> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     _Repository.InsertMany(documents, options, cancellationToken);
 }
コード例 #22
0
 public void AddReservation(string serie, ReservationSlot reservationSlot)
 {
     _offlineSlots.InsertMany(GetIdentityFromReservationSlot(serie, reservationSlot));
 }
コード例 #23
0
 public void InsertMany(List <T> documents)
 {
     _collection.InsertMany(documents);
 }
コード例 #24
0
 public int AddList(IEnumerable <TEntity> entities)
 {
     _collection.InsertMany(entities);
     return(entities.Count());
 }
コード例 #25
0
 public static void Insert(IEnumerable <T> documents)
 {
     collection.InsertMany(documents);
 }
コード例 #26
0
 internal override void ActualInsert(IList <TEntity> itemList)
 {
     _mongoCollection.InsertMany(itemList);
 }
コード例 #27
0
        public void AddRange(IEnumerable <T> Entities)
        {
            ConfigDbSet();

            DbSet.InsertMany(Entities);
        }
コード例 #28
0
 public void AddRange(IEnumerable <T> items)
 {
     _collection.InsertMany(items);
 }
コード例 #29
0
        static void MongoInsertFromDnsrecords()
        {
            try
            {
                List <TempZoneID> temp = DtToList <TempZoneID> .ConvertToModel(MySQLHelper.Query("select id as zoneid from Temp").Tables[0]);

                DataTable dtid = MySQLHelper.Query("select min(id),max(id) from zones").Tables[0];
                long      min  = Convert.ToInt32(dtid.Rows[0][0]);
                long      max  = Convert.ToInt32(dtid.Rows[0][1]);

                System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                watch.Start();//开始计时
                long index = min;
                do
                {
                    DataTable dt = MySQLHelper.Query("select d.id,d.zoneid,d.zone,d.host,d.type,d.data,d.ttl,d.view,d.mx_priority,d.userid,d.active from dnsrecords as d left join zones as t on d.ZoneID=t.id where d.Active='Y' and d.type<>'PTR' and d.ZoneID BETWEEN " + index + " and " + (index + 20000) + " and t.userid<>348672 and t.id is not NULL and t.Active='Y' and t.ForceStop='N' order by d.zone").Tables[0];
                    Console.WriteLine("GetDataTabel from mysql         Use Time={0};", watch.ElapsedMilliseconds);
                    List <dnsrecords> rListtemp = DtToList <dnsrecords> .ConvertToModel(dt);

                    Console.WriteLine("DataTable Convert to ModelList; Use time={0};", watch.ElapsedMilliseconds);
                    List <dnsrecords> rList = new List <dnsrecords>();
                    foreach (dnsrecords d in rListtemp)
                    {
                        if (temp.FindAll(tz => tz.zoneid == d.zoneid).Count == 0)
                        {
                            rList.Add(d);
                        }
                    }

                    List <dnsrecords>         unList = new List <dnsrecords>();
                    List <DnsRecordsSimple>[] dla    = new List <DnsRecordsSimple>[16] {
                        new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>()
                    };

                    foreach (dnsrecords dr in rList)
                    {
                        if (CheckRecordHost(dr.host, dr.type) && CheckRecordData(dr.data, dr.type, dr.view, dr.host))
                        {
                            DnsRecordsSimple d = Row2DnsRecords(dr);
                            string           collectionname = StringHelper.CalculateMD5Hash(d.domain).ToLower().Substring(0, 1);
                            int idx = Int32.Parse(collectionname, System.Globalization.NumberStyles.HexNumber);
                            dla[idx].Add(d);
                        }
                        else
                        {
                            unList.Add(dr);
                        }
                    }
                    Console.WriteLine("ModelList Convert and Filter;   Use time={0};", watch.ElapsedMilliseconds);

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

                    for (int i = 0; i < 16; i++)
                    {
                        IMongoCollection <DnsRecordsSimple> collection = db.GetCollection <DnsRecordsSimple>(i.ToString("x"));
                        if (dla[i].Count > 0)
                        {
                            collection.InsertMany(dla[i]);
                        }
                    }
                    Console.WriteLine("MongoDB Inserted;               Use time={0};", watch.ElapsedMilliseconds);
                    if (unList.Count > 0)
                    {
                        IMongoCollection <dnsrecords> collection2 = db.GetCollection <dnsrecords>("dnsrecordswrong");
                        collection2.InsertMany(unList);
                    }
                    Console.WriteLine("MongoDB Inserted Wrong Data;    Use time={0};", watch.ElapsedMilliseconds);

                    index = index + 20001;
                    Console.WriteLine("min={0};max={1};index={2};use time {3}", min, max, index, watch.ElapsedMilliseconds);
                    Console.WriteLine("==============================================");
                } while (index < max);
                Console.WriteLine("End min={0};max={1};index={2};use time {3}", min, max, index, watch.ElapsedMilliseconds);
                watch.Stop();//停止计时
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #30
0
ファイル: PostRepository.cs プロジェクト: martafina/NOSQL
 public void Add(IEnumerable <Post> posts) =>
 collection.InsertMany(posts);
コード例 #31
0
 public List <MealPlan> CreateMany(List <MealPlan> meals)
 {
     _mealPlans.InsertMany(meals);
     return(meals);
 }
コード例 #32
0
ファイル: MongoService.cs プロジェクト: shi-tou/MyMongoDB
        /// <summary>
        /// 插入多条数据
        /// </summary>
        /// <param name="list"></param>
        public void Insert <T>(List <T> list)
        {
            IMongoCollection <T> collection = database.GetCollection <T>(typeof(T).Name);

            collection.InsertMany(list);
        }
コード例 #33
0
        public MetricsData[] Get(int date)
        {
            List <MetricsData> list = new List <MetricsData>();

            if (VenvitoHelper.UseMongo)
            {
                IMongoCollection <MetricsDefinition> definitionCollection = VenvitoHelper.GetMongoDefinitionCollection();
                if (definitionCollection.Count(Builders <MetricsDefinition> .Filter.Empty) == 0)
                {
                    string contentRootPath          = m_HostingEnvironment.ContentRootPath;
                    string metricJson               = System.IO.File.ReadAllText(Path.Combine(contentRootPath, "App_Data/MetricsDefinitions.json"));
                    MetricsDefinition[] definitions = Newtonsoft.Json.JsonConvert.DeserializeObject <MetricsDefinition[]>(metricJson);
                    for (int i = 0; i < definitions.Length; i++)
                    {
                        definitions[i].sortOrder = i * 100;
                    }
                    definitionCollection.InsertMany(definitions);
                }

                List <MetricsData> result = new List <MetricsData>();

                IMongoCollection <MetricsData>     dataCollection = VenvitoHelper.GetMongoDataCollection();
                SortDefinition <MetricsDefinition> sortDefinition = Builders <MetricsDefinition> .Sort.Ascending(new StringFieldDefinition <MetricsDefinition>("sortOrder"));

                List <MetricsDefinition> metricsDefinitions = definitionCollection.Aggregate().Sort(sortDefinition).ToList <MetricsDefinition>();
                foreach (MetricsDefinition metricsDef in metricsDefinitions)
                {
                    FilterDefinition <MetricsData> filter = Builders <MetricsData> .Filter.And(
                        Builders <MetricsData> .Filter.Eq("code", metricsDef.code),
                        Builders <MetricsData> .Filter.Eq("date", date));

                    List <MetricsData> data        = dataCollection.FindSync <MetricsData>(filter).ToList <MetricsData>();
                    decimal            value       = (data.Count == 1 ? data[0].value : 0);
                    MetricsData        metricsData = new MetricsData()
                    {
                        code        = metricsDef.code,
                        description = metricsDef.description,
                        type        = metricsDef.type,
                        color       = metricsDef.color,
                        date        = date,
                        value       = value
                    };
                    result.Add(metricsData);
                }
                return(result.ToArray());
            }
            else
            {
                using (SqlConnection conn = VenvitoHelper.CreateDbConnection())
                {
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "usp_MetricsData_Get";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("Date", VenvitoHelper.IntToDate(date)));
                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                list.Add(new MetricsData
                                {
                                    date        = date,
                                    code        = Convert.ToString(dr["MetricsCode"]),
                                    description = Convert.ToString(dr["MetricsDescription"]),
                                    type        = Convert.ToString(dr["MetricsType"]),
                                    color       = Convert.ToString(dr["Color"]),
                                    value       = Convert.ToDecimal(dr["MetricsValue"])
                                });
                            }
                        }
                    }
                }
            }

            return(list.ToArray <MetricsData>());
        }
コード例 #34
0
ファイル: Program.cs プロジェクト: DavidHoerster/EventTest
 private static void PersistEvents(IMongoCollection<ReiEventBase> coll, ReportingEntityInstance instance)
 {
     var validations = instance.GetUncommittedChanges();
     coll.InsertMany(validations.OfType<ReiEventBase>());
     instance.MarkChangesAsCommitted();
 }