public void MoreComplexFilterWithOrConnector() { var dataOptions = new DataOptions(); dataOptions.Filter.Connector = FilterConnector.Or; dataOptions.Filter.Add("Title", "Test1", FilterOperation.NotContains); dataOptions.Filter.Add("Title", "Test2", FilterOperation.Equal); dataOptions.Filter.Add("Title", "Test3", FilterOperation.NotEqual); dataOptions.Filter.Add("Title", "Test4", FilterOperation.StartsWith); var queryCreator = new DataOptionsQueryCreator <PageProperties>(dataOptions); var orderQuery = queryCreator.GetOrderQuery(); var filterQuery = queryCreator.GetFilterQuery(); var filterParameters = queryCreator.GetFilterParameters(); Assert.AreEqual(orderQuery, string.Empty); Assert.AreEqual(filterQuery, "(!Title.Contains(@0) or Title == null) or Title == @1 or (Title != @2 or Title == null) or Title.StartsWith(@3)"); Assert.IsNotNull(filterParameters); Assert.AreEqual(filterParameters.Length, 4); Assert.AreEqual(filterParameters[0], "Test1"); Assert.AreEqual(filterParameters[1], "Test2"); Assert.AreEqual(filterParameters[2], "Test3"); Assert.AreEqual(filterParameters[3], "Test4"); }
public override void Execute(ExecutionContext context) { var connectionInfo = new ConnectionInfo { ConnectionName = (string)context.ResolveVariable(ConnectionName), DataSource = (string)context.ResolveVariable(DataSource), InitialCatalog = InitialCatalog, InitialCatalogName = (string)context.ResolveVariable(InitialCatalogName), UserName = (string)context.ResolveVariable(UserName), Password = (string)context.ResolveVariable(Password) }; var connectionString = MsSqlDataContext.GetConnectionString(connectionInfo); var initialData = InitialData.Load(new SenseNetServicesInitialData(), null); var dataOptions = Options.Create(DataOptions.GetLegacyConfiguration()); var connOptions = Options.Create(new ConnectionStringOptions { ConnectionString = connectionString }); var installer = new MsSqlDataInstaller(connOptions, NullLoggerFactory.Instance.CreateLogger <MsSqlDataInstaller>()); var dataProvider = new MsSqlDataProvider(dataOptions, connOptions, installer); installer.InstallInitialDataAsync(initialData, dataProvider, CancellationToken.None).GetAwaiter().GetResult(); }
public void DC_MSSQL_Construction_ConnectionString() { var connectionString = "ConnectionString1"; var dataContext = new MsSqlDataContext(connectionString, DataOptions.GetLegacyConfiguration(), CancellationToken.None); Assert.AreEqual(connectionString, dataContext.ConnectionString); }
public override DataProvider GetDataProvider() { var connOptions = Options.Create(ConnectionStringOptions.GetLegacyConnectionStrings()); return(new MsSqlDataProvider(Options.Create(DataOptions.GetLegacyConfiguration()), connOptions, new MsSqlDataInstaller(connOptions, NullLoggerFactory.Instance.CreateLogger <MsSqlDataInstaller>()))); }
public RootDatabase(IConfiguration config) { _options = new DataOptions(); config.Bind("data", _options); Database.EnsureCreated(); }
/* ===================================================================================== SQL DATA HANDLING */ private static async Task <TimestampData> GetTimestampDataForOneNodeIntegrityCheckAsync(string path, int[] excludedNodeTypeIds) { var checkNodeSql = "SELECT N.NodeId, V.VersionId, CONVERT(bigint, n.timestamp) NodeTimestamp, CONVERT(bigint, v.timestamp) VersionTimestamp, N.LastMajorVersionId, N.LastMinorVersionId from Versions V join Nodes N on V.NodeId = N.NodeId WHERE N.Path = '{0}' COLLATE Latin1_General_CI_AS"; if (excludedNodeTypeIds != null && excludedNodeTypeIds.Length > 0) { checkNodeSql += $" AND N.NodeTypeId NOT IN ({string.Join(", ", excludedNodeTypeIds)})"; } var sql = string.Format(checkNodeSql, path); using var ctx = new MsSqlDataContext(ConnectionStrings.ConnectionString, DataOptions.GetLegacyConfiguration(), CancellationToken.None); return(await ctx.ExecuteReaderAsync(sql, async (reader, cancel) => { cancel.ThrowIfCancellationRequested(); TimestampData dbNode = null; if (await reader.ReadAsync(cancel).ConfigureAwait(false)) { dbNode = new TimestampData { NodeId = reader.GetSafeInt32(reader.GetOrdinal("NodeId")), VersionId = reader.GetSafeInt32(reader.GetOrdinal("VersionId")), NodeTimestamp = reader.GetSafeInt64(reader.GetOrdinal("NodeTimestamp")), VersionTimestamp = reader.GetSafeInt64(reader.GetOrdinal("VersionTimestamp")), LastMajorVersionId = reader.GetSafeInt32(reader.GetOrdinal("LastMajorVersionId")), LastMinorVersionId = reader.GetSafeInt32(reader.GetOrdinal("LastMinorVersionId")), }; } return dbNode; }).ConfigureAwait(false)); }
private static object GetTestData(DataOptions dataOptions) { switch (dataOptions) { case DataOptions.Null: return(null); case DataOptions.Frst: return(new Hashtable { { 1, 1 } }); case DataOptions.Scnd: return(new Hashtable { { 2, 2 } }); case DataOptions.Wrng: return(new Hashtable { { 5, 1 } }); default: throw new ArgumentOutOfRangeException("dataOptions", dataOptions, null); } }
private void ImportBattleFromTypeAndFile(int selectedFileType, string fileName, bool setBattle = true) { DataOptions options = new DataOptions(); if (selectedFileType == (int)Import_Filters.json) { var importedBattle = XmlHelper.DeserializeFromFile(fileName); importedBattle.battle.msbtUpdated = true; // We want to be sure we write the new title when we save. options.AddDataTbl(importedBattle.battle); options.AddRangeDataTbl(importedBattle.fighters); options.AddDataTbl(importedBattle.spirit); } else if (selectedFileType == (int)Import_Filters.prc) { options = XmlHelper.ReadXML(fileName, dataTbls.config.labels_file_location); } SaveImportToDataTbls(options); if (setBattle) { var battle = (Battle)options.GetItemsOfType(typeof(Battle)).FirstOrDefault(); SetSelectedBattleByBattle(battle); } }
private void ImportBattleOverFile_Click(object sender, EventArgs e) { var importDialog = FileHelper.GetImportBattleFileDialog(title: "Import Custom Spirit Over Current.", initialDirectory: dataTbls.config.file_directory_custom_battles); if (importDialog.ShowDialog() == CommonFileDialogResult.Ok && !String.IsNullOrWhiteSpace(importDialog?.FileName)) { DataOptions options = new DataOptions(); if (importDialog.SelectedFileTypeIndex == (int)Import_Filters.json) { var importedBattle = XmlHelper.DeserializeFromFile(importDialog.FileName); importedBattle.battle.msbtUpdated = true; // We want to be sure we write the new title when we save. options.AddDataTbl(importedBattle.battle); options.AddRangeDataTbl(importedBattle.fighters); } else if (importDialog.SelectedFileTypeIndex == (int)Import_Filters.prc) { options = XmlHelper.ReadXML(importDialog.FileName, dataTbls.config.labels_file_location); } options.SetBattleIdsForAll(dataTbls.selectedBattle.battle_id); var battle = (Battle)options.GetItemsOfType(typeof(Battle)).FirstOrDefault(); SaveImportToDataTbls(options); SetSelectedBattleByBattle(battle); } }
private void ExecuteSql(string script, ExecutionContext context) { var connectionInfo = new ConnectionInfo { ConnectionName = null, DataSource = (string)context.ResolveVariable(DataSource), InitialCatalog = InitialCatalog.Initial, InitialCatalogName = (string)context.ResolveVariable(InitialCatalogName), UserName = (string)context.ResolveVariable(UserName), Password = (string)context.ResolveVariable(Password) }; var connectionString = MsSqlDataContext.GetConnectionString(connectionInfo) ?? ConnectionStrings.ConnectionString; //TODO: [DIREF] get options from DI through constructor using (var ctx = new MsSqlDataContext(connectionString, DataOptions.GetLegacyConfiguration(), CancellationToken.None)) { ctx.ExecuteReaderAsync(script, async(reader, cancel) => { do { if (reader.HasRows) { while (await reader.ReadAsync(cancel).ConfigureAwait(false)) { // empty code block, created only for checking the connection } } } while (reader.NextResult()); return(Task.FromResult(0)); }).GetAwaiter().GetResult(); } }
public override IBlobStorageMetaDataProvider GetBlobMetaDataProvider(DataProvider dataProvider) { //TODO: get services and options from outside return(new MsSqlBlobMetaDataProvider(Providers.Instance.BlobProviders, Options.Create(DataOptions.GetLegacyConfiguration()), Options.Create(BlobStorageOptions.GetLegacyConfiguration()), Options.Create(ConnectionStringOptions.GetLegacyConnectionStrings()))); }
public void NotExistingFilterProperty() { var dataOptions = new DataOptions(); dataOptions.Filter.Add("NotExistingProperty", null); var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions); queryCreator.GetFilterQuery(); }
public JsonElasticConfiguration( IConfigurationRoot config, ILoggerFactory loggerFactory, IHttpClientFactory factory, PolicyRegistry registry, DataOptions dataOptions) : base(factory, registry, loggerFactory, dataOptions) { _config = config; }
private void ExecuteSql(SqlScriptReader sqlReader, ExecutionContext context) { var connectionInfo = new ConnectionInfo { ConnectionName = (string)context.ResolveVariable(ConnectionName), DataSource = (string)context.ResolveVariable(DataSource), InitialCatalog = InitialCatalog, InitialCatalogName = (string)context.ResolveVariable(InitialCatalogName), UserName = (string)context.ResolveVariable(UserName), Password = (string)context.ResolveVariable(Password) }; var connectionString = MsSqlDataContext.GetConnectionString(connectionInfo, context.ConnectionStrings) ?? context.ConnectionStrings.Repository; while (sqlReader.ReadScript()) { var script = sqlReader.Script; var sb = new StringBuilder(); //TODO: [DIREF] get options from DI through constructor using (var ctx = new MsSqlDataContext(connectionString, DataOptions.GetLegacyConfiguration(), CancellationToken.None)) { ctx.ExecuteReaderAsync(script, async(reader, cancel) => { do { if (reader.HasRows) { var first = true; while (await reader.ReadAsync(cancel).ConfigureAwait(false)) { if (first) { for (int i = 0; i < reader.FieldCount; i++) { sb.Append(reader.GetName(i)).Append("\t"); } Logger.LogMessage(sb.ToString()); sb.Clear(); first = false; } for (int i = 0; i < reader.FieldCount; i++) { sb.Append(reader[i]).Append("\t"); } Logger.LogMessage(sb.ToString()); sb.Clear(); } } } while (await reader.NextResultAsync(cancel).ConfigureAwait(false)); return(Task.FromResult(0)); }).GetAwaiter().GetResult(); } } Logger.LogMessage("Script is successfully executed."); }
public TransactionWrapper(DbTransaction transaction, DataOptions options, TimeSpan timeout, CancellationToken cancel) { Status = TransactionStatus.Active; Transaction = transaction; Timeout = timeout == default ? TimeSpan.FromSeconds(options.TransactionTimeout) : timeout; CancellationToken = CombineCancellationToken(cancel); }
/// <summary> /// Constructor. /// </summary> /// <param name="options">The <see cref="DataOptions"/>.</param> public MySqlDataProvider(DataOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } this.Options = options; }
/// <inheritdoc /> protected BaseDbContext(DbContextOptions contextOptions, DataOptions dataOptions) : base(contextOptions) { this.Options = dataOptions ?? throw new ArgumentNullException(nameof(dataOptions)); this.SavingChanges += (_, _) => this.SavePendingEntityEvents(); this.SavingChanges += (_, _) => this.SaveSoftDeletion(); this.SavedChanges += async(_, _) => await this.ExecuteEntityEvents(); }
public DataService( IDbConnectionFactoryProvider dbConnectionFactoryProvider, IDataAccessLogger logger, DataOptions options) { _dbConnectionFactory = dbConnectionFactoryProvider.BuildConnectionFactory(); _logger = logger; _options = options; }
public MsSqlDataContext(string connectionString, DataOptions options, CancellationToken cancel) : base(options, cancel) { if (string.IsNullOrEmpty(connectionString)) { throw new ArgumentNullException(nameof(connectionString)); } ConnectionString = connectionString; }
/// <summary>Initializes a new instance of the EF6SecurityDataProvider class.</summary> public EF6SecurityDataProvider(IOptions <DataOptions> options, ILogger <EF6SecurityDataProvider> logger) { _options = options?.Value ?? new DataOptions(); _logger = logger; if (string.IsNullOrEmpty(_options.ConnectionString)) { _logger.LogError("No connection string was configured for the security database."); } }
protected ElasticConfiguration( IHttpClientFactory factory, PolicyRegistry registry, ILoggerFactory loggerFactory, DataOptions dataOptions ) { _logger = loggerFactory.CreateLogger(GetType()); _factory = factory; _registry = registry; DataOptions = dataOptions; }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddOptions(); var opts = new HarvesterOptions(); Configuration.Bind("Harvester", opts); services.AddSingleton(opts); var opts2 = new SonicElasticStoreOptions(); Configuration.Bind("SonicElasticStore", opts2); services.AddSingleton(opts2); var opts3 = new DataOptions(); Configuration.Bind("Data", opts3); services.AddSingleton(opts3); var opts4 = new TaskRunnerDelays(); Configuration.Bind("ReindexDelays", opts4); services.AddSingleton(opts4); services.AddSingleton(new PolicyRegistry()); services.Configure <IntegrationProperties>(Configuration.GetSection("Integration")); // Add framework services. services.AddMvc(options => { options.EnableEndpointRouting = false; options.Filters.Add(typeof(ProcessCustomerCodeAttribute)); }).AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); services.AddMemoryCache(); services.AddHttpClient(); var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new DefaultModule() { Configuration = Configuration }); containerBuilder.Populate(services); var container = containerBuilder.Build(); return(new AutofacServiceProvider(container)); }
//Sprawdzic popawnosc dzialania public bool RemoveDataOption(DataOptions dataOption) { var xAttribute = xElement.Attributes().First(attribute => attribute.Name == dataOption.ToString()); if (xAttribute == null) { return(false); } dataOptions.ToList().Remove(dataOption); xAttribute.Remove(); return(true); }
public override DataProvider GetDataProvider(IServiceProvider services) { var connectionStringOptions = Options.Create(new ConnectionStringOptions { Repository = RepositoryConnectionString }); var dbInstallerOptions = Options.Create(new MsSqlDatabaseInstallationOptions()); return(new MsSqlDataProvider(Options.Create(DataOptions.GetLegacyConfiguration()), connectionStringOptions, dbInstallerOptions, new MsSqlDatabaseInstaller(dbInstallerOptions, NullLoggerFactory.Instance.CreateLogger <MsSqlDatabaseInstaller>()), new MsSqlDataInstaller(connectionStringOptions, NullLoggerFactory.Instance.CreateLogger <MsSqlDataInstaller>()), NullLoggerFactory.Instance.CreateLogger <MsSqlDataProvider>())); }
/// <summary> /// Starts the scanning process of the Azure DevOps instance. /// </summary> /// <param name="dataOptions">Scanning options, determines the level and subjects of scanning.</param> /// <param name="collections">List of collections to be scanned.</param> /// <param name="azureDevOpsUrl">Uri of the Azure DevOps instance to be scanned.</param> /// <returns>Instance object holding all collected data.</returns> public Task <AzureDevOpsInstance> ScanAsync(DataOptions dataOptions, IEnumerable <string> collections, Uri azureDevOpsUrl) { if (collections == null) { throw new ArgumentNullException(nameof(collections)); } if (azureDevOpsUrl == null) { throw new ArgumentNullException(nameof(azureDevOpsUrl)); } return(this.ScanAzDOAsync(dataOptions, collections, azureDevOpsUrl)); }
private MsSqlDataProvider CreateDataProvider() { var connectionString = GetConnectionString(); var connOptions = Options.Create(new ConnectionStringOptions { Repository = connectionString }); var dbInstallerOptions = Options.Create(new MsSqlDatabaseInstallationOptions()); return(new MsSqlDataProvider(Options.Create(DataOptions.GetLegacyConfiguration()), connOptions, dbInstallerOptions, new MsSqlDatabaseInstaller(dbInstallerOptions, NullLoggerFactory.Instance.CreateLogger <MsSqlDatabaseInstaller>()), new MsSqlDataInstaller(connOptions, NullLoggerFactory.Instance.CreateLogger <MsSqlDataInstaller>()), NullLoggerFactory.Instance.CreateLogger <MsSqlDataProvider>())); }
public void ComplexFilterWithInnerFiltersAndOrderBy() { var dataOptions = new DataOptions(); dataOptions.Filter.Connector = FilterConnector.And; dataOptions.Filter.Add("Title", "Test1", FilterOperation.NotContains); dataOptions.Filter.Add("Title", "Test2", FilterOperation.NotContains); var innerFilter1 = new DataFilter(FilterConnector.Or); innerFilter1.Add("CreatedOn", Convert.ToDateTime(TestValueDate), FilterOperation.Greater); innerFilter1.Add("CreatedOn", Convert.ToDateTime(TestValueDate), FilterOperation.Less); innerFilter1.Add("CreatedOn", Convert.ToDateTime(TestValueDate)); var innerFilter2 = new DataFilter(FilterConnector.Or); innerFilter2.Add("ModifiedOn", Convert.ToDateTime(TestValueDate), FilterOperation.Greater); innerFilter2.Add("ModifiedOn", Convert.ToDateTime(TestValueDate), FilterOperation.Less); innerFilter2.Add("ModifiedOn", Convert.ToDateTime(TestValueDate)); dataOptions.Filter.Inner.Add(innerFilter1); dataOptions.Filter.Inner.Add(innerFilter2); dataOptions.Order.Add("CreatedOn", OrderDirection.Desc); dataOptions.Order.Add("Title"); dataOptions.Order.Add("Description", OrderDirection.Desc); var queryCreator = new DataOptionsQueryCreator <PageProperties>(dataOptions); var orderQuery = queryCreator.GetOrderQuery(); var filterQuery = queryCreator.GetFilterQuery(); var filterParameters = queryCreator.GetFilterParameters(); Assert.AreEqual(orderQuery, "CreatedOn desc, Title, Description desc"); var result = "(!Title.Contains(@0) or Title == null) and (!Title.Contains(@1) or Title == null) and (CreatedOn > @2 or CreatedOn < @3 or CreatedOn == @4) and (ModifiedOn > @5 or ModifiedOn < @6 or ModifiedOn == @7)"; Assert.AreEqual(filterQuery, result); Assert.IsNotNull(filterParameters); Assert.AreEqual(filterParameters.Length, 8); Assert.AreEqual(filterParameters[0], "Test1"); Assert.AreEqual(filterParameters[1], "Test2"); Assert.AreEqual(filterParameters[2], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[3], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[4], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[5], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[6], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[7], Convert.ToDateTime(TestValueDate)); }
public void SingleOrderByDescending() { var dataOptions = new DataOptions(); dataOptions.Order.Add("CreatedOn", OrderDirection.Desc); var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions); var orderQuery = queryCreator.GetOrderQuery(); var filterQuery = queryCreator.GetFilterQuery(); var filterParameters = queryCreator.GetFilterParameters(); Assert.IsNotNull(filterParameters); Assert.IsEmpty(filterParameters); Assert.AreEqual(filterQuery, string.Empty); Assert.AreEqual(orderQuery, "CreatedOn desc"); }
private static async Task <TimestampData[]> GetTimestampDataForRecursiveIntegrityCheckAsync(string path, int[] excludedNodeTypeIds) { var typeFilter = excludedNodeTypeIds != null && excludedNodeTypeIds.Length > 0 ? $"N.NodeTypeId NOT IN ({string.Join(", ", excludedNodeTypeIds)})" : null; string sql; if (path == null) { sql = "SELECT N.NodeId, V.VersionId, CONVERT(bigint, n.timestamp) NodeTimestamp, CONVERT(bigint, v.timestamp) VersionTimestamp, N.LastMajorVersionId, N.LastMinorVersionId from Versions V join Nodes N on V.NodeId = N.NodeId"; if (!string.IsNullOrEmpty(typeFilter)) { sql += " WHERE " + typeFilter; } } else { sql = string.Format("SELECT N.NodeId, V.VersionId, CONVERT(bigint, n.timestamp) NodeTimestamp, CONVERT(bigint, v.timestamp) VersionTimestamp, N.LastMajorVersionId, N.LastMinorVersionId from Versions V join Nodes N on V.NodeId = N.NodeId WHERE (N.Path = '{0}' COLLATE Latin1_General_CI_AS OR N.Path LIKE REPLACE('{0}', '_', '[_]') + '/%' COLLATE Latin1_General_CI_AS)", path); if (!string.IsNullOrEmpty(typeFilter)) { sql += " AND " + typeFilter; } } using var ctx = new MsSqlDataContext(ConnectionStrings.ConnectionString, DataOptions.GetLegacyConfiguration(), CancellationToken.None); return(await ctx.ExecuteReaderAsync(sql, async (reader, cancel) => { cancel.ThrowIfCancellationRequested(); var result = new List <TimestampData>(); while (await reader.ReadAsync(cancel).ConfigureAwait(false)) { result.Add(new TimestampData { NodeId = reader.GetSafeInt32(reader.GetOrdinal("NodeId")), VersionId = reader.GetSafeInt32(reader.GetOrdinal("VersionId")), NodeTimestamp = reader.GetSafeInt64(reader.GetOrdinal("NodeTimestamp")), VersionTimestamp = reader.GetSafeInt64(reader.GetOrdinal("VersionTimestamp")), LastMajorVersionId = reader.GetSafeInt32(reader.GetOrdinal("LastMajorVersionId")), LastMinorVersionId = reader.GetSafeInt32(reader.GetOrdinal("LastMinorVersionId")), }); } return result.ToArray(); }).ConfigureAwait(false)); }
public void SingleFilterByEqual() { var dataOptions = new DataOptions(); dataOptions.Filter.Add("CreatedOn", TestValueDate, FilterOperation.Equal); var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions); var orderQuery = queryCreator.GetOrderQuery(); var filterQuery = queryCreator.GetFilterQuery(); var filterParameters = queryCreator.GetFilterParameters(); Assert.AreEqual(orderQuery, string.Empty); Assert.AreEqual(filterQuery, "CreatedOn == @0"); Assert.IsNotNull(filterParameters); Assert.AreEqual(filterParameters.Length, 1); Assert.AreEqual(filterParameters[0], Convert.ToDateTime(TestValueDate)); }