示例#1
0
        private void generateFile_Click(object sender, EventArgs e)
        {
            string     directory           = Configuration.Directory();
            string     destinationDataType = DestinationDataComboBox.Text;
            string     fileName            = DestinationFileNameTextBox.Text + SetFileExtension(destinationDataType);
            DataFormat dataFormat;

            switch (destinationDataType)
            {
            case "JSON":
                dataFormat             = new JSONDataFormat();
                dataFormat.DataObjects = SetDataObjects.Set(allAttributes, KeepVals);
                dataFormat.WriteToFile(directory, fileName);
                break;

            case "XML":
                dataFormat             = new XMLDataFormat();
                dataFormat.DataObjects = SetDataObjects.Set(allAttributes, KeepVals);
                dataFormat.WriteToFile(directory, fileName);
                break;

            case "API":
                break;

            case "SQL":
                dataFormat             = new SqlDataFormat();
                dataFormat.DataObjects = SetDataObjects.Set(allAttributes, KeepVals);
                dataFormat.WriteToFile(directory, fileName);
                break;

            case "Excel":
                dataFormat             = new ExcelDataFormat();
                dataFormat.DataObjects = SetDataObjects.Set(allAttributes, KeepVals);
                dataFormat.WriteToFile(directory, fileName);
                break;

            case "Database":
                var source   = DbSourceText.Text;
                var catalog  = DbDatabaseText.Text;
                var userName = DbUserNameText.Text;
                var pass     = DbPasswordText.Text;
                dataFormat             = new DBDataFormat(source, catalog, userName, pass);
                StatusLabel.Text       = new DBDataFormat(source, catalog, userName, pass).DB.Status;
                dataFormat.DataObjects = SetDataObjects.Set(allAttributes, KeepVals);
                dataFormat.WriteToFile(directory, fileName);
                break;

            default:
                dataFormat = new JSONDataFormat();
                break;
            }
        }
示例#2
0
        private void AddRegions(IXLWorksheet worksheet, ExcelSheet sheet)
        {
            foreach (var dataRegion in sheet.Regions)
            {
                Throw <ArgumentNullException> .WhenObject.IsNull(() => dataRegion.Coordinates);

                _dataFormat = ExcelDataFormatFactory.GetDataFormat(dataRegion.ConfigurationDataFormat);
                _excelStyle = ExcelStyleFactory.GetStyle(dataRegion.ConfigurationExcelStyle);
                AddHeader(worksheet, dataRegion);
                AddRows(worksheet, dataRegion);
                SetStyles(worksheet, dataRegion);
                dataRegion.Coordinates.HeaderRowInitial++;
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            // Set up data
            string initialDirectory = "C:\\Users\\eedee\\Documents";
            string jsonSource       = "test_json.json";
            string jsonForDB        = "test_db_json.json";
            string excelSource      = "testExcel.xlsx";
            string apiSource        = "http://ewhiting.eastus.cloudapp.azure.com/midterm/Classes/Genre/read.php";

            // Basic demo
            List <string> attrs = new List <string>();

            attrs.Add("name");
            attrs.Add("job");
            attrs.Add("age");
            DataFormat excelDF = new ExcelDataFormat(initialDirectory + "\\" + jsonSource, attrs, SourceDataType.JSON);
            DataFormat jsonDF  = new JsonDataFormat(initialDirectory + "\\" + excelSource, attrs, SourceDataType.Excel);

            excelDF.WriteData(initialDirectory, "excelTest");
            jsonDF.WriteData(initialDirectory, "jsonTest");

            // API demo
            List <string> apiAttrs = new List <string>();

            apiAttrs.Add("id");
            apiAttrs.Add("name");
            apiAttrs.Add("picture_path");
            DataFormat xmlDF = new XmlDataFormat(apiSource, apiAttrs, SourceDataType.API);

            xmlDF.WriteData(initialDirectory, "xmlTest");

            // Bulk data actions demo
            List <DataFormat> dataFormats = new List <DataFormat>();

            dataFormats.Add(xmlDF);
            dataFormats.Add(jsonDF);
            dataFormats.Add(excelDF);
            BulkActions.WriteDataFormatsToFile(dataFormats, initialDirectory, "bulktest");

            // Generics Demo
            MultiDataFormat <DataFormat> jsonGeneric  = new MultiDataFormat <DataFormat>(jsonSource, attrs, SourceDataType.JSON);
            MultiDataFormat <DataFormat> excelGeneric = new MultiDataFormat <DataFormat>(excelSource, attrs, SourceDataType.Excel);
            List <DataFormat>            dfs          = new List <DataFormat>();

            List <MultiDataFormat <DataFormat> > genericDFs = new List <MultiDataFormat <DataFormat> >();

            genericDFs.Add(jsonGeneric);
            genericDFs.Add(excelGeneric);
            DataFormat excelFromGeneric = BulkActions.FromMultipleSources(genericDFs, "excel");

            excelFromGeneric.WriteData(initialDirectory, "GenericExcel");

            // Database demo
            List <string> dbAttrs = new List <string>();

            dbAttrs.Add("fname");
            dbAttrs.Add("lname");
            dbAttrs.Add("age");
            string             server   = Environment.MachineName;
            string             db       = "LearningTest";
            string             user     = "******";
            string             password = "******";
            DatabaseDataFormat dbDF     = new DatabaseDataFormat(
                server: server,
                catalog: db,
                username: user,
                password: password,
                dbSystem: "sqlserver",
                source: initialDirectory + "\\" + jsonForDB,
                KeepValues: dbAttrs,
                sourceDataType: SourceDataType.JSON
                );

            dbDF.WriteData("", "People");
        }
示例#4
0
 public ExcelReaderCreator(Stream stream, ExcelDataFormat format)
 {
     _reader = format == ExcelDataFormat.OpenXml
         ? ExcelReaderFactory.CreateOpenXmlReader(stream)
         : ExcelReaderFactory.CreateBinaryReader(stream);
 }