forked from equinor/witsml-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request equinor#464 from steinsiv/11-messageobject-api
MessageObject support in `WitsmlExplorer.Api`
- Loading branch information
Showing
10 changed files
with
295 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace WitsmlExplorer.Api.Jobs.Common | ||
{ | ||
public class MessageObjectReference | ||
{ | ||
public string Uid { get; set; } | ||
public string WellUid { get; set; } | ||
public string WellboreUid { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using WitsmlExplorer.Api.Models; | ||
|
||
namespace WitsmlExplorer.Api.Jobs | ||
{ | ||
public class CreateMessageObjectJob | ||
{ | ||
public MessageObject MessageObject { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace WitsmlExplorer.Api.Models | ||
{ | ||
public class MessageObject | ||
{ | ||
public string Uid { get; set; } | ||
public string Name { get; set; } | ||
public string WellUid { get; set; } | ||
public string WellName { get; set; } | ||
public string WellboreName { get; set; } | ||
public string WellboreUid { get; set; } | ||
public string MessageText { get; set; } | ||
|
||
public DateTime? DateTimeCreation { get; set; } | ||
public DateTime? DateTimeLastChange { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
Src/WitsmlExplorer.Api/Services/MessageObjectService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Serilog; | ||
using Witsml.Data; | ||
using Witsml.Extensions; | ||
using Witsml.ServiceReference; | ||
using WitsmlExplorer.Api.Models; | ||
|
||
namespace WitsmlExplorer.Api.Services | ||
{ | ||
public interface IMessageObjectService | ||
{ | ||
Task<MessageObject> GetMessageObject(string wellUid, string wellboreUid, string msgUid); | ||
Task<IEnumerable<MessageObject>> GetMessageObjects(string wellUid, string wellboreUid); | ||
} | ||
|
||
public class MessageObjectService : WitsmlService, IMessageObjectService | ||
{ | ||
public MessageObjectService(IWitsmlClientProvider witsmlClientProvider) : base(witsmlClientProvider) | ||
{ | ||
} | ||
|
||
public async Task<MessageObject> GetMessageObject(string wellUid, string wellboreUid, string msgUid) | ||
{ | ||
var query = CreateMessageQuery(wellUid, wellboreUid, msgUid); | ||
var result = await WitsmlClient.GetFromStoreAsync(query, OptionsIn.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) | ||
}; | ||
} | ||
|
||
public async Task<IEnumerable<MessageObject>> GetMessageObjects(string wellUid, string wellboreUid) | ||
{ | ||
var start = DateTime.Now; | ||
var query = CreateMessageQuery(wellUid, wellboreUid); | ||
var result = await WitsmlClient.GetFromStoreAsync(query, OptionsIn.All); | ||
var messageObject = result.Messages.FirstOrDefault(); | ||
if (messageObject == null) return null; | ||
|
||
var messageObjects = result.Messages | ||
.Select(messageObject => | ||
new MessageObject | ||
{ | ||
Uid = messageObject.Uid, | ||
Name = messageObject.Name, | ||
WellboreUid = messageObject.UidWellbore, | ||
WellboreName = messageObject.NameWellbore, | ||
WellUid = messageObject.UidWell, | ||
WellName = messageObject.NameWell, | ||
MessageText = messageObject.MessageText, | ||
DateTimeLastChange = StringHelpers.ToDateTime(messageObject.CommonData.DTimLastChange) | ||
}) | ||
.OrderBy(messageObject => messageObject.WellboreName).ToList(); | ||
var elapsed = DateTime.Now.Subtract(start).Milliseconds / 1000.0; | ||
Log.Debug($"Fetched {messageObjects.Count} messageobjects in {elapsed} seconds"); | ||
return messageObjects; | ||
} | ||
|
||
private static WitsmlMessages CreateMessageQuery(string wellUid, string wellboreUid, string messageUid) | ||
{ | ||
return new() | ||
{ | ||
Messages = new WitsmlMessage | ||
{ | ||
UidWellbore = wellboreUid, | ||
UidWell = wellUid, | ||
Uid = messageUid, | ||
CommonData = new WitsmlCommonData() | ||
}.AsSingletonList() | ||
}; | ||
} | ||
|
||
private static WitsmlMessages CreateMessageQuery(string wellUid, string wellboreUid) | ||
{ | ||
return new() | ||
{ | ||
Messages = new WitsmlMessage | ||
{ | ||
UidWellbore = wellboreUid, | ||
UidWell = wellUid, | ||
CommonData = new WitsmlCommonData() | ||
}.AsSingletonList() | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.