Exemple #1
0
        /// <summary>
        /// Create a new instance of the <see cref="Op"/> class that represents a GetData operation.
        /// </summary>
        /// <param name="path">Path of the node whose data must be retrieved</param>
        /// <param name="options">Options that specify how the data must be retrieved</param>
        /// <param name="optionsArgument">Argument for options</param>
        /// <param name="checkUsedForThisPath">Check operation that was used for this path</param>
        /// <returns>A GetData operation</returns>
        public static Op GetData(string path, RequestGetData.GetDataOptions options, RequestGetData.IGetDataOptionArgument optionsArgument, Op checkUsedForThisPath)
        {
            if (checkUsedForThisPath != null)
            {
                if (checkUsedForThisPath.OpType != OpCode.Check || !string.Equals(checkUsedForThisPath.Path, path))
                {
                    throw new ArgumentException("checkUsedForThisPath must be either null or a OpCheck for the same path");
                }
            }

            return(new Op(OpCode.GetData, new RequestGetData(path, options, optionsArgument, watcher: null)));
        }
Exemple #2
0
        /// <summary>
        /// Gets the data associated with the node at the given path.
        /// </summary>
        /// <param name="ringMaster">Interface to ringmaster</param>
        /// <param name="path">Node path</param>
        /// <param name="options">Options for this request</param>
        /// <param name="optionArgument">Argument for options</param>
        /// <param name="watcher">Watcher interface that receives notifications for changes to this path or null</param>
        /// <returns>Task that will resolve on success to the data associated with the node</returns>
        public static async Task <byte[]> GetData(
            this IRingMasterRequestHandler ringMaster,
            string path,
            RequestGetData.GetDataOptions options,
            RequestGetData.IGetDataOptionArgument optionArgument,
            IWatcher watcher)
        {
            RequestResponse response = await ringMaster.Request(
                new RequestGetData(
                    path,
                    options,
                    optionArgument,
                    watcher : watcher));

            ThrowIfError(response);
            return((byte[])response.Content);
        }
Exemple #3
0
        /// <summary>
        /// Serialize <see cref="RequestGetData.IGetDataOptionArgument"/>.
        /// </summary>
        /// <param name="optionArgument"><see cref="RequestGetData.IGetDataOptionArgument"/> to serialize</param>
        private void SerializeGetDataOptionArgument(RequestGetData.IGetDataOptionArgument optionArgument)
        {
            bool isNull = optionArgument == null;

            this.binaryWriter.Write((bool)isNull);

            if (!isNull)
            {
                this.binaryWriter.Write((byte)optionArgument.Option);
                if (optionArgument.Option == RequestGetData.GetDataOptions.FaultbackOnParentDataWithMatch)
                {
                    var m = (RequestGetData.GetDataOptionArgumentForMatch)optionArgument;
                    this.binaryWriter.Write((byte)m.Condition);
                    this.binaryWriter.Write((int)m.Position);
                    this.SerializeData((byte[])m.Bytes);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Deserialize <see cref="RequestGetData"/>
        /// </summary>
        /// <param name="uid"><c>uid</c> associated with the request</param>
        /// <param name="path">Path associated with the request</param>
        /// <returns>The deserialized request</returns>
        private RequestGetData DeserializeRequestGetData(ulong uid, string path)
        {
            IWatcher watcher = this.DeserializeWatcher();

            RequestGetData.GetDataOptions options = RequestGetData.GetDataOptions.None;

            byte readByte = this.binaryReader.ReadByte();

            options = (RequestGetData.GetDataOptions)readByte;

            RequestGetData.IGetDataOptionArgument optionArgument = null;
            if (this.serializationVersionUsed >= SerializationFormatVersions.Version14)
            {
                optionArgument = this.DeserializeGetDataOptionArgument();
            }

            if (options == RequestGetData.GetDataOptions.FaultbackOnParentData)
            {
                // If the option was Faultback on parent data, we will use an argumentformatch to simulate it.
                optionArgument = new RequestGetData.GetDataOptionArgumentForMatch(null, 0, RequestGetData.GetDataOptionArgumentForMatch.Comparison.Different);
            }

            return(new RequestGetData(path, options, optionArgument, watcher, uid));
        }