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);
        }
Exemple #5
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);
        }
        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 #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(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 #9
0
        public override async Task <(WorkerResult, RefreshAction)> Execute(DeleteMessageObjectsJob job)
        {
            Verify(job);

            var wellUid     = job.MessageObjects.First().WellUid;
            var wellboreUid = job.MessageObjects.First().WellboreUid;

            var messagesExpanded = $"[ {string.Join(", ", job.MessageObjects.Select(l => l.Uid))} ]";
            var jobDescription   = $"Delete {job.MessageObjects.Count()} Messages under wellUid: {wellUid}, wellboreUid: {wellboreUid}. Messages: {messagesExpanded}";

            var queries = job.MessageObjects.Select(l => MessageQueries.GetMessageById(l.WellUid, l.WellboreUid, l.Uid));
            var tasks   = queries.Select(q => witsmlClient.DeleteFromStoreAsync(q)).ToList();

            await Task.WhenAll(tasks);

            if (tasks.Any(t => t.IsFaulted))
            {
                var numFailed = tasks.Count(t => !t.Result.IsSuccessful);
                var reasons   = string.Join(",", tasks.Where(t => !t.Result.IsSuccessful).Select(t => t.Result.Reason).ToArray());
                Log.Error($"FAILURE deleting {numFailed} of {tasks.Count} Messages due to {reasons}");
                return(new WorkerResult(witsmlClient.GetServerHostname(), false, $"Job failed deleting {numFailed} messages", reasons), null);
            }

            Log.Information($"SUCCESS - {jobDescription}");
            return(
                new WorkerResult(witsmlClient.GetServerHostname(), true, $"{tasks.Count} messages deleted for wellbore {wellboreUid}"),
                new RefreshMessageObjects(witsmlClient.GetServerHostname(), wellUid, wellboreUid, RefreshType.Update)
                );
        }
