Esempio n. 1
0
        private void WriteLog()
        {
            _customLogger.WriteMessage($"There are [{_specificExporters.Count}] resolved exporters.");

            foreach (ISpecificUnifiExporter exporter in _specificExporters)
            {
                _customLogger.WriteMessage($"\tThere is [{exporter.GetType().Name}] exporter resolved.");
            }

            _customLogger.WriteMessage("\n");
        }
        public Task ExportAsync(string databaseName, string collectionName, IEnumerable <String> jsonDocuments, CancellationToken cancellationToken)
        {
            if (!_blacklist.IsBlacklisted($"{databaseName}.{collectionName}"))
            {
                cancellationToken.ThrowIfCancellationRequested();
                var    jsonDocument   = MergeDocumentsToCollectionJson(jsonDocuments, collectionName);
                byte[] collectionData = Encoding.UTF8.GetBytes(jsonDocument);
                string path           = CreateCollectionPath(_directoryWrapper, _rootPath, databaseName, _dateTimeStamp);
                path = GetCollectionFilePath(collectionName, path);
                _fileWrapper.WriteAllBytes(path, collectionData);
                _customLogger.WriteMessage($"Collection Name {collectionName} saved to file system");
            }
            else
            {
                _customLogger.WriteMessage($"FS: Blacklisted table: [{databaseName}.{collectionName}]", EventLogEntryType.Warning);
            }

            return(Task.CompletedTask);
        }
Esempio n. 3
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);
        }