public override DataSet ToDataSet(DataSetConvertParams context, string input) { DataSet ds = new DataSet(); //Conversion to JObject is to prevent automatic DateTime columns because they break when the value is an empty string JObject jInput = JsonConvert.DeserializeObject <JObject>(input, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }); //Handle Array with one value if (jInput.Count == 1 && jInput["root"] is JArray && ((JArray)jInput["root"]).Count == 1 && ((JArray)jInput["root"])[0] is JValue) { DataTable dt = new DataTable("root"); dt.Columns.Add("root_Text"); dt.Rows.Add(new object[] { ((JArray)jInput["root"])[0] }); ds.Tables.Add(dt); return(ds); } XmlDocument xmlDocument = (XmlDocument)JsonConvert.DeserializeXmlNode(jInput.ToString(), "root"); //We will add try catch with handling later ds.ReadXml(new XmlNodeReader(xmlDocument)); return(ds); }
public override DataSet ToDataSet(DataSetConvertParams context, Stream input) { StreamReader reader = new StreamReader(input); string text = reader.ReadToEnd(); return(_dataSetJsonStringConverter.ToDataSet(context, text)); }
public override DataSet ToDataSet(DataSetConvertParams context, string input) { byte[] byteArray = Encoding.ASCII.GetBytes(input); MemoryStream stream = new MemoryStream(byteArray); return(_dataSetXmlStreamConverter.ToDataSet(context, stream)); }
public override Stream FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args) { MemoryStream ms = new MemoryStream(); ds.WriteXml(ms); return(ms); }
public override DataSet ToDataSet(DataSetConvertParams context, Stream stream) { DataSet ds = new DataSet(); //Will add in try catch with handlings later ds.ReadXml(stream); return(ds); }
public override DataSet ToDataSet(DataSetConvertParams context, string input) { StreamReader sr = File.OpenText(input); DataSet ds = _dataSetJsonStreamConverter.ToDataSet(context, sr.BaseStream); ds.DataSetName = Path.GetFileName(input); return(ds); }
public override Stream FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args) { String json = _dataSetJsonStringConverter.FromDataSet(context, ds); byte[] byteArray = Encoding.ASCII.GetBytes(json); MemoryStream stream = new MemoryStream(byteArray); return(stream); }
public override String FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args) { SqliteClient sqliteClient = _dataSetSqliteClientConverter.FromDataSet(context, ds); sqliteClient.OpenConnection(); String dbPath = args.Length > 0 ? args[0].ToString() : $"{ds.DataSetName}.db"; sqliteClient.BackupDatabaseToFile(dbPath); sqliteClient.CloseConnection(); return(dbPath); }
public override DataSet ToDataSet(DataSetConvertParams context, String input) { String dbPath = $"Data Source={input};Version=3;"; SqliteClient sqliteClient = new SqliteClient(dbPath); sqliteClient.OpenConnection(); DataSet ds = sqliteClient.GetDataSet(); ds.DataSetName = Path.GetFileName(input); sqliteClient.CloseConnection(); return(ds); }
public override SqliteClient FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args) { SqliteClient sqliteClient = new SqliteClient(); sqliteClient.OpenConnection(); foreach (DataTable dt in ds.Tables) { sqliteClient.AddTables(dt); } //sqliteClient.CloseConnection(); return(sqliteClient); }
public DataSetConvertContext this[String extension] { get { DataSetConvertParams convertParams = new DataSetConvertParams(); switch (extension.ToLower()) { case "xml": case ".xml": IDataSetConverter xmlConverter = new DataSetXmlFileConverter(); _converters.TryAdd(extension.ToLower(), new DataSetConvertContext(xmlConverter, convertParams)); break; case "json": case ".json": IDataSetConverter jsonConverter = new DataSetJsonFileConverter(); _converters.TryAdd(extension.ToLower(), new DataSetConvertContext(jsonConverter, convertParams)); break; case "db": case ".db": case "sqlite": case ".sqlite": IDataSetConverter sqliteConverter = new DataSetSqliteFileConverter(); _converters.TryAdd(extension.ToLower(), new DataSetConvertContext(sqliteConverter, convertParams)); break; } if (!_converters.ContainsKey(extension.ToLower())) { return(null); } return(_converters[extension.ToLower()]); } set { if (!_converters.ContainsKey(extension.ToLower())) { _converters.TryAdd(extension.ToLower(), value); } else { _converters[extension.ToLower()] = value; } } }
public override string FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args) { String destinationPath = args.Length > 0 ? args[0].ToString() : ""; if (destinationPath != "") { if (!Directory.Exists(destinationPath)) { Directory.CreateDirectory(destinationPath); } foreach (DataTable dtbl in ds.Tables) { String strDtbl = _dataTableCsvFileConverter.FromDataTable(new DataTableConvertParams(), dtbl); File.WriteAllText(Path.Combine(destinationPath, $"{dtbl.TableName}.csv"), strDtbl); } } return(destinationPath); }
abstract public DataSet ToDataSet(DataSetConvertParams context, T input);
abstract public T FromDataSet(DataSetConvertParams context, DataSet dt, params object[] args);
public virtual DataSet ToDataSet(DataSetConvertParams context, params object[] args) { return(ToDataSet(context, (T)args[0])); }
public DataSetConvertContext(IDataSetConverter converter, DataSetConvertParams parameters) { Converter = converter; Params = parameters; }
public virtual Object FromDataSetToObject(DataSetConvertParams context, DataSet ds, params object [] args) { return((Object)FromDataSet(context, ds, args)); }
public override string FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args) { StreamReader sr = new StreamReader(_dataSetXmlStreamConverter.FromDataSet(context, ds)); return(sr.ReadToEnd()); }
public override string FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args) { string json = JsonConvert.SerializeObject(ds, Newtonsoft.Json.Formatting.Indented); return(json); }
public override string FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args) { return(_dataSetJsonStringConverter.FromDataSet(context, ds)); }
public override DataSet ToDataSet(DataSetConvertParams context, SqliteClient input) { return(input.GetDataSet()); }
public override DataSet ToDataSet(DataSetConvertParams context, string input) { throw new NotImplementedException(); }