public async Task ImportRtAsync(string tenantId, string key, IJobCancellationToken cancellationToken)
        {
            try
            {
                Logger.Info($"Reading input file from cache for RT import to '{tenantId}'");
                var tempFile = await GetTempFile(key);

                Logger.Info($"Starting import of file '{tempFile}'");
                var tenantContext = await _systemContext.CreateOrGetTenantContext(tenantId);

                using var session = await tenantContext.Repository.StartSessionAsync();

                // session.StartTransaction();

                await tenantContext.ImportRtModelAsync(session, tempFile, cancellationToken.ShutdownToken);

                // await session.CommitTransactionAsync();

                await ClearCache(key);

                Logger.Info($"Import of file '{tempFile}' completed.");
            }
            catch (Exception e)
            {
                Logger.Error(e, "Import failed with error.");
                throw;
            }
        }
Example #2
0
        public async Task Run(string tenantId, IJobCancellationToken cancellationToken)
        {
            try
            {
                Logger.Info($"Reading aggregatable attributes '{tenantId}'");

                var dataContext = await _systemContext.CreateOrGetTenantContext(tenantId);

                foreach (var entityCacheItem in dataContext.CkCache.GetCkEntities())
                {
                    cancellationToken?.ThrowIfCancellationRequested();

                    foreach (var attributeCacheItem in entityCacheItem.Attributes)
                    {
                        if (!attributeCacheItem.Value.IsAutoCompleteEnabled)
                        {
                            continue;
                        }

                        cancellationToken?.ThrowIfCancellationRequested();

                        using var session = await dataContext.Repository.StartSessionAsync();

                        session.StartTransaction();

                        var autoCompleteTexts = await dataContext.Repository.ExtractAutoCompleteValuesAsync(session, entityCacheItem.CkId,
                                                                                                            attributeCacheItem.Value.AttributeName, attributeCacheItem.Value.AutoCompleteFilter, attributeCacheItem.Value.AutoCompleteLimit);

                        await dataContext.Repository.UpdateAutoCompleteTexts(session, entityCacheItem.CkId, attributeCacheItem.Value.AttributeName, autoCompleteTexts.Select(x => x.Text));

                        await session.CommitTransactionAsync();
                    }
                }

                await _distributedCache.PublishAsync(CacheCommon.KeyTenantUpdate, tenantId);

                Logger.Info($"Aggregation of attribute values of data source '{tenantId}' completed.");
            }
            catch (Exception e)
            {
                Logger.Error(e, "Aggregation failed with error.");
                throw;
            }
        }
Example #3
0
        public async Task Run(string dataSource, IJobCancellationToken cancellationToken)
        {
            try
            {
                DateTime startDateTime     = DateTime.Now;
                var      dataSourceContext = await _systemContext.CreateOrGetTenantContext(dataSource);

                using var session = await dataSourceContext.Repository.StartSessionAsync();

                session.StartTransaction();

                var dataQueryQueryOperation = new DataQueryOperation
                {
                    FieldFilters = new[] { new FieldFilter(Constants.EnabledAttribute, FieldFilterOperator.Equals, true), }
                };

                var serviceHookResultSet =
                    await dataSourceContext.Repository.GetRtEntitiesByTypeAsync <RtSystemServiceHook>(session, dataQueryQueryOperation);

                foreach (var serviceHook in serviceHookResultSet.Result)
                {
                    var targetCkId         = serviceHook.GetAttributeStringValueOrDefault(Constants.QueryCkIdAttribute);
                    var serviceHookBaseUri = serviceHook.GetAttributeStringValueOrDefault(Constants.ServiceHookBaseUriAttribute);
                    var serviceHookAction  = serviceHook.GetAttributeStringValueOrDefault(Constants.ServiceHookActionAttribute);
                    var dataQueryOperation = new DataQueryOperation
                    {
                        FieldFilters = JsonConvert
                                       .DeserializeObject <FieldFilterDto[]>(
                            serviceHook.GetAttributeStringValueOrDefault(Constants.FieldFilterAttribute))
                                       .Select(f =>
                                               new FieldFilter(TransformAttributeName(f.AttributeName), (FieldFilterOperator)f.Operator, f.ComparisonValue))
                    };

                    if (CheckCancellation(cancellationToken.ShutdownToken))
                    {
                        return;
                    }

                    var result =
                        await dataSourceContext.Repository.GetRtEntitiesByTypeAsync(session, targetCkId, dataQueryOperation, 0, 500);

                    Logger.Info(
                        $"Processing '{result.TotalCount}' entities of type '{targetCkId}' at '{startDateTime}");

                    try
                    {
                        await CallServiceHook(serviceHookBaseUri, serviceHookAction, result.Result,
                                              cancellationToken.ShutdownToken);
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e);
                        // Ignore the error because the job is recurring
                    }

                    Logger.Info($"Processing done (start was at '{startDateTime}')");
                }

                await session.CommitTransactionAsync();
            }
            catch (Exception e)
            {
                Logger.Error(e);
                throw;
            }
        }