public void Stateless() { bool disposed = false; Task <Metadata> responseHeaders = Task.FromResult(new Metadata()); Metadata trailers = new Metadata(); var state = new AsyncCallState(responseHeaders, () => new Status(StatusCode.DataLoss, "oops"), () => trailers, () => disposed = true); Assert.AreSame(responseHeaders, state.ResponseHeadersAsync()); var status = state.GetStatus(); Assert.AreEqual(StatusCode.DataLoss, status.StatusCode); Assert.AreEqual("oops", status.Detail); Assert.AreSame(trailers, state.GetTrailers()); Assert.False(disposed); state.Dispose(); Assert.True(disposed); }
public void WithState() { var callbackState = new State(); var state = new AsyncCallState( obj => ((State)obj).responseHeaders, obj => ((State)obj).status, obj => ((State)obj).trailers, obj => ((State)obj).Dispose(), callbackState); Assert.AreSame(callbackState.responseHeaders, state.ResponseHeadersAsync()); var status = state.GetStatus(); Assert.AreEqual(StatusCode.DataLoss, status.StatusCode); Assert.AreEqual("oops", status.Detail); Assert.AreSame(callbackState.trailers, state.GetTrailers()); Assert.False(callbackState.disposed); state.Dispose(); Assert.True(callbackState.disposed); }
/// <summary> /// Adds comment to an object /// </summary> /// <param name="objectID">ID of the object which should be commented</param> /// <param name="objectType">Object type</param> /// <param name="getCommentsCompleted">Callback method which will be invoked after operation completes</param> /// <param name="userState">A user-defined object containing state information. /// This object is passed to the <paramref name="getCommentsCompleted"/> delegate as a part of response when the operation is completed</param> /// <exception cref="ArgumentException">Thrown if <paramref name="getCommentsCompleted"/> is <c>null</c></exception> public void GetComments(long objectID, ObjectType objectType, OperationFinished<GetCommentsResponse> getCommentsCompleted, object userState) { ThrowIfParameterIsNull(getCommentsCompleted, "getCommentsCompleted"); AsyncCallState<OperationFinished<GetCommentsResponse>> state = new AsyncCallState <OperationFinished<GetCommentsResponse>> { CallbackDelegate = getCommentsCompleted, UserState = userState }; _service.get_commentsCompleted += GetCommentsFinished; _service.get_commentsAsync(_apiKey, _token, objectID, ObjectType2String(objectType), state); }
/// <summary> /// Retrieves the details for a specified file by its ID /// </summary> /// <param name="fileID">File ID</param> /// <param name="getFileInfoCompleted">Callback method which will be invoked after operation completes</param> /// <param name="userState">A user-defined object containing state information. /// This object is passed to the <paramref name="getFileInfoCompleted"/> delegate as a part of response when the operation is completed</param> /// <exception cref="ArgumentException">Thrown if <paramref name="getFileInfoCompleted"/> is <c>null</c></exception> public void GetFileInfo(long fileID, OperationFinished<GetFileInfoResponse> getFileInfoCompleted, object userState) { ThrowIfParameterIsNull(getFileInfoCompleted, "getFileInfoCompleted"); _service.get_file_infoCompleted += GetFileInfoFinished; AsyncCallState<OperationFinished<GetFileInfoResponse>> state = new AsyncCallState <OperationFinished<GetFileInfoResponse>> { CallbackDelegate = getFileInfoCompleted, UserState = userState }; _service.get_file_infoAsync(_apiKey, _token, fileID, state); }
/// <summary> /// Asynchronously adds user comment to an item /// </summary> /// <param name="objectID">ID of the object to comment</param> /// <param name="objectType">Type of the object</param> /// <param name="commentText">The comment's message to be added</param> /// <param name="addCommentCompleted">Callback method which will be invoked after operation completes</param> /// <param name="userState">A user-defined object containing state information. /// This object is passed to the <paramref name="addCommentCompleted"/> delegate as a part of response when the operation is completed</param> /// <exception cref="ArgumentException">Thrown if <paramref name="addCommentCompleted"/> is <c>null</c></exception> public void AddComment( long objectID, ObjectType objectType, string commentText, OperationFinished<AddCommentResponse> addCommentCompleted, object userState) { ThrowIfParameterIsNull(addCommentCompleted, "addCommentCompleted"); AsyncCallState<OperationFinished<AddCommentResponse>> state = new AsyncCallState <OperationFinished<AddCommentResponse>> { CallbackDelegate = addCommentCompleted, UserState = userState }; _service.add_commentCompleted += AddCommentFinished; _service.add_commentAsync(_apiKey, _token, objectID, ObjectType2String(objectType), commentText, state); }