Exemple #10
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(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 #12
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 async Task <(WorkerResult workerResult, RefreshWellbore refreshAction)> Execute(DeleteLogObjectsJob job)
        {
            (WorkerResult workerResult, RefreshWellbore refreshAction)results;

            if (!job.LogReferences.Any())
            {
                throw new ArgumentException($"A minimum of one job is required");
            }
            if (job.LogReferences.Select(l => l.WellboreUid).Distinct().Count() != 1)
            {
                throw new ArgumentException($"All logs should belong to the same Wellbore");
            }

            var wellUid     = job.LogReferences.FirstOrDefault().WellUid;
            var wellboreUid = job.LogReferences.FirstOrDefault().WellboreUid;

            var logsExpanded   = $"[ {string.Join(", ",job.LogReferences.Select(l=>l.LogUid))} ]";
            var jobDescription = $"Delete {job.LogReferences.Count()} Logs under wellUid: {wellUid}, wellboreUid: {wellboreUid}. Logs: {logsExpanded}";

            var queries = job.LogReferences.Select(l => CreateRequest(l));
            var tasks   = queries.Select(q => witsmlClient.DeleteFromStoreAsync(q));

            await Task.WhenAll(tasks);

            if (tasks.Any(t => t.IsFaulted))
            {
                var numFailed = tasks.Count(t => !t.Result.IsSuccessful);
                var reasons   = string.Join(",", tasks.Where(t => !t.Result.IsSuccessful).Select(t => t.Result.Reason).ToArray());
                Log.Error($"FAILURE deleting {numFailed} of {tasks.Count()} Logs due to {reasons}");
                results =
                    (
                        new WorkerResult(witsmlClient.GetServerHostname(), false, $"Job failed deleting {numFailed} log objects. Reasons: {reasons}"),
                        null
                    );
            }
            else
            {
                Log.Information($"SUCCESS - {jobDescription}");
                results =
                    (
                        new WorkerResult(witsmlClient.GetServerHostname(), true, $"{tasks.Count()} log objects deleted for wellbore {wellboreUid}"),
                        new RefreshWellbore(witsmlClient.GetServerHostname(), wellUid, wellboreUid, RefreshType.Update)
                    );
            }
            return(results);
        }
        public override async Task <(WorkerResult, RefreshAction)> Execute(RenameMnemonicJob job)
        {
            Verify(job);

            var logHeader = await GetLog(job.LogReference);

            var mnemonics  = GetMnemonics(logHeader, job.Mnemonic);
            var startIndex = Index.Start(logHeader);
            var endIndex   = Index.End(logHeader);

            while (startIndex < endIndex)
            {
                var logData = await GetLogData(logHeader, mnemonics, startIndex, endIndex);

                if (logData == null)
                {
                    break;
                }

                var updatedWitsmlLog = CreateNewLogWithRenamedMnemonic(job, logHeader, mnemonics, logData);

                var result = await witsmlClient.UpdateInStoreAsync(updatedWitsmlLog);

                if (!result.IsSuccessful)
                {
                    Log.Error($"Failed to rename mnemonic from {job.Mnemonic} to {job.NewMnemonic} for " +
                              $"UidWell: {job.LogReference.WellUid}, UidWellbore: {job.LogReference.WellboreUid}, UidLog: {job.LogReference.LogUid}.");
                    return(new WorkerResult(witsmlClient.GetServerHostname(), false, $"Failed to rename Mnemonic from {job.Mnemonic} to {job.NewMnemonic}", result.Reason), null);
                }

                startIndex = Index.End(logData).AddEpsilon();
            }

            var resultDeleteOldMnemonic = await DeleteOldMnemonic(job.LogReference.WellUid, job.LogReference.WellboreUid, job.LogReference.LogUid, job.Mnemonic);

            if (!resultDeleteOldMnemonic.IsSuccess)
            {
                return(resultDeleteOldMnemonic, null);
            }

            Log.Information($"{GetType().Name} - Job successful. Mnemonic renamed from {job.Mnemonic} to {job.NewMnemonic}");
            return(
                new WorkerResult(witsmlClient.GetServerHostname(), true, $"Mnemonic renamed from {job.Mnemonic} to {job.NewMnemonic}"),
                new RefreshLogObject(witsmlClient.GetServerHostname(), job.LogReference.WellUid, job.LogReference.WellboreUid, job.LogReference.LogUid, RefreshType.Update));
        }
        public async Task <(WorkerResult, RefreshAction)> Execute(ModifyLogObjectJob job)
        {
            Verify(job.LogObject);

            var wellUid     = job.LogObject.WellUid;
            var wellboreUid = job.LogObject.WellboreUid;
            var logUid      = job.LogObject.Uid;

            var query = CreateRequest(wellUid, wellboreUid, logUid,
                                      new WitsmlLog
            {
                Uid         = logUid,
                UidWell     = wellUid,
                UidWellbore = wellboreUid,
                Name        = job.LogObject.Name
            });
            var result = await witsmlClient.UpdateInStoreAsync(query);

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

            Log.Error($"Job failed. An error occurred when modifying logobject: {job.LogObject.PrintProperties()}");
            var logQuery = LogQueries.QueryById(wellUid, wellboreUid, logUid);
            var logs     = await witsmlClient.GetFromStoreAsync(logQuery, OptionsIn.IdOnly);

            var log = logs.Logs.FirstOrDefault();
            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 update log", result.Reason, description), null);
        }
        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(DeleteTrajectoryJob job)
        {
            var wellUid       = job.TrajectoryReference.WellUid;
            var wellboreUid   = job.TrajectoryReference.WellboreUid;
            var trajectoryUid = job.TrajectoryReference.TrajectoryUid;

            var witsmlTrajectory = TrajectoryQueries.GetWitsmlTrajectoryById(wellUid, wellboreUid, trajectoryUid);
            var result           = await witsmlClient.DeleteFromStoreAsync(witsmlTrajectory);

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

            Log.Error("Failed to delete trajectory. WellUid: {WellUid}, WellboreUid: {WellboreUid}, Uid: {TrajectoryUid}",
                      wellUid,
                      wellboreUid,
                      trajectoryUid);

            witsmlTrajectory = TrajectoryQueries.GetWitsmlTrajectoryById(wellUid, wellboreUid, trajectoryUid);
            var queryResult = await witsmlClient.GetFromStoreAsync(witsmlTrajectory, new OptionsIn(ReturnElements.IdOnly));

            var trajectory = queryResult.Trajectories.First();
            EntityDescription description = null;

            if (trajectory != null)
            {
                description = new EntityDescription
                {
                    WellName     = trajectory.NameWell,
                    WellboreName = trajectory.NameWellbore,
                    ObjectName   = trajectory.Name
                };
            }
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to delete trajectory", result.Reason, description), null);
        }
        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 #22
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);
        }
        public async Task <(WorkerResult, RefreshAction)> Execute(TrimLogDataJob job)
        {
            var witsmlLogQuery = LogQueries.QueryById(job.LogObject.WellUid, job.LogObject.WellboreUid, job.LogObject.LogUid);
            var witsmlLogs     = await witsmlClient.GetFromStoreAsync(witsmlLogQuery, OptionsIn.HeaderOnly);

            var witsmlLog = witsmlLogs.Logs.First();

            var currentStartIndex = Index.Start(witsmlLog);
            var newStartIndex     = Index.Start(witsmlLog, job.StartIndex);
            var currentEndIndex   = Index.End(witsmlLog);
            var newEndIndex       = Index.End(witsmlLog, job.EndIndex);

            bool trimmedStartOfLog = false;

            if (currentStartIndex < newStartIndex && newStartIndex < currentEndIndex)
            {
                var trimLogObjectStartQuery = CreateRequest(
                    job.LogObject.WellUid,
                    job.LogObject.WellboreUid,
                    job.LogObject.LogUid,
                    witsmlLog.IndexType,
                    deleteTo: newStartIndex);

                var result = await witsmlClient.DeleteFromStoreAsync(trimLogObjectStartQuery);

                if (result.IsSuccessful)
                {
                    trimmedStartOfLog = true;
                }
                else
                {
                    Log.Error($"Job failed. An error occurred when trimming logobject start: {job.PrintProperties()}");
                    return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to update start of log", result.Reason, GetDescription(witsmlLog)), null);
                }
            }

            bool trimmedEndOfLog = false;

            if (currentEndIndex > newEndIndex && newEndIndex > currentStartIndex)
            {
                var trimLogObjectEndQuery = CreateRequest(
                    job.LogObject.WellUid,
                    job.LogObject.WellboreUid,
                    job.LogObject.LogUid,
                    witsmlLog.IndexType,
                    deleteFrom: newEndIndex);

                var result = await witsmlClient.DeleteFromStoreAsync(trimLogObjectEndQuery);

                if (result.IsSuccessful)
                {
                    trimmedEndOfLog = true;
                }
                else
                {
                    Log.Error($"Job failed. An error occurred when trimming logobject end: {job.PrintProperties()}");
                    return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to update end of log", result.Reason, GetDescription(witsmlLog)), null);
                }
            }

            var refreshAction = new RefreshLogObject(witsmlClient.GetServerHostname(), job.LogObject.WellUid, job.LogObject.WellboreUid, job.LogObject.LogUid, RefreshType.Update);

            if (trimmedStartOfLog && trimmedEndOfLog)
            {
                return(new WorkerResult(witsmlClient.GetServerHostname(), true, $"Updated start/end of log [{job.LogObject.LogUid}]"), refreshAction);
            }
            if (trimmedStartOfLog)
            {
                return(new WorkerResult(witsmlClient.GetServerHostname(), true, $"Updated start of log [{job.LogObject.LogUid}]"), refreshAction);
            }
            if (trimmedEndOfLog)
            {
                return(new WorkerResult(witsmlClient.GetServerHostname(), true, $"Updated end of log [{job.LogObject.LogUid}]"), refreshAction);
            }

            return(new WorkerResult(witsmlClient.GetServerHostname(), false, $"Failed to update start/end of log [{job.LogObject.LogUid}]", "Invalid index range"), null);
        }