Exemple #1
0
        public async Task <(WorkerResult, RefreshAction)> Execute(ModifyWellJob job)
        {
            Verify(job.Well);
            var wellUid  = job.Well.Uid;
            var wellName = job.Well.Name;
            var query    = WellQueries.UpdateQuery(wellUid, wellName);

            var result = await witsmlClient.UpdateInStoreAsync(query);

            if (result.IsSuccessful)
            {
                Log.Information("{JobType} - Job successful", GetType().Name);
                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Well updated ({wellName} [{wellUid}])");
                var refreshAction = new RefreshWell(witsmlClient.GetServerHostname(), job.Well.Uid, RefreshType.Update);
                return(workerResult, refreshAction);
            }

            var updatedWells = await witsmlClient.GetFromStoreAsync(query, OptionsIn.IdOnly);

            var updatedWell = updatedWells.Wells.First();
            var description = new EntityDescription
            {
                WellName = updatedWell.Name
            };

            Log.Error($"Job failed. An error occurred when modifying well: {job.Well.PrintProperties()}");
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to update well", result.Reason, description), null);
        }
        public async Task <(WorkerResult, RefreshAction)> Execute(CreateWellboreJob job)
        {
            var wellbore = job.Wellbore;

            Verify(wellbore);

            var wellboreToCreate = SetupWellboreToCreate(wellbore);

            var result = await witsmlClient.AddToStoreAsync(wellboreToCreate);

            if (result.IsSuccessful)
            {
                await WaitUntilWellboreHasBeenCreated(wellbore);

                Log.Information("{JobType} - Job successful", GetType().Name);
                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Wellbore created ({wellbore.Name} [{wellbore.Uid}])");
                var refreshAction = new RefreshWellbore(witsmlClient.GetServerHostname(), wellbore.WellUid, wellbore.Uid, RefreshType.Add);
                return(workerResult, refreshAction);
            }

            var description = new EntityDescription {
                WellboreName = wellbore.Name
            };

            Log.Error($"Job failed. An error occurred when creating wellbore: {job.Wellbore.PrintProperties()}");
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to create wellbore", result.Reason, description), null);
        }
        public async Task <(WorkerResult, RefreshAction)> Execute(CopyTrajectoryJob job)
        {
            var(trajectory, targetWellbore) = await FetchData(job);

            var copyTrajectoryQuery = CreateCopyTrajectoryQuery(trajectory, targetWellbore);
            var copyLogResult       = await witsmlClient.AddToStoreAsync(copyTrajectoryQuery);

            if (!copyLogResult.IsSuccessful)
            {
                var errorMessage = "Failed to copy trajectory.";
                Log.Error(
                    "{ErrorMessage} Source: UidWell: {SourceWellUid}, UidWellbore: {SourceWellboreUid}, Uid: {SourceTrajectoryUid}. " +
                    "Target: UidWell: {TargetWellUid}, UidWellbore: {TargetWellboreUid}.",
                    errorMessage,
                    job.Source.WellUid, job.Source.WellboreUid, job.Source.TrajectoryUid,
                    job.Target.WellUid, job.Target.WellboreUid);
                return(new WorkerResult(witsmlClient.GetServerHostname(), false, errorMessage, copyLogResult.Reason), null);
            }

            Log.Information("{JobType} - Job successful. Trajectory copied", GetType().Name);
            var refreshAction = new RefreshWellbore(witsmlClient.GetServerHostname(), job.Target.WellUid, job.Target.WellboreUid, RefreshType.Update);
            var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Trajectory {trajectory.Name} copied to: {targetWellbore.Name}");

            return(workerResult, refreshAction);
        }
