public static IEnumerable <int> InserDataCollection(this IDataBaseConnector connector, DataCollection collection, string tableName = null, int batchMount = 1000) { if (tableName == null) { tableName = collection.Name; } if (connector.RefreshTableNames().FirstOrDefault(d => d.Name == tableName) == null) { connector.CreateTable(collection.ComputeData.First(), tableName); } var i = 0; var list = new List <IFreeDocument>(); while (i < collection.Count) { list.Add(collection.ComputeData[i]); if (list.Count == batchMount) { connector.BatchInsert(list, tableName); list = new List <IFreeDocument>(); yield return(i); } i++; } connector.BatchInsert(list, collection.Name); }
public JoinDBTF() { dataManager = MainDescription.MainFrm.PluginDictionary["数据管理"] as IDataManager; ConnectorSelector = new ExtendSelector <IDataBaseConnector>(); TableSelector = new ExtendSelector <TableInfo>(); ImportColumns = new ObservableCollection <string>(); ConnectorSelector.GetItems = () => dataManager.CurrentConnectors.ToList(); ConnectorSelector.SelectChanged += (s, e) => TableSelector.SetSource(ConnectorSelector.SelectItem.RefreshTableNames()); TableSelector.SelectChanged += (s, e) => { IDataBaseConnector connector = ConnectorSelector.SelectItem; if (connector == null) { return; } TableInfo table = TableSelector.SelectItem; if (table == null) { return; } IEnumerable <IDictionarySerializable> datas = ConnectorSelector.SelectItem.GetEntities(table.Name, typeof(FreeDocument), 10, 0); IEnumerable <string> keys = datas.GetKeys(); ImportColumns.Clear(); foreach (string key in keys) { ImportColumns.Add(key); } }; }
public static IEnumerable <IFreeDocument> InserDataCollection(this IDataBaseConnector connector, DataCollection collection, string tableName = null, int batchMount = 1000) { return(collection.ComputeData.BatchDo(data => { if (tableName == null) { tableName = collection.Name; } List <string> columns = new List <string>(); var sample = data.MergeToDocument(); columns = data.GetKeys().ToList(); if (connector.RefreshTableNames().FirstOrDefault(d => d.Name == tableName) == null) { var result = connector.CreateTable(sample, tableName); if (result == false) { throw new Exception(String.Format(GlobalHelper.Get("key_349"), tableName)); } // connector.RefreshTableNames(); } return columns; }, (list, columns) => { connector.BatchInsert(list, (List <string>)columns, collection.Name); })); }
public override object TransformData(IFreeDocument datas) { object item = datas[Column]; IDataBaseConnector con = ConnectorSelector.SelectItem; if (con == null) { return(null); } TableInfo table = TableSelector.SelectItem; if (table == null) { return(null); } if (IsMutliDatas) { var r = con.TryFindEntities(table.Name, new Dictionary <string, object> { { KeyName, item } }, null, -1, SearchStrategy); if (r.Any() == false) { return(null); } var dicts = r.Select(d => d.DictSerialize()).ToList(); foreach (string importColumn in ImportColumns) { List <object> res = new List <object>(); for (int i = 0; i < dicts.Count; i++) { res.Add(dicts[i][importColumn]); } if (res.Count != 0) { datas.SetValue(importColumn, res); } } } else { var r = con.TryFindEntities(table.Name, new Dictionary <string, object> { { KeyName, item } }, null, 1, SearchStrategy).FirstOrDefault(); if (r == null) { return(null); } FreeDocument dict = r.DictSerialize(); foreach (string importColumn in ImportColumns) { datas.SetValue(importColumn, dict[importColumn]); } } return(null); }
public static List <T> TryFindEntities <T>(this IDataBaseConnector connector, string tableName, IDictionary <string, object> search) where T : class, IDictionarySerializable { var rs = connector.TryFindEntities(tableName, search, typeof(T)); return(rs.Select(d => d as T).ToList()); }
private void RefreshConnect(IDataBaseConnector connector) { if (!connector.ConnectDB()) { MessageBox.Show(connector.Name + "强制刷新连接失败"); return; } connector.RefreshTableNames(); }
private void RefreshConnect(IDataBaseConnector connector) { if (!connector.ConnectDB()) { MessageBox.Show(connector.Name + GlobalHelper.Get("key_259")); return; } connector.RefreshTableNames(); }
private void InitializeDataBaseConnection() { FluentNHibernateHelper.InitializeDatabase(); _barometricPressureDataBaseConnector = new BarometricPressureDataBaseConnector(_eventAggregator); _temperatureDataBaseConnector = new TemperatureDataBaseConnector(_eventAggregator); _eventAggregator.GetEvent <NewTemperature>().Subscribe(_temperatureDataBaseConnector.SaveMeasurement); _eventAggregator.GetEvent <NewBarPressure>().Subscribe(_barometricPressureDataBaseConnector.SaveMeasurement); }
private void DropTable(IDataBaseConnector connector, string dataName) { if ( MessageBox.Show( "确定对数据表" + dataName + "执行删除操作吗?", "警告信息", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { connector.DropTable(dataName); connector.RefreshTableNames(); } }
private void DropTable(IDataBaseConnector connector, string dataName) { if ( MessageBox.Show( GlobalHelper.Get("key_257") + dataName + GlobalHelper.Get("key_258"), GlobalHelper.Get("key_151"), MessageBoxButton.YesNo) == MessageBoxResult.Yes) { connector.DropTable(dataName); connector.RefreshTableNames(); } }
public static List <T> GetEntityList <T>(this IDataBaseConnector connector, string tableName, int mount = -1, int skip = 0) where T : class, IFreeDocument { var type = typeof(T); if (type.IsInterface) { type = typeof(FreeDocument); } var items = connector.GetEntities(tableName, type, mount, skip).Select(d => d as T).ToList(); return(items); }
public MvvmWindowFactory( IEventAggregator eventAggregator, ISensor temperatureSensor, ISensor barometricPressureSensor, IDataBaseConnector temperatuDataBaseConnector, IDataBaseConnector barometricPressureDataBaseConnector, ISettingsService settingsService) { _eventAggregator = eventAggregator; _temperatureSensor = temperatureSensor; _barometricPressureSensor = barometricPressureSensor; _temperatuDataBaseConnector = temperatuDataBaseConnector; _barometricPressureDataBaseConnector = barometricPressureDataBaseConnector; _settingsService = settingsService; }
public static IEnumerable <IFreeDocument> InserDataCollection(this IDataBaseConnector connector, DataCollection collection, string tableName = null, int batchMount = 1000) { return(collection.ComputeData.BatchDo(data => { if (tableName == null) { tableName = collection.Name; } if (connector.RefreshTableNames().FirstOrDefault(d => d.Name == tableName) == null) { connector.CreateTable(data, tableName); } return true; }, list => { connector.BatchInsert(list, collection.Name); })); }
public async Task <List <IFreeDocument> > GetDataFromDB(IDataBaseConnector db, string dataName, bool isNewData, int mount = -1) { if (db == null) { return(null); } var table = db.RefreshTableNames().FirstOrDefault(d => d.Name == dataName); var dataAll = new List <IFreeDocument>(); var task = TemporaryTask.AddTempTask(dataName + "数据导入", db.GetEntities(dataName, mount), dataAll.Add, null, table != null?table.Size:-1, notifyInterval: 1000); processManager.CurrentProcessTasks.Add(task); await Task.Run( () => task.Wait()); return(dataAll); }
public override void DictDeserialize(IDictionary <string, object> docu, Scenario scenario = Scenario.Database) { base.DictDeserialize(docu); ConnectorSelector.SelectItem = dataManager.CurrentConnectors.FirstOrDefault(d => d.Name == docu["Connector"].ToString()); TableSelector.InformPropertyChanged(""); IDataBaseConnector connector = ConnectorSelector.SelectItem; if (connector == null) { return; } TableSelector.SelectItem = TableSelector.Collection.FirstOrDefault(d => d.Name == docu["TableName"].ToString()); ImportColumns.Clear(); foreach (string item in docu["Columns"].ToString().Split(' ')) { ImportColumns.Add(item); } }
public DataCollection ReadCollection(IDataBaseConnector connector, string tableName, bool isVirtual) { if (isVirtual) { IItemsProvider <IFreeDocument> vir = null; TableInfo tableInfo = connector.RefreshTableNames().FirstOrDefault(d => d.Name == tableName); var enumable = connector as IEnumerableProvider <IFreeDocument>; if (enumable != null && enumable.CanSkip(tableInfo.Name) == false) { vir = new EnumableVirtualProvider <IFreeDocument>( enumable.GetEnumerable(tableInfo.Name), tableInfo.Size); } else { vir = new DataBaseVirtualProvider <IFreeDocument>(tableInfo.Connector, tableInfo.Name); } int count = 1000; if (connector.TypeName == "网页爬虫连接器") { count = 100; } var col = new VirtualDataCollection(vir, count) { Name = tableInfo.Name }; AddDataCollection(col); return(col); } else { Task <List <IFreeDocument> > datas = GetDataFromDB(connector, tableName, true); DataCollection col = AddDataCollection(datas.Result); return(col); } }
private void RefreshConnect(IDataBaseConnector connector) { if (!connector.ConnectDB()) { MessageBox.Show(connector.Name + "强制刷新连接失败"); return; } connector.RefreshTableNames(); }
public HistoryWindowViewModel(IDataBaseConnector dataBaseConnector, IEventAggregator eventAggregator) { _dataBaseConnector = dataBaseConnector; _eventAggregator = eventAggregator; }
public CatalogoService(IDataBaseConnector dbConnector) { this.db = dbConnector; }
public DataCollection ReadCollection(IDataBaseConnector connector, string tableName, bool isVirtual) { if (isVirtual) { IItemsProvider<IFreeDocument> vir = null; TableInfo tableInfo = connector.RefreshTableNames().FirstOrDefault(d => d.Name == tableName); var enumable = connector as IEnumerableProvider<IFreeDocument>; if (enumable != null && enumable.CanSkip(tableInfo.Name) == false) { vir = new EnumableVirtualProvider<IFreeDocument>( enumable.GetEnumerable(tableInfo.Name), tableInfo.Size); } else { vir = new DataBaseVirtualProvider<IFreeDocument>(tableInfo.Connector, tableInfo.Name); } int count = 1000; if (connector.TypeName == "网页爬虫连接器") count = 100; var col = new VirtualDataCollection( vir, count) { Name = tableInfo.Name }; AddDataCollection(col); return col; } else { Task<List<IFreeDocument>> datas = GetDataFromDB(connector, tableName, true); DataCollection col = AddDataCollection(datas.Result); return col; } }
public TableInfo(string name, IDataBaseConnector connector) { Name = name; Connector = connector; ColumnInfos = new List <ColumnInfo>(); }
public DataBaseVirtualCollection(IDataBaseConnector db, string mtableName) { connector = db; tableName = mtableName; }
private void DropTable(IDataBaseConnector connector, string dataName) { if ( MessageBox.Show( "确定对数据表" + dataName + "执行删除操作吗?", "警告信息", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { connector.DropTable(dataName); connector.RefreshTableNames(); } }
public DataBaseVirtualProvider(IDataBaseConnector db, string mtableName) { Connector = db; tableName = mtableName; }
public TemperatureHistoryWindowViewModel(IDataBaseConnector dataBaseConnector, IEventAggregator eventAggregator) : base(dataBaseConnector, eventAggregator) { Measurements = new ObservableCollection <TemperatureMeasurement>(); dataBaseConnector.GetSavedMeasurements().ForEach(m => Measurements.Add((TemperatureMeasurement)m)); eventAggregator.GetEvent <TemperatureSaved>().Subscribe(NewTemperature); }
/// <summary> /// 获取数据库中的所有实体,通过传递实例化委托,提升反射性能 /// </summary> /// <returns></returns> public static List <T> GetAllEntities <T>(this IDataBaseConnector connector, string tableName) where T : class, IFreeDocument, new() { return(connector.GetEntityList <T>(tableName)); }
public AddCourse(IDataBaseConnector dbConnector) { this.db = dbConnector; }
public async Task<List<IFreeDocument>> GetDataFromDB(IDataBaseConnector db, string dataName, bool isNewData, int mount = -1) { if (db == null) { return null; } var table = db.RefreshTableNames().FirstOrDefault(d => d.Name == dataName); var dataAll = new List<IFreeDocument>(); var task = TemporaryTask.AddTempTask(dataName + "数据导入", db.GetEntities(dataName, typeof (FreeDocument), mount), dataAll.Add,null,table!=null?table.Size:-1,notifyInterval:1000); processManager.CurrentProcessTasks.Add(task); await Task.Run( () => task.Wait()); return dataAll; }