コード例 #1
0
        private static async Task <WitsmlWellbore> GetWellbore(IWitsmlClient client, WellboreReference wellboreReference)
        {
            var query     = WellboreQueries.QueryByUid(wellboreReference.WellUid, wellboreReference.WellboreUid);
            var wellbores = await client.GetFromStoreAsync(query, OptionsIn.Requested);

            return(!wellbores.Wellbores.Any() ? null : wellbores.Wellbores.First());
        }
コード例 #2
0
        private static async Task <WitsmlWellbore> GetWellbore(IWitsmlClient client, WellboreReference wellboreReference)
        {
            var witsmlWellbore = WellboreQueries.GetWitsmlWellboreByUid(wellboreReference.WellUid, wellboreReference.WellboreUid);
            var wellbores      = await client.GetFromStoreAsync(witsmlWellbore, new OptionsIn(ReturnElements.Requested));

            return(!wellbores.Wellbores.Any() ? null : wellbores.Wellbores.First());
        }
コード例 #3
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);
        }
コード例 #4
0
        public async Task <Wellbore> GetWellbore(string wellUid, string wellboreUid)
        {
            var query  = WellboreQueries.QueryByUid(wellUid, wellboreUid);
            var result = await WitsmlClient.GetFromStoreAsync(query, OptionsIn.All);

            var witsmlWellbore = result.Wellbores.FirstOrDefault();

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

            return(new Wellbore
            {
                Uid = witsmlWellbore.Uid,
                Name = witsmlWellbore.Name,
                WellUid = witsmlWellbore.UidWell,
                WellName = witsmlWellbore.NameWell,
                WellborePurpose = witsmlWellbore.PurposeWellbore,
                WellboreParentUid = witsmlWellbore.ParentWellbore?.UidRef,
                WellboreParentName = witsmlWellbore.ParentWellbore?.Value,
                DateTimeCreation = StringHelpers.ToDateTime(witsmlWellbore.CommonData.DTimCreation),
                DateTimeLastChange = StringHelpers.ToDateTime(witsmlWellbore.CommonData.DTimLastChange),
                ItemState = witsmlWellbore.CommonData.ItemState
            });
        }
コード例 #5
0
        public async Task <IEnumerable <Wellbore> > GetWellbores(string wellUid = null)
        {
            var start = DateTime.Now;
            var query = string.IsNullOrEmpty(wellUid) ? WellboreQueries.QueryAll() : WellboreQueries.QueryByWell(wellUid);

            var result = await WitsmlClient.GetFromStoreAsync(query, OptionsIn.Requested);

            var wellbores = result.Wellbores
                            .Select(witsmlWellbore =>
                                    new Wellbore
            {
                Uid                = witsmlWellbore.Uid,
                Name               = witsmlWellbore.Name,
                WellUid            = witsmlWellbore.UidWell,
                WellName           = witsmlWellbore.NameWell,
                WellStatus         = witsmlWellbore.StatusWellbore,
                WellType           = witsmlWellbore.TypeWellbore,
                IsActive           = StringHelpers.ToBooleanSafe(witsmlWellbore.IsActive),
                DateTimeLastChange = StringHelpers.ToDateTime(witsmlWellbore.CommonData.DTimLastChange)
            })
                            .OrderBy(wellbore => wellbore.Name).ToList();
            var elapsed = DateTime.Now.Subtract(start).Milliseconds / 1000.0;

            Log.Debug($"Fetched {wellbores.Count} wellbores in {elapsed} seconds");
            return(wellbores);
        }
