public override 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 log object: {Log}", job.LogObject.PrintProperties());
            var logQuery = LogQueries.GetWitsmlLogById(wellUid, wellboreUid, logUid);
            var logs     = await witsmlClient.GetFromStoreAsync(logQuery, new OptionsIn(ReturnElements.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 async Task <IEnumerable <LogObject> > GetLogs(string wellUid, string wellboreUid)
        {
            var query  = LogQueries.QueryByWellbore(wellUid, wellboreUid);
            var result = await WitsmlClient.GetFromStoreAsync(query, OptionsIn.HeaderOnly);

            return(result.Logs.Select(log =>
                                      new LogObject
            {
                Uid = log.Uid,
                Name = log.Name,
                IndexType = log.IndexType,
                WellUid = log.UidWell,
                WellName = log.NameWell,
                WellboreUid = log.UidWellbore,
                WellboreName = log.NameWellbore,
                ServiceCompany = log.ServiceCompany,
                RunNumber = log.RunNumber,
                StartIndex = GetIndexAsString(log.IndexType, log.StartIndex, log.StartDateTimeIndex),
                EndIndex = GetIndexAsString(log.IndexType, log.EndIndex, log.EndDateTimeIndex),
                DateTimeLastChange = StringHelpers.ToDateTime(log.CommonData.DTimLastChange),
                IndexCurve = log.IndexCurve.Value
            }).OrderBy(log => log.Name));
        }
Exemplo n.º 4
0
        public async Task <LogObject> GetLog(string wellUid, string wellboreUid, string logUid, OptionsIn queryOptions)
        {
            var query  = LogQueries.GetWitsmlLogById(wellUid, wellboreUid, logUid);
            var result = await WitsmlClient.GetFromStoreAsync(query, queryOptions);

            var witsmlLog = result.Logs.FirstOrDefault();

            if (witsmlLog == null)
            {
                return(null);
            }

            var logObject = new LogObject
            {
                Uid            = witsmlLog.Uid,
                Name           = witsmlLog.Name,
                IndexType      = witsmlLog.IndexType,
                WellUid        = witsmlLog.UidWell,
                WellName       = witsmlLog.NameWell,
                WellboreUid    = witsmlLog.UidWellbore,
                WellboreName   = witsmlLog.NameWellbore,
                IndexCurve     = witsmlLog.IndexCurve.Value,
                ObjectGrowing  = StringHelpers.ToBooleanSafe(witsmlLog.ObjectGrowing),
                ServiceCompany = witsmlLog.ServiceCompany,
                RunNumber      = witsmlLog.RunNumber
            };

            if (string.IsNullOrEmpty(witsmlLog.IndexType))
            {
                return(logObject);
            }

            logObject.StartIndex = witsmlLog.GetStartIndexAsString();
            logObject.EndIndex   = witsmlLog.GetEndIndexAsString();

            return(logObject);
        }
Exemplo n.º 5
0
        public async Task <IEnumerable <LogObject> > GetLogs(string wellUid, string wellboreUid)
        {
            var witsmlLog = LogQueries.GetWitsmlLogsByWellbore(wellUid, wellboreUid);
            var result    = await WitsmlClient.GetFromStoreAsync(witsmlLog, new OptionsIn(ReturnElements.HeaderOnly));

            return(result.Logs.Select(log =>
                                      new LogObject
            {
                Uid = log.Uid,
                Name = log.Name,
                IndexType = log.IndexType,
                WellUid = log.UidWell,
                WellName = log.NameWell,
                WellboreUid = log.UidWellbore,
                WellboreName = log.NameWellbore,
                ObjectGrowing = StringHelpers.ToBooleanSafe(log.ObjectGrowing),
                ServiceCompany = log.ServiceCompany,
                RunNumber = log.RunNumber,
                StartIndex = log.GetStartIndexAsString(),
                EndIndex = log.GetEndIndexAsString(),
                DateTimeLastChange = StringHelpers.ToDateTime(log.CommonData.DTimLastChange),
                IndexCurve = log.IndexCurve.Value
            }).OrderBy(log => log.Name));
        }
        public JsonResult CreateLog(Log model)
        {
            int result = LogQueries.CreateLog(model, UserQueries.GetCurrentUsername());

            return(Json(new { result = result }));
        }
        // GET: Log
        public ActionResult Index(int type)
        {
            LogListViewModel model = LogQueries.GetLogByUser(UserQueries.GetCurrentUsername(), type);

            return(View(model));
        }
        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);
        }