/// <summary>
        /// Returns DataSet based on specified options.
        /// </summary>
        public override DataSet GetDataSet(StiFileDataOptions options)
        {
            var xmlOptions = options as StiXmlOptions;

            if (xmlOptions == null)
            {
                throw new NotSupportedException("Only StiXmlOptions accepted!");
            }

            if (xmlOptions.Content == null || xmlOptions.Content.Length == 0)
            {
                return(null);
            }

            //ADO.NET XML
            if (xmlOptions.IsAdoNet)
            {
                var dataSet = new DataSet {
                    EnforceConstraints = false
                };
                dataSet.Read(xmlOptions.Schema, xmlOptions.Content);
                return(dataSet);
            }
            //XML
            return(StiJsonToDataSetConverter.GetDataSetFromXml(xmlOptions.Content));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns schema object which contains information about structure of the database. Schema returned start at specified root element (if it applicable).
        /// </summary>
        public StiDataSchema RetrieveSchema(StiFileDataOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var dataSet = GetDataSet(options);

            if (dataSet == null)
            {
                return(null);
            }

            var schema = new StiDataSchema(this.ConnectionIdent);

            #region Tables
            foreach (DataTable table in dataSet.Tables)
            {
                var tableSchema = StiDataTableSchema.NewTable(table.TableName);

                foreach (DataColumn column in table.Columns)
                {
                    tableSchema.Columns.Add(new StiDataColumnSchema
                    {
                        Name = column.ColumnName,
                        Type = column.DataType
                    });
                }
                schema.Tables.Add(tableSchema);
            }
            #endregion

            #region Relations
            foreach (DataRelation relation in dataSet.Relations)
            {
                schema.Relations.Add(new StiDataRelationSchema
                {
                    Name             = relation.RelationName,
                    ParentSourceName = relation.ParentTable.TableName,
                    ChildSourceName  = relation.ChildTable.TableName,
                    ParentColumns    = relation.ParentColumns.Select(col => col.ColumnName).ToList(),
                    ChildColumns     = relation.ChildColumns.Select(col => col.ColumnName).ToList()
                });
            }
            #endregion

            schema.Relations = schema.Relations.OrderBy(e => e.Name).ToList();
            schema.Tables    = schema.Tables.OrderBy(e => e.Name).ToList();

            return(schema);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns DataSet based on specified options.
        /// </summary>
        public override DataSet GetDataSet(StiFileDataOptions options)
        {
            var jsonOptions = options as StiJsonOptions;

            if (jsonOptions == null)
            {
                throw new NotSupportedException("Only StiJsonOptions accepted!");
            }

            if (jsonOptions.Content == null || jsonOptions.Content.Length == 0)
            {
                return(null);
            }

            return(StiJsonToDataSetConverter.GetDataSet(jsonOptions.Content));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns DataSet based on specified options.
        /// </summary>
        public override DataSet GetDataSet(StiFileDataOptions options)
        {
            var excelOptions = options as StiExcelOptions;

            if (excelOptions == null)
            {
                throw new NotSupportedException("Only StiExcelOptions accepted!");
            }

            if (excelOptions.Content == null || excelOptions.Content.Length == 0)
            {
                return(null);
            }

            return(StiExcelHelper.GetDataSetFromExcelDocument(excelOptions.Content, excelOptions.FirstRowIsHeader));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns DataSet based on specified options.
        /// </summary>
        public override DataSet GetDataSet(StiFileDataOptions options)
        {
            var csvOptions = options as StiCsvOptions;

            if (csvOptions == null)
            {
                throw new NotSupportedException("Only StiCsvOptions accepted!");
            }

            if (csvOptions.Content == null || csvOptions.Content.Length == 0)
            {
                return(null);
            }

            return(StiCsvHelper.GetDataSet(csvOptions.Content, csvOptions.CodePage, csvOptions.Separator));
        }
        /// <summary>
        /// Returns DataSet based on specified options.
        /// </summary>
        public override DataSet GetDataSet(StiFileDataOptions options)
        {
            var dBaseOptions = options as StiDBaseOptions;

            if (dBaseOptions == null)
            {
                throw new NotSupportedException("Only StiDBaseOptions accepted!");
            }

            if (dBaseOptions.Content == null || dBaseOptions.Content.Length == 0)
            {
                return(null);
            }

            return(StiDBaseHelper.GetDataSet(dBaseOptions.Content, false, dBaseOptions.CodePage));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns StiTestConnectionResult that is the information of whether the connection string specified in this class is correct.
        /// </summary>
        /// <returns>The result of testing the connection string.</returns>
        public StiTestConnectionResult TestConnection(StiFileDataOptions options)
        {
            try
            {
                if (options == null || options.Content == null || options.Content.Length == 0)
                {
                    return(StiTestConnectionResult.MakeWrong(string.Format("{0} content is not found!", this.Name)));
                }

                var dataSet = GetDataSet(options);
                if (dataSet == null)
                {
                    return(StiTestConnectionResult.MakeWrong(string.Format("{0} content is not recognized!", this.Name)));
                }

                return(StiTestConnectionResult.MakeFine());
            }
            catch (Exception e)
            {
                return(StiTestConnectionResult.MakeWrong(e));
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Returns DataSet based on specified options.
 /// </summary>
 public abstract DataSet GetDataSet(StiFileDataOptions options);