예제 #1
0
        public void TestReadTabularData_FixedRange()
        {
            // Get configuration
            var cfg =
                ConfigurationManager.GetSection("Giga.Transformer") as TransformerConfigSection;
            if (cfg == null)
                throw new ConfigurationErrorsException("<Giga.Transformer> not exist in configuration!");

            // Get test file
            var filePath = GetTestFilePath("TransformerTest.xlsx");
            if (!File.Exists(filePath))
                throw new FileNotFoundException(String.Format("Test file {0} not found!", filePath));
            // Load entities from file
            var transformer = new Giga.Transformer.Transformer(cfg);
            var entities = transformer.Load<TestTabularData>(filePath, "TestNormalTabularData_FixedRange");
            foreach (TestTabularData entity in entities)
            {
                var serializer = new DataContractJsonSerializer(typeof(TestTabularData));
                var memStrm = new MemoryStream();
                var writer = new StreamWriter(memStrm, Encoding.UTF8);
                serializer.WriteObject(memStrm, entity);
                byte[] buf = memStrm.GetBuffer();
                String xmlStr = Encoding.UTF8.GetString(buf);
                Console.WriteLine(xmlStr);
            }
        }
예제 #2
0
        public void TestReadTabularData_FixedRange()
        {
            // Get configuration
            var cfg =
                ConfigurationManager.GetSection("Giga.Transformer") as TransformerConfigSection;

            if (cfg == null)
            {
                throw new ConfigurationErrorsException("<Giga.Transformer> not exist in configuration!");
            }

            // Get test file
            var filePath = GetTestFilePath("TransformerTest.xlsx");

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(String.Format("Test file {0} not found!", filePath));
            }
            // Load entities from file
            var transformer = new Giga.Transformer.Transformer(cfg);
            var entities    = transformer.Load <TestTabularData>(filePath, "TestNormalTabularData_FixedRange");

            foreach (TestTabularData entity in entities)
            {
                var serializer = new DataContractJsonSerializer(typeof(TestTabularData));
                var memStrm    = new MemoryStream();
                var writer     = new StreamWriter(memStrm, Encoding.UTF8);
                serializer.WriteObject(memStrm, entity);
                byte[] buf    = memStrm.GetBuffer();
                String xmlStr = Encoding.UTF8.GetString(buf);
                Console.WriteLine(xmlStr);
            }
        }
예제 #3
0
        public void TestWriteTabularData_FixedRange()
        {
            // Get configuration
            var cfg =
                ConfigurationManager.GetSection("Giga.Transformer") as TransformerConfigSection;

            if (cfg == null)
            {
                throw new ConfigurationErrorsException("<Giga.Transformer> not exist in configuration!");
            }
            // Get test file
            var filePath = GetTestFilePath("TransformerTest.xlsx");

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(String.Format("Test file {0} not found!", filePath));
            }
            // Create a new file
            var newFilePath = GetTestFilePath("TransformerTest_WriteTabular.xlsx");

            if (File.Exists(newFilePath))
            {
                File.Delete(newFilePath);
            }
            File.Copy(filePath, newFilePath);
            // Load entities from old file
            var transformer = new Giga.Transformer.Transformer(cfg);
            var entities    = transformer.Load <TestTabularData>(filePath, "TestNormalTabularData_FixedRange").ToList();

            foreach (TestTabularData entity in entities)
            {
                entity.DueDate     += new TimeSpan(1, 0, 0, 0);
                entity.Item        += 1;
                entity.PO          += "_new";
                entity.PODate      += new TimeSpan(1, 0, 0, 0);
                entity.ProductCode += "_new";
                entity.ProductName += "_new";
                entity.Qty         += 1;
                entity.Total       += 1;
                entity.UnitPrice   += 1;
                entity.Weight      += 1;
            }
            // Write entities to new file
            transformer.Save(newFilePath, "TestNormalTabularData_FixedRange", entities);
        }
예제 #4
0
 public void TestWriteTabularData_FixedRange()
 {
     // Get configuration
     var cfg =
         ConfigurationManager.GetSection("Giga.Transformer") as TransformerConfigSection;
     if (cfg == null)
         throw new ConfigurationErrorsException("<Giga.Transformer> not exist in configuration!");
     // Get test file
     var filePath = GetTestFilePath("TransformerTest.xlsx");
     if (!File.Exists(filePath))
         throw new FileNotFoundException(String.Format("Test file {0} not found!", filePath));
     // Create a new file
     var newFilePath = GetTestFilePath("TransformerTest_WriteTabular.xlsx");
     if (File.Exists(newFilePath))
         File.Delete(newFilePath);
     File.Copy(filePath, newFilePath);
     // Load entities from old file
     var transformer = new Giga.Transformer.Transformer(cfg);
     var entities = transformer.Load<TestTabularData>(filePath, "TestNormalTabularData_FixedRange").ToList();
     foreach (TestTabularData entity in entities)
     {
         entity.DueDate += new TimeSpan(1, 0, 0, 0);
         entity.Item += 1;
         entity.PO += "_new";
         entity.PODate += new TimeSpan(1, 0, 0, 0);
         entity.ProductCode += "_new";
         entity.ProductName += "_new";
         entity.Qty += 1;
         entity.Total += 1;
         entity.UnitPrice += 1;
         entity.Weight += 1;
     }
     // Write entities to new file
     transformer.Save(newFilePath, "TestNormalTabularData_FixedRange", entities);
 }