Exemple #1
0
 public MemoryMappedRecordNode(EsfCodec codec, byte[] bytes, int start)
     : base(codec, bytes[start - 1])
 {
     base.Codec         = codec;
     buffer             = bytes;
     mapStart           = start - 1;
     InvalidateSiblings = true;
 }
Exemple #2
0
 public void StartLoading(string file, EsfCodec codec)
 {
     this.file        = file;
     progress.Value   = 0;
     progress.Maximum = (int)new System.IO.FileInfo(file).Length;
     currentCodec     = codec;
     currentCodec.NodeReadFinished += Update;
 }
Exemple #3
0
        public string RunTest(string file, ToolStripProgressBar progress, ToolStripStatusLabel statusLabel)
        {
            string originalTitle = statusLabel.Text;

            statusLabel.Text = string.Format("Loading file {0}", Path.GetFileName(file));
            Application.DoEvents();
            string result;

            // ProgressUpdater updater = new ProgressUpdater(progress);
            using (Stream s = File.OpenRead(file)) {
                try {
                    EsfCodec codec = EsfCodecUtil.GetCodec(File.OpenRead(file));
                    if (codec != null)
                    {
                        //updater.StartLoading(file, codec);
                        TestsRun++;
                        EsfFile esfFile      = new EsfFile(s, codec);
                        string  testFileName = file + "_test";
                        EsfCodecUtil.WriteEsfFile(testFileName, esfFile);
//                        using (BinaryWriter writer = new BinaryWriter(File.Create(testFileName))) {
//                            codec.EncodeRootNode(writer, esfFile.RootNode);
//                        }
                        statusLabel.Text = string.Format("Saving file {0}", Path.GetFileName(file));
                        Application.DoEvents();
                        using (Stream reloadStream = File.OpenRead(testFileName)) {
                            EsfFile reloadedFile = new EsfFile(reloadStream, codec);
                            if (esfFile.Equals(reloadedFile))
                            {
                                TestSuccesses++;
                                result = string.Format("success Test {0}", file);
                            }
                            else
                            {
                                result = string.Format("FAIL Test {0}: Reload of save file different from original", file);
                            }
                        }
                        Application.DoEvents();
                        File.Delete(testFileName);
                    }
                    else
                    {
                        result = string.Format("not running test on {0}", file);
                    }
                } catch (Exception e) {
                    result = string.Format("FAIL Test of {0}: {1}", file, e);
                }
                s.Close();
                //updater.LoadingFinished();
            }
            statusLabel.Text = originalTitle;
            return(result);
        }
Exemple #4
0
        public string RunTest(string file, ToolStripProgressBar progress, ToolStripStatusLabel statusLabel)
        {
            string text = statusLabel.Text;

            statusLabel.Text = $"Loading file {Path.GetFileName(file)}";
            Application.DoEvents();
            string result;

            using (Stream stream = File.OpenRead(file))
            {
                try
                {
                    EsfCodec codec = EsfCodecUtil.GetCodec(File.OpenRead(file));
                    if (codec != null)
                    {
                        TestsRun++;
                        EsfFile esfFile = new EsfFile(stream, codec);
                        string  text2   = file + "_test";
                        EsfCodecUtil.WriteEsfFile(text2, esfFile);
                        statusLabel.Text = $"Saving file {Path.GetFileName(file)}";
                        Application.DoEvents();
                        using (Stream stream2 = File.OpenRead(text2))
                        {
                            EsfFile obj = new EsfFile(stream2, codec);
                            if (esfFile.Equals(obj))
                            {
                                TestSuccesses++;
                                result = $"success Test {file}";
                            }
                            else
                            {
                                result = $"FAIL Test {file}: Reload of save file different from original";
                            }
                        }
                        Application.DoEvents();
                        File.Delete(text2);
                    }
                    else
                    {
                        result = $"not running test on {file}";
                    }
                }
                catch (Exception arg)
                {
                    result = $"FAIL Test of {file}: {arg}";
                }
                stream.Close();
            }
            statusLabel.Text = text;
            return(result);
        }
Exemple #5
0
        static void testNew(string filename)
        {
            using (FileStream
                   logStream = File.Create(filename + "_log.txt"),
                   addressStream = File.Create(filename + "_address.txt")) {
                logWriter        = new StreamWriter(logStream);
                addressLogWriter = new StreamWriter(addressStream);
                EsfFile  file  = null;
                DateTime start = DateTime.Now;
                try {
                    Console.WriteLine("reading {0}", filename);
                    using (FileStream stream = File.OpenRead(filename)) {
                        EsfCodec codec = EsfCodecUtil.GetCodec(stream);
                        TicToc   timer = new TicToc();
                        codec.NodeReadStarting += timer.Tic;
                        codec.NodeReadFinished += timer.Toc;
                        // codec.NodeReadFinished += OutputNodeEnd;
                        file = EsfCodecUtil.LoadEsfFile(filename);
                        forceDecode(file.RootNode);
                        //file = new EsfFile(stream, codec);

                        timer.DumpAll();
                    }
                    Console.WriteLine("{0} read in {1} seconds", file, (DateTime.Now.Ticks - start.Ticks) / 10000000);
                    Console.WriteLine("Reading finished, saving now");
                } catch (Exception e) {
                    Console.WriteLine("Read failed: {0}, {1}", filename, e);
                }
                try {
                    string saveFile = filename + "_save";
                    if (file != null)
                    {
                        EsfCodecUtil.WriteEsfFile(saveFile, file);
                    }
                    //File.Delete(saveFile);
                } catch (Exception e) {
                    Console.WriteLine("Write {0} failed: {1}", filename, e);
                }
                logWriter.Flush();
                addressLogWriter.Flush();
            }
        }
Exemple #6
0
 public EsfNode Decode(Stream stream)
 {
     codecDelegate = EsfCodecUtil.GetCodec(stream);
     return(codecDelegate.Parse(stream));
 }
 public void StartLoading(string file, EsfCodec codec)
 {
     progress.Maximum = (int)new FileInfo(file).Length;
     currentCodec     = codec;
     currentCodec.NodeReadFinished += Update;
 }