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); }
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> /// Transforms the supplied data object to the specified version. /// </summary> /// <param name="collection">The data object collection.</param> /// <param name="dataVersion">The data schema version.</param> /// <returns>The transformed data object, if successful; otherwise, the original data object.</returns> public static IEnergisticsCollection Transform(IEnergisticsCollection collection, string dataVersion) { var objectType = ObjectTypes.GetObjectType(collection); var listType = ObjectTypes.GetObjectGroupType(objectType, dataVersion); var converter = _upgradeMethod.MakeGenericMethod(collection.GetType(), listType); try { collection = (IEnergisticsCollection)converter.Invoke(null, new object[] { collection }); collection.SetVersion(dataVersion); } catch (Exception ex) { _log.Warn($"Unable to convert to data schema version: {dataVersion}", ex); } return(collection); }
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> /// Converts a data object collection to XML and optionally converts to a requested version. /// </summary> /// <param name="request">The GetFromStore request.</param> /// <param name="collection">The data object collection.</param> /// <returns></returns> private string GetXmlOut(WMLS_GetFromStoreRequest request, IEnergisticsCollection collection) { if (collection == null) { return(string.Empty); } EnsureCapServerProviders(); var optionsIn = WitsmlOperationContext.Current.OptionsIn; string requestedVersion; // Attempt transformation if client requested a different version if (optionsIn.TryGetValue(OptionsIn.DataVersion.Keyword, out requestedVersion) && _capServerMap.ContainsKey(requestedVersion) && collection.GetVersion() != requestedVersion) { _log.Debug($"Transforming XMLOut to data schema version {requestedVersion}"); collection = WitsmlParser.Transform(collection, requestedVersion); } return(WitsmlParser.ToXml(collection)); }
/// <summary> /// Gets the type of the object. /// </summary> /// <param name="pluralObject">The plural object.</param> /// <returns>The WITSML data object type, as a string.</returns> public static string GetObjectType(IEnergisticsCollection pluralObject) { return(GetObjectType(pluralObject.GetType())); }