/// <summary> /// Executes the specified actions and returns the results of the executions. /// </summary> /// <param name="parameters">Parameters.</param> /// <param name="eventType">Event type.</param> /// <returns></returns> private async Task ExecuteActionsAsync(SaveParameters parameters, ETableDbEventType eventType) { var execution = await this.GetTableExecutionSources(parameters, eventType) .Select(e => new ExecutionSource() { ExecutionType = e.ExecutionType, ExecutionText = e.ExecutionText, TableConfiguration = new TableConfiguration() { ConnectionString = e.TableConfiguration.ConnectionString } }) .ToListAsync(); System.Collections.Concurrent.ConcurrentDictionary <string, object> resultDictionary = new System.Collections.Concurrent.ConcurrentDictionary <string, object>(); int index; for (index = 0; index < execution.Count; index++) { var factory = base.Context.QueryBuilderOptions.ConnectionsPool[execution[index].TableConfiguration.ConnectionString]; var q = new ParserFull(factory) .ParseToQuery(execution[index].ExecutionText, resultDictionary); var result = (await q.GetAsync()).Cast <IDictionary <string, object> >().ToList(); Parallel.For(0, result.Count, (i) => { Parallel.ForEach(result[i], (e) => { resultDictionary.AddOrUpdate(e.Key, e.Value, (f, g) => g); }); }); } foreach (string key in resultDictionary.Keys) { if (!parameters.AdditionalParameters.ContainsKey(key)) { parameters.AdditionalParameters.Add(key, resultDictionary[key]); } else { parameters.AdditionalParameters[key] = resultDictionary[key]; } } }
private IQueryable <ExecutionSource> GetTableExecutionSources(SaveParameters parameters, ETableDbEventType tableDbEventType) { var tables = base.GetTableDefinitions(parameters); switch (tableDbEventType) { case ETableDbEventType.BeforeCreate: case ETableDbEventType.AfterCreate: tables = tables.Where(e => e.TableDefinitionUi.AllowCreate); break; case ETableDbEventType.BeforeUpdate: case ETableDbEventType.AfterUpdate: tables = tables.Where(e => e.TableDefinitionUi.AllowEdit); break; case ETableDbEventType.BeforeDelete: case ETableDbEventType.AfterDelete: tables = tables.Where(e => e.TableDefinitionUi.AllowDelete); break; case ETableDbEventType.AfterCreateOrUpdate: case ETableDbEventType.BeforeCreateOrUpdate: tables = tables.Where(e => e.TableDefinitionUi.AllowCreate || e.TableDefinitionUi.AllowEdit); break; } return(tables .SelectMany(e => e.TableActions) .Where(e => (tableDbEventType == ETableDbEventType.BeforeCreate ? e.TableDbEventType == ETableDbEventType.BeforeCreateOrUpdate || e.TableDbEventType == ETableDbEventType.BeforeCreate : tableDbEventType == ETableDbEventType.AfterCreate ? e.TableDbEventType == ETableDbEventType.AfterCreateOrUpdate || e.TableDbEventType == ETableDbEventType.AfterCreate : tableDbEventType == ETableDbEventType.BeforeUpdate ? e.TableDbEventType == ETableDbEventType.BeforeCreateOrUpdate || e.TableDbEventType == ETableDbEventType.BeforeUpdate : tableDbEventType == ETableDbEventType.AfterUpdate ? e.TableDbEventType == ETableDbEventType.AfterCreateOrUpdate || e.TableDbEventType == ETableDbEventType.AfterUpdate : false) && e.ExecutionSource.ExecutionType != EExecutionType.JavaScript) .OrderBy(e => e.ExecutionOrder) .Select(e => e.ExecutionSource) ); }