Exemple #4
0
        public override async Task <(WorkerResult, RefreshAction)> Execute(CreateMudLogJob job)
        {
            var mudLog = job.MudLog;

            Verify(mudLog);

            var mudLogToCreate = SetupMudLogToCreate(mudLog);

            var result = await witsmlClient.AddToStoreAsync(mudLogToCreate);

            if (result.IsSuccessful)
            {
                await WaitUntilMudLogHasBeenCreated(mudLog);

                Log.Information("{JobType} - Job successful", GetType().Name);
                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"MudLog created ({mudLog.Name} [{mudLog.Uid}])");
                var refreshAction = new RefreshWellbore(witsmlClient.GetServerHostname(), mudLog.WellUid, mudLog.Uid, RefreshType.Add);
                return(workerResult, refreshAction);
            }

            var description = new EntityDescription {
                WellboreName = mudLog.WellboreName
            };

            Log.Error($"Job failed. An error occurred when creating MudLog: {job.MudLog.PrintProperties()}");
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to create MudLog", result.Reason, description), null);
        }
        public async Task <(WorkerResult, RefreshWell)> Execute(DeleteWellJob job)
        {
            var wellUid = job.WellReference.WellUid;

            var query  = WellQueries.DeleteQuery(wellUid);
            var result = await witsmlClient.DeleteFromStoreAsync(query);

            if (result.IsSuccessful)
            {
                Log.Information("{JobType} - Job successful.", GetType().Name);
                var refreshAction = new RefreshWell(witsmlClient.GetServerHostname(), wellUid, RefreshType.Remove);
                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Deleted well with uid ${wellUid}");
                return(workerResult, refreshAction);
            }

            Log.Error("Failed to delete well. WellUid: {WellUid}", wellUid);

            query = WellQueries.QueryByUid(wellUid);
            var queryResult = await witsmlClient.GetFromStoreAsync(query, OptionsIn.IdOnly);

            EntityDescription description = null;

            var wellbore = queryResult.Wells.FirstOrDefault();

            if (wellbore != null)
            {
                description = new EntityDescription
                {
                    ObjectName = wellbore.Name
                };
            }

            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to delete well", result.Reason, description), null);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        public override async Task <(WorkerResult, RefreshAction)> Execute(ModifyWellboreJob job)
        {
            Verify(job.Wellbore);

            var witsmlWellbore = WellboreQueries.UpdateWitsmlWellbore(job.Wellbore);
            var result         = await witsmlClient.UpdateInStoreAsync(witsmlWellbore);

            if (result.IsSuccessful)
            {
                Log.Information("{JobType} - Job successful", GetType().Name);
                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Wellbore updated ({job.Wellbore.Name} [{job.Wellbore.Uid}])");
                var refreshAction = new RefreshWellbore(witsmlClient.GetServerHostname(), job.Wellbore.WellUid, job.Wellbore.Uid, RefreshType.Update);
                return(workerResult, refreshAction);
            }
            var updatedWellbores = await witsmlClient.GetFromStoreAsync(witsmlWellbore, new OptionsIn(ReturnElements.IdOnly));

            var updatedWellbore = updatedWellbores.Wellbores.First();
            var description     = new EntityDescription
            {
                WellName     = updatedWellbore.NameWell,
                WellboreName = updatedWellbore.Name
            };

            Log.Error("Job failed. An error occurred when modifying wellbore: {Wellbore}", job.Wellbore.PrintProperties());
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to update wellbore", result.Reason, description), null);
        }
        public override async Task <(WorkerResult, RefreshAction)> Execute(CreateWellJob job)
        {
            var well = job.Well;

            Verify(well);

            var wellToCreate = WellQueries.CreateWitsmlWell(well);
            var result       = await witsmlClient.AddToStoreAsync(wellToCreate);

            if (result.IsSuccessful)
            {
                Log.Information("{JobType} - Job successful", GetType().Name);
                await WaitUntilWellHasBeenCreated(well);

                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Well created ({well.Name} [{well.Uid}])");
                var refreshAction = new RefreshWell(witsmlClient.GetServerHostname(), well.Uid, RefreshType.Add);
                return(workerResult, refreshAction);
            }

            var description = new EntityDescription {
                WellName = well.Name
            };

            Log.Error("Job failed. An error occurred when creating well: {Well}", job.Well.PrintProperties());
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to create well", result.Reason, description), null);
        }
Exemple #9
0
        public override async Task <(WorkerResult, RefreshAction)> Execute(CreateRiskJob job)
        {
            var risk = job.Risk;

            Verify(risk);

            var riskToCreate = SetupRiskToCreate(risk);

            var result = await witsmlClient.AddToStoreAsync(riskToCreate);

            if (result.IsSuccessful)
            {
                await WaitUntilRiskHasBeenCreated(risk);

                Log.Information("{JobType} - Job successful", GetType().Name);
                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Risk created ({risk.Name} [{risk.Uid}])");
                var refreshAction = new RefreshWellbore(witsmlClient.GetServerHostname(), risk.UidWell, risk.Uid, RefreshType.Add);
                return(workerResult, refreshAction);
            }

            var description = new EntityDescription {
                WellboreName = risk.NameWellbore
            };

            Log.Error($"Job failed. An error occurred when creating Risk: {job.Risk.PrintProperties()}");
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to create Risk", result.Reason, description), null);
        }
        public override async Task <(WorkerResult, RefreshAction)> Execute(DeleteRiskJob job)
        {
            var wellUid       = job.RiskReference.WellUid;
            var wellboreUid   = job.RiskReference.WellboreUid;
            var uid           = job.RiskReference.Uid;
            var deleteRequest = RiskQueries.DeleteRiskQuery(wellUid, wellboreUid, uid);

            var result = await witsmlClient.DeleteFromStoreAsync(deleteRequest);

            if (result.IsSuccessful)
            {
                Log.Information("{JobType} - Job successful", GetType().Name);
                var refreshAction = new RefreshWell(witsmlClient.GetServerHostname(), wellUid, RefreshType.Remove);
                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Deleted well with uid ${wellUid}");
                return(workerResult, refreshAction);
            }

            Log.Error("Failed to delete risk. WellUid: {WellUid}", wellUid);

            var query       = RiskQueries.QueryById(wellUid, wellboreUid, uid);
            var queryResult = await witsmlClient.GetFromStoreAsync(query, new OptionsIn(ReturnElements.IdOnly));

            EntityDescription description = null;
            var risk = queryResult.Risks.FirstOrDefault();

            if (risk != null)
            {
                description = new EntityDescription
                {
                    ObjectName = risk.Name
                };
            }
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to delete risk", result.Reason, description), null);
        }
Exemple #11
0
        public override async Task <(WorkerResult, RefreshAction)> Execute(ImportLogDataJob job)
        {
            var chunkSize   = 1000;
            var wellUid     = job.TargetLog.WellUid;
            var wellboreUid = job.TargetLog.WellboreUid;
            var logUid      = job.TargetLog.LogUid;
            var witsmlLog   = await GetLogHeader(wellUid, wellboreUid, logUid);

            if (witsmlLog == null)
            {
                var reason = $"Did not find witsml log for wellUid: {wellUid}, wellboreUid: {wellboreUid}, logUid: {logUid}";
                return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Unable to find log", reason), null);
            }

            var logCurveInfos = witsmlLog.LogCurveInfo.Where(logCurveInfo => job.Mnemonics.Contains(logCurveInfo.Mnemonic)).ToList();

            //Todo: find a way to determine the maximum amount of rows that can be sent to the WITSML server then pass that amount to the CreateImportQueries method
            var queries = CreateImportQueries(job, chunkSize).ToArray();

            //Todo: update import progress for the user using websockets
            for (var i = 0; i < queries.Length; i++)
            {
                var result = await witsmlClient.UpdateInStoreAsync(queries[i]);

                if (result.IsSuccessful)
                {
                    Log.Information("{JobType} - Query {QueryCount}/{CurrentQuery} successful", GetType().Name, queries.Length, i + 1);
                }
                else
                {
                    Log.Error("Failed to import curve data for log object. WellUid: {WellUid}, WellboreUid: {WellboreUid}, Uid: {LogUid}, Mnemonics: {MnemonicsString}. Failed import at query:{QueryNumber} with the chunkSize of {ChunkSize} and total number of queries:{QueriesLength}",
                              wellUid,
                              wellboreUid,
                              logUid,
                              string.Join(", ", job.Mnemonics),
                              i,
                              chunkSize,
                              queries.Length);

                    return(new WorkerResult(witsmlClient.GetServerHostname(), result.IsSuccessful, $"Failed to import curve data from row: {i * chunkSize}", result.Reason, witsmlLog.GetDescription()), null);
                }
            }

            Log.Information("{JobType} - Job successful", GetType().Name);

            var refreshAction  = new RefreshLogObject(witsmlClient.GetServerHostname(), wellUid, wellboreUid, logUid, RefreshType.Update);
            var mnemonicsOnLog = string.Join(", ", logCurveInfos.Select(logCurveInfo => logCurveInfo.Mnemonic));
            var workerResult   = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Imported curve info values for mnemonics: {mnemonicsOnLog}, for log: {logUid}");

            return(workerResult, refreshAction);
        }
        public override async Task <(WorkerResult, RefreshAction)> Execute(CopyLogDataJob job)
        {
            var(sourceLog, targetLog) = await GetLogs(job);

            var mnemonicsToCopy = job.SourceLogCurvesReference.Mnemonics.Any()
                ? job.SourceLogCurvesReference.Mnemonics.Distinct().ToList()
                : sourceLog.LogCurveInfo.Select(lci => lci.Mnemonic).ToList();

            var targetLogMnemonics        = targetLog.LogCurveInfo.Select(lci => lci.Mnemonic);
            var existingMnemonicsInTarget = mnemonicsToCopy.Where(mnemonic => targetLogMnemonics.Contains(mnemonic, StringComparer.OrdinalIgnoreCase)).ToList();
            var newMnemonicsInTarget      = mnemonicsToCopy.Where(mnemonic => !targetLogMnemonics.Contains(mnemonic, StringComparer.OrdinalIgnoreCase)).ToList();

            try
            {
                VerifyMatchingIndexTypes(sourceLog, targetLog);
                VerifyValidInterval(sourceLog);
                VerifyMatchingIndexCurves(sourceLog, targetLog);
                VerifyIndexCurveIsIncludedInMnemonics(sourceLog, newMnemonicsInTarget, existingMnemonicsInTarget);
                await VerifyTargetHasRequiredLogCurveInfos(sourceLog, job.SourceLogCurvesReference.Mnemonics, targetLog);
            }
            catch (Exception e)
            {
                Log.Error(e, "Failed to copy log data");
                return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to copy log data", e.Message), null);
            }

            var copyResultForExistingMnemonics = await CopyLogData(sourceLog, targetLog, job, existingMnemonicsInTarget);

            if (!copyResultForExistingMnemonics.Success)
            {
                var message = $"Failed to copy curves for existing mnemonics to log. Copied a total of {copyResultForExistingMnemonics.NumberOfRowsCopied} rows";
                return(LogAndReturnErrorResult(message));
            }

            var copyResultForNewMnemonics = await CopyLogData(sourceLog, targetLog, job, newMnemonicsInTarget);

            if (!copyResultForNewMnemonics.Success)
            {
                var message = $"Failed to copy curves for new mnemonics to log. Copied a total of {copyResultForNewMnemonics.NumberOfRowsCopied} rows";
                return(LogAndReturnErrorResult(message));
            }

            var totalRowsCopied = copyResultForExistingMnemonics.NumberOfRowsCopied + copyResultForNewMnemonics.NumberOfRowsCopied;

            Log.Information("{JobType} - Job successful. {Count} rows copied", GetType().Name, totalRowsCopied);
            var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"{totalRowsCopied} rows copied");
            var refreshAction = new RefreshLogObject(witsmlClient.GetServerHostname(), job.TargetLogReference.WellUid, job.TargetLogReference.WellboreUid, job.TargetLogReference.LogUid, RefreshType.Update);

            return(workerResult, refreshAction);
        }
        public override async Task <(WorkerResult, RefreshAction)> Execute(DeleteMnemonicsJob job)
        {
            var wellUid         = job.LogObject.WellUid;
            var wellboreUid     = job.LogObject.WellboreUid;
            var logUid          = job.LogObject.LogUid;
            var mnemonics       = new ReadOnlyCollection <string>(job.Mnemonics.ToList());
            var mnemonicsString = string.Join(", ", mnemonics);

            var query  = LogQueries.DeleteMnemonics(wellUid, wellboreUid, logUid, mnemonics);
            var result = await witsmlClient.DeleteFromStoreAsync(query);

            if (result.IsSuccessful)
            {
                Log.Information("{JobType} - Job successful", GetType().Name);
                var refreshAction = new RefreshLogObject(witsmlClient.GetServerHostname(), wellUid, wellboreUid, logUid, RefreshType.Update);
                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Deleted mnemonics: {mnemonicsString} for log: {logUid}");
                return(workerResult, refreshAction);
            }

            Log.Error("Failed to delete mnemonics for log object. WellUid: {WellUid}, WellboreUid: {WellboreUid}, Uid: {LogUid}, Mnemonics: {MnemonicsString}",
                      wellUid,
                      wellboreUid,
                      logUid,
                      mnemonics);

            query = LogQueries.GetWitsmlLogById(wellUid, wellboreUid, logUid);
            var queryResult = await witsmlClient.GetFromStoreAsync(query, new OptionsIn(ReturnElements.IdOnly));

            var log = queryResult.Logs.First();
            EntityDescription description = null;

            if (log != null)
            {
                description = new EntityDescription
                {
                    WellName     = log.NameWell,
                    WellboreName = log.NameWellbore,
                    ObjectName   = log.Name
                };
            }

            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to delete mnemonics", result.Reason, description), null);
        }
        public override async Task <(WorkerResult, RefreshAction)> Execute(ModifyMessageObjectJob job)
        {
            var modifyMessageQuery  = MessageQueries.CreateMessageObject(job.MessageObject);
            var modifyMessageResult = await witsmlClient.UpdateInStoreAsync(modifyMessageQuery);

            if (!modifyMessageResult.IsSuccessful)
            {
                const string errorMessage = "Failed to modify message object";
                Log.Error("{ErrorMessage}. Target: UidWell: {TargetWellUid}, UidWellbore: {TargetWellboreUid}",
                          errorMessage, job.MessageObject.WellUid, job.MessageObject.WellboreUid);
                return(new WorkerResult(witsmlClient.GetServerHostname(), false, errorMessage, modifyMessageResult.Reason), null);
            }

            Log.Information("{JobType} - Job successful. MessageObject modified", GetType().Name);
            var refreshAction = new RefreshMessageObjects(witsmlClient.GetServerHostname(), job.MessageObject.WellUid, job.MessageObject.WellboreUid, RefreshType.Update);
            var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"MessageObject {job.MessageObject.Name} updated for {job.MessageObject.WellboreName}");

            return(workerResult, refreshAction);
        }
        public override async Task <(WorkerResult, RefreshAction)> Execute(DeleteCurveValuesJob job)
        {
            var wellUid     = job.LogReference.WellUid;
            var wellboreUid = job.LogReference.WellboreUid;
            var logUid      = job.LogReference.LogUid;
            var witsmlLog   = await GetLogHeader(wellUid, wellboreUid, logUid);

            if (witsmlLog == null)
            {
                var reason = $"Did not find witsml log for wellUid: {wellUid}, wellboreUid: {wellboreUid}, logUid: {logUid}";
                return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Unable to find log", reason), null);
            }

            var logCurveInfos = witsmlLog.LogCurveInfo.Where(logCurveInfo => job.Mnemonics.Contains(logCurveInfo.Mnemonic)).ToList();
            var deleteQueries = CreateDeleteQueries(job, witsmlLog, logCurveInfos);

            foreach (var query in deleteQueries)
            {
                var result = await witsmlClient.DeleteFromStoreAsync(query);

                if (result.IsSuccessful)
                {
                    Log.Information("{JobType} - Job successful", GetType().Name);
                }
                else
                {
                    Log.Error("Failed to delete mnemonics for log object. WellUid: {WellUid}, WellboreUid: {WellboreUid}, Uid: {LogUid}, Mnemonics: {MnemonicsString}",
                              wellUid,
                              wellboreUid,
                              logUid,
                              string.Join(", ", job.Mnemonics));

                    return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to delete mnemonics", result.Reason, witsmlLog.GetDescription()), null);
                }
            }

            var refreshAction  = new RefreshLogObject(witsmlClient.GetServerHostname(), wellUid, wellboreUid, logUid, RefreshType.Update);
            var mnemonicsOnLog = string.Join(", ", logCurveInfos.Select(logCurveInfo => logCurveInfo.Mnemonic));
            var workerResult   = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Deleted curve info values for mnemonics: {mnemonicsOnLog}, for log: {logUid}");

            return(workerResult, refreshAction);
        }
        public async Task <(WorkerResult, RefreshAction)> Execute(CreateLogJob job)
        {
            var targetWellbore = await GetWellbore(witsmlClient, job.LogObject);

            var copyLogQuery    = CreateLogQuery(job, targetWellbore);
            var createLogResult = await witsmlClient.AddToStoreAsync(copyLogQuery);

            if (!createLogResult.IsSuccessful)
            {
                var errorMessage = "Failed to create log.";
                Log.Error("{ErrorMessage}. Target: UidWell: {TargetWellUid}, UidWellbore: {TargetWellboreUid}.",
                          errorMessage, job.LogObject.WellUid, job.LogObject.WellboreUid);
                return(new WorkerResult(witsmlClient.GetServerHostname(), false, errorMessage, createLogResult.Reason), null);
            }

            Log.Information("{JobType} - Job successful. Log object created", GetType().Name);
            var refreshAction = new RefreshWellbore(witsmlClient.GetServerHostname(), job.LogObject.WellUid, job.LogObject.WellboreUid, RefreshType.Update);
            var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Log object {job.LogObject.Name} created for {targetWellbore.Name}");

            return(workerResult, refreshAction);
        }
        public override async Task <(WorkerResult, RefreshAction)> Execute(BatchModifyWellJob job)
        {
            Verify(job.Wells);

            var wellsToUpdate   = job.Wells.Select(WellQueries.UpdateWitsmlWell);
            var updateWellTasks = wellsToUpdate.Select(wellToUpdate => witsmlClient.UpdateInStoreAsync(wellToUpdate));

            Task  resultTask = Task.WhenAll(updateWellTasks);
            await resultTask;

            if (resultTask.Status == TaskStatus.Faulted)
            {
                Log.Error("Job failed. An error occurred when batch updating wells");
                return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to batch update well properties"), null);
            }

            Log.Information("{JobType} - Job successful", GetType().Name);
            var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, "Batch updated well properties");
            var wells         = job.Wells.Select(well => well.Uid).ToArray();
            var refreshAction = new RefreshWells(witsmlClient.GetServerHostname(), wells, RefreshType.BatchUpdate);

            return(workerResult, refreshAction);
        }
