예제 #1
0
        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);
        }
예제 #2
0
        public override DataSet ToDataSet(DataSetConvertParams context, Stream input)
        {
            StreamReader reader = new StreamReader(input);
            string       text   = reader.ReadToEnd();

            return(_dataSetJsonStringConverter.ToDataSet(context, text));
        }
예제 #3
0
        public override DataSet ToDataSet(DataSetConvertParams context, string input)
        {
            byte[]       byteArray = Encoding.ASCII.GetBytes(input);
            MemoryStream stream    = new MemoryStream(byteArray);

            return(_dataSetXmlStreamConverter.ToDataSet(context, stream));
        }
예제 #4
0
        public override Stream FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args)
        {
            MemoryStream ms = new MemoryStream();

            ds.WriteXml(ms);
            return(ms);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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;
                }
            }
        }
예제 #12
0
        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);
        }
예제 #13
0
 abstract public DataSet ToDataSet(DataSetConvertParams context, T input);
예제 #14
0
 abstract public T FromDataSet(DataSetConvertParams context, DataSet dt, params object[] args);
예제 #15
0
 public virtual DataSet ToDataSet(DataSetConvertParams context, params object[] args)
 {
     return(ToDataSet(context, (T)args[0]));
 }
예제 #16
0
 public DataSetConvertContext(IDataSetConverter converter, DataSetConvertParams parameters)
 {
     Converter = converter;
     Params    = parameters;
 }
예제 #17
0
 public virtual Object FromDataSetToObject(DataSetConvertParams context, DataSet ds, params object [] args)
 {
     return((Object)FromDataSet(context, ds, args));
 }
예제 #18
0
        public override string FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args)
        {
            StreamReader sr = new StreamReader(_dataSetXmlStreamConverter.FromDataSet(context, ds));

            return(sr.ReadToEnd());
        }
예제 #19
0
        public override string FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args)
        {
            string json = JsonConvert.SerializeObject(ds, Newtonsoft.Json.Formatting.Indented);

            return(json);
        }
예제 #20
0
 public override string FromDataSet(DataSetConvertParams context, DataSet ds, params object[] args)
 {
     return(_dataSetJsonStringConverter.FromDataSet(context, ds));
 }
예제 #21
0
 public override DataSet ToDataSet(DataSetConvertParams context, SqliteClient input)
 {
     return(input.GetDataSet());
 }
예제 #22
0
 public override DataSet ToDataSet(DataSetConvertParams context, string input)
 {
     throw new NotImplementedException();
 }