Esempio n. 1
0
        public async Task <MessageObject> GetMessageObject(string wellUid, string wellboreUid, string msgUid)
        {
            var witsmlMessage = MessageQueries.GetMessageById(wellUid, wellboreUid, msgUid);
            var result        = await WitsmlClient.GetFromStoreAsync(witsmlMessage, new OptionsIn(ReturnElements.All));

            var messageObject = result.Messages.FirstOrDefault();

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

            return(new MessageObject
            {
                WellboreUid = messageObject.UidWellbore,
                WellboreName = messageObject.NameWellbore,
                WellUid = messageObject.UidWell,
                WellName = messageObject.NameWell,
                Uid = messageObject.Uid,
                Name = messageObject.Name,
                MessageText = messageObject.MessageText,
                DateTimeCreation = StringHelpers.ToDateTime(messageObject.CommonData.DTimCreation),
                DateTimeLastChange = StringHelpers.ToDateTime(messageObject.CommonData.DTimLastChange)
            });
        }
Esempio 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)
                );
        }