예제 #1
0
        static void Main(string[] args)
        {
            IEnumerable <string> files = Directory.EnumerateFiles(".", "*.csv");

            foreach (string fileSrc in files)
            {
                Console.WriteLine("R {0}", fileSrc);
                CANLib.CANopen_Magic_Log log = new CANopen_Magic_Log();
                log.Load(fileSrc);

                Console.WriteLine("C");
                CANLib.GVRET_Log logConverted = new GVRET_Log(log);

                string fileTgt = @"GVRET\" + Path.GetFileName(fileSrc);
                Console.WriteLine("W {0}", fileTgt);
                if (!Directory.Exists("GVRET"))
                {
                    Directory.CreateDirectory("GVRET");
                }
                logConverted.Save(fileTgt);
            }
        }
예제 #2
0
        public void RoundTrip()
        {
            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            string[] resourceNames = executingAssembly.GetManifestResourceNames();
            foreach (string resourceName in resourceNames)
            {
                Stream streamSrc = executingAssembly.GetManifestResourceStream(resourceName);

                Stream streamTgt = new MemoryStream((int)streamSrc.Length);
                using (StreamWriter streamWriter = new StreamWriter(streamTgt, new UTF8Encoding(false), bufferSize, true))
                {
                    using (StreamReader streamReader = new StreamReader(streamSrc, Encoding.UTF8, false, bufferSize, true))
                    {
                        CANLib.Log log = null;
                        switch (resourceName)
                        {
                        case "CANLibUnitTest.Resources.BusMasterLog.log":
                            log = new BusMaster_Log();
                            break;

                        case "CANLibUnitTest.Resources.CRTD_Log.txt":
                            log = new CRTD_Log();
                            break;

                        case "CANLibUnitTest.Resources.GVRET_Log.csv":
                            log = new GVRET_Log();
                            break;

                        case "CANLibUnitTest.Resources.MicrochipLog.log":
                            log = new Microchip_Log();
                            break;

                        case "CANLibUnitTest.Resources.post-186027.csv":
                            log = new CANopen_Magic_Log();
                            break;
                        }
                        log.Load(streamReader, dataPointLimit);
                        Assert.AreNotEqual(log.DataCount, 0u);
                        log.Save(streamWriter);
                    }

                    streamWriter.Flush();
                }

                if (dataPointLimit == 0)
                {
                    Assert.AreEqual(streamSrc.Length, streamTgt.Length);
                }

                streamSrc.Position = 0;
                streamTgt.Position = 0;

                using (StreamReader streamReaderTgt = new StreamReader(streamTgt, Encoding.UTF8))
                {
                    using (StreamReader streamReaderSrc = new StreamReader(streamSrc, Encoding.UTF8))
                    {
                        while (!streamReaderTgt.EndOfStream)
                        {
                            string lineSrc = streamReaderSrc.ReadLine();
                            string lineTgt = streamReaderTgt.ReadLine();
                            Assert.AreEqual(lineSrc, lineTgt);
                        }
                        if (dataPointLimit == 0)
                        {
                            Assert.IsTrue(streamReaderSrc.EndOfStream);
                        }
                    }
                }
            }
        }