/// <summary>
        /// Load the parameters which identify the request
        /// </summary>
        /// <param name="mq"></param>
        /// <param name="xpath"></param>
        /// <param name="request"></param>
        private void getRequestIdentifiers(MdoQuery mq, ref string xpath, ref string request)
        {
            // generate the rpc string sent to VistA
            request = mq.buildMessage();
            request = StringUtils.stripInvalidXmlCharacters(request);
            request = StringUtils.stripNonPrintableChars(request);

            // build the xPath of the query node in the mockconnection file keyed
            // from rpcname, num rpc params, and each rpc param value
            string additionalArgs = "";
            int id = 1;
            foreach (VistaQuery.Parameter param in mq.Parameters)
            {
                string value = getParamValue(param);
                additionalArgs += String.Format(" and @p{0}='{1}'", id++, value);
            }

            xpath = String.Format("//{0}[@{1}='{2}' and count(@*)={3} {4}]", QUERY_NODE, RPC_ATTR, mq.RpcName, mq.Parameters.Count + 1, additionalArgs);
        }
        public void query2(MdoQuery mq)
        {
            string request = "";
            string xpath = "";
            getRequestIdentifiers(mq, ref xpath, ref request);

            XmlDocument doc = new XmlDocument();
            doc.Load( Path.Combine(XmlResourcePath, "MockConnection" + siteId + ".xml"));

            XmlNodeList list = doc.SelectNodes("//query");
            foreach (XmlNode node in list)
            {
                string value = node.SelectSingleNode("value").InnerText;
                XmlNode responseNode = node.SelectSingleNode("response");

                if (value.Equals(request))
                {
                    String response = responseNode.InnerText;
                    if (null != responseNode.Attributes["type"])
                    {
                        response = FileIOUtils.readFromFile(Path.Combine(DataResourcePath, response));
                    }

                    addRequest(mq, response, false);
                    return;
                }
            }
        }
        /// <summary>
        /// Adds the request/response to the document or saves the response to an external file
        /// </summary>
        /// <param name="request">request to save</param>
        /// <param name="response">the response for the request</param>
        public void addRequest(MdoQuery mq, string response, bool update)
        {
            string request = "";
            string xPathQueryBase = "";

            getRequestIdentifiers(mq, ref xPathQueryBase, ref request);

            XmlNode query = selectRpc(xPathQueryBase);
            if (null == query)
            {
                addQuery(mq.RpcName, mq.Parameters, request, response);
            }
            else if (update)
            {
                updateQuery(query, request, response);
            }
        }
        /// <summary>
        /// Performs the mock query, retrieving the result from the preloaded XML document
        /// but throws an exception if the document does not contain the call
        /// </summary>
        /// <param name="request">the request to look up</param>
        /// <returns>a valid response string</returns>
        public string query(MdoQuery mq)
        {
            string request = "";
            string xPathQueryBase = "";

            getRequestIdentifiers(mq, ref xPathQueryBase, ref request);

            XmlNode query = selectRpc(xPathQueryBase);

            if (null != query)
            {
                verifyStoredRequest(query, request);

                return getResponse(query);
            }
            else
            {
                throw new ArgumentException("No such call in " + MockConnectionFileName + ":\n@ xpath: " + xPathQueryBase);
            }
        }
Beispiel #5
0
        public override object query(MdoQuery mq, AbstractPermission permission = null)
        {
            string request = mq.buildMessage();

            string response = (string)base.query(mq, permission);

            if (displayRPCList)
            {
                Console.WriteLine(request);
            }

            if (saveAuthConnect || (Account.IsAuthorized && !isCreateContextRequest(request) && !isDisconnectRequest(request)))
            {
                requests.Add(request);
                responses.Add(response);

                if (saveResults)
                {
                    xmlSource.addRequest(mq, response, UpdateResults);
                }
            }

            return response;
        }