Exemplo n.º 1
0
        public async Task ProcessJob(JobInfo job, UserAccount userAccount, IProgressLog progressLog)
        {
            // Delete the schema from documentDB
            try
            {
                progressLog.UpdateStatus(JobStatus.Running, $"Deleting schema {job.SchemaId}");
                await _schemaStore.DeleteSchemaAsync(null, job.SchemaId);

                progressLog.UpdateStatus(JobStatus.Running, "Schema deleted successfully");
            }
            catch (Exception ex)
            {
                progressLog.Error("Failed to remove schema record");
                Log.Error(ex, "Failed to remove schema record");
                throw new WorkerException(ex, "Failed to delete schema record.");
            }
        }
Exemplo n.º 2
0
        public async Task ProcessJob(JobInfo job, UserAccount userAccount, IProgressLog progressLog)
        {
            _progressLog = progressLog;
            // Save the schema to documentDB
            try
            {
                Log.Debug("Create schema. Schema file Id: {schemaFileId}", job.SchemaFileId);
                _progressLog.UpdateStatus(JobStatus.Running, "Create schema");
                // get schema from file store
                if (!string.IsNullOrEmpty(job.SchemaFileId))
                {
                    // Parse the JSON metadata
                    JObject schemaJson;
                    var     schemaFileStream = await _jobFileStore.GetFileAsync(job.SchemaFileId);

                    using (var sr = new StreamReader(schemaFileStream))
                    {
                        using (var jr = new JsonTextReader(sr))
                        {
                            schemaJson = JObject.Load(jr);
                        }
                    }
                    if (schemaJson != null)
                    {
                        _progressLog.UpdateStatus(JobStatus.Running, "Retrieved DataDock schema file.");

                        MakeRelative(schemaJson,
                                     $"{_configuration.PublishUrl}{(_configuration.PublishUrl.EndsWith("/") ? string.Empty : "/")}{job.OwnerId}/{job.RepositoryId}/");

                        Log.Debug("Create schema: OwnerId: {ownerId} RepositoryId: {repoId} SchemaFileId: {schemaFileId}",
                                  job.OwnerId, job.RepositoryId, job.SchemaFileId);

                        var schemaInfo = new SchemaInfo
                        {
                            OwnerId      = job.OwnerId,
                            RepositoryId = job.RepositoryId,
                            LastModified = DateTime.UtcNow,
                            SchemaId     = Guid.NewGuid().ToString(),
                            Schema       = schemaJson,
                        };
                        _progressLog.UpdateStatus(JobStatus.Running, "Creating schema record.");

                        await _schemaStore.CreateOrUpdateSchemaRecordAsync(schemaInfo);

                        _progressLog.UpdateStatus(JobStatus.Running, "Schema record created successfully.");
                    }
                    else
                    {
                        _progressLog.UpdateStatus(JobStatus.Failed,
                                                  "Unable to create schema - unable to retrieve schema JSON from temporary file storage");
                        throw new WorkerException(
                                  "Unable to create schema - unable to retrieve schema JSON from temporary file storage");
                    }
                }
                else
                {
                    _progressLog.UpdateStatus(JobStatus.Failed, "Unable to create schema - missing file Id");
                    throw new WorkerException("Unable to create schema - missing file Id");
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to update schema record");
                _progressLog.UpdateStatus(JobStatus.Failed, "Failed to update schema record");

                throw new WorkerException(ex,
                                          "Failed to update schema record.");
            }
        }