public async Task <(WorkerResult, RefreshAction)> Execute(CopyLogJob job) { var(log, targetWellbore) = await FetchData(job); var copyLogQuery = CreateCopyLogQuery(log, targetWellbore); var copyLogResult = await witsmlClient.AddToStoreAsync(copyLogQuery); if (!copyLogResult.IsSuccessful) { var errorMessage = "Failed to copy log."; LogError(job, errorMessage); return(new WorkerResult(witsmlClient.GetServerHostname(), false, errorMessage, copyLogResult.Reason), null); } var copyLogDataJob = CreateCopyLogDataJob(job, log); var copyLogDataResult = await copyLogDataWorker.Execute(copyLogDataJob); if (!copyLogDataResult.Item1.IsSuccess) { var errorMessage = "Failed to copy log data."; LogError(job, errorMessage); return(new WorkerResult(witsmlClient.GetServerHostname(), false, errorMessage, copyLogResult.Reason), null); } Log.Information("{JobType} - Job successful. Log object copied", GetType().Name); var refreshAction = new RefreshWellbore(witsmlClient.GetServerHostname(), job.Target.WellUid, job.Target.WellboreUid, RefreshType.Update); var workerResult = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Log object {log.Name} copied to: {targetWellbore.Name}"); return(workerResult, refreshAction); }
public override async Task <(WorkerResult, RefreshAction)> Execute(CopyLogJob job) { var(sourceLogs, targetWellbore) = await FetchSourceLogsAndTargetWellbore(job); var copyLogsQuery = sourceLogs.Select(log => CreateCopyLogQuery(log, targetWellbore)); var copyLogTasks = copyLogsQuery.Select(logToCopy => witsmlClient.AddToStoreAsync(logToCopy)); Task copyLogTasksResult = Task.WhenAll(copyLogTasks); await copyLogTasksResult; if (copyLogTasksResult.Status == TaskStatus.Faulted) { var errorMessage = "Failed to copy log."; LogError(job, errorMessage); return(new WorkerResult(witsmlClient.GetServerHostname(), false, errorMessage), null); } var copyLogDataJobs = sourceLogs.Select(log => CreateCopyLogDataJob(job, log)); var copyLogDataTasks = copyLogDataJobs.Select(copyLogDataJob => copyLogDataWorker.Execute(copyLogDataJob)); Task copyLogDataResultTask = Task.WhenAll(copyLogDataTasks); await copyLogDataResultTask; if (copyLogDataResultTask.Status == TaskStatus.Faulted) { var errorMessage = "Failed to copy log data."; LogError(job, errorMessage); return(new WorkerResult(witsmlClient.GetServerHostname(), false, errorMessage), null); } Log.Information("{JobType} - Job successful. Log object copied", GetType().Name); var refreshAction = new RefreshWellbore(witsmlClient.GetServerHostname(), job.Target.WellUid, job.Target.WellboreUid, RefreshType.Update); var copiedLogsMessage = sourceLogs.Length == 1 ? $"Log object {sourceLogs[0].Name}" : $"{sourceLogs.Length} logs" + $" copied to: {targetWellbore.Name}"; var workerResult = new WorkerResult(witsmlClient.GetServerHostname(), true, copiedLogsMessage); return(workerResult, refreshAction); }
public async Task CreateJob(JobType jobType, Stream jobStream) { WorkerResult result; RefreshAction refreshAction = null; switch (jobType) { case JobType.CopyLog: var copyLogJob = await jobStream.Deserialize <CopyLogJob>(); (result, refreshAction) = await copyLogWorker.Execute(copyLogJob); break; case JobType.CopyLogData: var copyLogDataJob = await jobStream.Deserialize <CopyLogDataJob>(); (result, refreshAction) = await copyLogDataWorker.Execute(copyLogDataJob); break; case JobType.CopyTrajectory: var copyTrajectoryJob = await jobStream.Deserialize <CopyTrajectoryJob>(); (result, refreshAction) = await copyTrajectoryWorker.Execute(copyTrajectoryJob); break; case JobType.TrimLogObject: var trimLogObjectJob = await jobStream.Deserialize <TrimLogDataJob>(); (result, refreshAction) = await trimLogObjectWorker.Execute(trimLogObjectJob); break; case JobType.ModifyLogObject: var modifyLogObjectJob = await jobStream.Deserialize <ModifyLogObjectJob>(); (result, refreshAction) = await modifyLogObjectWorker.Execute(modifyLogObjectJob); break; case JobType.DeleteCurveValues: var deleteCurveValuesJob = await jobStream.Deserialize <DeleteCurveValuesJob>(); (result, refreshAction) = await deleteCurveValuesWorker.Execute(deleteCurveValuesJob); break; case JobType.DeleteLogObjects: var deleteLogObjectsJob = await jobStream.Deserialize <DeleteLogObjectsJob>(); (result, refreshAction) = await deleteLogObjectsWorker.Execute(deleteLogObjectsJob); break; case JobType.DeleteMnemonics: var deleteMnemonicsJob = await jobStream.Deserialize <DeleteMnemonicsJob>(); (result, refreshAction) = await deleteMnemonicsWorker.Execute(deleteMnemonicsJob); break; case JobType.DeleteWell: var deleteWellJob = await jobStream.Deserialize <DeleteWellJob>(); (result, refreshAction) = await deleteWellWorker.Execute(deleteWellJob); break; case JobType.DeleteWellbore: var deleteWellboreJob = await jobStream.Deserialize <DeleteWellboreJob>(); (result, refreshAction) = await deleteWellboreWorker.Execute(deleteWellboreJob); break; case JobType.RenameMnemonic: var modifyLogCurveInfoJob = await jobStream.Deserialize <RenameMnemonicJob>(); (result, refreshAction) = await renameMnemonicWorker.Execute(modifyLogCurveInfoJob); break; case JobType.ModifyWell: var modifyWellJob = await jobStream.Deserialize <ModifyWellJob>(); (result, refreshAction) = await modifyWellWorker.Execute(modifyWellJob); break; case JobType.ModifyWellbore: var modifyWellboreJob = await jobStream.Deserialize <ModifyWellboreJob>(); (result, refreshAction) = await modifyWellboreWorker.Execute(modifyWellboreJob); break; case JobType.DeleteTrajectory: var deleteTrajectoryJob = await jobStream.Deserialize <DeleteTrajectoryJob>(); result = await deleteTrajectoryWorker.Execute(deleteTrajectoryJob); break; case JobType.CreateLogObject: var createLogObject = await jobStream.Deserialize <CreateLogJob>(); (result, refreshAction) = await createLogWorker.Execute(createLogObject); break; case JobType.CreateWell: var createWellJob = await jobStream.Deserialize <CreateWellJob>(); (result, refreshAction) = await createWellWorker.Execute(createWellJob); break; case JobType.CreateWellbore: var createWellboreJob = await jobStream.Deserialize <CreateWellboreJob>(); (result, refreshAction) = await createWellboreWorker.Execute(createWellboreJob); break; default: throw new ArgumentOutOfRangeException(nameof(jobType), jobType, $"No worker setup to execute {jobType.GetDisplayName()}"); } if (hubContext != null) { await hubContext.Clients.All.SendCoreAsync("jobFinished", new object[] { result }); if (refreshAction != null) { await hubContext.Clients.All.SendCoreAsync("refresh", new object[] { refreshAction }); } } }