Пример #1
0
 /// <summary>
 /// write record
 /// </summary>
 /// <param name="record"></param>
 /// <exception cref="ArgumentNullException">record is null</exception>
 public void Write(Data.IRecord record)
 {
     if (record == null)
     {
         throw new ArgumentNullException("record");
     }
     record.Write(this);
 }
Пример #2
0
        /// <summary>
        /// execute async
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="xid"></param>
        /// <param name="code"></param>
        /// <param name="record"></param>
        /// <param name="callback"></param>
        /// <param name="asyncState"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">callback is null.</exception>
        private Task <T> ExecuteAsync <T>(int xid, Data.OpCode code, Data.IRecord record,
                                          Action <TaskCompletionSource <T>, ZookResponse> callback, object asyncState = null)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            var source = new TaskCompletionSource <T>(asyncState);

            this.Send(new Request <ZookResponse>(xid, code.ToString(), Utils.Marshaller.Serialize(xid, code, record, true),
                                                 ex => source.TrySetException(ex),
                                                 response =>
            {
                if (response.ZXID > 0)
                {
                    this._lastZxid = response.ZXID;
                }
                callback(source, response);
            }));

            return(source.Task);
        }