Beispiel #1
0
        /// <summary>
        /// Validates the WITSML Store API request.
        /// </summary>
        /// <param name="providers">The capServer providers.</param>
        /// <exception cref="WitsmlException"></exception>
        public static void ValidateRequest(IEnumerable <ICapServerProvider> providers)
        {
            var context = WitsmlOperationContext.Current;

            _log.DebugFormat("Validating WITSML request for {0}", context.Request.ObjectType);

            ValidateUserAgent(WebOperationContext.Current);

            context.OptionsIn = OptionsIn.Parse(context.Request.Options);

            // Document version is derived from the input string so it needs to be decompressed before the below checks.
            context.RequestCompressed = ValidateCompressedInput(context.Request.Function, context.Request.Xml, context.OptionsIn);

            var xml = context.RequestCompressed ? CompressionUtil.DecompressRequest(context.Request.Xml) : context.Request.Xml;

            context.Document = ValidateInputTemplate(xml);

            var dataSchemaVersion = ObjectTypes.GetVersion(context.Document.Root);

            ValidateDataSchemaVersion(dataSchemaVersion);

            var capServerProvider = providers.FirstOrDefault(x => x.DataSchemaVersion == dataSchemaVersion);

            if (capServerProvider == null)
            {
                throw new WitsmlException(ErrorCodes.DataObjectNotSupported,
                                          "WITSML object type not supported: " + context.Request.ObjectType + "; Version: " + dataSchemaVersion);
            }

            capServerProvider.ValidateRequest();
            context.DataSchemaVersion = dataSchemaVersion;
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <summary>
        /// Performs validation for the specified function and supplied parameters.
        /// </summary>
        public override void ValidateRequest()
        {
            var context  = WitsmlOperationContext.Current;
            var request  = context.Request;
            var document = context.Document;

            Logger.DebugFormat("Validating WITSML request for {0}; Function: {1}", request.ObjectType, request.Function);

            base.ValidateRequest();

            var optionsIn = OptionsIn.Parse(request.Options);

            if (request.Function == Functions.GetFromStore)
            {
                ValidateKeywords(optionsIn,
                                 OptionsIn.ReturnElements.Keyword,
                                 OptionsIn.MaxReturnNodes.Keyword,
                                 OptionsIn.RequestLatestValues.Keyword,
                                 OptionsIn.RequestPrivateGroupOnly.Keyword,
                                 OptionsIn.RequestObjectSelectionCapability.Keyword,
                                 OptionsIn.CompressionMethod.Keyword,
                                 OptionsIn.DataVersion.Keyword,
                                 OptionsIn.IntervalRangeInclusion.Keyword);
                ValidateRequestMaxReturnNodes(optionsIn);
                ValidateRequestRequestLatestValue(optionsIn);
                ValidateRequestObjectSelectionCapability(optionsIn, request.ObjectType, document);
                ValidateEmptyRootElement(request.ObjectType, document);
                ValidateReturnElements(optionsIn, request.ObjectType);
                ValidateIntervalRangeInclusion(optionsIn, request.ObjectType);
                ValidateSelectionCriteria(document);
            }
            else if (request.Function == Functions.AddToStore)
            {
                ValidateKeywords(optionsIn, OptionsIn.CompressionMethod.Keyword, OptionsIn.DataVersion.Keyword);
                ValidateCompressionMethod(optionsIn, GetCapServer().CapServer.CompressionMethod);
                ValidateEmptyRootElement(request.ObjectType, document);
                ValidateSingleChildElement(request.ObjectType, document);
            }
            else if (request.Function == Functions.UpdateInStore)
            {
                ValidateKeywords(optionsIn, OptionsIn.CompressionMethod.Keyword, OptionsIn.DataVersion.Keyword);
                ValidateCompressionMethod(optionsIn, GetCapServer().CapServer.CompressionMethod);
                ValidateEmptyRootElement(request.ObjectType, document);
                ValidateSingleChildElement(request.ObjectType, document);
            }
            else if (request.Function == Functions.DeleteFromStore)
            {
                ValidateKeywords(optionsIn, OptionsIn.CascadedDelete.Keyword, OptionsIn.DataVersion.Keyword);
                ValidateCascadedDelete(optionsIn, GetCapServer().CapServer.CascadedDelete.GetValueOrDefault());
                ValidateEmptyRootElement(request.ObjectType, document);
                ValidateSingleChildElement(request.ObjectType, document);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Submits an asynchronous query to the WITSML server for a given function type.
        /// The results of a query are displayed in the Results and Messages tabs.
        /// </summary>
        /// <param name="functionType">Type of the function.</param>
        /// <param name="optionsIn">The options in.</param>
        /// <param name="isPartialQuery">if set to <c>true</c> [is partial query].</param>
        public void SubmitQuery(Functions functionType, string optionsIn = null, bool isPartialQuery = false)
        {
            // Trim query text before submitting request
            string xmlIn = XmlQuery.Text.Trim();

            // Format the text of XmlQuery
            XmlQuery.SetText(xmlIn);

            _log.DebugFormat("Query submitted for function '{0}'", functionType);

            // Options In
            if (string.IsNullOrEmpty(optionsIn))
            {
                optionsIn = GetOptionsIn(functionType, isPartialQuery);
            }
            else if (isPartialQuery)
            {
                var optionsInUpdated = new List <OptionsIn> {
                    OptionsIn.ReturnElements.DataOnly
                };
                var optionsInFromPreviousQuery = OptionsIn.Parse(optionsIn);
                foreach (var key in optionsInFromPreviousQuery.Keys)
                {
                    if (key != OptionsIn.ReturnElements.All.Key && key != OptionsIn.ReturnElements.DataOnly.Key)
                    {
                        optionsInUpdated.Add(new OptionsIn(key, optionsInFromPreviousQuery[key]));
                    }
                }
                optionsIn = OptionsIn.Join(optionsInUpdated.ToArray());
            }

            // Output Request
            OutputRequestMessages(functionType, functionType == Functions.GetCap ? string.Empty : xmlIn, optionsIn);

            Runtime.ShowBusy();

            Task.Run(async() =>
            {
                // Call internal SubmitQuery method with references to all inputs and outputs.
                var result = await SubmitQuery(functionType, xmlIn, optionsIn);

                // Clear any previous query results if this is not a partial query
                if (!isPartialQuery)
                {
                    ClearQueryResults();
                }

                ShowSubmitResult(functionType, result, isPartialQuery);
                Runtime.ShowBusy(false);
            });
        }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WitsmlQueryParser" /> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="objectType">The object type.</param>
        /// <param name="options">The options.</param>
        public WitsmlQueryParser(XElement element, string objectType, string options)
        {
            Root       = element;
            ObjectType = objectType;
            Options    = OptionsIn.Parse(options);

            _options   = options;
            _namespace = element.GetDefaultNamespace();

            _element  = element;
            _elements = element.Attributes("version").Any()
                ? element.Elements(_namespace + objectType)
                : new[] { element };

            QueryCount = _elements.Count();
        }
Beispiel #6
0
        /// <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 = OptionsIn.Parse(request.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 selected item's details using a GetFromStore request.
 /// </summary>
 public void GetObjectDetailsWithExtraOptionsIn()
 {
     if (CanGetObjectHeader && !string.IsNullOrWhiteSpace(ExtraOptionsIn))
     {
         var optionsIn = new List <OptionsIn> {
             OptionsIn.ReturnElements.All
         };
         var extraOptions = OptionsIn.Parse(ExtraOptionsIn);
         foreach (var extraOptionsKey in extraOptions.Keys)
         {
             try
             {
                 optionsIn.Add(new OptionsIn(extraOptionsKey, extraOptions[extraOptionsKey]));
             }
             catch
             {
                 //ignore if invalid optionsIn pair
             }
         }
         GetObjectDetails(optionsIn.ToArray());
     }
 }
Beispiel #8
0
        /// <summary>
        /// Returns the capServer object that describes the capabilities of the server for one Data Schema Version.
        /// </summary>
        /// <param name="request">The request object encapsulating the method input parameters.</param>
        /// <returns>A positive value indicates a success; a negative value indicates an error.</returns>
        public WMLS_GetCapResponse WMLS_GetCap(WMLS_GetCapRequest request)
        {
            try
            {
                WitsmlOperationContext.Current.Request = request.ToContext();
                EnsureCapServerProviders();

                _log.Debug(WebOperationContext.Current.ToLogMessage());
                _log.Debug(request.ToLogMessage());

                UserAuthorizationProvider.CheckSoapAccess();

                var options = OptionsIn.Parse(request.OptionsIn);
                var version = OptionsIn.GetValue(options, new OptionsIn.DataVersion(_defaultDataSchemaVersion));

                // return error if WITSML 1.3.1 not supported AND dataVersion not specified (required in WITSML 1.4.1)
                if (!_capServerMap.ContainsKey(OptionsIn.DataVersion.Version131.Value) && !options.ContainsKey(OptionsIn.DataVersion.Keyword))
                {
                    throw new WitsmlException(ErrorCodes.MissingDataVersion);
                }

                if (_capServerMap.ContainsKey(version))
                {
                    var response = new WMLS_GetCapResponse((short)ErrorCodes.Success, _capServerMap[version].ToXml(), string.Empty);
                    _log.Debug(response.ToLogMessage());
                    return(response);
                }

                throw new WitsmlException(ErrorCodes.DataVersionNotSupported, "Data schema version not supported: " + version);
            }
            catch (WitsmlException ex)
            {
                var response = new WMLS_GetCapResponse((short)ex.ErrorCode, string.Empty, ex.Message);
                _log.Error(response.ToLogMessage(_log.IsWarnEnabled));
                return(response);
            }
        }