Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: DirectWriterBenchmark <path-to-MST>");

                return;
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            string masterPath = args[0];

            try
            {
                DirectUtility.CreateDatabase64(masterPath);

                using (DirectAccess64 accessor = new DirectAccess64(masterPath))
                {
                    for (int i = 0; i < 10000; i++)
                    {
                        if (i % 1000 == 0)
                        {
                            Console.Write(".");
                        }

                        MarcRecord record = new MarcRecord();
                        record.BeginUpdate(100);
                        for (int tag = 200; tag < 300; tag++)
                        {
                            record.Fields.Add
                            (
                                new RecordField
                                (
                                    tag,
                                    "Это поле номер " + tag
                                )
                            );
                        }
                        record.EndUpdate();
                        accessor.WriteRecord(record);
                    }

                    Console.WriteLine();

                    for (int approach = 0; approach < 10; approach++)
                    {
                        Console.WriteLine("Approach {0}", approach + 1);
                        for (int mfn = 1; mfn <= 1000; mfn++)
                        {
                            MarcRecord record = accessor.ReadRecord(mfn)
                                                .ThrowIfNull("accessor.ReadRecord(mfn)");
                            record.Fields.Add
                            (
                                new RecordField
                                (
                                    300,
                                    "Запись отредактирована " + DateTime.Now
                                )
                            );
                            accessor.WriteRecord(record);
                        }
                    }
                }

                stopwatch.Stop();
                Console.WriteLine
                (
                    "Elapsed: {0}",
                    stopwatch.Elapsed
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Need two arguments");
                return;
            }

            string inputFileName = args[0]
                                   .ThrowIfNull("inputFileName");
            string outputFileName = args[1]
                                    .ThrowIfNull("outputFileName");
            string mstFileName = Path.ChangeExtension(outputFileName, ".mst")
                                 .ThrowIfNull("mstFileName");
            string xrfFileName = Path.ChangeExtension(outputFileName, ".xrf")
                                 .ThrowIfNull("xrfFileName");

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                DirectUtility.CreateMasterFile64(outputFileName);

                int mfn = 0;
                using (Stream mstFile = new FileStream(mstFileName,
                                                       FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                    using (Stream xrfFile = File.OpenWrite(xrfFileName))
                        using (StreamReader reader = File.OpenText(inputFileName))
                        {
                            MstControlRecord64 control = new MstControlRecord64
                            {
                                NextPosition = MstControlRecord64.RecordSize
                            };
                            control.Write(mstFile);

                            MarcRecord marcRecord;
                            while ((marcRecord = PlainText.ReadRecord(reader)) != null)
                            {
                                if (mfn % 100 == 0)
                                {
                                    Console.Write(" {0} ", mfn);
                                }

                                marcRecord.Mfn     = ++mfn;
                                marcRecord.Version = 1;
                                marcRecord.Status  = RecordStatus.Last;
                                long        position  = mstFile.Position;
                                MstRecord64 mstRecord = MstRecord64.EncodeRecord(marcRecord);
                                mstRecord.Prepare();
                                mstRecord.Write(mstFile);

                                xrfFile.WriteInt64Network(position);
                                xrfFile.WriteInt32Network((int)RecordStatus.NonActualized);
                            }

                            if (mfn != 0)
                            {
                                // Update the control record
                                long nextPosition = mstFile.Length;
                                mstFile.Seek(0, SeekOrigin.Begin);
                                control              = MstControlRecord64.Read(mstFile);
                                control.Blocked      = 0;
                                control.NextMfn      = mfn;
                                control.NextPosition = nextPosition;

                                mstFile.Seek(0, SeekOrigin.Begin);
                                control.Write(mstFile);
                            }
                        }

                Console.WriteLine(" Total: {0}", mfn);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            stopwatch.Stop();
            TimeSpan elapsed = stopwatch.Elapsed;

            Console.WriteLine("Elapsed: {0}", elapsed.ToAutoString());
        }