/////////////////////////////////////////////////////////////////////// public static ReturnCode UploadValuesAsync( Interpreter interpreter, IClientData clientData, StringList arguments, CallbackFlags callbackFlags, Uri uri, string method, NameValueCollection collection, ref Result error ) { TraceOps.DebugTrace(String.Format( "UploadValuesAsync: interpreter = {0}, clientData = {1}, " + "arguments = {2}, callbackFlags = {3}, uri = {4}, " + "method = {5}, collection = {6}", FormatOps.InterpreterNoThrow(interpreter), FormatOps.WrapOrNull(clientData), FormatOps.WrapOrNull(true, true, arguments), FormatOps.WrapOrNull(callbackFlags), FormatOps.WrapOrNull(uri), FormatOps.WrapOrNull(method), FormatOps.NameValueCollection(collection, true)), typeof(WebOps).Name, TracePriority.NetworkDebug); ReturnCode code = ReturnCode.Ok; WebClient webClient = null; try { ICallback callback = CommandCallback.Create( MarshalFlags.Default, callbackFlags, ObjectFlags.Callback, ByRefArgumentFlags.None, interpreter, null, null, arguments, ref error); if (callback != null) { try { Result localError = null; webClient = CreateClient( interpreter, "UploadValuesAsync", clientData, ref localError); if (webClient != null) { callback.ClientData = new ClientData( new AnyTriplet <WebClient, Uri, IAnyPair <string, NameValueCollection> >( webClient, uri, new AnyPair <string, NameValueCollection>(method, collection))); webClient.UploadValuesCompleted += new UploadValuesCompletedEventHandler( UploadValuesAsyncCompleted); /* NO RESULT */ webClient.UploadValuesAsync( uri, method, collection, callback); } else if (localError != null) { error = localError; code = ReturnCode.Error; } else { error = "could not create web client"; code = ReturnCode.Error; } } catch (Exception e) { error = e; code = ReturnCode.Error; } } else { code = ReturnCode.Error; } } finally { if ((code != ReturnCode.Ok) && (webClient != null)) { ReturnCode disposeCode; Result disposeError = null; disposeCode = ObjectOps.TryDispose( webClient, ref disposeError); if (disposeCode != ReturnCode.Ok) { DebugOps.Complain( interpreter, disposeCode, disposeError); } } } return(code); }
/////////////////////////////////////////////////////////////////////// #region Upload Values Methods public static ReturnCode UploadValues( Interpreter interpreter, IClientData clientData, Uri uri, string method, NameValueCollection collection, bool trusted, ref byte[] bytes, ref Result error ) { bool wasTrusted = UpdateOps.IsTrusted(); TraceOps.DebugTrace(String.Format( "UploadValues: interpreter = {0}, clientData = {1}, " + "uri = {2}, method = {3}, collection = {4}, trusted = {5}, " + "wasTrusted = {6}", FormatOps.InterpreterNoThrow(interpreter), FormatOps.WrapOrNull(clientData), FormatOps.WrapOrNull(uri), FormatOps.WrapOrNull(method), FormatOps.NameValueCollection(collection, true), trusted, wasTrusted), typeof(WebOps).Name, TracePriority.NetworkDebug); ReturnCode code = trusted ? wasTrusted ? ReturnCode.Ok : UpdateOps.SetTrusted(trusted, ref error) : ReturnCode.Ok; if (code == ReturnCode.Ok) { try { try { Result localError = null; using (WebClient webClient = CreateClient( interpreter, "UploadValues", clientData, ref localError)) { if (webClient != null) { bytes = webClient.UploadValues( uri, method, collection); return(ReturnCode.Ok); } else if (localError != null) { error = localError; } else { error = "could not create web client"; } } } catch (Exception e) { error = e; } } finally { if (trusted && !wasTrusted) { ReturnCode untrustCode; Result untrustError = null; untrustCode = UpdateOps.SetTrusted( false, ref untrustError); if (untrustCode != ReturnCode.Ok) { DebugOps.Complain( interpreter, untrustCode, untrustError); } } } } return(ReturnCode.Error); }