/// <summary> /// Adds a data object to the data store. /// </summary> /// <param name="parser">The input template parser.</param> /// <param name="dataObject">The data object to be added.</param> public override void Add(WitsmlQueryParser parser, Log dataObject) { using (var transaction = GetTransaction()) { transaction.SetContext(dataObject.GetUri()); // Add ChannelSets + data via the ChannelSet data adapter foreach (var childParser in parser.ForkProperties("ChannelSet", ObjectTypes.ChannelSet)) { var channelSet = WitsmlParser.Parse <ChannelSet>(childParser.Root); ChannelSetDataAdapter.Add(childParser, channelSet); } // Clear ChannelSet data properties foreach (var channelSet in dataObject.ChannelSet) { channelSet.Data = null; } InsertEntity(dataObject); // Commit transaction transaction.Commit(); } }
/// <summary> /// Sets the current object. /// </summary> /// <param name="objectType">The data object type.</param> /// <param name="xml">The XML string.</param> /// <param name="version">The WITSML version.</param> /// <param name="bindDataGrid">True if grid can be bound with results.</param> /// <param name="keepGridData">True if not clearing data when querying partial results.</param> /// <param name="retrieveObjectSelection">if set to <c>true</c> the retrieve object selection setting is selected.</param> /// <param name="errorHandler">The error handler.</param> public void SetCurrentObject(string objectType, string xml, string version, bool bindDataGrid, bool keepGridData, bool retrieveObjectSelection, Action <WitsmlException> errorHandler) { var document = WitsmlParser.Parse(xml); var family = ObjectTypes.GetFamily(document.Root); var dataType = ObjectTypes.GetObjectGroupType(objectType, family, version); var dataObject = WitsmlParser.Parse(dataType, document.Root); var collection = dataObject as IEnergisticsCollection; TypeDecorationManager.Register(dataType); CurrentObject = collection == null ? dataObject : collection.Items.Count > 1 ? collection.Items : collection.Items.Count == 1 ? collection.Items[0] : collection; if ((collection == null || collection.Items.Count == 1) && (bindDataGrid || keepGridData)) { ObjectData?.SetCurrentObject(objectType, CurrentObject, keepGridData, retrieveObjectSelection, errorHandler); } else { ObjectData?.ClearDataTable(); } }
/// <summary> /// Invoked during execution of the query, with the /// pre populated expression tree. /// </summary> /// <param name="expression">Target expression block</param> /// <returns>Expected result</returns> public IEnumerable <T> Execute(Ast.Expression expression) { Visit(expression); var optionsIn = string.Join(";", Options.Select(x => $"{x.Key}={x.Value}")); var objectType = ObjectTypes.GetObjectType <T>(); var xmlIn = WitsmlParser.ToXml(Query, true); var originalXmlIn = xmlIn; if (Context.Connection.CompressRequests) { ClientCompression.Compress(ref xmlIn, ref optionsIn); } Context.LogQuery(Functions.GetFromStore, objectType, originalXmlIn, optionsIn); using (var client = Context.Connection.CreateClientProxy().WithUserAgent()) { var wmls = (IWitsmlClient)client; string suppMsgOut, xmlOut = string.Empty; var result = Enumerable.Empty <T>(); short returnCode; try { returnCode = wmls.WMLS_GetFromStore(objectType, xmlIn, optionsIn, null, out xmlOut, out suppMsgOut); } catch (Exception ex) { Logger.ErrorFormat("Error querying store: {0}", ex); returnCode = -1; suppMsgOut = "Error querying store:" + ex.GetBaseException().Message; } try { // Handle servers that compress the response to a compressed request. if (Context.Connection.CompressRequests) { xmlOut = ClientCompression.SafeDecompress(xmlOut); } if (returnCode > 0) { var document = WitsmlParser.Parse(xmlOut); var response = WitsmlParser.Parse <TList>(document.Root); result = (IEnumerable <T>)response.Items; } } catch (WitsmlException ex) { Logger.ErrorFormat("Error parsing query response: {0}{2}{2}{1}", xmlOut, ex, Environment.NewLine); returnCode = (short)ex.ErrorCode; suppMsgOut = ex.Message + " " + ex.GetBaseException().Message; } Context.LogResponse(Functions.GetFromStore, objectType, originalXmlIn, optionsIn, xmlOut, returnCode, suppMsgOut); return(result); } }
/// <summary> /// Creates a new <see cref="WitsmlQueryParser"/> from the specified data object. /// </summary> /// <param name="dataObject">The data object.</param> /// <returns>A new <see cref="WitsmlQueryParser"/> instance.</returns> protected virtual WitsmlQueryParser CreateQueryParser(TObject dataObject) { var document = WitsmlParser.Parse(WitsmlParser.ToXml(dataObject)); var objectType = ObjectTypes.GetObjectType(dataObject as AbstractObject); return(new WitsmlQueryParser(document.Root, objectType, null)); }
public void Well200DataAdapter_Well_Can_Be_Parsed_And_Validated() { var wellTitle = "Well 01 - 160316-000508-840"; string xml = @"<?xml version=""1.0""?> <Well xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" uuid=""81f60891-b69c-4515-870f-0d1954dcac11"" xmlns=""http://www.energistics.org/energyml/data/witsmlv2""> <Citation xmlns=""http://www.energistics.org/energyml/data/commonv2""> <Title>" + wellTitle + @"</Title> <Originator>DevKit200Aspect</Originator> <Creation>2016-03-16T05:05:08.8416296Z</Creation> <Format>PDS.WITSMLstudio.Store.IntegrationTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</Format> </Citation> <PcInterest uom=""%"">100</PcInterest> <TimeZone>-06:00</TimeZone> <GeographicLocationWGS84> <Latitude uom=""dega"">28.5597</Latitude> <Longitude uom=""dega"">-90.6671</Longitude> <Crs xmlns:q1=""http://www.energistics.org/energyml/data/commonv2"" xsi:type=""q1:GeodeticEpsgCrs""> <q1:EpsgCode>26914</q1:EpsgCode> </Crs> </GeographicLocationWGS84> </Well>"; var document = WitsmlParser.Parse(xml); var well = WitsmlParser.Parse <Well>(document.Root); Assert.IsNotNull(well); Assert.AreEqual(wellTitle, well.Citation.Title); }
public void SidewallCore141WitsmlStore_GetFromStore_Can_Transform_SidewallCore() { AddParents(); DevKit.AddAndAssert <SidewallCoreList, SidewallCore>(SidewallCore); // Re-initialize all capServer providers DevKit.Store.CapServerProviders = null; DevKit.Container.BuildUp(DevKit.Store); string typeIn, queryIn; var query = DevKit.List(DevKit.CreateQuery(SidewallCore)); DevKit.SetupParameters <SidewallCoreList, SidewallCore>(query, ObjectTypes.SidewallCore, out typeIn, out queryIn); var options = OptionsIn.Join(OptionsIn.ReturnElements.All, OptionsIn.DataVersion.Version131); var request = new WMLS_GetFromStoreRequest(typeIn, queryIn, options, null); var response = DevKit.Store.WMLS_GetFromStore(request); Assert.IsFalse(string.IsNullOrWhiteSpace(response.XMLout)); Assert.AreEqual((short)ErrorCodes.Success, response.Result); var result = WitsmlParser.Parse(response.XMLout); var version = ObjectTypes.GetVersion(result.Root); Assert.AreEqual(OptionsIn.DataVersion.Version131.Value, version); }
private IEnergisticsCollection ExecuteGetFromStoreQuery(string objectType, string xmlIn, string optionsIn, bool logQuery = true, bool logResponse = true) { IEnergisticsCollection result = null; string suppMsgOut, xmlOut; var originalXmlIn = xmlIn; if (Connection.CompressRequests) { ClientCompression.Compress(ref xmlIn, ref optionsIn); } if (logQuery) { LogQuery(Functions.GetFromStore, objectType, originalXmlIn, optionsIn); } var returnCode = ExecuteQuery(Functions.GetFromStore, objectType, xmlIn, optionsIn, out xmlOut, out suppMsgOut); if (returnCode < 1) { if (logResponse) { LogResponse(Functions.GetFromStore, objectType, xmlIn, optionsIn, null, returnCode, suppMsgOut); } return(null); } try { // Handle servers that compress the response to a compressed request. if (Connection.CompressRequests) { xmlOut = ClientCompression.SafeDecompress(xmlOut); } if (returnCode > 0) { var document = WitsmlParser.Parse(xmlOut); var family = ObjectTypes.GetFamily(document.Root); var listType = ObjectTypes.GetObjectGroupType(objectType, family, DataSchemaVersion); result = WitsmlParser.Parse(listType, document.Root) as IEnergisticsCollection; } } catch (WitsmlException ex) { _log.ErrorFormat("Error parsing query response: {0}{2}{2}{1}", xmlOut, ex, Environment.NewLine); returnCode = (short)ex.ErrorCode; suppMsgOut = ex.Message + " " + ex.GetBaseException().Message; } if (logResponse) { LogResponse(Functions.GetFromStore, objectType, originalXmlIn, optionsIn, xmlOut, returnCode, suppMsgOut); } return(result); }
/// <summary> /// Processes the GetFromStore query result. /// </summary> /// <param name="xmlOut">The XML out.</param> /// <param name="optionsIn">The options in.</param> /// <returns>An XML string.</returns> private string ProcessQueryResult(string xmlOut, string optionsIn) { if (string.IsNullOrWhiteSpace(xmlOut)) { return(xmlOut); } if (string.IsNullOrWhiteSpace(Model.OutputPath)) { return(xmlOut); } var options = OptionsIn.Parse(optionsIn); var returnElements = OptionsIn.GetValue(options, OptionsIn.ReturnElements.Requested); var outputPath = new DirectoryInfo(Path.Combine(Model.OutputPath, returnElements)).FullName; var isAutoSave = xmlOut.Length > Model.TruncateSize; var xmlOutOriginal = xmlOut; if (isAutoSave) { xmlOut = $"<!-- WARNING: Response larger than {Model.TruncateSize} characters -->"; } else if (QueryResults.IsPrettyPrintAllowed && QueryResults.IsPrettyPrintEnabled) { var document = WitsmlParser.Parse(xmlOut); xmlOut = document.ToString(); } if (Model.IsSaveQueryResponse || isAutoSave) { Task.Run(async() => { Runtime.ShowBusy(); try { var document = WitsmlParser.Parse(xmlOutOriginal); outputPath = await SaveQueryResult(outputPath, document, Model.IsSplitResults); if (isAutoSave) { var message = $"{Environment.NewLine}<!-- Results automatically saved to {outputPath} -->"; QueryResults.Append(message); } } catch (Exception ex) { _log.Error("Error saving query results to file", ex); } finally { Runtime.ShowBusy(false); } }); } return(xmlOut); }
/// <summary> /// Creates a new <see cref="WitsmlQueryParser"/> from the specified data object. /// </summary> /// <param name="dataObject">The data object.</param> /// <returns>A new <see cref="WitsmlQueryParser"/> instance.</returns> protected override WitsmlQueryParser CreateQueryParser(TObject dataObject) { var container = CreateCollection(dataObject.AsList()); var document = WitsmlParser.Parse(WitsmlParser.ToXml(container)); var objectType = ObjectTypes.GetObjectType(container); return(new WitsmlQueryParser(document.Root, objectType, null)); }
/// <summary> /// Puts the specified data object into the data store. /// </summary> /// <param name="dataObject">The data object.</param> public virtual void Put(DataObject dataObject) { var context = WitsmlOperationContext.Current; context.Document = WitsmlParser.Parse(context.Request.Xml); var parser = new WitsmlQueryParser(context.Document.Root, context.Request.ObjectType, null); Put(parser); }
/// <summary> /// Gets the cached capServers object as an <see cref="XDocument"/>. /// </summary> /// <returns>The <see cref="XDocument"/> instance.</returns> protected XDocument GetCapServerDocument() { if (_capServerDoc != null) { return(_capServerDoc); } _capServerDoc = WitsmlParser.Parse(ToXml()); return(_capServerDoc); }
/// <summary> /// Parses the nested element to the specified type. /// </summary> /// <param name="type">The type.</param> /// <param name="element">The element.</param> /// <returns>The parsed object.</returns> /// <exception cref="WitsmlException"></exception> protected object ParseNestedElement(Type type, XElement element) { if (element.DescendantsAndSelf().Any(e => (!e.HasAttributes && string.IsNullOrWhiteSpace(e.Value)) || e.Attributes().Any(a => string.IsNullOrWhiteSpace(a.Value)))) { throw new WitsmlException(ErrorCodes.EmptyNewElementsOrAttributes); } var clone = element.UpdateRootElementName(type); return(WitsmlParser.Parse(type, clone)); }
private static TrajectoryStation GetTrajectoryStation(IDataObject dataObjectGet) { if (dataObjectGet.Data == null) { return(null); } var growingPartXml = dataObjectGet.GetString(); var trajectoryStationObject = WitsmlParser.Parse <TrajectoryStation>(WitsmlParser.Parse(growingPartXml).Root); return(trajectoryStationObject); }
/// <summary> /// Updates the growing data object query. /// </summary> /// <param name="xmlOut">The XML out.</param> /// <returns>The updated growing data object query.</returns> public string UpdateDataQuery(string xmlOut) { var queryDoc = WitsmlParser.Parse(QueryIn); var resultDoc = WitsmlParser.Parse(xmlOut); if (ObjectTypes.Log.EqualsIgnoreCase(ObjectType)) { return(UpdateLogDataQuery(queryDoc, resultDoc)); } return(string.Empty); }
/// <summary> /// Updates a data object in the data store. /// </summary> /// <param name="parser">The input template parser.</param> /// <param name="dataObject">The data object to be updated.</param> public override void Update(WitsmlQueryParser parser, Log dataObject) { // Update ChannelSets + data via the ChannelSet data adapter foreach (var childParser in parser.ForkProperties("ChannelSet", ObjectTypes.ChannelSet)) { var channelSet = WitsmlParser.Parse <ChannelSet>(childParser.Root); ChannelSetDataAdapter.Update(childParser, channelSet); } var uri = GetUri(dataObject); UpdateEntity(parser, uri); }
private static EtpUri? GetUriFromXml(XElement element, string version, string objectType) { var type = ObjectTypes.GetObjectGroupType(objectType, version) ?? ObjectTypes.GetObjectType(objectType, version); var entity = WitsmlParser.Parse(type, element?.Document?.Root, false); var collection = entity as IEnergisticsCollection; var uri = collection?.Items .OfType<IDataObject>() .Select(x => x.GetUri()) .FirstOrDefault() ?? (entity as AbstractObject)?.GetUri(); return uri; }
public WMLS_DeleteFromStoreResponse Delete <TList, TObject>(TObject entity, string wmlTypeIn = null, string capClient = null, string optionsIn = null, bool partialDelete = false) where TList : IEnergisticsCollection { string typeIn, xmlIn; SetupParameters <TList, TObject>(List(entity), wmlTypeIn, out typeIn, out xmlIn); if (!partialDelete) { var element = WitsmlParser.Parse(xmlIn); WitsmlParser.RemoveEmptyElements(element.Root); xmlIn = element.ToString(); } return(DeleteFromStore(typeIn, xmlIn, capClient, optionsIn)); }
/// <summary> /// Formats the specified XML. /// </summary> /// <param name="xml">The XML.</param> /// <returns>The formatted XML.</returns> public static string Format(string xml) { if (string.IsNullOrWhiteSpace(xml)) { return(string.Empty); } try { return(WitsmlParser.Parse(xml, false).ToString()); } catch { return(string.Empty); } }
/// <summary> /// Partially delete the log data. /// </summary> /// <param name="uri">The URI.</param> /// <param name="parser">The parser.</param> /// <param name="channels">The current logCurve information.</param> /// <param name="currentRanges">The current channel index ranges.</param> protected override void PartialDeleteLogData(EtpUri uri, WitsmlQueryParser parser, List <LogCurveInfo> channels, Dictionary <string, Range <double?> > currentRanges) { var uidToMnemonics = channels.ToDictionary(c => c.Uid, c => c.Mnemonic.Value); var updatedRanges = new Dictionary <string, Range <double?> >(); WitsmlParser.RemoveEmptyElements(parser.Root); var delete = WitsmlParser.Parse <LogList>(parser.Root, false).Log.FirstOrDefault(); var current = GetEntity(uri); delete.IndexType = current.IndexType; delete.Direction = current.Direction; var indexRange = currentRanges[current.IndexCurve]; if (!indexRange.Start.HasValue || !ToDeleteLogData(delete, parser)) { return; } TimeSpan?offset = null; var indexCurve = current.IndexCurve; var indexChannel = current.LogCurveInfo.FirstOrDefault(l => l.Mnemonic.Value == indexCurve); if (DeleteAllLogData(current, delete, updatedRanges)) { ChannelDataChunkAdapter.Delete(uri); foreach (var curve in current.LogCurveInfo) { updatedRanges.Add(curve.Mnemonic.Value, new Range <double?>(null, null)); } } else { var deletedChannels = GetDeletedChannels(current, uidToMnemonics); var defaultDeleteRange = GetDefaultDeleteRange(current, delete); var isTimeLog = current.IsTimeLog(); var updateRanges = GetDeleteQueryIndexRange(delete, channels, uidToMnemonics, indexCurve, current.IsIncreasing(), isTimeLog); offset = currentRanges[indexCurve].Offset; var ranges = MergePartialDeleteRanges(deletedChannels, defaultDeleteRange, currentRanges, updateRanges, indexCurve, current.IsIncreasing()); ChannelDataChunkAdapter.PartialDeleteLogData(uri, indexCurve, current.IsIncreasing(), isTimeLog, deletedChannels, ranges, updatedRanges); } UpdateIndexRange(uri, current, updatedRanges, updatedRanges.Keys.ToList(), current.IsTimeLog(), indexChannel?.Unit, offset, false, true); }
/// <summary> /// Adds a data object to the data store. /// </summary> /// <param name="parser">The input template parser.</param> /// <param name="dataObject">The data object to be added.</param> public override void Add(WitsmlQueryParser parser, Log dataObject) { // Add ChannelSets + data via the ChannelSet data adapter foreach (var childParser in parser.ForkProperties("ChannelSet", ObjectTypes.ChannelSet)) { var channelSet = WitsmlParser.Parse <ChannelSet>(childParser.Root); ChannelSetDataAdapter.Add(childParser, channelSet); } // Clear ChannelSet data properties foreach (var channelSet in dataObject.ChannelSet) { channelSet.Data = null; } InsertEntity(dataObject); }
private IEnergisticsCollection ExecuteGetFromStoreQuery(string objectType, string xmlIn, string optionsIn, bool logQuery = true, bool logResponse = true) { if (logQuery) { LogQuery(Functions.GetFromStore, objectType, xmlIn, optionsIn); } IEnergisticsCollection result = null; string suppMsgOut, xmlOut; var returnCode = ExecuteQuery(Functions.GetFromStore, objectType, xmlIn, optionsIn, out xmlOut, out suppMsgOut); if (returnCode < 1) { if (logResponse) { LogResponse(Functions.GetFromStore, objectType, xmlIn, optionsIn, null, returnCode, suppMsgOut); } return(null); } try { if (returnCode > 0) { var listType = ObjectTypes.GetObjectGroupType(objectType, DataSchemaVersion); var document = WitsmlParser.Parse(xmlOut); result = WitsmlParser.Parse(listType, document.Root) as IEnergisticsCollection; } } catch (WitsmlException ex) { _log.ErrorFormat("Error parsing query response: {0}{2}{2}{1}", xmlOut, ex, Environment.NewLine); returnCode = (short)ex.ErrorCode; suppMsgOut = ex.Message + " " + ex.GetBaseException().Message; } if (logResponse) { LogResponse(Functions.GetFromStore, objectType, xmlIn, optionsIn, xmlOut, returnCode, suppMsgOut); } return(result); }
/// <summary> /// Validates the required WITSML input template. /// </summary> /// <param name="xml">The XML input template.</param> /// <exception cref="WitsmlException"></exception> public static XDocument ValidateInputTemplate(string xml) { _log.Debug("Validating WITSML input template."); if (string.IsNullOrWhiteSpace(xml)) { throw new WitsmlException(ErrorCodes.MissingInputTemplate); } XDocument doc = WitsmlParser.Parse(xml); if (string.IsNullOrEmpty(GetNamespace(doc))) { throw new WitsmlException(ErrorCodes.MissingDefaultWitsmlNamespace); } return(doc); }
private IEnergisticsCollection ExecuteQuery(string objectType, string xmlIn, string optionsIn) { LogQuery(Functions.GetFromStore, objectType, xmlIn, optionsIn); using (var client = Connection.CreateClientProxy()) { var wmls = (IWitsmlClient)client; string suppMsgOut, xmlOut = string.Empty; IEnergisticsCollection result = null; short returnCode; try { returnCode = wmls.WMLS_GetFromStore(objectType, xmlIn, optionsIn, null, out xmlOut, out suppMsgOut); } catch (Exception ex) { _log.ErrorFormat("Error querying store: {0}", ex); returnCode = -1; suppMsgOut = "Error querying store:" + ex.GetBaseException().Message; } try { if (returnCode > 0) { var listType = ObjectTypes.GetObjectGroupType(objectType, DataSchemaVersion); var document = WitsmlParser.Parse(xmlOut); result = WitsmlParser.Parse(listType, document.Root) as IEnergisticsCollection; } } catch (WitsmlException ex) { _log.ErrorFormat("Error parsing query response: {0}{2}{2}{1}", xmlOut, ex, Environment.NewLine); returnCode = (short)ex.ErrorCode; suppMsgOut = ex.Message + " " + ex.GetBaseException().Message; } LogResponse(Functions.GetFromStore, objectType, xmlIn, optionsIn, xmlOut, returnCode, suppMsgOut); return(result); } }
/// <summary> /// Updates a data object in the data store. /// </summary> /// <param name="parser">The input template parser.</param> /// <param name="dataObject">The data object to be updated.</param> public override void Update(WitsmlQueryParser parser, Log dataObject) { using (var transaction = GetTransaction()) { transaction.SetContext(dataObject.GetUri()); // Update ChannelSets + data via the ChannelSet data adapter foreach (var childParser in parser.ForkProperties("ChannelSet", ObjectTypes.ChannelSet)) { var channelSet = WitsmlParser.Parse <ChannelSet>(childParser.Root); ChannelSetDataAdapter.Update(childParser, channelSet); } var uri = GetUri(dataObject); UpdateEntity(parser, uri); // Commit transaction transaction.Commit(); } }
/// <summary> /// Parses the nested element to the specified type. /// </summary> /// <param name="type">The type.</param> /// <param name="element">The element.</param> /// <returns>The parsed object.</returns> /// <exception cref="WitsmlException"></exception> protected object ParseNestedElement(Type type, XElement element) { if (element.DescendantsAndSelf().Any(e => (!e.HasAttributes && string.IsNullOrWhiteSpace(e.Value)) || e.Attributes().Any(a => string.IsNullOrWhiteSpace(a.Value)))) { throw new WitsmlException(ErrorCodes.EmptyNewElementsOrAttributes); } var clone = element.UpdateRootElementName(type); try { return(WitsmlParser.Parse(type, clone)); } catch { // Try again without the default namespace specified clone = new XElement(clone) { Name = clone.Name.LocalName }; return(WitsmlParser.Parse(type, clone)); } }
/// <summary> /// Puts the growing part for a growing object. /// </summary> /// <param name="etpAdapter">The ETP adapter.</param> /// <param name="uri">The growing obejct's URI.</param> /// <param name="contentType">Type of the content.</param> /// <param name="data">The data.</param> public override void PutGrowingPart(IEtpAdapter etpAdapter, EtpUri uri, string contentType, byte[] data) { var dataObject = etpAdapter.CreateDataObject(); dataObject.Data = data; // Convert byte array to TrajectoryStation var trajectoryStationXml = dataObject.GetString(); var tsDocument = WitsmlParser.Parse(trajectoryStationXml); var trajectoryStation = WitsmlParser.Parse <TrajectoryStation>(tsDocument.Root); // Merge TrajectoryStation into the Trajectory if it is not null if (trajectoryStation != null) { // Get the Trajectory for the uri var entity = GetEntity(uri); entity.TrajectoryStation = trajectoryStation.AsList(); var document = WitsmlParser.Parse(WitsmlParser.ToXml(entity)); var parser = new WitsmlQueryParser(document.Root, ObjectTypes.GetObjectType <Trajectory>(), null); UpdateTrajectoryWithStations(parser, entity, uri, true); } }
protected virtual DataObject GetDataObject(string objectType, string version, object dataObject, bool includeObjectData) { var jObject = dataObject as JObject; if (jObject != null || dataObject is string) { var type = ObjectTypes.GetObjectGroupType(objectType, version) ?? ObjectTypes.GetObjectType(objectType, version); dataObject = jObject?.ToObject(type) ?? WitsmlParser.Parse(type, WitsmlParser.Parse(dataObject.ToString()).Root); } var collection = dataObject as IEnergisticsCollection; var iDataObject = collection?.Items?.OfType <IDataObject>().FirstOrDefault(); var cDataObject = iDataObject as ICommonDataObject; var aDataObject = dataObject as Witsml200.AbstractObject; var uri = iDataObject?.GetUri() ?? aDataObject?.GetUri() ?? new EtpUri(); var name = iDataObject?.Name ?? aDataObject?.Citation?.Title; var lastChanged = cDataObject?.CommonData?.DateTimeLastChange?.ToUnixTimeMicroseconds() ?? aDataObject?.Citation?.LastUpdate?.ToUnixTimeMicroseconds(); var etpDataObject = new DataObject(); // Do not return DataObject.Data if not requested in original subscription StoreStoreProvider.SetDataObject( etpDataObject, includeObjectData ? dataObject : null, uri, name, -1, lastChanged.GetValueOrDefault()); return(etpDataObject); }
private void UpdateInput(bool fromXml = true) { var input = Data.Document.Text; if (string.IsNullOrWhiteSpace(input)) { return; } XDocument doc; try { doc = WitsmlParser.Parse(input); ResetDataEditorBorderColor(); } catch (Exception ex) { _log.Warn("Error parsing data object XML", ex); DataEditorBorderColor = "#FFFF0000"; return; } var root = doc.Root; if (root == null) { return; } var version = root.Attribute("version"); bool match; if (version != null) { var ns = root.GetDefaultNamespace(); if (string.IsNullOrWhiteSpace(version.Value)) { return; } var dataObject = root.Elements().FirstOrDefault(); var nameElement = dataObject?.Element(ns + "name"); if (nameElement == null) { nameElement = new XElement(ns + "name"); dataObject?.AddFirst(nameElement); } match = CheckInputDataXmlMatch(dataObject, version.Value, "uid", nameElement); if (!match) { UpdateInput(dataObject, version.Value, "uid", nameElement, fromXml); } } else { var schemaVersion = OptionsIn.DataVersion.Version200; if (string.IsNullOrWhiteSpace(schemaVersion?.Value)) { return; } var citationRoot = root .Elements() .FirstOrDefault(e => e.Name.LocalName == "Citation"); var nameElement = citationRoot ?.Elements() .FirstOrDefault(e => e.Name.LocalName == "Title"); var ns = citationRoot?.GetDefaultNamespace(); if (ns != null && nameElement == null) { nameElement = new XElement(ns + "Title"); citationRoot.AddFirst(nameElement); } match = CheckInputDataXmlMatch(root, schemaVersion.Value, "uuid", nameElement); if (!match) { UpdateInput(root, schemaVersion.Value, "uuid", nameElement, fromXml); } } if (!fromXml && !match) { Data.SetText(doc.ToString()); } }
/// <summary> /// Partially delete the log data. /// </summary> /// <param name="uri">The URI.</param> /// <param name="parser">The parser.</param> /// <param name="channels">The current logCurve information.</param> /// <param name="currentRanges">The current channel index ranges.</param> protected override void PartialDeleteLogData(EtpUri uri, WitsmlQueryParser parser, List <LogCurveInfo> channels, Dictionary <string, Range <double?> > currentRanges) { var uidToMnemonics = channels.ToDictionary(c => c.Uid, c => c.Mnemonic.Value); var updatedRanges = new Dictionary <string, Range <double?> >(); WitsmlParser.RemoveEmptyElements(parser.Root); var delete = WitsmlParser.Parse <LogList>(parser.Root, false).Log.FirstOrDefault(); var current = GetEntity(uri); delete.IndexType = current.IndexType; delete.Direction = current.Direction; var indexRange = currentRanges[current.IndexCurve]; var headerOnlyDeletion = !indexRange.Start.HasValue || !ToDeleteLogData(delete, parser); // Audit if only the header is being updated if (headerOnlyDeletion) { AuditPartialDeleteHeaderOnly(delete, parser); UpdateGrowingObject(current, null); return; } TimeSpan?offset = null; var indexCurve = current.IndexCurve; var indexChannel = current.LogCurveInfo.FirstOrDefault(l => l.Mnemonic.Value == indexCurve); if (DeleteAllLogData(current, delete, updatedRanges)) { ChannelDataChunkAdapter.Delete(uri); foreach (var curve in current.LogCurveInfo) { updatedRanges.Add(curve.Mnemonic.Value, new Range <double?>(null, null)); } AuditPartialDelete(current, GetMnemonics(uri), indexRange.Start, indexRange.End); } else { var deletedChannels = GetDeletedChannels(current, uidToMnemonics); var defaultDeleteRange = GetDefaultDeleteRange(current, delete); var isTimeLog = current.IsTimeLog(); var updateRanges = GetDeleteQueryIndexRange(delete, channels, uidToMnemonics, indexCurve, current.IsIncreasing(), isTimeLog); offset = currentRanges[indexCurve].Offset; var ranges = MergePartialDeleteRanges(deletedChannels, defaultDeleteRange, currentRanges, updateRanges, indexCurve, current.IsIncreasing()); ChannelDataChunkAdapter.PartialDeleteLogData(uri, indexCurve, current.IsIncreasing(), isTimeLog, deletedChannels, ranges, updatedRanges); var affectedMnemonics = updatedRanges.Keys.Where(x => x != indexCurve).ToArray(); if (defaultDeleteRange.IsClosed()) { AuditPartialDelete(current, affectedMnemonics, defaultDeleteRange.Start, defaultDeleteRange.End); } else { // If full channels were deleted if (deletedChannels.Count > 0) { var minRange = channels.Where(x => deletedChannels.ContainsIgnoreCase(x.Mnemonic.Value)) .Min(x => x.GetIndexRange(current.IsIncreasing(), isTimeLog).Start); var maxRange = channels.Where(x => deletedChannels.ContainsIgnoreCase(x.Mnemonic.Value)) .Max(x => x.GetIndexRange(current.IsIncreasing(), isTimeLog).End); AuditPartialDelete(current, deletedChannels.ToArray(), minRange, maxRange, true); } else { AuditPartialDelete(current, affectedMnemonics, updateRanges.Min(x => x.Value.Start), updateRanges.Max(x => x.Value.End)); } } } var logHeaderUpdate = GetIndexRangeUpdate(uri, current, updatedRanges, updatedRanges.Keys.ToList(), current.IsTimeLog(), indexChannel?.Unit, offset, true); UpdateGrowingObject(current, logHeaderUpdate); }
public WitsmlQueryParser Parser <T>(T entity, string options = null) { var document = WitsmlParser.Parse(EnergisticsConverter.ObjectToXml(entity)); return(new WitsmlQueryParser(document.Root, ObjectTypes.GetObjectType <T>(), options)); }