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);
        }
Exemplo n.º 2
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)
                );
        }
Exemplo n.º 3
0
        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);
        }
        private async Task <WorkerResult> DeleteOldMnemonic(string wellUid, string wellboreUid, string logUid, string mnemonic)
        {
            var query  = LogQueries.DeleteMnemonics(wellUid, wellboreUid, logUid, new[] { mnemonic });
            var result = await witsmlClient.DeleteFromStoreAsync(query);

            if (result.IsSuccessful)
            {
                return(new WorkerResult(witsmlClient.GetServerHostname(), true, $"Successfully deleted old mnemonic"));
            }

            Log.Error("Failed to delete old mnemonic. WellUid: {WellUid}, WellboreUid: {WellboreUid}, Uid: {LogUid}, Mnemonic: {Mnemonic}", wellUid, wellboreUid, logUid, mnemonic);
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, $"Failed to delete old mnemonic {mnemonic} while renaming mnemonic", result.Reason));
        }
        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(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(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 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);
        }
Exemplo n.º 9
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 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);
        }