Example #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);
            }
        }
        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);
            }
        }
Example #3
0
        /// <summary>
        /// Save data to excel file
        /// </summary>
        /// <param name="filePath"></param>
        public void Save(String filePath)
        {
            // Get configuration
            var cfg =
                ConfigurationManager.GetSection("Giga.Transformer") as TransformerConfigSection;

            if (cfg == null)
            {
                throw new ConfigurationErrorsException("<Giga.Transformer> not exist in configuration!");
            }
            // Load entities from file
            var transformer = new Giga.Transformer.Transformer(cfg);

            transformer.SaveOne(filePath, "RdPurchaseOrder", this);
        }
Example #4
0
        /// <summary>
        /// Load data from excel file
        /// </summary>
        /// <param name="filePath">Path of excel file</param>
        /// <returns></returns>
        public static TestEmbededData Load(String filePath)
        {
            // Get configuration
            var cfg =
                ConfigurationManager.GetSection("Giga.Transformer") as TransformerConfigSection;

            if (cfg == null)
            {
                throw new ConfigurationErrorsException("<Giga.Transformer> not exist in configuration!");
            }
            // Load entities from file
            var transformer = new Giga.Transformer.Transformer(cfg);

            return(transformer.LoadOne <TestEmbededData>(filePath, "RdPurchaseOrder"));
        }
Example #5
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);
        }
Example #6
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);
 }
Example #7
0
 /// <summary>
 /// Load data from excel file
 /// </summary>
 /// <param name="filePath">Path of excel file</param>
 /// <returns></returns>
 public static TestEmbededData Load(String filePath)
 {
     // Get configuration
     var cfg =
         ConfigurationManager.GetSection("Giga.Transformer") as TransformerConfigSection;
     if (cfg == null)
         throw new ConfigurationErrorsException("<Giga.Transformer> not exist in configuration!");
     // Load entities from file
     var transformer = new Giga.Transformer.Transformer(cfg);
     return transformer.LoadOne<TestEmbededData>(filePath, "RdPurchaseOrder");
 }
Example #8
0
 /// <summary>
 /// Save data to excel file
 /// </summary>
 /// <param name="filePath"></param>
 public void Save(String filePath)
 {
     // Get configuration
     var cfg =
         ConfigurationManager.GetSection("Giga.Transformer") as TransformerConfigSection;
     if (cfg == null)
         throw new ConfigurationErrorsException("<Giga.Transformer> not exist in configuration!");
     // Load entities from file
     var transformer = new Giga.Transformer.Transformer(cfg);
     transformer.SaveOne(filePath, "RdPurchaseOrder",this);
 }