当前位置: 首页>>代码示例>>C#>>正文


C# MongoConnection类代码示例

本文整理汇总了C#中MongoConnection的典型用法代码示例。如果您正苦于以下问题:C# MongoConnection类的具体用法?C# MongoConnection怎么用?C# MongoConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MongoConnection类属于命名空间,在下文中一共展示了MongoConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        /// <summary>
        /// Initializes migration with the connection object
        /// </summary>
        /// <param name="connection">MongoConnection object</param>
        public void Initialize(MongoConnection connection)
        {
            if (connection == null)
                throw new ArgumentNullException("connection");

            Connection = connection;
        }
开发者ID:bestpetrovich,项目名称:devicehive-.net,代码行数:11,代码来源:MigrationBase.cs

示例2: MongoInsertMessage

 internal MongoInsertMessage(
     MongoConnection connection,
     string collectionFullName
 )
     : base(connection, MessageOpcode.Insert) {
     this.collectionFullName = collectionFullName;
 }
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoInsertMessage.cs

示例3: MongoDbDataTest

        public MongoDbDataTest()
        {
            var connection = new MongoConnection();

            DataContext = new DataContext(typeof(MongoConnection).Assembly);
            DataContext.SetRepositoryCreator(type => Activator.CreateInstance(type, connection));
        }
开发者ID:bestpetrovich,项目名称:devicehive-.net,代码行数:7,代码来源:MongoDbDataTest.cs

示例4: MongoMessage

 protected MongoMessage(
     MongoConnection connection,
     MessageOpcode opcode
 ) {
     this.connection = connection;
     this.opcode = opcode;
 }
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoMessage.cs

