public void CreateDatabase_Test1() { IrbisConnection connection = Connection .ThrowIfNull("Connection"); const string DatabaseName = "NEWDB2"; const string Description = "New database 2"; connection.CreateDatabase ( DatabaseName, Description, false, null ); Write("{0} created | ", DatabaseName); Thread.Sleep(700); int maxMfn = connection.GetMaxMfn(DatabaseName); Write("MaxMfn={0} | ", maxMfn); Thread.Sleep(700); connection.DeleteDatabase(DatabaseName); Write("{0} deleted", DatabaseName); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: NetworkReaderBenchmark <path-to-MST>"); return; } string connectionString = args[0]; try { IrbisEncoding.RelaxUtf8(); Console.WriteLine("Open"); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); using (IrbisConnection connection = new IrbisConnection(connectionString)) { int maxMfn = connection.GetMaxMfn(); Console.WriteLine("Max MFN={0}", maxMfn); IEnumerable <MarcRecord> batch = BatchRecordReader.WholeDatabase ( connection, connection.Database, 1000, reader => { Console.Write('.'); } ); foreach (MarcRecord record in batch) { if (record.Modified) { Console.WriteLine("Very strange!"); } } } stopwatch.Stop(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Close"); Console.WriteLine ( "Elapsed: {0} sec", stopwatch.Elapsed.ToSecondString() ); } catch (Exception exception) { Console.WriteLine(exception); } }
static int Main(string[] arguments) { try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string connectionString = CM.AppSettings["connectionString"]; if (string.IsNullOrEmpty(connectionString)) { Console.WriteLine("Connection string not specified"); return(1); } CommandLineParser parser = new CommandLineParser(); ParsedCommandLine parsed = parser.Parse(arguments); if (parsed.PositionalArguments.Count != 0) { connectionString = parsed.PositionalArguments[0]; } using (IrbisConnection connection = new IrbisConnection(connectionString)) { int maxMfn = connection.GetMaxMfn(); string expression = RequestPrefixes.Unfulfilled /* I=0 */ + " + " + RequestPrefixes.Reserved; /* I=2 */ if (parsed.HaveSwitch("expression")) { expression = parsed.GetSwitch("expression") .ThrowIfNull() .Value; } expression = expression.ThrowIfNull("expression"); Console.Write("Reading good records "); MarcRecord[] goodRecords = BatchRecordReader.Search ( connection, connection.Database, expression, 1000, batch => Console.Write(".") ) .ToArray(); Console.WriteLine(); Console.WriteLine ( "Good records loaded: {0}", goodRecords.Length ); if (goodRecords.Length == maxMfn) { Console.WriteLine("No truncation needed, exiting"); return(0); } connection.TruncateDatabase(connection.Database); Console.WriteLine("Database truncated"); using (BatchRecordWriter writer = new BatchRecordWriter ( connection, connection.Database, 500 )) { foreach (MarcRecord record in goodRecords) { record.Version = 0; record.Mfn = 0; writer.Append(record); } } Console.WriteLine("Good records restored"); stopwatch.Stop(); Console.WriteLine ( "Elapsed: {0}", stopwatch.Elapsed.ToAutoString() ); } } catch (Exception ex) { Console.WriteLine(ex); return(1); } return(0); }
static void Main(string[] args) { if (args.Length != 2) { return; } _irbisConnectionString = args[0]; _sqlConnectionString = args[1]; try { _stopwatch = new Stopwatch(); _stopwatch.Start(); Sql2000DataProvider dataProvider = new Sql2000DataProvider(); using (_irbisConnection = new IrbisConnection(_irbisConnectionString)) using (_database = new DbManager(dataProvider, _sqlConnectionString)) { Console.WriteLine ( "Started at: {0}", DateTime.Now.ToLongUniformString() ); int maxMfn = _irbisConnection.GetMaxMfn(); Console.WriteLine("Max MFN={0}", maxMfn); _database .SetCommand("delete from [dbo].[irbisdata]") .ExecuteNonQuery(); Console.WriteLine("table truncated"); BatchRecordReader batch = (BatchRecordReader)BatchRecordReader.WholeDatabase ( _irbisConnection, _irbisConnection.Database, 500 ); foreach (MarcRecord record in batch) { try { ProcessRecord(record); } catch (Exception exception) { Console.WriteLine("Exception: {0}", exception.Message); Debug.WriteLine(exception); } } _database .SetCommand("EXECUTE [upload_done]") .ExecuteNonQuery(); _database .SetCommand("insert into [FlagTable] default values") .ExecuteNonQuery(); _stopwatch.Stop(); TimeSpan elapsed = _stopwatch.Elapsed; Console.WriteLine ( "Elapsed: {0}", elapsed.ToAutoString() ); } } catch (Exception exception) { Console.WriteLine(exception); } }
private static void Main() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { string connectionString = ConfigurationUtility .GetString("connectionString") .ThrowIfNull("connectionString not set"); Threshold = IrbisDate.ConvertStringToDate ( ConfigurationUtility .GetString("threshold") .ThrowIfNull("threshold not set") ); LowerBound = DateTime.MinValue; string lowerText = ConfigurationUtility.GetString("lowerBound"); if (!string.IsNullOrEmpty(lowerText)) { LowerBound = IrbisDate.ConvertStringToDate(lowerText); } Console.WriteLine("Loading readers"); List <ReaderInfo> allReaders = new List <ReaderInfo>(); OldReaders = new BlockingCollection <ReaderInfo>(); using (IrbisConnection connection = new IrbisConnection(connectionString)) { ReaderManager manager = new ReaderManager(connection) { OmitDeletedRecords = true }; manager.BatchRead += (obj, ea) => Console.Write("."); string[] databases = ConfigurationUtility.GetString("databases") .ThrowIfNull("databases not specified") .Split ( new[] { ' ', ';', ',' }, StringSplitOptions.RemoveEmptyEntries ); foreach (string database in databases) { Console.WriteLine ( "Database: {0}, records: {1}", database, connection.GetMaxMfn(database) - 1 ); allReaders.AddRange ( manager.GetAllReaders(database) ); Console.WriteLine(); } } WriteDelimiter(); Console.WriteLine("Merging"); Console.WriteLine("Records before merging: {0}", allReaders.Count); allReaders = ReaderManager.MergeReaders(allReaders); Console.WriteLine("Records after merging: {0}", allReaders.Count); WriteDelimiter(); Console.WriteLine("Filtering"); ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = 4 }; Parallel.ForEach(allReaders, options, ProcessReader); ReaderInfo[] oldReaders = OldReaders.ToArray(); WriteDelimiter(); Console.WriteLine("Sorting"); oldReaders = oldReaders.OrderBy ( reader => reader.FullName ) .ToArray(); WriteDelimiter(); Console.WriteLine ( "Create table: {0} lines", oldReaders.Length ); Workbook workbook = new Workbook(); workbook.CreateNewDocument(); Worksheet worksheet = workbook.Worksheets[0]; int row = 0; worksheet.Cells[row, 0].Value = "ФИО"; worksheet.Cells[row, 1].Value = "Билет"; worksheet.Cells[row, 2].Value = "Регистрация"; worksheet.Cells[row, 3].Value = "Кол-во"; worksheet.Cells[row, 4].Value = "Последнее событие"; worksheet.Cells[row, 5].Value = "Отделы"; DrawBorders(worksheet, row); row++; for (int i = 0; i < oldReaders.Length; i++) { if (i % 100 == 0) { Console.Write("."); } ReaderInfo reader = oldReaders[i]; string lastDate = (string)reader.UserData; if (string.IsNullOrEmpty(lastDate)) { lastDate = "--"; } string departments = StringUtility.Join ( ", ", reader.Registrations .Select(reg => reg.Chair) .Concat ( reader.Visits .Select(visit => visit.Department) ) .NonEmptyLines() .Distinct() ); worksheet.Cells[row, 0].Value = reader.FullName; worksheet.Cells[row, 1].Value = reader.Ticket; worksheet.Cells[row, 2].Value = reader.RegistrationDate .ToShortDateString(); worksheet.Cells[row, 3].Value = reader.Visits.Length + reader.Registrations.Length; worksheet.Cells[row, 4].Value = lastDate; worksheet.Cells[row, 5].Value = departments; DrawBorders(worksheet, row); row++; } WriteDelimiter(); workbook.SaveDocument(OutputFile); Console.WriteLine("All done"); stopwatch.Stop(); TimeSpan elapsed = stopwatch.Elapsed; Console.WriteLine("Elapsed: {0}", elapsed); Console.WriteLine("Old readers: {0}", oldReaders.Length); } catch (Exception exception) { Console.WriteLine(exception); } }
static void Main() { try { StartTime = DateTime.Now; // Устанавливаем обработчик прерывания Console.CancelKeyPress += Console_CancelKeyPress; ReadConfiguration(); using (Log = new StreamWriter(LogFileName, true, Encoding.Default)) { int mfnBefore, mfnAfter; WriteLogLine(new string('=', 70)); WriteLogLine("Импорт начат: {0}", StartTime); WriteLogLine(string.Empty); string[] inputFiles = DiscoverFiles(); WriteLogLine("Найдено файлов: {0}", inputFiles.Length); if (inputFiles.Length == 0) { WriteLogLine("Нет импортируемых файлов, завершаемся"); return; } Array.Sort(inputFiles); using (Client = new IrbisConnection()) { //using (Buffer = new RecordBuffer(Client, 100)) { //Buffer.Actualize = true; //Buffer.Database = Client.Database; //Buffer.BatchWrite += Buffer_BatchWrite; Client.ParseConnectionString(ConnectionString); WriteLog("Подключение к серверу... "); Client.Connect(); WriteLogLine("успешно"); Fst = FstFile.ParseServerFile ( Client, FstFileName ); WriteLogLine("Файл FST содержит {0} строк", Fst.Lines.Count); if (Fst.Lines.Count == 0) { WriteLogLine("Плохой файл FST, завершаемся"); return; } Magazines = LoadMagazines(); WriteLogLine ( "Сводных описаний импортируемых журналов в каталоге: {0}", Magazines.Count ); if (Magazines.Count == 0) { WriteLogLine("Нет импортируемых журналов в каталоге"); return; } mfnBefore = Client.GetMaxMfn(); using (Queue = new QueueEngine <RecordTask> ( Environment.ProcessorCount, QueueLength )) { //Queue.Waiting += Queue_Waiting; int index = 0; foreach (string inputFile in inputFiles) { if (GoOn) { ProcessFile ( ++index, inputFile ); if (GoOn && DeleteProcessedFiles) { WriteLog("Удаляем файл... "); File.Delete(inputFile); WriteLogLine("удален"); } } // if } // foreach WriteLogLine("Длина очереди: {0}", Queue.QueueLength); WriteLog("Ожидаем завершения обработки записей в очереди: "); } // using Queue if (!GoOn) { WriteLogLine("Импорт прерван пользователем"); } WriteLogLine("Отправка на сервер оставшихся записей"); } // using Buffer mfnAfter = Client.GetMaxMfn(); } // using Client WriteLogLine("Произведено корректное отключение от сервера"); TimeSpan elapsedTime = DateTime.Now - StartTime; WriteLogLine ( "Затрачено времени: {0}", elapsedTime ); WriteLogLine ( "Импортировано файлов: {0}, записей: {1}", FileCount, RecordCount ); WriteLogLine ( "MFN до={0}, после={1}", mfnBefore, mfnAfter ); } } catch (Exception exception) { Log = null; WriteLogLine ( "ВОЗНИКЛА ОШИБКА: {0}", exception ); WriteLogLine("Аварийное завершение"); } }