Exemple #1
0
        /// <summary>
        /// Adds an oBIX XML batch item to the current batch request.
        /// </summary>
        /// <param name="Op">The oBIX Operation type, being one of obix:Read, obix:Write, or obix:Invoke</param>
        /// <param name="uri">The URI of the read, write or Invoke</param>
        /// <param name="ObixParameters">An optional XML parameter to be supplied to an oBIX:Write, or obix:Invoke</param>
        /// <returns>An instance of the newly created ObixXmlBatchItem, or null if an error occured.</returns>
        public ObixXmlBatchItem AddXmlBatchItem(ObixBatchOperation Op, string uri, XElement ObixParameters = null) {
            ObixXmlBatchItem item = new ObixXmlBatchItem(Op, uri, ObixParameters);
            
            if (item == null) {
                return null; 
            }

            try {
                lock (__batchItemListMutex) {
                    XmlBatchItemList.Add(item);
                }
            } catch (Exception) {
                return null;
            }

            return item;
        }
Exemple #2
0
        /// <summary>
        /// Adds an oBIX XML batch item to the current batch request.
        /// </summary>
        /// <param name="Op">The oBIX Operation type, being one of obix:Read, obix:Write, or obix:Invoke</param>
        /// <param name="uri">The URI of the read, write or Invoke</param>
        /// <param name="ObixParameters">An optional XML parameter to be supplied to an oBIX:Write, or obix:Invoke</param>
        /// <returns>An instance of the newly created ObixXmlBatchItem, or null if an error occured.</returns>
        public ObixXmlBatchItem AddXmlBatchItem(ObixBatchOperation Op, string uri, XElement ObixParameters = null)
        {
            ObixXmlBatchItem item = new ObixXmlBatchItem(Op, uri, ObixParameters);

            if (item == null)
            {
                return(null);
            }

            try {
                lock (__batchItemListMutex) {
                    XmlBatchItemList.Add(item);
                }
            } catch (Exception) {
                return(null);
            }

            return(item);
        }
Exemple #3
0
        /// <summary>
        /// Parses an obix:BatchOut contract referenced by <paramref name="BatchOutContract"/> from an oBIX server into the XML batch referenced by <paramref name="BatchObject"/>.
        ///
        /// Results returned from an oBIX server are placed into the XmlBatchResponse property of each item in the XmlBatch container.
        /// </summary>
        /// <param name="BatchOutContract">A reference to an XElement containing the XML obix:BatchOut contract</param>
        /// <param name="BatchObject">A reference to the XmlBatch object containing the request data to bind to.</param>
        /// <returns>kObixClientSuccess if the operation is to succeed without error, another value otherwise.</returns>
        protected ObixResult ParseBatchOutContract(ref XElement BatchOutContract, ref XmlBatch BatchObject)
        {
            IEnumerable <XElement> batchOutElements = null;
            int batchOutCount = 0;

            if (BatchOutContract == null || BatchObject == null)
            {
                return(ObixClient.ErrorStack.Push(GetType(), ObixResult.kObixClientInputError, "ParseBatchOutContract failed: Provided BatchOutContract or BatchObject is null."));
            }

            if (BatchOutContract.ObixIs() != "obix:BatchOut")
            {
                return(ObixClient.ErrorStack.Push(GetType(), ObixResult.kObixServerError, "The response provided from the obix:Batch operation was not an obix:BatchOut contract."));
            }

            batchOutElements = BatchOutContract.Elements();
            if (batchOutElements == null)
            {
                return(ObixClient.ErrorStack.Push(GetType(), ObixResult.kObixClientXMLParseError, "batchOutElements is null."));
            }

            batchOutCount = batchOutElements.Count();
            if (batchOutCount != BatchObject.BatchItemCount)
            {
                return(ObixClient.ErrorStack.Push(GetType(), ObixResult.kObixClientXMLParseError, "The number of response objects in the obix:BatchOut contract does not match " +
                                                  "the number of items in the obix:BatchIn contract.  Something on the server side is really broken."));
            }

            for (int i = 0; i < batchOutCount; i++)
            {
                XElement         batchOutNode = batchOutElements.ElementAt(i);
                ObixXmlBatchItem batchItem    = BatchObject.GetXmlBatchItem(i);

                if (batchOutNode == null || batchItem == null)
                {
                    return(ObixClient.ErrorStack.Push(GetType(), ObixResult.kObixClientXMLElementNotFoundError, "Could not bind the obix:BatchOut node to the batch item, one of the nodes is null."));
                }

                batchItem.XmlBatchResponse = batchOutNode;
            }

            return(ObixResult.kObixClientSuccess);
        }