示例5: Authenticate

        // public methods
        /// <summary>
        /// Authenticates the connection against the given database.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="credential">The credential.</param>
        public void Authenticate(MongoConnection connection, MongoCredential credential)
        {
            string nonce;
            try
            {
                var nonceCommand = new CommandDocument("getnonce", 1);
                var nonceResult = RunCommand(connection, credential.Source, nonceCommand);
                nonce = nonceResult.Response["nonce"].AsString;
            }
            catch (MongoCommandException ex)
            {
                throw new MongoAuthenticationException("Error getting nonce for authentication.", ex);
            }

            try
            {
                var passwordDigest = ((PasswordEvidence)credential.Evidence).ComputeMongoCRPasswordDigest(credential.Username);
                var digest = MongoUtils.Hash(nonce + credential.Username + passwordDigest);
                var authenticateCommand = new CommandDocument
                {
                    { "authenticate", 1 },
                    { "user", credential.Username },
                    { "nonce", nonce },
                    { "key", digest }
                };

                RunCommand(connection, credential.Source, authenticateCommand);
            }
            catch (MongoCommandException ex)
            {
                var message = string.Format("Invalid credential for database '{0}'.", credential.Source);
                throw new MongoAuthenticationException(message, ex);
            }
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:40,代码来源:MongoCRAuthenticationProtocol.cs

示例6: Execute

        // public methods
        public WriteConcernResult Execute(MongoConnection connection)
        {
            var serverInstance = connection.ServerInstance;
            if (serverInstance.Supports(FeatureId.WriteCommands) && _args.WriteConcern.Enabled)
            {
                var emulator = new UpdateOpcodeOperationEmulator(_args);
                return emulator.Execute(connection);
            }

            SendMessageWithWriteConcernResult sendMessageResult;
            using (var buffer = new BsonBuffer(new MultiChunkBuffer(BsonChunkPool.Default), true))
            {
                var requests = _args.Requests.ToList();
                if (requests.Count != 1)
                {
                    throw new NotSupportedException("Update opcode only supports a single update request.");
                }
                var updateRequest = (UpdateRequest)requests[0];

                var flags = UpdateFlags.None;
                if (updateRequest.IsMultiUpdate ?? false) { flags |= UpdateFlags.Multi; }
                if (updateRequest.IsUpsert ?? false) { flags |= UpdateFlags.Upsert; }

                var maxDocumentSize = connection.ServerInstance.MaxDocumentSize;
                var query = updateRequest.Query ?? new QueryDocument();

                var message = new MongoUpdateMessage(WriterSettings, CollectionFullName, _args.CheckElementNames, flags, maxDocumentSize, query, updateRequest.Update);
                message.WriteTo(buffer);

                sendMessageResult =  SendMessageWithWriteConcern(connection, buffer, message.RequestId, ReaderSettings, WriterSettings, WriteConcern);
            }

            return WriteConcern.Enabled ? ReadWriteConcernResult(connection, sendMessageResult) : null;
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:35,代码来源:UpdateOpcodeOperation.cs

示例7: Execute

        // public methods
        public BulkWriteResult Execute(MongoConnection connection)
        {
            var serverInstance = connection.ServerInstance;
            if (!serverInstance.Supports(FeatureId.WriteOpcodes))
            {
                throw new NotSupportedException("Write opcodes are not supported.");
            }

            var batchResults = new List<BulkWriteBatchResult>();
            var remainingRequests = new List<WriteRequest>();
            var hasWriteErrors = false;

            var originalIndex = 0;
            foreach (WriteRequest request in _args.Requests)
            {
                if (hasWriteErrors && _args.IsOrdered)
                {
                    remainingRequests.Add(request);
                    continue;
                }

                var batchResult = EmulateSingleRequest(connection, request, originalIndex);
                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
                originalIndex++;
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _args.WriteConcern.Enabled);
            return combiner.CreateResultOrThrowIfHasErrors(remainingRequests);
        }
开发者ID:ExM,项目名称:mongo-csharp-driver,代码行数:32,代码来源:BulkUnmixedWriteOperationEmulatorBase.cs

示例8: Execute

        // public methods
        public virtual BulkWriteResult Execute(MongoConnection connection)
        {
            var batchResults = new List<BulkWriteBatchResult>();
            var remainingRequests = Enumerable.Empty<WriteRequest>();
            var hasWriteErrors = false;

            var decoratedRequests = DecorateRequests(_args.Requests);
            using (var enumerator = decoratedRequests.GetEnumerator())
            {
                var originalIndex = 0;
                Batch<WriteRequest> batch = new FirstBatch<WriteRequest>(enumerator);
                while (batch != null)
                {
                    if (hasWriteErrors && _args.IsOrdered)
                    {
                        remainingRequests = remainingRequests.Concat(batch.RemainingItems);
                        break;
                    }

                    var batchResult = ExecuteBatch(connection, batch, originalIndex);
                    batchResults.Add(batchResult);

                    hasWriteErrors |= batchResult.HasWriteErrors;
                    originalIndex += batchResult.BatchCount;
                    batch = batchResult.NextBatch;
                }
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _args.WriteConcern.Enabled);
            return combiner.CreateResultOrThrowIfHasErrors(remainingRequests);
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:32,代码来源:BulkUnmixedWriteOperationBase.cs

示例9: Execute

        // public methods
        public BulkWriteResult Execute(MongoConnection connection)
        {
            var batchResults = new List<BulkWriteBatchResult>();
            var remainingRequests = Enumerable.Empty<WriteRequest>();
            var hasWriteErrors = false;

            var runCount = 0;
            foreach (var run in FindRuns())
            {
                runCount++;

                if (hasWriteErrors && _isOrdered)
                {
                    remainingRequests = remainingRequests.Concat(run.Requests);
                    continue;
                }

                var batchResult = ExecuteBatch(connection, run);
                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
            }

            if (runCount == 0)
            {
                throw new InvalidOperationException("Bulk write operation is empty.");
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _writeConcern.Enabled);
            return combiner.CreateResultOrThrowIfHasErrors(remainingRequests);
        }
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:32,代码来源:BulkMixedWriteOperation.cs

示例10: ImportToSqlAndMongo

        public static void ImportToSqlAndMongo(BoardgameSimulatorData data, MongoConnection mongoData, string filePath = "../../../DataSources/xml/")
        {
            if (!Directory.Exists(filePath))
            {
                Console.WriteLine("There are no xml files present in " + filePath + " suitable for importing!");
                return;
            }

            var files = Directory.GetFiles(filePath).Select(x => x).Where(x => Path.GetExtension(x) == ".xml");

            Console.WriteLine("Importing from xml into Sql and MongoDb initialized.");

            foreach (var file in files)
            {
                var heroes = GetHeroes(file);
                var items = GetItems(file);

                Console.WriteLine("importing into sql...");
                AddHeroesToSql(heroes, data);
                AddItemsToSql(items, data);

                Console.WriteLine("importing into mongodb...");
                AddHeroesToMongo(heroes, mongoData);
                AddItemsToMongo(items, mongoData);
            }

            Console.WriteLine("Importing from xml into Sql and MongoDb completed!");
        }
开发者ID:Team-Neptunium,项目名称:Databases-Team-Neptunium,代码行数:28,代码来源:XmlImporter.cs

示例11: Authenticate

        // public methods
        /// <summary>
        /// Authenticates the connection against the given database.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="credential">The credential.</param>
        public void Authenticate(MongoConnection connection, MongoCredential credential)
        {
            var nonceCommand = new CommandDocument("getnonce", 1);
            var commandResult = connection.RunCommand(credential.Source, QueryFlags.None, nonceCommand, false);
            if (!commandResult.Ok)
            {
                throw new MongoAuthenticationException(
                    "Error getting nonce for authentication.",
                    new MongoCommandException(commandResult));
            }

            var nonce = commandResult.Response["nonce"].AsString;
            var passwordDigest = MongoUtils.Hash(credential.Username + ":mongo:" + ((PasswordEvidence)credential.Evidence).Password);
            var digest = MongoUtils.Hash(nonce + credential.Username + passwordDigest);
            var authenticateCommand = new CommandDocument
                {
                    { "authenticate", 1 },
                    { "user", credential.Username },
                    { "nonce", nonce },
                    { "key", digest }
                };

            commandResult = connection.RunCommand(credential.Source, QueryFlags.None, authenticateCommand, false);
            if (!commandResult.Ok)
            {
                var message = string.Format("Invalid credential for database '{0}'.", credential.Source);
                throw new MongoAuthenticationException(
                    message,
                    new MongoCommandException(commandResult));
            }
        }
开发者ID:wireclub,项目名称:mongo-csharp-driver,代码行数:37,代码来源:MongoCRAuthenticationProtocol.cs

示例12: Initialize

        /// <summary>
        /// Initializes the mechanism.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="credential">The credential.</param>
        /// <returns>The initial step.</returns>
        public ISaslStep Initialize(MongoConnection connection, MongoCredential credential)
        {
            var serviceName = credential.GetMechanismProperty<string>("SERVICE_NAME", "mongodb");
            var canonicalizeHostname = credential.GetMechanismProperty<bool>("CANONICALIZE_HOST_NAME", false);

            var hostname = connection.ServerInstance.Address.Host;
            if (canonicalizeHostname)
            {
                var entry = Dns.GetHostEntry(hostname);
                if (entry != null)
                {
                    hostname = entry.HostName;
                }
            }

            // TODO: provide an override to force the use of gsasl?
            if (__useGsasl)
            {
                return new GsaslGssapiImplementation(
                    serviceName,
                    hostname,
                    credential.Username,
                    credential.Evidence);
            }

            return new WindowsGssapiImplementation(
                serviceName,
                hostname,
                credential.Username,
                credential.Evidence);
        }
开发者ID:ExM,项目名称:mongo-csharp-driver,代码行数:37,代码来源:GssapiMechanism.cs

示例13: MongoKillCursorsMessage

 internal MongoKillCursorsMessage(
     MongoConnection connection,
     params long[] cursorIds
 )
     : base(connection, MessageOpcode.KillCursors) {
     this.cursorIds = cursorIds;
 }
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoKillCursorsMessages.cs

示例14: AddItemsToMongo

        private static void AddItemsToMongo(List<DummyItem> items, MongoConnection mongoData)
        {
            mongoData.Database.DropCollection("items");

            var itemsCollection = new GenericData<DummyItem>(mongoData.Database, "items");

            itemsCollection.Collection.InsertBatch(items);
        }
开发者ID:Team-Neptunium,项目名称:Databases-Team-Neptunium,代码行数:8,代码来源:XmlImporter.cs

示例15: CreateConnectionPool

        private static MongoConnection[] CreateConnectionPool(Int32 count)
        {
            var connections = new MongoConnection[count];

            for (var i = 0; i < count; i++)
                connections[i] = new MongoConnection(Host, Port, Serializer);

            return connections;
        }
开发者ID:naighes,项目名称:ReactiveMongo,代码行数:9,代码来源:Program.cs


注:本文中的MongoConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。