/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmMqttDSO(ConfigDataset configDataset, DataSourceConfig dataSourceConfig) : this() { this.configDataset = configDataset ?? throw new ArgumentNullException(nameof(configDataset)); this.dataSourceConfig = dataSourceConfig ?? throw new ArgumentNullException(nameof(dataSourceConfig)); options = new MqttDSO(dataSourceConfig.CustomOptions); }
static void Main(string[] args) { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build(); var ds = new DataSourceConfig(); configuration.GetSection("DataSourceConfig").Bind(ds); DataSourceConfig.UrlValue = ds.Url; var userService = new UserService(new InMemoryRepository()); //var userService = new UserService(new MongoRepository()); // both works, you can switch and try var users = userService.Get(); var result1 = users.Count(); var result2 = users.Max(u => u.RuledYears); var result3 = users.GroupBy(x => x.Hse) .Select(record => new { HouseName = record.Key, Years = record.Sum(r => r.RuledYears) }) .OrderByDescending(r => r.Years) .FirstOrDefault(); var result4 = users.GroupBy(x => x.FirstName) .Select(record => new { FirstName = record.Key, Occurrence = record.Count() }) .OrderByDescending(r => r.Occurrence) .FirstOrDefault(); }
/// <summary> /// Adds a Data Source to a DataSourceConfig /// </summary> /// <param name="list">The DataSourceList where the DataSource will be add</param> /// <param name="source">The IQueryable to add</param> /// <param name="type"></param> /// <returns></returns> public static DataSourceConfig AddSource(this DataSourceRepository list, IQueryable source, Type type) { var config = new DataSourceConfig(source, type); list.Add(config); return(config); }
/// <summary> /// Create DBHelper /// </summary> /// <param name="dsName"></param> /// <param name="dsConfig"></param> static void CreateDBHelper(string dsName, DataSourceConfig dsConfig) { if (string.IsNullOrEmpty(dsConfig.dialectClass)) { throw new ArgumentNullException("配置文件错误:请检查[dsConfig]配置"); } try { string[] classNameArray = dsConfig.dialectClass.Split(new char[] { ':', '-' }); string className = classNameArray[1]; string assemblyName = classNameArray[0]; Type type = null; type = Assembly.Load(assemblyName).GetType(className, true); IDBHelper instance = Activator.CreateInstance(type, dsConfig.Parameters) as IDBHelper; DBHelperCache.Add(dsName, instance); } catch (ArgumentNullException) { throw new Exception("DBHelper添加失败:数据源名[dsName]不能为空"); } catch (ArgumentException) { throw new Exception("DBHelper添加失败:已存在同名的数据源"); } }
/// <summary> /// Add a Join to DataSource /// </summary> /// <typeparam name="T1"></typeparam> /// <typeparam name="T2"></typeparam> /// <param name="config"></param> /// <param name="key1"></param> /// <param name="key2"></param> /// <returns></returns> public static DataSourceConfig <T1> WithJoin <T1, T2>(this DataSourceConfig <T1> config, string key1, string key2) where T1 : class { config.Joins.Add(new DataSourceJoinConfig <T1, T2>(key1, key2)); return(config); }
/// <summary> /// 根据数据源名称获得相应的DBHelper /// 若缓存中有则直接返回 /// /// </summary> /// <param name="dsName">data source name(lowcase)</param> /// <returns></returns> public static IDBHelper GetHelper(string dsName) { //If Null, init data source list first; if (DataSourceList == null) { //默认使用DBHelper.config,这里可以按需求修改为默认使用App.config XmlConfigurator.Configure("DBHelper.config"); } if (string.IsNullOrEmpty(dsName)) { dsName = "default"; } dsName = dsName.ToLower();//配置文件中dsName要小写 if (DataSourceList.ContainsKey(dsName)) { //实例化 DataSourceConfig dsConfig = DataSourceList[dsName]; string[] classNameArray = dsConfig.dialectClass.Split(new char[] { ':', '-' }); string className = classNameArray[1]; string assemblyName = classNameArray[0]; Type type = null; if (string.IsNullOrEmpty(dsConfig.dialectClass)) { throw new ArgumentNullException("配置文件错误:请检查Dialect配置"); } type = Assembly.Load(assemblyName).GetType(className, true); IDBHelper instance = Activator.CreateInstance(type, dsConfig.Parameters) as IDBHelper; return(instance); } else { throw new Exception("Not found data source [" + dsName + "], please check config file."); } }
private DataSourceFactory(string name) { name = name.ToLower(); DataSourceConfig dsConfig = DBHelperFactory2.DataSourceMap[name]; this.m_dataSourceName = dsConfig.dataSourceName; this.m_connectionString = dsConfig.connStr; this.m_providerName = dsConfig.providerName; string dbDialectClass = dsConfig.dialectClass; m_dbDialect = (IDbDialect)ToolKit.CreateInstance(dbDialectClass); //默认配置 this.m_minSize = 50; this.m_maxSize = 100; this.m_usePool = true; this.m_timeOut = 1000; try { this.m_minSize = dsConfig.minSize; } catch { } try { this.m_maxSize = dsConfig.maxSize; } catch { } try { this.m_timeOut = dsConfig.timeOut; } catch { } try { this.m_usePool = dsConfig.pooled; } catch { } }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmScadaServerDSO(ConfigDataset configDataset, AppDirs appDirs, DataSourceConfig dataSourceConfig) : this() { this.configDataset = configDataset ?? throw new ArgumentNullException(nameof(configDataset)); this.appDirs = appDirs ?? throw new ArgumentNullException(nameof(appDirs)); this.dataSourceConfig = dataSourceConfig ?? throw new ArgumentNullException(nameof(dataSourceConfig)); options = new ScadaServerDSO(dataSourceConfig.CustomOptions); }
/// <summary> /// Initializes a new instance of the class. /// </summary> public DataSourceLogic(ICommContext commContext, DataSourceConfig dataSourceConfig) { CommContext = commContext ?? throw new ArgumentNullException(nameof(commContext)); DataSourceConfig = dataSourceConfig ?? throw new ArgumentNullException(nameof(dataSourceConfig)); Code = dataSourceConfig.Code; Title = CommUtils.GetDataSourceTitle(Code, dataSourceConfig.Name); IsReady = false; }
/// <summary> /// Adds a generic Data Source to a DataSourceConfig /// </summary> /// <typeparam name="T">The DataSource Type</typeparam> /// <param name="list">The DataSourceList where the DataSource will be add</param> /// <param name="source">The IQueryable to add</param> /// <returns></returns> public static DataSourceConfig <T> AddSource <T>(this DataSourceRepository list, IQueryable <T> source) where T : class { var config = new DataSourceConfig <T>(source); list.Add(config); return(config); }
/// <summary> /// Adds an item to the list view according to the specified data source. /// </summary> private void AddDataSourceItem(DataSourceConfig dataSourceConfig) { int index = 0; lvDataSource.InsertItem(CreateDataSourceItem(dataSourceConfig, ref index), true); txtCode.Focus(); ChildFormTag.Modified = true; }
public async Task SaveAllLengthsCombinationsAsync(List <WordChunksLengthCombination> wordChunksLengthCombinations) { //var content = string.Join(Environment.NewLine, // wordChunksLengthCombinations // .Select(x => x.ToString()) // .ToList()); var content = JsonConvert.SerializeObject(wordChunksLengthCombinations); await WriteTextAsync(DataSourceConfig.GetLengthsCombinationsFilePath(), content); }
public async Task <List <WordChunk> > GetAllWordChunksAsync() { var result = (await ReadAllLinesAsync(DataSourceConfig.GetInputFilePath())) .Select(x => new WordChunk { Text = x }) .ToList(); return(result); }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmDataSources(IAdminContext adminContext, CommApp commApp) : this() { this.adminContext = adminContext ?? throw new ArgumentNullException(nameof(adminContext)); this.commApp = commApp ?? throw new ArgumentNullException(nameof(commApp)); commConfig = commApp.AppConfig; changing = false; dataSourceClipboard = null; SetColumnNames(); }
/// <summary> /// Init DataSource List; /// Init DBHelper Cache /// </summary> /// <param name="xnl"></param> /// <returns></returns> private static Dictionary <string, DataSourceConfig> InitDS(XmlNodeList xnl) { System.Collections.Generic.Dictionary <string, DataSourceConfig> dsTable = new Dictionary <string, DataSourceConfig>(); try { foreach (XmlNode xl in xnl) { DataSourceConfig dsConfig = new DataSourceConfig(); string dsName = xl.Attributes["name"].Value; string dialect = xl.Attributes["dialect"].Value; dsConfig.dataSourceName = dsName; dsConfig.dialectClass = dialect; XmlNodeList parmNodeList = xl.SelectNodes("parm"); int i = 0; object[] parmList = new object[parmNodeList.Count]; foreach (XmlNode parmNode in parmNodeList) { //参数个数要与构造函数对应 否则要进行转换 string id = parmNode.Attributes["id"].Value; string value = parmNode.Attributes["value"].Value; parmList[i] = value; i++; } dsConfig.Parameters = parmList; dsTable.Add(dsName, dsConfig); //添加到DBHelperCache string[] classNameArray = dsConfig.dialectClass.Split(new char[] { ':', '-' }); string className = classNameArray[1]; string assemblyName = classNameArray[0]; Type type = null; if (string.IsNullOrEmpty(dsConfig.dialectClass)) { throw new ArgumentNullException("配置文件错误:请检查Dialect配置"); } try { type = Assembly.Load(assemblyName).GetType(className, true); IDBHelper instance = Activator.CreateInstance(type, dsConfig.Parameters) as IDBHelper; DBHelperCache.Add(dsName, instance); } catch (Exception) { //如果Assembly.Load失败,不做处理 } } } catch (Exception ex) { throw new DBConfigException(ex); } return(dsTable); }
public UpshotConfigBuilder DataSource <TDataController>(Expression <Func <TDataController, object> > queryOperation, string serviceUrl, string clientName) where TDataController : DataController { IDataSourceConfig dataSourceConfig = new DataSourceConfig <TDataController>(htmlHelper, bufferChanges, queryOperation, serviceUrl, clientName); if (dataSources.ContainsKey(dataSourceConfig.ClientName)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Cannot have multiple data sources with the same clientName. Found multiple data sources with the name '{0}'", dataSourceConfig.ClientName)); } dataSources.Add(dataSourceConfig.ClientName, dataSourceConfig); return(this); }
private void btnCopy_Click(object sender, EventArgs e) { // copy the selected data source if (GetSelectedItem(out _, out DataSourceConfig dataSourceConfig)) { btnPaste.Enabled = true; dataSourceClipboard = dataSourceConfig.DeepClone(); } lvDataSource.Focus(); }
public void BuildValueProvider_GivenMultipleSourceBuilders_ValueProviderShouldContainEveryDataSource() { DataSourceConfig.DataSources.Clear(); DataSourceConfig.DataSources.Add("source1", new MockSourceProvider(1)); DataSourceConfig.DataSources.Add("source2", new MockSourceProvider(2)); DataSourceConfig.DataSources.Add("source3", new MockSourceProvider(3)); DataSourceConfig.DataSources.Add("source4", new MockSourceProvider(4)); var valueProvider = DataSourceConfig.BuildValueProvider(null, null); valueProvider.GetValues <int>("key").ShouldBe(new[] { 1, 2, 3, 4 }); }
public void ParseJson() { var dataSourceConfig = new DataSourceConfig(); var name = dataSourceConfig.ParseJson("{ \"p-mysql\": [ { \"credentials\": { \"hostname\": \"localhost\", \"port\": 3306, \"name\": \"uservices_test\", \"username\": \"root\", \"password\": \"\" } } ] }"); Assert.Equal("server=localhost;user id=root;password=;port=3306;database=uservices_test;", name); var address = dataSourceConfig.ParseJson("{ \"p-mysql\": [ { \"credentials\": { \"hostname\": \"127.0.0.1\", \"port\": 3306, \"name\": \"uservices_test\", \"username\": \"root\", \"password\": \"\" } } ] }"); Assert.Equal("server=127.0.0.1;user id=root;password=;port=3306;database=uservices_test;", address); }
/// <summary> /// Add a Join to DataSource /// </summary> /// <typeparam name="T1"></typeparam> /// <typeparam name="T2"></typeparam> /// <param name="config"></param> /// <param name="key"></param> /// <returns></returns> public static DataSourceConfig <T1> WithJoin <T1, T2>(this DataSourceConfig <T1> config, string key) where T1 : class { if (config == null) { throw new ArgumentNullException("config"); } config.Joins.Add(new DataSourceJoinConfig <T1, T2>(key, key)); return(config); }
public async Task <List <WordChunksLengthCombination> > GetWordChunksLengthCombinationsFromCacheAsync() { var content = string.Concat(await ReadAllLinesAsync(DataSourceConfig.GetLengthsCombinationsFilePath())); if (string.IsNullOrEmpty(content)) { return(await Task.FromResult(new List <WordChunksLengthCombination>())); } var result = JsonConvert.DeserializeObject <List <WordChunksLengthCombination> >(content); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="SqlDataSource"/> class. /// </summary> /// <param name="sourceConfig"></param> public SqlDataSource( DataSourceConfig sourceConfig) { _sourceConfig = sourceConfig; if (sourceConfig.Config.connectionString != null && !string.IsNullOrWhiteSpace(sourceConfig.Config.connectionString.ToString())) { _connectionString = sourceConfig.Config.connectionString; } else { _connectionString = $"User ID={sourceConfig.Config.userName};Password={sourceConfig.Config.password};Data Source={sourceConfig.Config.server};Initial Catalog={sourceConfig.Config.name};Persist Security Info=False;"; } }
/// <summary> /// Creates a new list view item that represents the specified data source. /// </summary> private static ListViewItem CreateDataSourceItem(DataSourceConfig dataSourceConfig, ref int index) { return(new ListViewItem(new string[] { (++index).ToString(), AdminUtils.GetCheckedString(dataSourceConfig.Active), dataSourceConfig.Code, dataSourceConfig.Name, dataSourceConfig.Driver }) { Tag = dataSourceConfig }); }
public static IDataSource Provide( DataSourceType dataSourceType, DataSourceConfig dataSourceConfig = null) { switch (dataSourceType) { case DataSourceType.InMemoryFake: return(new InMemoryFakeDataSource()); case DataSourceType.SqlServer: return(new SqlDataSource(dataSourceConfig)); } throw new ArgumentOutOfRangeException(nameof(dataSourceType), dataSourceType, null); }
/// <summary> /// Gets the selected list view item and the corresponding data source configuration. /// </summary> private bool GetSelectedItem(out ListViewItem item, out DataSourceConfig dataSourceConfig) { if (lvDataSource.SelectedItems.Count > 0) { item = lvDataSource.SelectedItems[0]; dataSourceConfig = (DataSourceConfig)item.Tag; return(true); } else { item = null; dataSourceConfig = null; return(false); } }
private void button1_Click(object sender, EventArgs e) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "DBHelper.config"); } catch { throw new DBFileNotFoundException(); } System.Collections.Generic.Dictionary <string, DataSourceConfig> dsTable = new Dictionary <string, DataSourceConfig>(); XmlNodeList xnl = xmlDoc.DocumentElement.SelectNodes("DataSource"); try { foreach (XmlNode xl in xnl) { DataSourceConfig dsConfig = new DataSourceConfig(); string dsName = xl.Attributes["name"].Value; string dialect = xl.Attributes["dialect"].Value; dsConfig.dataSourceName = dsName; dsConfig.dialectClass = dialect; XmlNodeList parmNodeList = xl.SelectNodes("parm"); int i = 0; object[] parmList = new object[parmNodeList.Count]; foreach (XmlNode parmNode in parmNodeList) { //参数个数要与构造函数对应 否则要进行转换 string id = parmNode.Attributes["id"].Value; string value = parmNode.Attributes["value"].Value; parmList[i] = value; i++; } dsConfig.Parameters = parmList; dsTable.Add(dsName, dsConfig); } } catch (Exception ex) { throw new DBConfigException(ex); } }
private int curDataSkipped; // the number of skipped slices of current data /// <summary> /// Initializes a new instance of the class. /// </summary> public MqttDSL(ICommContext commContext, DataSourceConfig dataSourceConfig) : base(commContext, dataSourceConfig) { dsOptions = new MqttDSO(dataSourceConfig.CustomOptions); dsLog = CreateLog(DriverUtils.DriverCode); mqttClientHelper = new MqttClientHelper(dsOptions.ConnectionOptions, dsLog); commandTopic = dsOptions.PublishOptions.RootTopic + CommandTopic; dataLifetime = TimeSpan.FromSeconds(dsOptions.PublishOptions.DataLifetime); deviceFilter = dsOptions.PublishOptions.DeviceFilter.Count > 0 ? new HashSet <int>(dsOptions.PublishOptions.DeviceFilter) : null; maxQueueSize = Math.Max(dsOptions.PublishOptions.MaxQueueSize, MinQueueSize); curDataQueue = new Queue <QueueItem <DeviceSlice> >(maxQueueSize); topicByDevice = new Dictionary <int, DeviceTopics>(); thread = null; terminated = false; curDataSkipped = 0; }
public static void GetDataSource(CompositeTag dataSourceTag) { foreach (CompositeTag childConfig in dataSourceTag.SubTags) { DataSourceConfig dsConfig = new DataSourceConfig(); String id = childConfig.TryGetAttributeValueAt("id"); dsConfig.dataSourceName = id; dsConfig.url = GetTagValue(childConfig, "connectionString"); dsConfig.dialectClass = GetTagValue(childConfig, "dialectClass"); dsConfig.providerName = GetTagValue(childConfig, "providerName"); String tempValue = null; tempValue = GetTagValue(childConfig, "minSize"); if (tempValue != null) { dsConfig.minSize = Convert.ToInt32(tempValue); } tempValue = GetTagValue(childConfig, "maxSize"); if (tempValue != null) { dsConfig.maxSize = Convert.ToInt32(tempValue); } tempValue = GetTagValue(childConfig, "timeOut"); if (tempValue != null) { dsConfig.timeOut = Convert.ToInt32(tempValue); } tempValue = GetTagValue(childConfig, "usePool"); if (tempValue != null) { dsConfig.pooled = Convert.ToBoolean(tempValue); } if (DataSourceList.ContainsKey(id)) { DataSourceList[id] = dsConfig; } else { DataSourceList.Add(id, dsConfig); } } }
/// <summary> /// Displays the specified data source properties. /// </summary> private void DisplayDataSource(DataSourceConfig dataSourceConfig) { if (dataSourceConfig == null) { chkActive.Checked = false; txtCode.Text = ""; txtName.Text = ""; cbDriver.Text = ""; txtOptions.Text = ""; } else { chkActive.Checked = dataSourceConfig.Active; txtCode.Text = dataSourceConfig.Code; txtName.Text = dataSourceConfig.Name; cbDriver.Text = dataSourceConfig.Driver; txtOptions.Text = dataSourceConfig.CustomOptions.ToString(); } }
public void GetConnection() { Environment.SetEnvironmentVariable("VCAP_SERVICES", @" { ""p-mysql"": [ { ""credentials"": { ""hostname"": ""localhost"", ""port"": ""3306"", ""name"": ""a_test_database"", ""username"": ""a_test_user"", ""password"": ""a_test_password"" } } ] }"); var actual = new DataSourceConfig().GetConnection().ConnectionString; Assert.Equal("Server=localhost;User Id=a_test_user;Password=a_test_password;Port=3306;Database=a_test_database", actual); }