コード例 #1
0
ファイル: AnyToDataTable.cs プロジェクト: eyedia/idpe
        private DataTable GenerateInputDataFromInterface(string interfaceName)
        {
            if ((!string.IsNullOrEmpty(interfaceName)) &&
                (Type.GetType(interfaceName) != null))
            {
                object             objInputFileGenerator = Activator.CreateInstance(Type.GetType(interfaceName), Job);
                InputFileGenerator inputFileGenerator    = (InputFileGenerator)objInputFileGenerator;
                DataTable          table = new DataTable();
                try
                {
                    //try 1: with fileName
                    table = inputFileGenerator.GenerateFileContent(Job.FileName);
                }
                catch (NotImplementedException)
                {
                    try
                    {
                        //try 2: with fileContent
                        StringBuilder sb = new StringBuilder(Job.FileContent.ToString());
                        table = inputFileGenerator.GenerateFileContent(sb);
                    }
                    catch (NotImplementedException)
                    {
                        Job.TraceError("The datasource '{0}' has not implemented '{1}' interface."
                                       , Job.DataSource.Name, interfaceName);
                    }
                }

                Job.CsvRows.Clear();

                if (Job.DataSource.IsFirstRowHeader)
                {
                    string columnNames = string.Empty;
                    foreach (IdpeAttribute attrib in Job.DataSource.AcceptableAttributes)
                    {
                        columnNames += "\"" + attrib.Name + "\",";
                    }
                    Job.CsvRows.Add(columnNames);
                }

                foreach (DataRow row in table.Rows)
                {
                    string rowAsString = string.Empty;
                    foreach (object col in row.ItemArray)
                    {
                        rowAsString += "\"" + (col == DBNull.Value ? string.Empty : col.ToString()) + "\",";
                    }
                    if (rowAsString.Length > 0)
                    {
                        rowAsString = rowAsString.Substring(0, rowAsString.Length - 1);
                    }
                    Job.CsvRows.Add(rowAsString);
                }
                return(table);
            }
            return(new DataTable());
        }
コード例 #2
0
ファイル: AnyToDataTable.cs プロジェクト: eyedia/idpe
        private DataTable GenerateInputDataFromXml(StringBuilder xmlContent, string interfaceName)
        {
            if ((!string.IsNullOrEmpty(interfaceName)) &&
                (Type.GetType(interfaceName) != null))
            {
                object             objInputFileGenerator = Activator.CreateInstance(Type.GetType(interfaceName), Job);
                InputFileGenerator inputFileGenerator    = (InputFileGenerator)objInputFileGenerator;
                DataTable          table = inputFileGenerator.GenerateFileContent(xmlContent);

                Job.CsvRows.Clear();
                if (Job.DataSource.IsFirstRowHeader)
                {
                    string columnNames = string.Empty;
                    foreach (IdpeAttribute attrib in Job.DataSource.AcceptableAttributes)
                    {
                        columnNames += "\"" + attrib.Name + "\",";
                    }
                    Job.CsvRows.Add(columnNames);
                }

                foreach (DataRow row in table.Rows)
                {
                    string rowAsString = string.Empty;
                    foreach (object col in row.ItemArray)
                    {
                        rowAsString += "\"" + (col == DBNull.Value ? string.Empty : col.ToString()) + "\",";
                    }
                    if (rowAsString.Length > 0)
                    {
                        rowAsString = rowAsString.Substring(0, rowAsString.Length - 1);
                    }
                    Job.CsvRows.Add(rowAsString);
                }
                return(table);
            }
            return(new DataTable());
        }