Exemplo n.º 1
0
        /// <summary>
        ///  Method useful for adding a MongoTestEntry object to MongoDB using the TestFixture's MongoDataBaseWriter<T> class
        /// </summary>
        /// <param name="message"></param>
        /// <param name="collectionName"></param>
        protected void AddMongoEntryDatabaseT(string message = "Hello World", string collectionName = MONGO_COLLECTION_1_NAME)
        {
            Entry mongoEntry = new Entry();

            mongoEntry.Message   = message;
            mongoEntry.TimeStamp = DateTime.Now;

            _databaseWriterT.Write(collectionName, mongoEntry);
        }
Exemplo n.º 2
0
        public void Save()
        {
            BlockingCollection <string> lineBuffer =
                new BlockingCollection <string>(BufferSize);

            BlockingCollection <DatabaseObjects> objectBuffer =
                new BlockingCollection <DatabaseObjects>(BufferSize);

            var fileRead   = _taskFactory.StartNew(() => _fileReader.Read(lineBuffer));
            var fileParser = _taskFactory.StartNew(() => _parser.Parse(lineBuffer, objectBuffer));
            //var fileParser = _taskFactory.StartNew(() => _parser.Parse(lineBuffer, objectBuffer));
            var database = _taskFactory.StartNew(() => _writer.Write(objectBuffer));

            //var database = _taskFactory.StartNew(() =>  _writer.Write(parserBuffer));

            Task.WaitAll(fileRead, fileParser, database);
        }
Exemplo n.º 3
0
 public void Write <T>(T entry)
 {
     _databaseWriter.Write(_collectionName, entry);
 }
Exemplo n.º 4
0
        public Task ExportAsync(string databaseName, string collectionName, IEnumerable <String> jsonDocuments, CancellationToken cancellationToken)
        {
            if (!_blacklist.IsBlacklisted($"{databaseName}.{collectionName}") && jsonDocuments.Any())
            {
                var documents  = jsonDocuments.ToList();
                var totalCount = documents.Count();

                int logCounter1 = 0;
                int counter     = 0;
                while ((counter = documents.Count()) > 0)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    var documentsToProcess = documents.Take(_batchSize).ToList();

                    Dictionary <string, string> documentDictionary = new Dictionary <string, string>();
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine($"Collection Name: {collectionName} | Going to check {documentsToProcess.Count} / {totalCount} these ids:");
                    foreach (var jsonDocument in documentsToProcess)
                    {
                        documents.Remove(jsonDocument);
                        string id = GetId(jsonDocument);

                        logCounter1++;
                        stringBuilder.AppendLine($"{id} -> {logCounter1} / {totalCount}");
                        documentDictionary.Add(id, jsonDocument);
                    }

                    string concatenatedIds = string.Join(", ", documentDictionary.Keys.Select(d => $"'{d}'"));
                    var    checkCommand    = _checkerCommandCreatorProvider.GetCommandCreator(databaseName, collectionName, concatenatedIds);
                    if (checkCommand != null)
                    {
                        var ids = _checker.Check(checkCommand).ToList();

                        AddLines(stringBuilder, 3);
                        var documentsToProcessPairs = documentDictionary.Where(d => !ids.Any(d2 => string.Equals(d2.Value, d.Key, StringComparison.CurrentCultureIgnoreCase))).Select(d => d).ToList();

                        documentDictionary.Clear();
                        documentsToProcessPairs.ForEach(d => documentDictionary.Add(d.Key, d.Value));
                    }

                    stringBuilder.AppendLine("Going to write these ids:");
                    if (documentDictionary.Any())
                    {
                        foreach (var item in documentDictionary)
                        {
                            stringBuilder.AppendLine(item.Key);
                        }

                        AddLines(stringBuilder, 3);
                        var writeCommand = _writerCommandCreatorProvider.GetCommandCreator(databaseName, collectionName, documentDictionary);
                        if (writeCommand != null && _writer.Write(writeCommand))
                        {
                            stringBuilder.AppendLine("Ids were written");
                        }
                        else
                        {
                            stringBuilder.AppendLine("Ids were NOT written");
                        }
                    }

                    _customLogger.WriteMessage(stringBuilder.ToString());
                    stringBuilder.Clear();
                }
            }
            else
            {
                _customLogger.WriteMessage($"SQL: Blacklisted table: [{databaseName}.{collectionName}]", EventLogEntryType.Warning);
            }

            return(Task.CompletedTask);
        }