コード例 #6
0
        public override async Task <(WorkerResult, RefreshAction)> Execute(CreateWellboreJob job)
        {
            var wellbore = job.Wellbore;

            Verify(wellbore);

            var wellboreToCreate = WellboreQueries.CreateWitsmlWellbore(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: {Wellbore}", job.Wellbore.PrintProperties());
            return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to create wellbore", result.Reason, description), null);
        }
コード例 #7
0
        private static async Task <WitsmlWellbore> GetWellbore(IWitsmlClient client, LogObject logObject)
        {
            var query     = WellboreQueries.GetWitsmlWellboreByUid(logObject.WellUid, logObject.WellboreUid);
            var wellbores = await client.GetFromStoreAsync(query, new OptionsIn(ReturnElements.Requested));

            return(!wellbores.Wellbores.Any() ? null : wellbores.Wellbores.First());
        }
コード例 #8
0
        public async Task <Wellbore> GetWellbore(string wellUid, string wellboreUid)
        {
            var query  = WellboreQueries.GetWitsmlWellboreByUid(wellUid, wellboreUid);
            var result = await WitsmlClient.GetFromStoreAsync(query, new OptionsIn(ReturnElements.All));

            var witsmlWellbore = result.Wellbores.FirstOrDefault();

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

            return(new Wellbore
            {
                Uid = witsmlWellbore.Uid,
                Name = witsmlWellbore.Name,
                WellUid = witsmlWellbore.UidWell,
                WellName = witsmlWellbore.NameWell,
                Number = witsmlWellbore.Number,
                SuffixAPI = witsmlWellbore.SuffixAPI,
                NumGovt = witsmlWellbore.NumGovt,
                WellStatus = witsmlWellbore.StatusWellbore,
                WellborePurpose = witsmlWellbore.PurposeWellbore,
                WellboreParentUid = witsmlWellbore.ParentWellbore?.UidRef,
                WellboreParentName = witsmlWellbore.ParentWellbore?.Value,
                WellType = witsmlWellbore.TypeWellbore,
                Shape = witsmlWellbore.Shape,
                DTimeKickoff = string.IsNullOrEmpty(witsmlWellbore.DTimKickoff) ? null : StringHelpers.ToDateTime(witsmlWellbore.DTimKickoff),
                Md = (witsmlWellbore.Md == null) ? null : new LengthMeasure {
                    Uom = witsmlWellbore.Md.Uom, Value = decimal.Parse(witsmlWellbore.Md.Value)
                },
                Tvd = (witsmlWellbore.Tvd == null) ? null : new LengthMeasure {
                    Uom = witsmlWellbore.Tvd.Uom, Value = decimal.Parse(witsmlWellbore.Tvd.Value)
                },
                MdKickoff = (witsmlWellbore.MdKickoff == null) ? null : new LengthMeasure {
                    Uom = witsmlWellbore.MdKickoff.Uom, Value = decimal.Parse(witsmlWellbore.MdKickoff.Value)
                },
                TvdKickoff = (witsmlWellbore.TvdKickoff == null) ? null : new LengthMeasure {
                    Uom = witsmlWellbore.TvdKickoff.Uom, Value = decimal.Parse(witsmlWellbore.TvdKickoff.Value)
                },
                MdPlanned = (witsmlWellbore.MdPlanned == null) ? null : new LengthMeasure {
                    Uom = witsmlWellbore.MdPlanned.Uom, Value = decimal.Parse(witsmlWellbore.MdPlanned.Value)
                },
                TvdPlanned = (witsmlWellbore.TvdPlanned == null) ? null : new LengthMeasure {
                    Uom = witsmlWellbore.TvdPlanned.Uom, Value = decimal.Parse(witsmlWellbore.TvdPlanned.Value)
                },
                MdSubSeaPlanned = (witsmlWellbore.MdSubSeaPlanned == null) ? null : new LengthMeasure {
                    Uom = witsmlWellbore.MdSubSeaPlanned.Uom, Value = decimal.Parse(witsmlWellbore.MdSubSeaPlanned.Value)
                },
                TvdSubSeaPlanned = (witsmlWellbore.TvdSubSeaPlanned == null) ? null : new LengthMeasure {
                    Uom = witsmlWellbore.TvdSubSeaPlanned.Uom, Value = decimal.Parse(witsmlWellbore.TvdSubSeaPlanned.Value)
                },
                DayTarget = (witsmlWellbore.DayTarget == null) ? null : new DayMeasure {
                    Uom = witsmlWellbore.DayTarget.Uom, Value = int.Parse(witsmlWellbore.DayTarget.Value)
                },
                DateTimeCreation = StringHelpers.ToDateTime(witsmlWellbore.CommonData.DTimCreation),
                DateTimeLastChange = StringHelpers.ToDateTime(witsmlWellbore.CommonData.DTimLastChange),
                ItemState = witsmlWellbore.CommonData.ItemState
            });
        }
コード例 #9
0
        private async Task WaitUntilWellboreHasBeenCreated(Wellbore wellbore)
        {
            var isWellboreCreated = false;
            var witsmlWellbore    = WellboreQueries.GetWitsmlWellboreByUid(wellbore.WellUid, wellbore.Uid);
            var maxRetries        = 30;

            while (!isWellboreCreated)
            {
                if (--maxRetries == 0)
                {
                    throw new InvalidOperationException($"Not able to read newly created wellbore with name {wellbore.Name} (id={wellbore.Uid})");
                }
                Thread.Sleep(1000);
                var wellboreResult = await witsmlClient.GetFromStoreAsync(witsmlWellbore, new OptionsIn(ReturnElements.IdOnly));

                isWellboreCreated = wellboreResult.Wellbores.Any();
            }
        }
コード例 #10
0
        public async Task <(WorkerResult, RefreshWellbore)> Execute(DeleteWellboreJob job)
        {
            var wellUid     = job.WellboreReference.WellUid;
            var wellboreUid = job.WellboreReference.WellboreUid;

            var query  = WellboreQueries.DeleteWellboreQuery(wellUid, wellboreUid);
            var result = await witsmlClient.DeleteFromStoreAsync(query);

            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);

            query = WellboreQueries.QueryByUid(wellUid, wellboreUid);
            var queryResult = await witsmlClient.GetFromStoreAsync(query, OptionsIn.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);
        }