Exemple #18
0
        public override async Task <(WorkerResult, RefreshAction)> Execute(DeleteWellboreJob job)
        {
            var wellUid     = job.WellboreReference.WellUid;
            var wellboreUid = job.WellboreReference.WellboreUid;

            var witsmlWellbore = WellboreQueries.DeleteWitsmlWellbore(wellUid, wellboreUid);
            var result         = await witsmlClient.DeleteFromStoreAsync(witsmlWellbore);

            if (result.IsSuccessful)
            {
                Log.Information("{JobType} - Job successful", GetType().Name);
                var refreshAction = new RefreshWellbore(witsmlClient.GetServerHostname(), wellUid, wellboreUid, RefreshType.Remove);
                var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"Deleted wellbore: ${wellboreUid}");
                return(workerResult, refreshAction);
            }

            Log.Error("Failed to delete wellbore. WellUid: {WellUid}, WellboreUid: {WellboreUid}",
                      wellUid,
                      wellboreUid);

            witsmlWellbore = WellboreQueries.GetWitsmlWellboreByUid(wellUid, wellboreUid);
            var queryResult = await witsmlClient.GetFromStoreAsync(witsmlWellbore, new OptionsIn(ReturnElements.IdOnly));

            EntityDescription description = null;
            var wellbore = queryResult.Wellbores.FirstOrDefault();

            if (wellbore != null)
            {
                description = new EntityDescription
                {
                    WellName   = wellbore.NameWell,
                    ObjectName = wellbore.Name
                };
            }

            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to delete wellbore", result.Reason, description), null);
        }
        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);
        }