diff options
author | Jose <jose@zeroc.com> | 2016-07-07 11:49:14 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2016-07-07 11:49:14 +0200 |
commit | b3a329dc11fed649d2871ec30cc831ac1122f045 (patch) | |
tree | 6b2db98e1d2d0c07591a4c4b5e354b30e9b6113d /csharp/src | |
parent | Fixed bug where marshalling of optional object dictionaries as parameters wou... (diff) | |
download | ice-b3a329dc11fed649d2871ec30cc831ac1122f045.tar.bz2 ice-b3a329dc11fed649d2871ec30cc831ac1122f045.tar.xz ice-b3a329dc11fed649d2871ec30cc831ac1122f045.zip |
Update C# mapping with async/await
Diffstat (limited to 'csharp/src')
23 files changed, 2434 insertions, 1958 deletions
diff --git a/csharp/src/Glacier2/msbuild/glacier2.csproj b/csharp/src/Glacier2/msbuild/glacier2.csproj index 08baa671e0a..6c7ddcc62c3 100644 --- a/csharp/src/Glacier2/msbuild/glacier2.csproj +++ b/csharp/src/Glacier2/msbuild/glacier2.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\Assemblies\Glacier2.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{D765A8A0-01C2-4EEE-B6C0-5DD6F9C1087A}</ProjectGuid> @@ -79,6 +83,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file diff --git a/csharp/src/Ice/AsyncResult.cs b/csharp/src/Ice/AsyncResult.cs index 5fad90abb05..95729efe018 100644 --- a/csharp/src/Ice/AsyncResult.cs +++ b/csharp/src/Ice/AsyncResult.cs @@ -26,8 +26,8 @@ namespace Ice /// /// <summary> - /// Callback for the successful completion of an operation - /// that returns no data. + /// Callback to inform when a call has been passed to the local + /// transport. /// </summary> /// public delegate void SentCallback(bool sentSynchronously); @@ -54,6 +54,7 @@ namespace Ice ObjectPrx getProxy(); bool isCompleted_(); + void waitForCompleted(); bool isSent(); @@ -67,7 +68,6 @@ namespace Ice AsyncResult whenSent(Ice.AsyncCallback cb); AsyncResult whenSent(Ice.SentCallback cb); - AsyncResult whenCompleted(Ice.ExceptionCallback excb); } @@ -82,18 +82,15 @@ namespace Ice namespace IceInternal { - using System.Collections.Generic; using System.Diagnostics; using System.Threading; - public delegate void ProxyTwowayCallback<T>(Ice.AsyncResult result, T cb, Ice.ExceptionCallback excb); - public delegate void ProxyOnewayCallback<T>(T cb); - - public class AsyncResultI : Ice.AsyncResult + abstract public class AsyncResultI : Ice.AsyncResult { public virtual void cancel() { - cancel(new Ice.InvocationCanceledException()); + Debug.Assert(outgoing_ != null); + outgoing_.cancel(); } public Ice.Communicator getCommunicator() @@ -125,7 +122,7 @@ namespace IceInternal { while((state_ & StateDone) == 0) { - System.Threading.Monitor.Wait(this); + Monitor.Wait(this); } } } @@ -142,9 +139,9 @@ namespace IceInternal { lock(this) { - while((state_ & StateSent) == 0 && _exception == null) + while((state_ & StateSent) == 0 && exception_ == null) { - System.Threading.Monitor.Wait(this); + Monitor.Wait(this); } } } @@ -153,22 +150,22 @@ namespace IceInternal { lock(this) { - if(_exception != null) + if(exception_ != null) { - throw _exception; + throw exception_; } } } public bool sentSynchronously() { - return sentSynchronously_; // No lock needed + Debug.Assert(outgoing_ != null); + return outgoing_.sentSynchronously(); // No lock needed } // // Implementation of System.IAsyncResult properties // - public bool IsCompleted { get @@ -181,11 +178,12 @@ namespace IceInternal { get { + Debug.Assert(outgoing_ != null); if(getProxy() != null && getProxy().ice_isTwoway()) { return false; } - return sentSynchronously_; + return outgoing_.sentSynchronously(); } } @@ -203,19 +201,27 @@ namespace IceInternal { lock(this) { - if(_waitHandle == null) + if(waitHandle_ == null) { - _waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset); + waitHandle_ = new EventWaitHandle(false, EventResetMode.ManualReset); } if((state_ & StateDone) != 0) { - _waitHandle.Set(); + waitHandle_.Set(); } - return _waitHandle; + return waitHandle_; } } } + public OutgoingAsyncBase OutgoingAsync + { + get + { + return outgoing_; + } + } + public Ice.AsyncResult whenSent(Ice.AsyncCallback cb) { lock(this) @@ -224,22 +230,22 @@ namespace IceInternal { throw new System.ArgumentException("callback is null"); } - if(_sentCallback != null) + if(sentCallback_ != null) { throw new System.ArgumentException("sent callback already set"); } - _sentCallback = cb; + sentCallback_ = cb; if((state_ & StateSent) == 0) { return this; } } - if(sentSynchronously_) + if(outgoing_.sentSynchronously()) { try { - _sentCallback(this); + sentCallback_(this); } catch(System.Exception ex) { @@ -252,7 +258,7 @@ namespace IceInternal { try { - _sentCallback(this); + sentCallback_(this); } catch(System.Exception ex) { @@ -271,21 +277,21 @@ namespace IceInternal { throw new System.ArgumentException("callback is null"); } - if(_sentCallback != null) + if(sentCallback_ != null) { throw new System.ArgumentException("sent callback already set"); } - _sentCallback = (Ice.AsyncResult result) => - { - cb(result.sentSynchronously()); - }; + sentCallback_ = (Ice.AsyncResult r) => + { + cb(r.sentSynchronously()); + }; if((state_ & StateSent) == 0) { return this; } } - if(sentSynchronously_) + if(outgoing_.sentSynchronously()) { try { @@ -313,12 +319,6 @@ namespace IceInternal return this; } - public Ice.AsyncResult whenCompletedWithAsyncCallback(Ice.AsyncCallback cb) - { - setCompletedCallback(cb); - return this; - } - public Ice.AsyncResult whenCompleted(Ice.ExceptionCallback cb) { if(cb == null) @@ -342,103 +342,6 @@ namespace IceInternal return _operation; } - public void invokeSent(Ice.AsyncCallback cb) - { - Debug.Assert(cb != null); - try - { - cb(this); - } - catch(System.Exception ex) - { - warning(ex); - } - - if(observer_ != null) - { - Ice.ObjectPrx proxy = getProxy(); - if(proxy == null || !proxy.ice_isTwoway()) - { - observer_.detach(); - observer_ = null; - } - } - } - - public void invokeSentAsync(Ice.AsyncCallback cb) - { - // - // This is called when it's not safe to call the exception callback synchronously - // from this thread. Instead the exception callback is called asynchronously from - // the client thread pool. - // - Debug.Assert(cb != null); - try - { - instance_.clientThreadPool().dispatch(() => - { - invokeSent(cb); - }, cachedConnection_); - } - catch(Ice.CommunicatorDestroyedException) - { - } - } - - public void invokeCompleted(Ice.AsyncCallback cb) - { - Debug.Assert(cb != null); - try - { - cb(this); - } - catch(System.Exception ex) - { - warning(ex); - } - - if(observer_ != null) - { - observer_.detach(); - observer_ = null; - } - } - - public void invokeCompletedAsync(Ice.AsyncCallback cb) - { - // - // This is called when it's not safe to call the exception callback synchronously - // from this thread. Instead the exception callback is called asynchronously from - // the client thread pool. - // - Debug.Assert(cb != null); - - // CommunicatorDestroyedException is the only exception that can propagate directly. - instance_.clientThreadPool().dispatch(() => - { - invokeCompleted(cb); - }, cachedConnection_); - } - - public virtual void cancelable(CancellationHandler handler) - { - lock(this) - { - if(_cancellationException != null) - { - try - { - throw _cancellationException; - } - finally - { - _cancellationException = null; - } - } - _cancellationHandler = handler; - } - } - public bool wait() { lock(this) @@ -450,121 +353,30 @@ namespace IceInternal state_ |= StateEndCalled; while((state_ & StateDone) == 0) { - System.Threading.Monitor.Wait(this); + Monitor.Wait(this); } - if(_exception != null) + if(exception_ != null) { - throw _exception; + throw exception_; } return (state_ & StateOK) != 0; } } - public virtual void cacheMessageBuffers() - { - } - - protected AsyncResultI(Ice.Communicator communicator, Instance instance, string op, object cookie) + protected AsyncResultI(Ice.Communicator communicator, + Instance instance, + string op, + object cookie, + Ice.AsyncCallback cb) { instance_ = instance; - sentSynchronously_ = false; state_ = 0; _communicator = communicator; _operation = op; - _exception = null; + exception_ = null; _cookie = cookie; - } - - protected Ice.AsyncCallback sent(bool done) - { - lock(this) - { - Debug.Assert(_exception == null); - - bool alreadySent = (state_ & StateSent) != 0; - state_ |= StateSent; - if(done) - { - state_ |= StateDone | StateOK; - _cancellationHandler = null; - if(observer_ != null && _sentCallback == null) - { - observer_.detach(); - observer_ = null; - } - - // - // For oneway requests after the data has been sent - // the buffers can be reused unless this is a - // collocated invocation. For collocated invocations - // the buffer won't be reused because it has already - // been marked as cached in invokeCollocated. - // - cacheMessageBuffers(); - } - if(_waitHandle != null) - { - _waitHandle.Set(); - } - System.Threading.Monitor.PulseAll(this); - return !alreadySent ? _sentCallback : null; - } - } - - protected Ice.AsyncCallback finished(bool ok) - { - lock(this) - { - state_ |= StateDone; - if(ok) - { - state_ |= StateOK; - } - _cancellationHandler = null; - if(_completedCallback == null) - { - if(observer_ != null) - { - observer_.detach(); - observer_ = null; - } - } - if(_waitHandle != null) - { - _waitHandle.Set(); - } - System.Threading.Monitor.PulseAll(this); - return _completedCallback; - } - } - - protected Ice.AsyncCallback finished(Ice.Exception ex) - { - lock(this) - { - state_ |= StateDone; - _exception = ex; - _cancellationHandler = null; - if(observer_ != null) - { - observer_.failed(ex.ice_id()); - } - if(_completedCallback == null) - { - if(observer_ != null) - { - observer_.detach(); - observer_ = null; - } - } - if(_waitHandle != null) - { - _waitHandle.Set(); - } - System.Threading.Monitor.PulseAll(this); - return _completedCallback; - } + completedCallback_ = cb; } protected void setCompletedCallback(Ice.AsyncCallback cb) @@ -575,16 +387,16 @@ namespace IceInternal { throw new System.ArgumentException("callback is null"); } - if(_completedCallback != null) + if(completedCallback_ != null) { throw new System.ArgumentException("callback already set"); } - _completedCallback = cb; + completedCallback_ = cb; if((state_ & StateDone) == 0) { return; } - else if((getProxy() == null || !getProxy().ice_isTwoway()) && _exception == null) + else if((getProxy() == null || !getProxy().ice_isTwoway()) && exception_ == null) { return; } @@ -594,7 +406,14 @@ namespace IceInternal { try { - cb(this); + try + { + cb(this); + } + catch(System.AggregateException ex) + { + throw ex.InnerException; + } } catch(System.Exception ex) { @@ -603,44 +422,21 @@ namespace IceInternal }, cachedConnection_); } - protected virtual Ice.AsyncCallback getCompletedCallback() - { - return (Ice.AsyncResult result) => - { - Debug.Assert(exceptionCallback_ != null); - try - { - ((AsyncResultI)result).wait(); - } - catch(Ice.Exception ex) - { - exceptionCallback_(ex); - return; - } - }; - } + abstract protected Ice.AsyncCallback getCompletedCallback(); - protected void cancel(Ice.LocalException ex) + public static AsyncResultI check(Ice.AsyncResult r, Ice.ObjectPrx prx, string operation) { - CancellationHandler handler; - lock(this) + if(r != null && r.getProxy() != prx) { - _cancellationException = ex; - if(_cancellationHandler == null) - { - return; - } - handler = _cancellationHandler; + throw new System.ArgumentException("Proxy for call to end_" + operation + + " does not match proxy that was used to call corresponding begin_" + + operation + " method"); } - handler.asyncRequestCanceled((OutgoingAsyncBase)this, ex); + return check(r, operation); } - protected virtual Ice.Instrumentation.InvocationObserver getObserver() - { - return observer_; - } - protected static T check<T>(Ice.AsyncResult r, string operation) + public static AsyncResultI check(Ice.AsyncResult r, string operation) { if(r == null) { @@ -651,11 +447,11 @@ namespace IceInternal throw new System.ArgumentException("Incorrect operation for end_" + operation + " method: " + r.getOperation()); } - if(!(r is T)) + if(!(r is AsyncResultI)) { throw new System.ArgumentException("Incorrect AsyncResult object for end_" + operation + " method"); } - return (T)r; + return (AsyncResultI)r; } protected void warning(System.Exception ex) @@ -666,29 +462,25 @@ namespace IceInternal } } - protected IceInternal.Instance instance_; + protected Instance instance_; protected Ice.Instrumentation.InvocationObserver observer_; protected Ice.Connection cachedConnection_; - protected bool sentSynchronously_; private readonly Ice.Communicator _communicator; private readonly string _operation; private readonly object _cookie; - private Ice.Exception _exception; - private EventWaitHandle _waitHandle; - - private CancellationHandler _cancellationHandler; - private Ice.LocalException _cancellationException; + protected Ice.Exception exception_; + protected EventWaitHandle waitHandle_; - private Ice.AsyncCallback _completedCallback; - private Ice.AsyncCallback _sentCallback; + protected Ice.AsyncCallback completedCallback_; + protected Ice.AsyncCallback sentCallback_; protected Ice.ExceptionCallback exceptionCallback_; protected const int StateOK = 0x1; protected const int StateDone = 0x2; protected const int StateSent = 0x4; protected const int StateEndCalled = 0x8; - protected const int StateCachedBuffers = 0x10; protected int state_; + protected OutgoingAsyncBase outgoing_; } } diff --git a/csharp/src/Ice/CollocatedRequestHandler.cs b/csharp/src/Ice/CollocatedRequestHandler.cs index 9e8ce8b777d..d0f793a5914 100644 --- a/csharp/src/Ice/CollocatedRequestHandler.cs +++ b/csharp/src/Ice/CollocatedRequestHandler.cs @@ -42,9 +42,9 @@ namespace IceInternal return previousHandler == this ? newHandler : this; } - public bool sendAsyncRequest(ProxyOutgoingAsyncBase outAsync, out Ice.AsyncCallback sentCallback) + public int sendAsyncRequest(ProxyOutgoingAsyncBase outAsync) { - return outAsync.invokeCollocated(this, out sentCallback); + return outAsync.invokeCollocated(this); } public void asyncRequestCanceled(OutgoingAsyncBase outAsync, Ice.LocalException ex) @@ -59,10 +59,9 @@ namespace IceInternal _asyncRequests.Remove(requestId); } _sendAsyncRequests.Remove(outAsync); - Ice.AsyncCallback cb = outAsync.completed(ex); - if(cb != null) + if(outAsync.exception(ex)) { - outAsync.invokeCompletedAsync(cb); + outAsync.invokeExceptionAsync(); } _adapter.decDirectCount(); // invokeAll won't be called, decrease the direct count. return; @@ -76,10 +75,9 @@ namespace IceInternal if(e.Value == o) { _asyncRequests.Remove(e.Key); - Ice.AsyncCallback cb = outAsync.completed(ex); - if(cb != null) + if(outAsync.exception(ex)) { - outAsync.invokeCompletedAsync(cb); + outAsync.invokeExceptionAsync(); } return; } @@ -90,7 +88,6 @@ namespace IceInternal public void sendResponse(int requestId, Ice.OutputStream os, byte status, bool amd) { - Ice.AsyncCallback cb = null; OutgoingAsyncBase outAsync; lock(this) { @@ -113,21 +110,24 @@ namespace IceInternal if(_asyncRequests.TryGetValue(requestId, out outAsync)) { - _asyncRequests.Remove(requestId); outAsync.getIs().swap(iss); - cb = outAsync.completed(); + if(!outAsync.response()) + { + outAsync = null; + } + _asyncRequests.Remove(requestId); } } - if(cb != null) + if(outAsync != null) { if(amd) { - outAsync.invokeCompletedAsync(cb); + outAsync.invokeResponseAsync(); } else { - outAsync.invokeCompleted(cb); + outAsync.invokeResponse(); } } _adapter.decDirectCount(); @@ -166,8 +166,7 @@ namespace IceInternal return null; } - public bool invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestNum, bool synchronous, - out Ice.AsyncCallback sentCallback) + public int invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestNum, bool synchronous) { // // Increase the direct count to prevent the thread pool from being destroyed before @@ -198,54 +197,37 @@ namespace IceInternal } outAsync.attachCollocatedObserver(_adapter, requestId); - - if(synchronous) + if(!synchronous || !_response || _reference.getInvocationTimeout() > 0) { - // - // Treat this collocated call as if it is a synchronous invocation. - // - if(_reference.getInvocationTimeout() > 0 || !_response) - { - // Don't invoke from the user thread, invocation timeouts wouldn't work otherwise. - _adapter.getThreadPool().dispatch(() => + // Don't invoke from the user thread if async or invocation timeout is set + _adapter.getThreadPool().dispatch( + () => { - if(sentAsync(outAsync)) + if (sentAsync(outAsync)) { invokeAll(outAsync.getOs(), requestId, batchRequestNum); } }, null); - } - else if(_dispatcher) - { - _adapter.getThreadPool().dispatchFromThisThread(() => + } + else if(_dispatcher) + { + _adapter.getThreadPool().dispatchFromThisThread( + () => { - if(sentAsync(outAsync)) + if (sentAsync(outAsync)) { invokeAll(outAsync.getOs(), requestId, batchRequestNum); } }, null); - } - else // Optimization: directly call invokeAll if there's no dispatcher. - { - if(sentAsync(outAsync)) - { - invokeAll(outAsync.getOs(), requestId, batchRequestNum); - } - } - sentCallback = null; } - else + else // Optimization: directly call invokeAll if there's no dispatcher. { - _adapter.getThreadPool().dispatch(() => + if (sentAsync(outAsync)) { - if(sentAsync(outAsync)) - { - invokeAll(outAsync.getOs(), requestId, batchRequestNum); - } - }, null); - sentCallback = null; + invokeAll(outAsync.getOs(), requestId, batchRequestNum); + } } - return false; + return OutgoingAsyncBase.AsyncStatusQueued; } private bool sentAsync(OutgoingAsyncBase outAsync) @@ -256,13 +238,13 @@ namespace IceInternal { return false; // The request timed-out. } - } - Ice.AsyncCallback cb = outAsync.sent(); - if(cb != null) - { - outAsync.invokeSent(cb); + if(!outAsync.sent()) + { + return true; + } } + outAsync.invokeSent(); return true; } @@ -338,25 +320,32 @@ namespace IceInternal } OutgoingAsyncBase outAsync; - Ice.AsyncCallback cb = null; lock(this) { if(_asyncRequests.TryGetValue(requestId, out outAsync)) { + if(!outAsync.exception(ex)) + { + outAsync = null; + } _asyncRequests.Remove(requestId); - cb = outAsync.completed(ex); } } - if(cb != null) + if(outAsync != null) { + // + // If called from an AMD dispatch, invoke asynchronously + // the completion callback since this might be called from + // the user code. + // if(amd) { - outAsync.invokeCompletedAsync(cb); + outAsync.invokeExceptionAsync(); } else { - outAsync.invokeCompleted(cb); + outAsync.invokeException(); } } } diff --git a/csharp/src/Ice/CommunicatorI.cs b/csharp/src/Ice/CommunicatorI.cs index ce4a70aa580..8e968058c16 100644 --- a/csharp/src/Ice/CommunicatorI.cs +++ b/csharp/src/Ice/CommunicatorI.cs @@ -9,10 +9,13 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; +using System.Threading; + +using IceInternal; namespace Ice { - sealed class CommunicatorI : Communicator { public void destroy() @@ -162,8 +165,16 @@ namespace Ice public void flushBatchRequests() { - AsyncResult r = begin_flushBatchRequests(); - end_flushBatchRequests(r); + flushBatchRequestsAsync().Wait(); + } + + public Task flushBatchRequestsAsync(IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()) + { + var completed = new FlushBatchTaskCompletionCallback(progress, cancel); + var outgoing = new CommunicatorFlushBatchAsync(instance_, completed); + outgoing.invoke(__flushBatchRequests_name); + return completed.Task; } public AsyncResult begin_flushBatchRequests() @@ -173,49 +184,59 @@ namespace Ice private const string __flushBatchRequests_name = "flushBatchRequests"; - public AsyncResult begin_flushBatchRequests(AsyncCallback cb, object cookie) + private class CommunicatorFlushBatchCompletionCallback : AsyncResultCompletionCallback { - IceInternal.OutgoingConnectionFactory connectionFactory = instance_.outgoingConnectionFactory(); - IceInternal.ObjectAdapterFactory adapterFactory = instance_.objectAdapterFactory(); - - // - // This callback object receives the results of all invocations - // of Connection.begin_flushBatchRequests. - // - IceInternal.CommunicatorFlushBatch result = - new IceInternal.CommunicatorFlushBatch(this, instance_, __flushBatchRequests_name, cookie); - - if(cb != null) + public CommunicatorFlushBatchCompletionCallback(Ice.Communicator communicator, + Instance instance, + string op, + object cookie, + Ice.AsyncCallback callback) + : base(communicator, instance, op, cookie, callback) { - result.whenCompletedWithAsyncCallback(cb); } - connectionFactory.flushAsyncBatchRequests(result); - adapterFactory.flushAsyncBatchRequests(result); - - // - // Inform the callback that we have finished initiating all of the - // flush requests. If all of the requests have already completed, - // the callback is invoked now. - // - result.ready(); + protected override Ice.AsyncCallback getCompletedCallback() + { + return (Ice.AsyncResult result) => + { + try + { + result.throwLocalException(); + } + catch(Ice.Exception ex) + { + exceptionCallback_?.Invoke(ex); + } + }; + } + }; + public AsyncResult begin_flushBatchRequests(AsyncCallback cb, object cookie) + { + var result = new CommunicatorFlushBatchCompletionCallback(this, instance_, __flushBatchRequests_name, cookie, cb); + var outgoing = new CommunicatorFlushBatchAsync(instance_, result); + outgoing.invoke(__flushBatchRequests_name); return result; } public void end_flushBatchRequests(AsyncResult result) { - IceInternal.CommunicatorFlushBatch outAsync = - IceInternal.CommunicatorFlushBatch.check(result, this, __flushBatchRequests_name); - outAsync.wait(); + if(result != null && result.getCommunicator() != this) + { + const string msg = "Communicator for call to end_" + __flushBatchRequests_name + + " does not match communicator that was used to call corresponding begin_" + + __flushBatchRequests_name + " method"; + throw new ArgumentException(msg); + } + AsyncResultI.check(result, __flushBatchRequests_name).wait(); } - public Ice.ObjectPrx createAdmin(ObjectAdapter adminAdapter, Identity adminIdentity) + public ObjectPrx createAdmin(ObjectAdapter adminAdapter, Identity adminIdentity) { return instance_.createAdmin(adminAdapter, adminIdentity); } - public Ice.ObjectPrx getAdmin() + public ObjectPrx getAdmin() { return instance_.getAdmin(); } @@ -295,5 +316,4 @@ namespace Ice private IceInternal.Instance instance_; } - } diff --git a/csharp/src/Ice/ConnectRequestHandler.cs b/csharp/src/Ice/ConnectRequestHandler.cs index b8e3363577e..d53aef9513a 100644 --- a/csharp/src/Ice/ConnectRequestHandler.cs +++ b/csharp/src/Ice/ConnectRequestHandler.cs @@ -35,7 +35,7 @@ namespace IceInternal return previousHandler == this ? newHandler : this; } - public bool sendAsyncRequest(ProxyOutgoingAsyncBase outAsync, out Ice.AsyncCallback sentCallback) + public int sendAsyncRequest(ProxyOutgoingAsyncBase outAsync) { lock(this) { @@ -47,11 +47,10 @@ namespace IceInternal if(!initialized()) { _requests.AddLast(outAsync); - sentCallback = null; - return false; + return OutgoingAsyncBase.AsyncStatusQueued; } } - return outAsync.invokeRemote(_connection, _compress, _response, out sentCallback); + return outAsync.invokeRemote(_connection, _compress, _response); } public void asyncRequestCanceled(OutgoingAsyncBase outAsync, Ice.LocalException ex) @@ -71,10 +70,9 @@ namespace IceInternal if(p.Value == outAsync) { _requests.Remove(p); - Ice.AsyncCallback cb = outAsync.completed(ex); - if(cb != null) + if(outAsync.exception(ex)) { - outAsync.invokeCompletedAsync(cb); + outAsync.invokeExceptionAsync(); } return; } @@ -161,14 +159,13 @@ namespace IceInternal foreach(ProxyOutgoingAsyncBase outAsync in _requests) { - Ice.AsyncCallback cb = outAsync.completed(_exception); - if(cb != null) + if(outAsync.exception(_exception)) { - outAsync.invokeCompletedAsync(cb); + outAsync.invokeExceptionAsync(); } } _requests.Clear(); - System.Threading.Monitor.PulseAll(this); + Monitor.PulseAll(this); } } @@ -248,13 +245,9 @@ namespace IceInternal { try { - Ice.AsyncCallback sentCallback = null; - if(outAsync.invokeRemote(_connection, _compress, _response, out sentCallback)) + if((outAsync.invokeRemote(_connection, _compress, _response) & OutgoingAsyncBase.AsyncStatusInvokeSentCallback) != 0) { - if(sentCallback != null) - { - outAsync.invokeSentAsync(sentCallback); - } + outAsync.invokeSentAsync(); } } catch(RetryException ex) @@ -269,10 +262,9 @@ namespace IceInternal catch(Ice.LocalException ex) { exception = ex; - Ice.AsyncCallback cb = outAsync.completed(ex); - if(cb != null) + if(outAsync.exception(ex)) { - outAsync.invokeCompletedAsync(cb); + outAsync.invokeExceptionAsync(); } } } @@ -308,7 +300,7 @@ namespace IceInternal _proxies.Clear(); _proxy = null; // Break cyclic reference count. - System.Threading.Monitor.PulseAll(this); + Monitor.PulseAll(this); } } diff --git a/csharp/src/Ice/ConnectionFactory.cs b/csharp/src/Ice/ConnectionFactory.cs index d68b7e808c1..ef41ce0143a 100644 --- a/csharp/src/Ice/ConnectionFactory.cs +++ b/csharp/src/Ice/ConnectionFactory.cs @@ -256,7 +256,7 @@ namespace IceInternal } } - public void flushAsyncBatchRequests(CommunicatorFlushBatch outAsync) + public void flushAsyncBatchRequests(CommunicatorFlushBatchAsync outAsync) { ICollection<Ice.ConnectionI> c = new List<Ice.ConnectionI>(); @@ -1256,7 +1256,7 @@ namespace IceInternal } } - public void flushAsyncBatchRequests(CommunicatorFlushBatch outAsync) + public void flushAsyncBatchRequests(CommunicatorFlushBatchAsync outAsync) { // // connections() is synchronized, no need to synchronize here. diff --git a/csharp/src/Ice/ConnectionI.cs b/csharp/src/Ice/ConnectionI.cs index ba5668eac74..252909df781 100644 --- a/csharp/src/Ice/ConnectionI.cs +++ b/csharp/src/Ice/ConnectionI.cs @@ -10,15 +10,17 @@ namespace Ice { using System; - using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Threading; - using Ice.Instrumentation; + using System.Threading.Tasks; + using System.Linq; - public sealed class ConnectionI : - IceInternal.EventHandler, IceInternal.ResponseHandler, IceInternal.CancellationHandler, Connection + using Instrumentation; + using IceInternal; + + public sealed class ConnectionI : IceInternal.EventHandler, ResponseHandler, CancellationHandler, Connection { public interface StartCallback { @@ -26,7 +28,7 @@ namespace Ice void connectionStartFailed(ConnectionI connection, LocalException ex); } - private class TimeoutCallback : IceInternal.TimerTask + private class TimeoutCallback : TimerTask { public TimeoutCallback(ConnectionI connection) { @@ -56,7 +58,7 @@ namespace Ice throw _exception; } - if(!initialize(IceInternal.SocketOperation.None) || !validate(IceInternal.SocketOperation.None)) + if(!initialize(SocketOperation.None) || !validate(SocketOperation.None)) { _startCallback = callback; return; @@ -93,7 +95,7 @@ namespace Ice throw _exception; } - if(!initialize(IceInternal.SocketOperation.None) || !validate(IceInternal.SocketOperation.None)) + if(!initialize(SocketOperation.None) || !validate(SocketOperation.None)) { // // Wait for the connection to be validated. @@ -135,7 +137,7 @@ namespace Ice if(_acmLastActivity > -1) { - _acmLastActivity = IceInternal.Time.currentMonotonicTimeMillis(); + _acmLastActivity = Time.currentMonotonicTimeMillis(); } setState(StateActive); } @@ -315,7 +317,7 @@ namespace Ice } } - public void monitor(long now, IceInternal.ACMConfig acm) + public void monitor(long now, ACMConfig acm) { lock(this) { @@ -347,7 +349,7 @@ namespace Ice } } - if(_readStream.size() > IceInternal.Protocol.headerSize || !_writeStream.isEmpty()) + if(_readStream.size() > Protocol.headerSize || !_writeStream.isEmpty()) { // // If writing or reading, nothing to do, the connection @@ -382,21 +384,21 @@ namespace Ice } } - public bool sendAsyncRequest(IceInternal.OutgoingAsyncBase og, bool compress, bool response, - int batchRequestNum, out Ice.AsyncCallback sentCallback) + public int sendAsyncRequest(OutgoingAsyncBase og, bool compress, bool response, + int batchRequestNum) { OutputStream os = og.getOs(); lock(this) { + // + // If the exception is closed before we even have a chance + // to send our request, we always try to send the request + // again. + // if(_exception != null) { - // - // If the connection is closed before we even have a chance - // to send our request, we always try to send the request - // again. - // - throw new IceInternal.RetryException(_exception); + throw new RetryException(_exception); } Debug.Assert(_state > StateNotValidated); @@ -413,7 +415,6 @@ namespace Ice // This will throw if the request is canceled. // og.cancelable(this); - int requestId = 0; if(response) { @@ -430,25 +431,24 @@ namespace Ice // // Fill in the request ID. // - os.pos(IceInternal.Protocol.headerSize); + os.pos(Protocol.headerSize); os.writeInt(requestId); } else if(batchRequestNum > 0) { - os.pos(IceInternal.Protocol.headerSize); + os.pos(Protocol.headerSize); os.writeInt(batchRequestNum); } og.attachRemoteObserver(initConnectionInfo(), _endpoint, requestId); - bool sent; + int status = OutgoingAsyncBase.AsyncStatusQueued; try { - OutgoingMessage msg = new OutgoingMessage(og, os, compress, requestId); - sent = sendMessage(msg); - sentCallback = msg.sentCallback; + OutgoingMessage message = new OutgoingMessage(og, os, compress, requestId); + status = sendMessage(message); } - catch(LocalException ex) + catch(Ice.LocalException ex) { setState(StateClosed, ex); Debug.Assert(_exception != null); @@ -462,51 +462,88 @@ namespace Ice // _asyncRequests[requestId] = og; } - return sent; + return status; } } - public IceInternal.BatchRequestQueue getBatchRequestQueue() + public BatchRequestQueue getBatchRequestQueue() { return _batchRequestQueue; } public void flushBatchRequests() { - end_flushBatchRequests(begin_flushBatchRequests()); + flushBatchRequestsAsync().Wait(); } - public AsyncResult begin_flushBatchRequests() + private class ConnectionFlushBatchCompletionCallback : AsyncResultCompletionCallback { - return begin_flushBatchRequestsInternal(null, null); + public ConnectionFlushBatchCompletionCallback(Ice.Connection connection, + Ice.Communicator communicator, + Instance instance, + string op, + object cookie, + Ice.AsyncCallback callback) + : base(communicator, instance, op, cookie, callback) + { + _connection = connection; + } + + public override Ice.Connection getConnection() + { + return _connection; + } + + protected override Ice.AsyncCallback getCompletedCallback() + { + return (Ice.AsyncResult result) => + { + try + { + result.throwLocalException(); + } + catch(Ice.Exception ex) + { + exceptionCallback_?.Invoke(ex); + } + }; + } + + private Ice.Connection _connection; } - public AsyncResult begin_flushBatchRequests(AsyncCallback cb, object cookie) + public Task flushBatchRequestsAsync(IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()) { - return begin_flushBatchRequestsInternal(cb, cookie); + var completed = new FlushBatchTaskCompletionCallback(progress, cancel); + var outgoing = new ConnectionFlushBatchAsync(this, _instance, completed); + outgoing.invoke(__flushBatchRequests_name); + return completed.Task; } - public void end_flushBatchRequests(AsyncResult r) + public AsyncResult begin_flushBatchRequests(AsyncCallback cb = null, object cookie = null) { - IceInternal.ConnectionFlushBatch outAsync = - IceInternal.ConnectionFlushBatch.check(r, this, __flushBatchRequests_name); - outAsync.wait(); + var result = new ConnectionFlushBatchCompletionCallback(this, _communicator, _instance, + __flushBatchRequests_name, cookie, cb); + var outgoing = new ConnectionFlushBatchAsync(this, _instance, result); + outgoing.invoke(__flushBatchRequests_name); + return result; } - private const string __flushBatchRequests_name = "flushBatchRequests"; - - private AsyncResult begin_flushBatchRequestsInternal(AsyncCallback cb, object cookie) + public void end_flushBatchRequests(AsyncResult r) { - IceInternal.ConnectionFlushBatch result = - new IceInternal.ConnectionFlushBatch(this, _communicator, _instance, __flushBatchRequests_name, cookie); - if(cb != null) + if(r != null && r.getConnection() != this) { - result.whenCompletedWithAsyncCallback(cb); + const string msg = "Connection for call to end_" + __flushBatchRequests_name + + " does not match connection that was used to call corresponding begin_" + + __flushBatchRequests_name + " method"; + throw new ArgumentException(msg); } - result.invoke(); - return result; + AsyncResultI.check(r, __flushBatchRequests_name).wait(); } + private const string __flushBatchRequests_name = "flushBatchRequests"; + public void setCloseCallback(CloseCallback callback) { lock(this) @@ -595,40 +632,40 @@ namespace Ice return; // The request has already been or will be shortly notified of the failure. } - LinkedListNode<OutgoingMessage> p; - for(p = _sendStreams.First; p != null; p = p.Next) + + OutgoingMessage o = _sendStreams.FirstOrDefault(m => m.outAsync == outAsync); + if(o != null) { - OutgoingMessage o = p.Value; - if(o.outAsync == outAsync) + if(o.requestId > 0) { - if(o.requestId > 0) - { - _asyncRequests.Remove(o.requestId); - } + _asyncRequests.Remove(o.requestId); + } - if(ex is Ice.ConnectionTimeoutException) + if(ex is Ice.ConnectionTimeoutException) + { + setState(StateClosed, ex); + } + else + { + // + // If the request is being sent, don't remove it from the send streams, + // it will be removed once the sending is finished. + // + if(o == _sendStreams.First.Value) { - setState(StateClosed, ex); + o.canceled(); } else { - // - // If the request is being sent, don't remove it from the send streams, - // it will be removed once the sending is finished. - // o.canceled(); - if(o != _sendStreams.First.Value) - { - _sendStreams.Remove(p); - } - Ice.AsyncCallback cb = outAsync.completed(ex); - if(cb != null) - { - outAsync.invokeCompletedAsync(cb); - } + _sendStreams.Remove(o); + } + if(outAsync.exception(ex)) + { + outAsync.invokeExceptionAsync(); } - return; } + return; } if(outAsync is IceInternal.OutgoingAsync) @@ -644,10 +681,9 @@ namespace Ice else { _asyncRequests.Remove(kvp.Key); - Ice.AsyncCallback cb = outAsync.completed(ex); - if(cb != null) + if(outAsync.exception(ex)) { - outAsync.invokeCompletedAsync(cb); + outAsync.invokeExceptionAsync(); } } return; @@ -680,7 +716,7 @@ namespace Ice throw _exception; } - sendMessage(new OutgoingMessage(os, compressFlag != 0, true)); + sendMessage(new OutgoingMessage(os, compressFlag > 0, true)); if(_state == StateClosing && _dispatchCount == 0) { @@ -1226,17 +1262,16 @@ namespace Ice { foreach(OutgoingMessage m in sentCBs) { - if(m.sentCallback != null) + if(m.invokeSent) { - m.outAsync.invokeSent(m.sentCallback); + m.outAsync.invokeSent(); } if(m.receivedReply) { IceInternal.OutgoingAsync outAsync = (IceInternal.OutgoingAsync)m.outAsync; - Ice.AsyncCallback cb = outAsync.completed(); - if(cb != null) + if(outAsync.response()) { - outAsync.invokeCompleted(cb); + outAsync.invokeResponse(); } } } @@ -1249,7 +1284,7 @@ namespace Ice // if(info.outAsync != null) { - info.outAsync.invokeCompleted(info.completedCallback); + info.outAsync.invokeResponse(); ++dispatchedCount; } @@ -1333,7 +1368,7 @@ namespace Ice // unecessary thread creation, especially if this is called on shutdown). // if(_startCallback == null && _sendStreams.Count == 0 && _asyncRequests.Count == 0 && - _closeCallback == null && _heartbeatCallback == null) + _closeCallback == null && _heartbeatCallback == null) { finish(); return; @@ -1415,40 +1450,38 @@ namespace Ice // if(message.isSent || message.receivedReply) { - if(message.sent() && message.sentCallback != null) + if(message.sent() && message.invokeSent) { - message.outAsync.invokeSent(message.sentCallback); + message.outAsync.invokeSent(); } if(message.receivedReply) { IceInternal.OutgoingAsync outAsync = (IceInternal.OutgoingAsync)message.outAsync; - Ice.AsyncCallback cb = outAsync.completed(); - if(cb != null) + if(outAsync.response()) { - outAsync.invokeCompleted(cb); + outAsync.invokeResponse(); } } _sendStreams.RemoveFirst(); } } - foreach(OutgoingMessage m in _sendStreams) + foreach (OutgoingMessage o in _sendStreams) { - m.completed(_exception); - if(m.requestId > 0) // Make sure finished isn't called twice. + o.completed(_exception); + if(o.requestId > 0) // Make sure finished isn't called twice. { - _asyncRequests.Remove(m.requestId); + _asyncRequests.Remove(o.requestId); } } - _sendStreams.Clear(); + _sendStreams.Clear(); // Must be cleared before _requests because of Outgoing* references in OutgoingMessage } foreach(IceInternal.OutgoingAsyncBase o in _asyncRequests.Values) { - Ice.AsyncCallback cb = o.completed(_exception); - if(cb != null) + if(o.exception(_exception)) { - o.invokeCompleted(cb); + o.invokeException(); } } _asyncRequests.Clear(); @@ -1919,7 +1952,8 @@ namespace Ice os.writeByte(_compressionSupported ? (byte)1 : (byte)0); os.writeInt(IceInternal.Protocol.headerSize); // Message size. - if(sendMessage(new OutgoingMessage(os, false, false))) + if((sendMessage(new OutgoingMessage(os, false, false)) & + IceInternal.OutgoingAsyncBase.AsyncStatusSent) != 0) { setState(StateClosingPending); @@ -1951,8 +1985,7 @@ namespace Ice os.writeInt(IceInternal.Protocol.headerSize); // Message size. try { - OutgoingMessage message = new OutgoingMessage(os, false, false); - sendMessage(message); + sendMessage(new OutgoingMessage(os, false, false)); } catch(Ice.LocalException ex) { @@ -2238,7 +2271,7 @@ namespace Ice return IceInternal.SocketOperation.None; } - private bool sendMessage(OutgoingMessage message) + private int sendMessage(OutgoingMessage message) { Debug.Assert(_state < StateClosed); @@ -2246,7 +2279,7 @@ namespace Ice { message.adopt(); _sendStreams.AddLast(message); - return false; + return IceInternal.OutgoingAsyncBase.AsyncStatusQueued; } // @@ -2287,13 +2320,17 @@ namespace Ice observerFinishWrite(message.stream.getBuffer()); } - message.sent(); + int status = IceInternal.OutgoingAsyncBase.AsyncStatusSent; + if(message.sent()) + { + status = status | IceInternal.OutgoingAsyncBase.AsyncStatusInvokeSentCallback; + } if(_acmLastActivity > -1) { _acmLastActivity = IceInternal.Time.currentMonotonicTimeMillis(); } - return true; + return status; } message.adopt(); @@ -2302,7 +2339,7 @@ namespace Ice _sendStreams.AddLast(message); scheduleTimeout(op); _threadPool.register(this, op); - return false; + return IceInternal.OutgoingAsyncBase.AsyncStatusQueued; } private OutputStream doCompress(OutputStream uncompressed, bool compress) @@ -2365,10 +2402,9 @@ namespace Ice public int invokeNum; public int requestId; public byte compress; - public IceInternal.ServantManager servantManager; + public ServantManager servantManager; public ObjectAdapter adapter; - public IceInternal.OutgoingAsyncBase outAsync; - public Ice.AsyncCallback completedCallback; + public OutgoingAsyncBase outAsync; public HeartbeatCallback heartbeatCallback; public int messageDispatchCount; } @@ -2492,16 +2528,15 @@ namespace Ice break; } - case IceInternal.Protocol.replyMsg: + case Protocol.replyMsg: { IceInternal.TraceUtil.traceRecv(info.stream, _logger, _traceLevels); info.requestId = info.stream.readInt(); - IceInternal.OutgoingAsyncBase outAsync = null; - if(_asyncRequests.TryGetValue(info.requestId, out outAsync)) + if(_asyncRequests.TryGetValue(info.requestId, out info.outAsync)) { _asyncRequests.Remove(info.requestId); - outAsync.getIs().swap(info.stream); + info.outAsync.getIs().swap(info.stream); // // If we just received the reply for a request which isn't acknowledge as @@ -2509,20 +2544,19 @@ namespace Ice // will be processed once the write callback is invoked for the message. // OutgoingMessage message = _sendStreams.Count > 0 ? _sendStreams.First.Value : null; - if(message != null && message.outAsync == outAsync) + if(message != null && message.outAsync == info.outAsync) { message.receivedReply = true; } + else if(info.outAsync.response()) + { + ++info.messageDispatchCount; + } else { - info.completedCallback = outAsync.completed(); - if(info.completedCallback != null) - { - info.outAsync = outAsync; - ++info.messageDispatchCount; - } + info.outAsync = null; } - System.Threading.Monitor.PulseAll(this); // Notify threads blocked in close(false) + Monitor.PulseAll(this); // Notify threads blocked in close(false) } break; } @@ -2877,23 +2911,20 @@ namespace Ice this.stream = stream; this.compress = compress; this._adopt = adopt; - this.isSent = false; - this.requestId = 0; } internal OutgoingMessage(IceInternal.OutgoingAsyncBase outAsync, OutputStream stream, bool compress, int requestId) { + this.outAsync = outAsync; this.stream = stream; this.compress = compress; - this.outAsync = outAsync; this.requestId = requestId; - this.isSent = false; } internal void canceled() { - Debug.Assert(outAsync != null); + Debug.Assert(outAsync != null); // Only requests can timeout. outAsync = null; } @@ -2910,34 +2941,36 @@ namespace Ice internal bool sent() { + stream = null; if(outAsync != null) { - sentCallback = outAsync.sent(); + invokeSent = outAsync.sent(); + return invokeSent ||receivedReply; } - return sentCallback != null || receivedReply; + return false; } internal void completed(LocalException ex) { if(outAsync != null) { - Ice.AsyncCallback cb = outAsync.completed(ex); - if(cb != null) + if(outAsync.exception(ex)) { - outAsync.invokeCompleted(cb); + outAsync.invokeException(); } } + stream = null; } - internal OutputStream stream; + internal Ice.OutputStream stream; internal IceInternal.OutgoingAsyncBase outAsync; - internal bool receivedReply; internal bool compress; internal int requestId; internal bool _adopt; internal bool prepared; internal bool isSent; - internal Ice.AsyncCallback sentCallback = null; + internal bool invokeSent; + internal bool receivedReply; } private Communicator _communicator; diff --git a/csharp/src/Ice/ConnectionRequestHandler.cs b/csharp/src/Ice/ConnectionRequestHandler.cs index bdec3ab6806..40e13fe7691 100644 --- a/csharp/src/Ice/ConnectionRequestHandler.cs +++ b/csharp/src/Ice/ConnectionRequestHandler.cs @@ -41,9 +41,9 @@ namespace IceInternal return this; } - public bool sendAsyncRequest(ProxyOutgoingAsyncBase outAsync, out Ice.AsyncCallback sentCallback) + public int sendAsyncRequest(ProxyOutgoingAsyncBase outAsync) { - return outAsync.invokeRemote(_connection, _compress, _response, out sentCallback); + return outAsync.invokeRemote(_connection, _compress, _response); } public void asyncRequestCanceled(OutgoingAsyncBase outAsync, Ice.LocalException ex) diff --git a/csharp/src/Ice/ObjectAdapterFactory.cs b/csharp/src/Ice/ObjectAdapterFactory.cs index 80555d942ba..5fba2d4db52 100644 --- a/csharp/src/Ice/ObjectAdapterFactory.cs +++ b/csharp/src/Ice/ObjectAdapterFactory.cs @@ -212,7 +212,7 @@ namespace IceInternal } } - public void flushAsyncBatchRequests(CommunicatorFlushBatch outAsync) + public void flushAsyncBatchRequests(CommunicatorFlushBatchAsync outAsync) { List<Ice.ObjectAdapterI> adapters; lock(this) diff --git a/csharp/src/Ice/ObjectAdapterI.cs b/csharp/src/Ice/ObjectAdapterI.cs index f6dec965c71..50bdc56ad33 100644 --- a/csharp/src/Ice/ObjectAdapterI.cs +++ b/csharp/src/Ice/ObjectAdapterI.cs @@ -689,7 +689,7 @@ namespace Ice } } - public void flushAsyncBatchRequests(CommunicatorFlushBatch outAsync) + public void flushAsyncBatchRequests(CommunicatorFlushBatchAsync outAsync) { List<IncomingConnectionFactory> f; lock(this) diff --git a/csharp/src/Ice/OutgoingAsync.cs b/csharp/src/Ice/OutgoingAsync.cs index 0f376ede850..d9160e9239a 100644 --- a/csharp/src/Ice/OutgoingAsync.cs +++ b/csharp/src/Ice/OutgoingAsync.cs @@ -7,29 +7,180 @@ // // ********************************************************************** +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; + namespace IceInternal { - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Threading; + public interface OutgoingAsyncCompletionCallback + { + void init(OutgoingAsyncBase og); + + bool handleSent(bool done, bool alreadySent); + bool handleException(Ice.Exception ex); + bool handleResponse(bool ok, OutgoingAsyncBase og); - public class OutgoingAsyncBase : AsyncResultI + void handleInvokeSent(bool sentSynchronously, OutgoingAsyncBase og); + void handleInvokeException(Ice.Exception ex, OutgoingAsyncBase og); + void handleInvokeResponse(bool ok, OutgoingAsyncBase og); + } + + public abstract class OutgoingAsyncBase { - public virtual Ice.AsyncCallback sent() + public virtual bool sent() + { + return sentImpl(true); + } + + public virtual bool exception(Ice.Exception ex) + { + return exceptionImpl(ex); + } + + public virtual bool response() { - return sent(true); + Debug.Assert(false); // Must be overriden by request that can handle responses + return false; } - public virtual Ice.AsyncCallback completed(Ice.Exception ex) + public void invokeSentAsync() { - return finished(ex); + // + // This is called when it's not safe to call the sent callback + // synchronously from this thread. Instead the exception callback + // is called asynchronously from the client thread pool. + // + try + { + instance_.clientThreadPool().dispatch(this.invokeSent, cachedConnection_); + } + catch(Ice.CommunicatorDestroyedException) + { + } + } + + public void invokeExceptionAsync() + { + // + // CommunicatorDestroyedCompleted is the only exception that can propagate directly + // from this method. + // + instance_.clientThreadPool().dispatch(this.invokeException, cachedConnection_); + } + + public void invokeResponseAsync() + { + // + // CommunicatorDestroyedCompleted is the only exception that can propagate directly + // from this method. + // + instance_.clientThreadPool().dispatch(this.invokeResponse, cachedConnection_); + } + + public void invokeSent() + { + try + { + _completionCallback.handleInvokeSent(sentSynchronously_, this); + } + catch(System.Exception ex) + { + warning(ex); + } + + if(observer_ != null && _doneInSent) + { + observer_.detach(); + observer_ = null; + } + } + public void invokeException() + { + try + { + try + { + throw _ex; + } + catch(Ice.Exception ex) + { + _completionCallback.handleInvokeException(ex, this); + } + } + catch(System.Exception ex) + { + warning(ex); + } + + if(observer_ != null) + { + observer_.detach(); + observer_ = null; + } } - public virtual Ice.AsyncCallback completed() + public void invokeResponse() { - Debug.Assert(false); // Must be implemented by classes that handle responses - return null; + if(_ex != null) + { + invokeException(); + return; + } + + try + { + try + { + _completionCallback.handleInvokeResponse((state_ & StateOK) != 0, this); + } + catch(Ice.Exception ex) + { + if(_completionCallback.handleException(ex)) + { + _completionCallback.handleInvokeException(ex, this); + } + } + catch(System.AggregateException ex) + { + throw ex.InnerException; + } + } + catch(System.Exception ex) + { + warning(ex); + } + + if(observer_ != null) + { + observer_.detach(); + observer_ = null; + } + } + + public virtual void cancelable(IceInternal.CancellationHandler handler) + { + lock(this) + { + if(_cancellationException != null) + { + try + { + throw _cancellationException; + } + catch(Ice.LocalException) + { + _cancellationException = null; + throw; + } + } + _cancellationHandler = handler; + } + } + public void cancel() + { + cancel(new Ice.InvocationCanceledException()); } public void attachRemoteObserver(Ice.ConnectionInfo info, Ice.Endpoint endpt, int requestId) @@ -63,50 +214,192 @@ namespace IceInternal return os_; } - public virtual Ice.InputStream getIs() + public Ice.InputStream getIs() { - return null; // Must be implemented by classes that handle responses + return is_; } - protected OutgoingAsyncBase(Ice.Communicator com, Instance instance, string op, object cookie) : - base(com, instance, op, cookie) + public virtual void cacheMessageBuffers() { - os_ = new Ice.OutputStream(instance, Ice.Util.currentProtocolEncoding); } - protected OutgoingAsyncBase(Ice.Communicator com, Instance instance, string op, object cookie, - Ice.OutputStream os) : - base(com, instance, op, cookie) + public virtual void throwUserException() { - os_ = os; } - protected new Ice.AsyncCallback sent(bool done) + protected OutgoingAsyncBase(Instance instance, OutgoingAsyncCompletionCallback completionCallback, + Ice.OutputStream os = null, Ice.InputStream iss = null) { - if(done) + instance_ = instance; + sentSynchronously_ = false; + _doneInSent = false; + state_ = 0; + os_ = os ?? new Ice.OutputStream(instance, Ice.Util.currentProtocolEncoding); + is_ = iss ?? new Ice.InputStream(instance, Ice.Util.currentProtocolEncoding); + _completionCallback = completionCallback; + if(_completionCallback != null) + { + _completionCallback.init(this); + } + } + + protected virtual bool sentImpl(bool done) + { + lock(this) { + bool alreadySent = (state_ & StateSent) > 0; + state_ |= StateSent; + if(done) + { + _doneInSent = true; + if(childObserver_ != null) + { + childObserver_.detach(); + childObserver_ = null; + } + _cancellationHandler = null; + + // + // For oneway requests after the data has been sent + // the buffers can be reused unless this is a + // collocated invocation. For collocated invocations + // the buffer won't be reused because it has already + // been marked as cached in invokeCollocated. + // + cacheMessageBuffers(); + } + + bool invoke = _completionCallback.handleSent(done, alreadySent); + if(!invoke && _doneInSent && observer_ != null) + { + observer_.detach(); + observer_ = null; + } + return invoke; + } + } + + protected virtual bool exceptionImpl(Ice.Exception ex) + { + lock(this) + { + _ex = ex; if(childObserver_ != null) { + childObserver_.failed(ex.ice_id()); childObserver_.detach(); childObserver_ = null; } + _cancellationHandler = null; + + if(observer_ != null) + { + observer_.failed(ex.ice_id()); + } + bool invoke = _completionCallback.handleException(ex); + if(!invoke && observer_ != null) + { + observer_.detach(); + observer_ = null; + } + return invoke; } - return base.sent(done); } + protected virtual bool responseImpl(bool ok) + { + lock(this) + { + if(ok) + { + state_ |= StateOK; + } + + _cancellationHandler = null; - protected new Ice.AsyncCallback finished(Ice.Exception ex) + bool invoke; + try + { + invoke = _completionCallback.handleResponse(ok, this); + } + catch(Ice.Exception ex) + { + _ex = ex; + invoke = _completionCallback.handleException(ex); + } + if(!invoke && observer_ != null) + { + observer_.detach(); + observer_ = null; + } + return invoke; + } + } + + protected void cancel(Ice.LocalException ex) { - if(childObserver_ != null) + CancellationHandler handler; { - childObserver_.failed(ex.ice_id()); - childObserver_.detach(); - childObserver_ = null; + lock(this) + { + _cancellationException = ex; + if(_cancellationHandler == null) + { + return; + } + handler = _cancellationHandler; + } } - return base.finished(ex); + handler.asyncRequestCanceled(this, ex); } - protected Ice.OutputStream os_; + void warning(System.Exception ex) + { + if(instance_.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.AMICallback", 1) > 0) + { + instance_.initializationData().logger.warning("exception raised by AMI callback:\n" + ex); + } + } + + // + // This virtual method is necessary for the communicator flush + // batch requests implementation. + // + virtual protected Ice.Instrumentation.InvocationObserver getObserver() + { + return observer_; + } + + public bool sentSynchronously() + { + return sentSynchronously_; + } + + protected Instance instance_; + protected Ice.Connection cachedConnection_; + protected bool sentSynchronously_; + protected int state_; + + protected Ice.Instrumentation.InvocationObserver observer_; protected Ice.Instrumentation.ChildInvocationObserver childObserver_; + + protected Ice.OutputStream os_; + protected Ice.InputStream is_; + + private bool _doneInSent; + private Ice.Exception _ex; + private Ice.LocalException _cancellationException; + private CancellationHandler _cancellationHandler; + private OutgoingAsyncCompletionCallback _completionCallback; + + protected const int StateOK = 0x1; + protected const int StateDone = 0x2; + protected const int StateSent = 0x4; + protected const int StateEndCalled = 0x8; + protected const int StateCachedBuffers = 0x10; + + public const int AsyncStatusQueued = 0; + public const int AsyncStatusSent = 1; + public const int AsyncStatusInvokeSentCallback = 2; } // @@ -117,21 +410,10 @@ namespace IceInternal // public abstract class ProxyOutgoingAsyncBase : OutgoingAsyncBase, TimerTask { - public static ProxyOutgoingAsyncBase check(Ice.AsyncResult r, Ice.ObjectPrx prx, string operation) - { - return ProxyOutgoingAsyncBase.check<ProxyOutgoingAsyncBase>(r, prx, operation); - } - - public abstract bool invokeRemote(Ice.ConnectionI con, bool compress, bool resp, out Ice.AsyncCallback cb); - - public abstract bool invokeCollocated(CollocatedRequestHandler handler, out Ice.AsyncCallback cb); + public abstract int invokeRemote(Ice.ConnectionI connection, bool compress, bool response); + public abstract int invokeCollocated(CollocatedRequestHandler handler); - public override Ice.ObjectPrx getProxy() - { - return proxy_; - } - - public override Ice.AsyncCallback completed(Ice.Exception exc) + public override bool exception(Ice.Exception exc) { if(childObserver_ != null) { @@ -157,13 +439,26 @@ namespace IceInternal // the retry interval is 0. This method can be called with the // connection locked so we can't just retry here. // - instance_.retryQueue().add(this, handleException(exc)); - return null; + instance_.retryQueue().add(this, proxy_.handleException__(exc, handler_, mode_, _sent, ref _cnt)); + return false; } catch(Ice.Exception ex) { - return finished(ex); // No retries, we're done + return exceptionImpl(ex); // No retries, we're done + } + } + + public override void cancelable(CancellationHandler handler) + { + if(proxy_.reference__().getInvocationTimeout() == -2 && cachedConnection_ != null) + { + int timeout = cachedConnection_.timeout(); + if(timeout > 0) + { + instance_.timer().schedule(this, timeout); + } } + base.cancelable(handler); } public void retryException(Ice.Exception ex) @@ -181,44 +476,28 @@ namespace IceInternal } catch(Ice.Exception exc) { - Ice.AsyncCallback cb = completed(exc); - if(cb != null) + if(exception(exc)) { - invokeCompletedAsync(cb); + invokeExceptionAsync(); } } } - public override void cancelable(CancellationHandler handler) - { - if(proxy_.reference__().getInvocationTimeout() == -2 && cachedConnection_ != null) - { - int timeout = cachedConnection_.timeout(); - if(timeout > 0) - { - instance_.timer().schedule(this, timeout); - } - } - base.cancelable(handler); - } - public void retry() { invokeImpl(false); } - - public virtual void abort(Ice.Exception ex) + public void abort(Ice.Exception ex) { Debug.Assert(childObserver_ == null); - Ice.AsyncCallback cb = finished(ex); - if(cb != null) + if(exceptionImpl(ex)) { - invokeCompletedAsync(cb); + invokeExceptionAsync(); } else if(ex is Ice.CommunicatorDestroyedException) { // - // If it's a communicator destroyed exception, don't swallow + // If it's a communicator destroyed exception, swallow // it but instead notify the user thread. Even if no callback // was provided. // @@ -226,29 +505,11 @@ namespace IceInternal } } - public void runTimerTask() - { - if(proxy_.reference__().getInvocationTimeout() == -2) - { - cancel(new Ice.ConnectionTimeoutException()); - } - else - { - cancel(new Ice.InvocationTimeoutException()); - } - } - - protected ProxyOutgoingAsyncBase(Ice.ObjectPrxHelperBase prx, string op, object cookie) : - base(prx.ice_getCommunicator(), prx.reference__().getInstance(), op, cookie) - { - proxy_ = prx; - mode_ = Ice.OperationMode.Normal; - _cnt = 0; - _sent = false; - } - - protected ProxyOutgoingAsyncBase(Ice.ObjectPrxHelperBase prx, string op, object cookie, Ice.OutputStream os) : - base(prx.ice_getCommunicator(), prx.reference__().getInstance(), op, cookie, os) + protected ProxyOutgoingAsyncBase(Ice.ObjectPrxHelperBase prx, + OutgoingAsyncCompletionCallback completionCallback, + Ice.OutputStream os = null, + Ice.InputStream iss = null) : + base(prx.reference__().getInstance(), completionCallback, os, iss) { proxy_ = prx; mode_ = Ice.OperationMode.Normal; @@ -256,17 +517,6 @@ namespace IceInternal _sent = false; } - protected static T check<T>(Ice.AsyncResult r, Ice.ObjectPrx prx, string operation) - { - if(r != null && r.getProxy() != prx) - { - throw new System.ArgumentException("Proxy for call to end_" + operation + - " does not match proxy that was used to call corresponding begin_" + - operation + " method"); - } - return check<T>(r, operation); - } - protected void invokeImpl(bool userThread) { try @@ -279,12 +529,9 @@ namespace IceInternal instance_.timer().schedule(this, invocationTimeout); } } - else // If not called from the user thread, it's called from the retry queue + else if(observer_ != null) { - if(observer_ != null) - { - observer_.retried(); - } + observer_.retried(); } while(true) @@ -293,22 +540,22 @@ namespace IceInternal { _sent = false; handler_ = proxy_.getRequestHandler__(); - Ice.AsyncCallback sentCallback; - if(handler_.sendAsyncRequest(this, out sentCallback)) + int status = handler_.sendAsyncRequest(this); + if((status & AsyncStatusSent) != 0) { if(userThread) { sentSynchronously_ = true; - if(sentCallback != null) + if((status & AsyncStatusInvokeSentCallback) != 0) { - invokeSent(sentCallback); // Call from the user thread. + invokeSent(); // Call the sent callback from the user thread. } } else { - if(sentCallback != null) + if((status & AsyncStatusInvokeSentCallback) != 0) { - invokeSentAsync(sentCallback); // Call from a client thread pool thread. + invokeSentAsync(); // Call the sent callback from a client thread pool thread. } } } @@ -326,7 +573,7 @@ namespace IceInternal childObserver_.detach(); childObserver_ = null; } - int interval = handleException(ex); + int interval = proxy_.handleException__(ex, handler_, mode_, _sent, ref _cnt); if(interval > 0) { instance_.retryQueue().add(this, interval); @@ -349,15 +596,13 @@ namespace IceInternal { throw; } - Ice.AsyncCallback cb = finished(ex); // No retries, we're done - if(cb != null) + else if(exceptionImpl(ex)) // No retries, we're done { - invokeCompletedAsync(cb); + invokeExceptionAsync(); } } } - - protected new Ice.AsyncCallback sent(bool done) + protected override bool sentImpl(bool done) { _sent = true; if(done) @@ -367,33 +612,39 @@ namespace IceInternal instance_.timer().cancel(this); } } - return base.sent(done); + return base.sentImpl(done); } - - protected new Ice.AsyncCallback finished(Ice.Exception ex) + protected override bool exceptionImpl(Ice.Exception ex) { if(proxy_.reference__().getInvocationTimeout() != -1) { instance_.timer().cancel(this); } - return base.finished(ex); + return base.exceptionImpl(ex); } - protected new Ice.AsyncCallback finished(bool ok) + protected override bool responseImpl(bool ok) { if(proxy_.reference__().getInvocationTimeout() != -1) { instance_.timer().cancel(this); } - return base.finished(ok); + return base.responseImpl(ok); } - protected virtual int handleException(Ice.Exception exc) + public void runTimerTask() { - return proxy_.handleException__(exc, handler_, mode_, _sent, ref _cnt); + if(proxy_.reference__().getInvocationTimeout() == -2) + { + cancel(new Ice.ConnectionTimeoutException()); + } + else + { + cancel(new Ice.InvocationTimeoutException()); + } } - protected Ice.ObjectPrxHelperBase proxy_; + protected readonly Ice.ObjectPrxHelperBase proxy_; protected RequestHandler handler_; protected Ice.OperationMode mode_; @@ -401,41 +652,28 @@ namespace IceInternal private bool _sent; } + // + // Class for handling Slice operation invocations + // public class OutgoingAsync : ProxyOutgoingAsyncBase { - public new static OutgoingAsync check(Ice.AsyncResult r, Ice.ObjectPrx prx, string operation) + public OutgoingAsync(Ice.ObjectPrxHelperBase prx, OutgoingAsyncCompletionCallback completionCallback, + Ice.OutputStream os = null, Ice.InputStream iss = null) : + base(prx, completionCallback, os, iss) { - return ProxyOutgoingAsyncBase.check<OutgoingAsync>(r, prx, operation); + encoding_ = Protocol.getCompatibleEncoding(proxy_.reference__().getEncoding()); + synchronous_ = false; } - public OutgoingAsync(Ice.ObjectPrx prx, string operation, object cookie) : - base((Ice.ObjectPrxHelperBase)prx, operation, cookie) - { - _encoding = Protocol.getCompatibleEncoding(proxy_.reference__().getEncoding()); - _is = null; - } - - public OutgoingAsync(Ice.ObjectPrx prx, string operation, object cookie, Ice.InputStream istr, - Ice.OutputStream ostr) : - base((Ice.ObjectPrxHelperBase)prx, operation, cookie, ostr) - { - _encoding = Protocol.getCompatibleEncoding(proxy_.reference__().getEncoding()); - _is = istr; - } - - public void prepare(string operation, Ice.OperationMode mode, Dictionary<string, string> ctx, - bool explicitCtx, bool synchronous) + public void prepare(string operation, Ice.OperationMode mode, Dictionary<string, string> context, + bool synchronous) { Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(proxy_.reference__().getProtocol())); mode_ = mode; - _synchronous = synchronous; + synchronous_ = synchronous; - if(explicitCtx && ctx == null) - { - ctx = _emptyContext; - } - observer_ = ObserverHelper.get(proxy_, operation, ctx); + observer_ = ObserverHelper.get(proxy_, operation, context); switch(proxy_.reference__().getMode()) { @@ -477,12 +715,12 @@ namespace IceInternal os_.writeByte((byte)mode); - if(ctx != null) + if(context != null) { // // Explicit context // - Ice.ContextHelper.write(os_, ctx); + Ice.ContextHelper.write(os_, context); } else { @@ -502,74 +740,23 @@ namespace IceInternal } } } - - public override Ice.AsyncCallback sent() + public override bool sent() { - return sent(!proxy_.ice_isTwoway()); // done = true if not a two-way proxy (no response expected) - } - - public override bool invokeRemote(Ice.ConnectionI con, bool compress, bool resp, out Ice.AsyncCallback sentCB) - { - cachedConnection_ = con; - return con.sendAsyncRequest(this, compress, resp, 0, out sentCB); - } - - public override bool invokeCollocated(CollocatedRequestHandler handler, out Ice.AsyncCallback sentCB) - { - // The stream cannot be cached if the proxy is not a twoway or there is an invocation timeout set. - if(!proxy_.ice_isTwoway() || proxy_.reference__().getInvocationTimeout() != -1) - { - // Disable caching by marking the streams as cached! - state_ |= StateCachedBuffers; - } - return handler.invokeAsyncRequest(this, 0, _synchronous, out sentCB); + return base.sentImpl(!proxy_.ice_isTwoway()); // done = true if it's not a two-way proxy } - public override void abort(Ice.Exception ex) + public override bool response() { - Reference.Mode mode = proxy_.reference__().getMode(); - if(mode == Reference.Mode.ModeBatchOneway || mode == Reference.Mode.ModeBatchDatagram) - { - proxy_.getBatchRequestQueue__().abortBatchRequest(os_); - } - - base.abort(ex); - } - - public void invoke() - { - Reference.Mode mode = proxy_.reference__().getMode(); - if(mode == Reference.Mode.ModeBatchOneway || mode == Reference.Mode.ModeBatchDatagram) - { - sentSynchronously_ = true; - proxy_.getBatchRequestQueue__().finishBatchRequest(os_, proxy_, getOperation()); - finished(true); - return; // Don't call sent/completed callback for batch AMI requests - } - - // - // NOTE: invokeImpl doesn't throw so this can be called from the - // try block with the catch block calling abort() in case of an - // exception. - // - invokeImpl(true); // userThread = true - } - - override public Ice.AsyncCallback completed() - { - Debug.Assert(_is != null); // _is has been initialized prior to this call - // // NOTE: this method is called from ConnectionI.parseMessage // with the connection locked. Therefore, it must not invoke // any user callbacks. // - Debug.Assert(proxy_.ice_isTwoway()); // Can only be called for twoways. if(childObserver_ != null) { - childObserver_.reply(_is.size() - Protocol.headerSize - 4); + childObserver_.reply(is_.size() - Protocol.headerSize - 4); childObserver_.detach(); childObserver_ = null; } @@ -577,208 +764,229 @@ namespace IceInternal byte replyStatus; try { - replyStatus = _is.readByte(); + replyStatus = is_.readByte(); switch(replyStatus) { - case ReplyStatus.replyOK: - { - break; - } - - case ReplyStatus.replyUserException: - { - if(observer_ != null) + case ReplyStatus.replyOK: { - observer_.userException(); + break; } - break; - } - - case ReplyStatus.replyObjectNotExist: - case ReplyStatus.replyFacetNotExist: - case ReplyStatus.replyOperationNotExist: - { - Ice.Identity id = new Ice.Identity(); - id.read__(_is); - - // - // For compatibility with the old FacetPath. - // - string[] facetPath = _is.readStringSeq(); - string facet; - if(facetPath.Length > 0) + case ReplyStatus.replyUserException: { - if(facetPath.Length > 1) + if(observer_ != null) { - throw new Ice.MarshalException(); + observer_.userException(); } - facet = facetPath[0]; - } - else - { - facet = ""; - } - - string operation = _is.readString(); - - Ice.RequestFailedException ex = null; - switch(replyStatus) - { - case ReplyStatus.replyObjectNotExist: - { - ex = new Ice.ObjectNotExistException(); break; } + case ReplyStatus.replyObjectNotExist: case ReplyStatus.replyFacetNotExist: - { - ex = new Ice.FacetNotExistException(); - break; - } - case ReplyStatus.replyOperationNotExist: { - ex = new Ice.OperationNotExistException(); - break; - } + Ice.Identity ident = new Ice.Identity(); + ident.read__(is_); + + // + // For compatibility with the old FacetPath. + // + string[] facetPath = is_.readStringSeq(); + ; + string facet; + if(facetPath.Length > 0) + { + if(facetPath.Length > 1) + { + throw new Ice.MarshalException(); + } + facet = facetPath[0]; + } + else + { + facet = ""; + } - default: - { - Debug.Assert(false); - break; - } - } + string operation = is_.readString(); - ex.id = id; - ex.facet = facet; - ex.operation = operation; - throw ex; - } + Ice.RequestFailedException ex = null; + switch(replyStatus) + { + case ReplyStatus.replyObjectNotExist: + { + ex = new Ice.ObjectNotExistException(); + break; + } - case ReplyStatus.replyUnknownException: - case ReplyStatus.replyUnknownLocalException: - case ReplyStatus.replyUnknownUserException: - { - string unknown = _is.readString(); + case ReplyStatus.replyFacetNotExist: + { + ex = new Ice.FacetNotExistException(); + break; + } - Ice.UnknownException ex = null; - switch(replyStatus) - { - case ReplyStatus.replyUnknownException: - { - ex = new Ice.UnknownException(); - break; - } + case ReplyStatus.replyOperationNotExist: + { + ex = new Ice.OperationNotExistException(); + break; + } - case ReplyStatus.replyUnknownLocalException: - { - ex = new Ice.UnknownLocalException(); - break; + default: + { + Debug.Assert(false); + break; + } + } + + ex.id = ident; + ex.facet = facet; + ex.operation = operation; + throw ex; } + case ReplyStatus.replyUnknownException: + case ReplyStatus.replyUnknownLocalException: case ReplyStatus.replyUnknownUserException: { - ex = new Ice.UnknownUserException(); - break; + string unknown = is_.readString(); + + Ice.UnknownException ex = null; + switch(replyStatus) + { + case ReplyStatus.replyUnknownException: + { + ex = new Ice.UnknownException(); + break; + } + + case ReplyStatus.replyUnknownLocalException: + { + ex = new Ice.UnknownLocalException(); + break; + } + + case ReplyStatus.replyUnknownUserException: + { + ex = new Ice.UnknownUserException(); + break; + } + + default: + { + Debug.Assert(false); + break; + } + } + + ex.unknown = unknown; + throw ex; } default: { - Debug.Assert(false); - break; - } + throw new Ice.UnknownReplyStatusException(); } - - ex.unknown = unknown; - throw ex; } - default: - { - throw new Ice.UnknownReplyStatusException(); - } - } - - return finished(replyStatus == ReplyStatus.replyOK); + return responseImpl(replyStatus == ReplyStatus.replyOK); } catch(Ice.Exception ex) { - return completed(ex); + return exception(ex); } } - public Ice.OutputStream startWriteParams(Ice.FormatType format) - { - os_.startEncapsulation(_encoding, format); - return os_; - } - - public void endWriteParams() + public override int invokeRemote(Ice.ConnectionI connection, bool compress, bool response) { - os_.endEncapsulation(); + cachedConnection_ = connection; + return connection.sendAsyncRequest(this, compress, response, 0); } - public void writeEmptyParams() + public override int invokeCollocated(CollocatedRequestHandler handler) { - os_.writeEmptyEncapsulation(_encoding); - } - - public void writeParamEncaps(byte[] encaps) - { - if(encaps == null || encaps.Length == 0) - { - os_.writeEmptyEncapsulation(_encoding); - } - else + // The stream cannot be cached if the proxy is not a twoway or there is an invocation timeout set. + if(!proxy_.ice_isTwoway() || proxy_.reference__().getInvocationTimeout() != -1) { - os_.writeEncapsulation(encaps); + // Disable caching by marking the streams as cached! + state_ |= StateCachedBuffers; } + return handler.invokeAsyncRequest(this, 0, synchronous_); } - public Ice.InputStream startReadParams() + public new void abort(Ice.Exception ex) { - _is.startEncapsulation(); - return _is; - } + Reference.Mode mode = proxy_.reference__().getMode(); + if(mode == Reference.Mode.ModeBatchOneway || mode == Reference.Mode.ModeBatchDatagram) + { + // + // If we didn't finish a batch oneway or datagram request, we + // must notify the connection about that we give up ownership + // of the batch stream. + // + proxy_.getBatchRequestQueue__().abortBatchRequest(os_); + } - public void endReadParams() - { - _is.endEncapsulation(); + base.abort(ex); } - public void readEmptyParams() + public void invoke(string operation) { - _is.skipEmptyEncapsulation(); - } + Reference.Mode mode = proxy_.reference__().getMode(); + if(mode == Reference.Mode.ModeBatchOneway || mode == Reference.Mode.ModeBatchDatagram) + { + sentSynchronously_ = true; + proxy_.getBatchRequestQueue__().finishBatchRequest(os_, proxy_, operation); + responseImpl(true); + return; // Don't call sent/completed callback for batch AMI requests + } - public byte[] readParamEncaps() - { - Ice.EncodingVersion encoding; - return _is.readEncapsulation(out encoding); + // + // NOTE: invokeImpl doesn't throw so this can be called from the + // try block with the catch block calling abort() in case of an + // exception. + // + invokeImpl(true); // userThread = true } - override public Ice.InputStream getIs() + public void invoke(string operation, + Ice.OperationMode mode, + Ice.FormatType format, + Dictionary<string, string> context, + bool synchronous, + System.Action<Ice.OutputStream> write) { - // _is can already be initialized if the invocation is retried - if(_is == null) + try + { + prepare(operation, mode, context, synchronous); + if(write != null) + { + os_.startEncapsulation(encoding_, format); + write(os_); + os_.endEncapsulation(); + } + else + { + os_.writeEmptyEncapsulation(encoding_); + } + invoke(operation); + } + catch(Ice.Exception ex) { - _is = new Ice.InputStream(instance_, Ice.Util.currentProtocolEncoding); + abort(ex); } - return _is; } - public void throwUserException() + public override void throwUserException() { try { - _is.startEncapsulation(); - _is.throwException(null); + is_.startEncapsulation(); + is_.throwException(); } - catch(Ice.UserException) + catch(Ice.UserException ex) { - _is.endEncapsulation(); - throw; + is_.endEncapsulation(); + userException_?.Invoke(ex); + throw new Ice.UnknownUserException(ex.ice_id()); } } @@ -795,140 +1003,274 @@ namespace IceInternal state_ |= StateCachedBuffers; } - if(_is != null) + if(is_ != null) { - _is.reset(); + is_.reset(); } os_.reset(); - proxy_.cacheMessageBuffers(_is, os_); + proxy_.cacheMessageBuffers(is_, os_); - _is = null; + is_ = null; os_ = null; } } - private Ice.EncodingVersion _encoding; - private Ice.InputStream _is; - - // - // If true this AMI request is being used for a generated synchronous invocation. - // - private bool _synchronous; - - private static Dictionary<string, string> _emptyContext = new Dictionary<string, string>(); + protected readonly Ice.EncodingVersion encoding_; + protected System.Action<Ice.UserException> userException_; + protected bool synchronous_; } - public class CommunicatorFlushBatch : IceInternal.AsyncResultI + public class OutgoingAsyncT<T> : OutgoingAsync { - public static CommunicatorFlushBatch check(Ice.AsyncResult r, Ice.Communicator com, string operation) + public OutgoingAsyncT(Ice.ObjectPrxHelperBase prx, + OutgoingAsyncCompletionCallback completionCallback, + Ice.OutputStream os = null, + Ice.InputStream iss = null) : + base(prx, completionCallback, os, iss) { - if(r != null && r.getCommunicator() != com) - { - throw new System.ArgumentException("Communicator for call to end_" + operation + - " does not match communicator that was used to call " + - "corresponding begin_" + operation + " method"); - } - return AsyncResultI.check<CommunicatorFlushBatch>(r, operation); } - public CommunicatorFlushBatch(Ice.Communicator communicator, Instance instance, string op, object cookie) : - base(communicator, instance, op, cookie) + public void invoke(string operation, + Ice.OperationMode mode, + Ice.FormatType format, + Dictionary<string, string> context, + bool synchronous, + System.Action<Ice.OutputStream> write = null, + System.Action<Ice.UserException> userException = null, + System.Func<Ice.InputStream, T> read = null) { + read_ = read; + userException_ = userException; + base.invoke(operation, mode, format, context, synchronous, write); + } - observer_ = ObserverHelper.get(instance, op); + public T result__(bool ok) + { + try + { + if(ok) + { + if(read_ == null) + { + if(is_ == null || is_.isEmpty()) + { + // + // If there's no response (oneway, batch-oneway proxies), we just set the promise + // on completion without reading anything from the input stream. This is required for + // batch invocations. + // + } + else + { + is_.skipEmptyEncapsulation(); + } + return default(T); + } + else + { + is_.startEncapsulation(); + T r = read_(is_); + is_.endEncapsulation(); + return r; + } + } + else + { + throwUserException(); + return default(T); // make compiler happy + } + } + finally + { + cacheMessageBuffers(); + } + } - // - // _useCount is initialized to 1 to prevent premature callbacks. - // The caller must invoke ready() after all flush requests have - // been initiated. - // - _useCount = 1; + protected System.Func<Ice.InputStream, T> read_; + } + + // + // Class for handling the proxy's begin_ice_flushBatchRequest request. + // + class ProxyFlushBatchAsync : ProxyOutgoingAsyncBase + { + public ProxyFlushBatchAsync(Ice.ObjectPrxHelperBase prx, OutgoingAsyncCompletionCallback completionCallback) : + base(prx, completionCallback) + { } - public void flushConnection(Ice.ConnectionI con) + public override int invokeRemote(Ice.ConnectionI connection, bool compress, bool response) { - lock(this) + if(_batchRequestNum == 0) { - ++_useCount; + if(sent()) + { + return AsyncStatusSent | AsyncStatusInvokeSentCallback; + } + else + { + return AsyncStatusSent; + } } + cachedConnection_ = connection; + return connection.sendAsyncRequest(this, compress, false, _batchRequestNum); + } - try + public override int invokeCollocated(CollocatedRequestHandler handler) + { + if(_batchRequestNum == 0) { - Ice.AsyncCallback sentCB = null; - FlushBatch flush = new FlushBatch(this); - int batchRequestNum = con.getBatchRequestQueue().swap(flush.getOs()); - if(batchRequestNum == 0) + if(sent()) { - flush.sent(); + return AsyncStatusSent | AsyncStatusInvokeSentCallback; } else { - con.sendAsyncRequest(flush, false, false, batchRequestNum, out sentCB); + return AsyncStatusSent; } - Debug.Assert(sentCB == null); } - catch(Ice.LocalException) + return handler.invokeAsyncRequest(this, _batchRequestNum, false); + } + + public void invoke(string operation) + { + Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(proxy_.reference__().getProtocol())); + observer_ = ObserverHelper.get(proxy_, operation, null); + _batchRequestNum = proxy_.getBatchRequestQueue__().swap(os_); + invokeImpl(true); // userThread = true + } + + private int _batchRequestNum; + } + + // + // Class for handling the proxy's begin_ice_getConnection request. + // + class ProxyGetConnection : ProxyOutgoingAsyncBase + { + public ProxyGetConnection(Ice.ObjectPrxHelperBase prx, OutgoingAsyncCompletionCallback completionCallback) : + base(prx, completionCallback) + { + } + + public override int invokeRemote(Ice.ConnectionI connection, bool compress, bool response) + { + cachedConnection_ = connection; + if(responseImpl(true)) { - doCheck(false); - throw; + invokeResponseAsync(); } + return AsyncStatusSent; } - public void ready() + public override int invokeCollocated(CollocatedRequestHandler handler) { - doCheck(true); + if(responseImpl(true)) + { + invokeResponseAsync(); + } + return AsyncStatusSent; } - private void doCheck(bool userThread) + public void invoke(string operation) { - lock(this) + observer_ = ObserverHelper.get(proxy_, operation, null); + invokeImpl(true); // userThread = true + } + } + + class ConnectionFlushBatchAsync : OutgoingAsyncBase + { + public ConnectionFlushBatchAsync(Ice.ConnectionI connection, + Instance instance, + OutgoingAsyncCompletionCallback completionCallback) : + base(instance, completionCallback) + { + _connection = connection; + } + + public void invoke(string operation) + { + observer_ = ObserverHelper.get(instance_, operation); + try { - Debug.Assert(_useCount > 0); - if(--_useCount > 0) + int status; + int batchRequestNum = _connection.getBatchRequestQueue().swap(os_); + if(batchRequestNum == 0) { - return; + status = AsyncStatusSent; + if(sent()) + { + status = status | AsyncStatusInvokeSentCallback; + } + } + else + { + status = _connection.sendAsyncRequest(this, false, false, batchRequestNum); } - } - Ice.AsyncCallback sentCB = sent(true); - if(userThread) + if((status & AsyncStatusSent) != 0) + { + sentSynchronously_ = true; + if((status & AsyncStatusInvokeSentCallback) != 0) + { + invokeSent(); + } + } + } + catch(RetryException ex) { - sentSynchronously_ = true; - if(sentCB != null) + try + { + throw ex.get(); + } + catch(Ice.LocalException ee) { - invokeSent(sentCB); + if(exception(ee)) + { + invokeExceptionAsync(); + } } } - else + catch(Ice.Exception ex) { - if(sentCB != null) + if(exception(ex)) { - invokeSentAsync(sentCB); + invokeExceptionAsync(); } } } + private readonly Ice.ConnectionI _connection; + }; + + public class CommunicatorFlushBatchAsync : OutgoingAsyncBase + { class FlushBatch : OutgoingAsyncBase { - public FlushBatch(CommunicatorFlushBatch outAsync) : - base(outAsync.getCommunicator(), outAsync.instance_, outAsync.getOperation(), null) + public FlushBatch(CommunicatorFlushBatchAsync outAsync, + Instance instance, + Ice.Instrumentation.InvocationObserver observer) : base(instance, null) { _outAsync = outAsync; + _observer = observer; } - public override Ice.AsyncCallback sent() + public override bool + sent() { if(childObserver_ != null) { childObserver_.detach(); childObserver_ = null; } - _outAsync.doCheck(false); - return null; + _outAsync.check(false); + return false; } - public override Ice.AsyncCallback completed(Ice.Exception ex) + public override bool + exception(Ice.Exception ex) { if(childObserver_ != null) { @@ -936,233 +1278,289 @@ namespace IceInternal childObserver_.detach(); childObserver_ = null; } - _outAsync.doCheck(false); - return null; + _outAsync.check(false); + return false; } - protected override Ice.Instrumentation.InvocationObserver getObserver() + protected override Ice.Instrumentation.InvocationObserver + getObserver() { - return _outAsync.getObserver(); + return _observer; } - private CommunicatorFlushBatch _outAsync; - } - private int _useCount; - } - + private CommunicatorFlushBatchAsync _outAsync; + private Ice.Instrumentation.InvocationObserver _observer; + }; - public class ConnectionFlushBatch : OutgoingAsyncBase - { - public static ConnectionFlushBatch check(Ice.AsyncResult r, Ice.Connection con, string operation) + public CommunicatorFlushBatchAsync(Instance instance, OutgoingAsyncCompletionCallback callback) : + base(instance, callback) { - if(r != null && r.getConnection() != con) - { - throw new System.ArgumentException("Connection for call to end_" + operation + - " does not match connection that was used to call " + - "corresponding begin_" + operation + " method"); - } - return AsyncResultI.check<ConnectionFlushBatch>(r, operation); - } - - public ConnectionFlushBatch(Ice.ConnectionI con, Ice.Communicator communicator, Instance instance, string op, - object cookie) : - base(communicator, instance, op, cookie) - { - _connection = con; + // + // _useCount is initialized to 1 to prevent premature callbacks. + // The caller must invoke ready() after all flush requests have + // been initiated. + // + _useCount = 1; } - public override Ice.Connection getConnection() + public void flushConnection(Ice.ConnectionI con) { - return _connection; - } + lock(this) + { + ++_useCount; + } - public void invoke() - { try { - int batchRequestNum = _connection.getBatchRequestQueue().swap(os_); - - bool isSent = false; - Ice.AsyncCallback sentCB; + var flushBatch = new FlushBatch(this, instance_, _observer); + int batchRequestNum = con.getBatchRequestQueue().swap(flushBatch.getOs()); if(batchRequestNum == 0) { - isSent = true; - sentCB = sent(); + flushBatch.sent(); } else { - isSent = _connection.sendAsyncRequest(this, false, false, batchRequestNum, out sentCB); + con.sendAsyncRequest(flushBatch, false, false, batchRequestNum); } + } + catch(Ice.LocalException) + { + check(false); + throw; + } + } - if(isSent) - { - sentSynchronously_ = true; - if(sentCB != null) - { - invokeSent(sentCB); - } - } + public void invoke(string operation) + { + _observer = ObserverHelper.get(instance_, operation); + if(_observer != null) + { + _observer.attach(); } - catch(RetryException ex) + instance_.outgoingConnectionFactory().flushAsyncBatchRequests(this); + instance_.objectAdapterFactory().flushAsyncBatchRequests(this); + check(true); + } + + public void check(bool userThread) + { + lock(this) { - Ice.AsyncCallback cb = completed(ex.get()); - if(cb != null) + Debug.Assert(_useCount > 0); + if(--_useCount > 0) { - invokeCompletedAsync(cb); + return; } } - catch(Ice.Exception ex) + + if(sentImpl(true)) { - Ice.AsyncCallback cb = completed(ex); - if(cb != null) + if(userThread) { - invokeCompletedAsync(cb); + sentSynchronously_ = true; + invokeSent(); + } + else + { + invokeSentAsync(); } } } - private Ice.ConnectionI _connection; - } + private int _useCount; + private Ice.Instrumentation.InvocationObserver _observer; + }; - public class ProxyFlushBatch : ProxyOutgoingAsyncBase + public abstract class TaskCompletionCallback<T> : TaskCompletionSource<T>, OutgoingAsyncCompletionCallback { - public new static ProxyFlushBatch check(Ice.AsyncResult r, Ice.ObjectPrx prx, string operation) + public TaskCompletionCallback(System.IProgress<bool> progress, CancellationToken cancellationToken) { - return ProxyOutgoingAsyncBase.check<ProxyFlushBatch>(r, prx, operation); + _progress = progress; + _cancellationToken = cancellationToken; } - public ProxyFlushBatch(Ice.ObjectPrxHelperBase prx, string operation, object cookie) : - base(prx, operation, cookie) + public void init(OutgoingAsyncBase outgoing) { - observer_ = ObserverHelper.get(prx, operation); - _batchRequestNum = prx.getBatchRequestQueue__().swap(os_); + if(_cancellationToken.CanBeCanceled) + { + _cancellationToken.Register(outgoing.cancel); + } } - public override bool invokeRemote(Ice.ConnectionI con, bool compress, bool resp, out Ice.AsyncCallback sentCB) + public virtual bool handleSent(bool done, bool alreadySent) { - if(_batchRequestNum == 0) + if(done) { - sentCB = sent(); - return true; + SetResult(default(T)); } - cachedConnection_ = con; - return con.sendAsyncRequest(this, compress, false, _batchRequestNum, out sentCB); + return _progress != null && !alreadySent; // Invoke the sent callback only if not already invoked. } - public override bool invokeCollocated(CollocatedRequestHandler handler, out Ice.AsyncCallback sentCB) + public bool handleException(Ice.Exception ex) { - if(_batchRequestNum == 0) - { - sentCB = sent(); - return true; - } - return handler.invokeAsyncRequest(this, _batchRequestNum, false, out sentCB); + SetException(ex); + return false; } - public void invoke() + public abstract bool handleResponse(bool ok, OutgoingAsyncBase og); + + public void handleInvokeSent(bool sentSynchronously, OutgoingAsyncBase og) { - Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(proxy_.reference__().getProtocol())); - invokeImpl(true); // userThread = true + _progress.Report(sentSynchronously); } - private int _batchRequestNum; + public void handleInvokeException(Ice.Exception ex, OutgoingAsyncBase og) + { + Debug.Assert(false); + } + + public void handleInvokeResponse(bool ok, OutgoingAsyncBase og) + { + Debug.Assert(false); + } + + private readonly CancellationToken _cancellationToken; + private readonly System.IProgress<bool> _progress; } - public class ProxyGetConnection : ProxyOutgoingAsyncBase, Ice.AsyncResult<Ice.Callback_Object_ice_getConnection> + public class OperationTaskCompletionCallback<T> : TaskCompletionCallback<T> { - public new static ProxyGetConnection check(Ice.AsyncResult r, Ice.ObjectPrx prx, string operation) + public OperationTaskCompletionCallback(System.IProgress<bool> progress, CancellationToken cancellationToken) : + base(progress, cancellationToken) { - return ProxyOutgoingAsyncBase.check<ProxyGetConnection>(r, prx, operation); } - public ProxyGetConnection(Ice.ObjectPrxHelperBase prx, string operation, - ProxyTwowayCallback<Ice.Callback_Object_ice_getConnection> cb, object cookie) : - base(prx, operation, cookie) + public override bool handleResponse(bool ok, OutgoingAsyncBase og) { - observer_ = ObserverHelper.get(prx, operation); - _completed = cb; + SetResult(((OutgoingAsyncT<T>)og).result__(ok)); + return false; } + } - public override bool invokeRemote(Ice.ConnectionI con, bool compress, bool resp, out Ice.AsyncCallback sentCB) + public class FlushBatchTaskCompletionCallback : TaskCompletionCallback<object> + { + public FlushBatchTaskCompletionCallback(System.IProgress<bool> progress, CancellationToken cancellationToken) : + base(progress, cancellationToken) { - sentCB = null; - cachedConnection_ = con; - Ice.AsyncCallback cb = finished(true); - if(cb != null) - { - invokeCompletedAsync(cb); - } - return true; } - public override bool invokeCollocated(CollocatedRequestHandler handler, out Ice.AsyncCallback sentCB) + public override bool handleResponse(bool ok, OutgoingAsyncBase og) { - sentCB = null; - Ice.AsyncCallback cb = finished(true); - if(cb != null) - { - invokeCompletedAsync(cb); - } - return true; + SetResult(null); + return false; } + } - public void invoke() + abstract public class AsyncResultCompletionCallback : AsyncResultI, OutgoingAsyncCompletionCallback + { + public AsyncResultCompletionCallback(Ice.Communicator com, Instance instance, string op, object cookie, + Ice.AsyncCallback cb) : + base(com, instance, op, cookie, cb) { - invokeImpl(true); // userThread = true } - new public Ice.AsyncResult<Ice.Callback_Object_ice_getConnection> whenCompleted(Ice.ExceptionCallback excb) + public void init(OutgoingAsyncBase outgoing) { - base.whenCompleted(excb); - return this; + outgoing_ = outgoing; } - virtual public Ice.AsyncResult<Ice.Callback_Object_ice_getConnection> - whenCompleted(Ice.Callback_Object_ice_getConnection cb, Ice.ExceptionCallback excb) + public bool handleSent(bool done, bool alreadySent) { - if(cb == null && excb == null) + lock(this) { - throw new System.ArgumentException("callback is null"); + state_ |= StateSent; + if(done) + { + state_ |= StateDone | StateOK; + } + if(waitHandle_ != null) + { + waitHandle_.Set(); + } + Monitor.PulseAll(this); + + // + // Invoke the sent callback only if not already invoked. + // + return !alreadySent && sentCallback_ != null; } + } + + public bool handleException(Ice.Exception ex) + { lock(this) { - if(_responseCallback != null || exceptionCallback_ != null) + state_ |= StateDone; + exception_ = ex; + if(waitHandle_ != null) { - throw new System.ArgumentException("callback already set"); + waitHandle_.Set(); } - _responseCallback = cb; - exceptionCallback_ = excb; + Monitor.PulseAll(this); + return completedCallback_ != null; } - setCompletedCallback(getCompletedCallback()); - return this; } - new public Ice.AsyncResult<Ice.Callback_Object_ice_getConnection> whenSent(Ice.SentCallback cb) + public bool handleResponse(bool ok, OutgoingAsyncBase og) { - base.whenSent(cb); - return this; + lock(this) + { + state_ |= StateDone; + if(ok) + { + state_ |= StateOK; + } + if(waitHandle_ != null) + { + waitHandle_.Set(); + } + Monitor.PulseAll(this); + return completedCallback_ != null; + } } - protected override Ice.AsyncCallback getCompletedCallback() + public void handleInvokeSent(bool sentSynchronously, OutgoingAsyncBase og) { - return (Ice.AsyncResult result) => { _completed(this, _responseCallback, exceptionCallback_); }; + sentCallback_(this); } - private ProxyTwowayCallback<Ice.Callback_Object_ice_getConnection> _completed; - private Ice.Callback_Object_ice_getConnection _responseCallback = null; + public void handleInvokeException(Ice.Exception ex, OutgoingAsyncBase og) + { + try + { + completedCallback_(this); + } + catch(Ice.Exception e) + { + throw new System.AggregateException(e); + } + } + + public void handleInvokeResponse(bool ok, OutgoingAsyncBase og) + { + try + { + completedCallback_(this); + } + catch(Ice.Exception e) + { + throw new System.AggregateException(e); + } + } } - public abstract class OutgoingAsync<T> : OutgoingAsync, Ice.AsyncResult<T> + abstract public class ProxyAsyncResultCompletionCallback<T> : AsyncResultCompletionCallback, Ice.AsyncResult<T> { - public OutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, object cookie) : - base(prx, operation, cookie) + public ProxyAsyncResultCompletionCallback(Ice.ObjectPrxHelperBase proxy, string operation, object cookie, + Ice.AsyncCallback cb) : + base(proxy.ice_getCommunicator(), proxy.reference__().getInstance(), operation, cookie, cb) { + _proxy = proxy; } - public OutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, object cookie, Ice.InputStream iss, - Ice.OutputStream os) : - base(prx, operation, cookie, iss, os) + public override Ice.ObjectPrx getProxy() { + return _proxy; } new public Ice.AsyncResult<T> whenCompleted(Ice.ExceptionCallback excb) @@ -1197,73 +1595,45 @@ namespace IceInternal } protected T responseCallback_; + private Ice.ObjectPrx _proxy; } - public class TwowayOutgoingAsync<T> : OutgoingAsync<T> - { - public TwowayOutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, ProxyTwowayCallback<T> cb, - object cookie) : - base(prx, operation, cookie) - { - Debug.Assert(cb != null); - _completed = cb; - } - - public TwowayOutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, ProxyTwowayCallback<T> cb, - object cookie, Ice.InputStream iss, Ice.OutputStream os) : - base(prx, operation, cookie, iss, os) - { - Debug.Assert(cb != null); - _completed = cb; - } - - override protected Ice.AsyncCallback getCompletedCallback() - { - return (Ice.AsyncResult result) => { _completed(this, responseCallback_, exceptionCallback_); }; - } - - private ProxyTwowayCallback<T> _completed; - } - - public class OnewayOutgoingAsync<T> : OutgoingAsync<T> + public class OperationAsyncResultCompletionCallback<T, R> : ProxyAsyncResultCompletionCallback<T> { - public OnewayOutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, ProxyOnewayCallback<T> cb, - object cookie) : - base(prx, operation, cookie) + public OperationAsyncResultCompletionCallback(System.Action<T, R> completed, + Ice.ObjectPrxHelperBase proxy, + string operation, + object cookie, + Ice.AsyncCallback callback) : + base(proxy, operation, cookie, callback) { - Debug.Assert(cb != null); - _completed = cb; - } - - public OnewayOutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, ProxyOnewayCallback<T> cb, - object cookie, Ice.InputStream iss, Ice.OutputStream os) : - base(prx, operation, cookie, iss, os) - { - Debug.Assert(cb != null); - _completed = cb; + _completed = completed; } override protected Ice.AsyncCallback getCompletedCallback() { - return (Ice.AsyncResult result) => + return (Ice.AsyncResult r) => { + Debug.Assert(r == this); try { - IceInternal.OutgoingAsync outAsync__ = (IceInternal.OutgoingAsync)result; - ((Ice.ObjectPrxHelperBase)(outAsync__.getProxy())).end__(outAsync__, outAsync__.getOperation()); - } - catch(Ice.Exception ex__) - { - if(exceptionCallback_ != null) + R result = ((OutgoingAsyncT<R>)outgoing_).result__(wait()); + try { - exceptionCallback_(ex__); + _completed(responseCallback_, result); } - return; + catch(Ice.Exception ex) + { + throw new System.AggregateException(ex); + } + } + catch(Ice.Exception ex) + { + exceptionCallback_?.Invoke(ex); } - _completed(responseCallback_); }; } - private ProxyOnewayCallback<T> _completed; + private System.Action<T, R> _completed; } } diff --git a/csharp/src/Ice/Proxy.cs b/csharp/src/Ice/Proxy.cs index c912662cbdc..e79d6bdfe62 100644 --- a/csharp/src/Ice/Proxy.cs +++ b/csharp/src/Ice/Proxy.cs @@ -10,7 +10,11 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; + using IceUtilInternal; +using IceInternal; namespace Ice { @@ -52,6 +56,43 @@ namespace Ice public delegate void Callback_Object_ice_getConnection(Connection ret__); /// <summary> + /// Value type to allow differenciate between a context that is explicity set to + /// empty (empty or null dictionary) and a context that has non been set. + /// </summary> + public struct OptionalContext + { + private OptionalContext(Dictionary<string, string> ctx) + { + _ctx = ctx == null ? _emptyContext : ctx; + } + + /// <summary> + /// Implicit conversion between Dictionary<string, string> and + /// OptionalContext. + /// </summary> + /// <param name="ctx">Dictionary to convert.</param> + /// <returns>OptionalContext value representing the dictionary</returns> + public static implicit operator OptionalContext(Dictionary<string, string> ctx) + { + return new OptionalContext(ctx); + } + + /// <summary> + /// Implicit conversion between OptionalContext and + /// Dictionary<string, string> + /// </summary> + /// <param name="value">OptionalContext value to convert</param> + /// <returns>The Dictionary object.</returns> + public static implicit operator Dictionary<string, string>(OptionalContext value) + { + return value._ctx; + } + + private Dictionary<string, string> _ctx; + static private Dictionary<string, string> _emptyContext = new Dictionary<string, string>(); + } + + /// <summary> /// Base interface of all object proxies. /// </summary> public interface ObjectPrx @@ -65,225 +106,204 @@ namespace Ice /// <summary> /// Tests whether this object supports a specific Slice interface. /// </summary> - /// <param name="id__">The type ID of the Slice interface to test against.</param> - /// <returns>True if the target object has the interface specified by id__ or derives - /// from the interface specified by id__.</returns> - bool ice_isA(string id__); - - /// <summary> - /// Tests whether this object supports a specific Slice interface. - /// </summary> - /// <param name="id__">The type ID of the Slice interface to test against.</param> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <returns>True if the target object has the interface specified by id__ or derives - /// from the interface specified by id__.</returns> - bool ice_isA(string id__, Dictionary<string, string> context__); + /// <param name="id">The type ID of the Slice interface to test against.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <returns>True if the target object has the interface specified by id or derives + /// from the interface specified by id.</returns> + bool ice_isA(string id, OptionalContext context = new OptionalContext()); /// <summary> /// Tests whether this object supports a specific Slice interface. /// </summary> /// <param name="id">The type ID of the Slice interface to test against.</param> - /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_isA> begin_ice_isA(string id); - + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + Task<bool> ice_isAAsync(string id, + OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()); /// <summary> /// Tests whether this object supports a specific Slice interface. /// </summary> /// <param name="id">The type ID of the Slice interface to test against.</param> - /// <param name="context__">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_isA> begin_ice_isA(string id, Dictionary<string, string> context__); + AsyncResult begin_ice_isA(string id, AsyncCallback callback, object cookie); /// <summary> /// Tests whether this object supports a specific Slice interface. /// </summary> /// <param name="id">The type ID of the Slice interface to test against.</param> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_isA(string id, AsyncCallback cb__, object cookie__); + AsyncResult begin_ice_isA(string id, OptionalContext context, AsyncCallback callback, object cookie); /// <summary> /// Tests whether this object supports a specific Slice interface. /// </summary> /// <param name="id">The type ID of the Slice interface to test against.</param> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_isA(string id, Dictionary<string, string> context__, AsyncCallback cb__, object cookie__); + AsyncResult<Callback_Object_ice_isA> begin_ice_isA(string id, OptionalContext context = new OptionalContext()); /// <summary> /// Tests whether this object supports a specific Slice interface. /// </summary> - /// <param name="r__">The asynchronous result object returned by <code>begin_ice_isA</code>.</param> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_isA</code>.</param> /// <returns>True if the object supports the Slice interface, false otherwise.</returns> - bool end_ice_isA(AsyncResult r__); - - /// <summary> - /// Tests whether the target object of this proxy can be reached. - /// </summary> - void ice_ping(); + bool end_ice_isA(AsyncResult result); /// <summary> /// Tests whether the target object of this proxy can be reached. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> - void ice_ping(Dictionary<string, string> context__); + /// <param name="context">The context dictionary for the invocation.</param> + void ice_ping(OptionalContext context = new OptionalContext()); /// <summary> /// Tests whether the target object of this proxy can be reached. /// </summary> - /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_ping> begin_ice_ping(); + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + Task ice_pingAsync(OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()); /// <summary> /// Tests whether the target object of this proxy can be reached. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_ping> begin_ice_ping(Dictionary<string, string> context__); + AsyncResult begin_ice_ping(AsyncCallback callback, object cookie); /// <summary> /// Tests whether the target object of this proxy can be reached. /// </summary> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_ping(AsyncCallback cb__, object cookie__); + AsyncResult begin_ice_ping(OptionalContext context, AsyncCallback callback, object cookie); /// <summary> /// Tests whether the target object of this proxy can be reached. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_ping(Dictionary<string, string> context__, AsyncCallback cb__, object cookie__); + AsyncResult<Callback_Object_ice_ping> begin_ice_ping(OptionalContext context = new OptionalContext()); /// <summary> /// Tests whether the target object of this proxy can be reached. /// </summary> - /// <param name="r__">The asynchronous result object returned by <code>begin_ice_ping</code>.</param> - void end_ice_ping(AsyncResult r__); - - /// <summary> - /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. - /// </summary> - /// <returns>The Slice type IDs of the interfaces supported by the target object, in base-to-derived - /// order. The first element of the returned array is always ::Ice::Object.</returns> - string[] ice_ids(); + /// <param name="result">The asynchronous result object returned by <code>begin_ice_ping</code>.</param> + void end_ice_ping(AsyncResult result); /// <summary> /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>The Slice type IDs of the interfaces supported by the target object, in base-to-derived /// order. The first element of the returned array is always ::Ice::Object.</returns> - string[] ice_ids(Dictionary<string, string> context__); + string[] ice_ids(OptionalContext context = new OptionalContext()); /// <summary> /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. /// </summary> - /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_ids> begin_ice_ids(); + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + Task<string[]> ice_idsAsync(OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()); /// <summary> /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_ids> begin_ice_ids(Dictionary<string, string> context__); + AsyncResult begin_ice_ids(AsyncCallback callback, object cookie); /// <summary> /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. /// </summary> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_ids(AsyncCallback cb__, object cookie__); + AsyncResult begin_ice_ids(OptionalContext context, AsyncCallback callback, object cookie); /// <summary> /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_ids(Dictionary<string, string> context__, AsyncCallback cb__, object cookie__); + AsyncResult<Callback_Object_ice_ids> begin_ice_ids(OptionalContext context = new OptionalContext()); /// <summary> /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. /// </summary> - /// <param name="r__">The asynchronous result object returned by <code>begin_ice_ids</code>.</param> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_ids</code>.</param> /// <returns>The Slice type IDs of the interfaces supported by the target object, in base-to-derived /// order. The first element of the returned array is always ::Ice::Object.</returns> - string[] end_ice_ids(AsyncResult r__); + string[] end_ice_ids(AsyncResult result); /// <summary> /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. /// </summary> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>The Slice type ID of the most-derived interface.</returns> - string ice_id(); - - /// <summary> - /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. - /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <returns>The Slice type ID of the most-derived interface.</returns> - string ice_id(Dictionary<string, string> context__); + string ice_id(OptionalContext context = new OptionalContext()); /// <summary> /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. /// </summary> - /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_id> begin_ice_id(); + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + Task<string> ice_idAsync(OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()); /// <summary> /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_id> begin_ice_id(Dictionary<string, string> context__); + AsyncResult begin_ice_id(AsyncCallback callback, object cookie); /// <summary> /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. /// </summary> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_id(AsyncCallback cb__, object cookie__); + AsyncResult begin_ice_id(OptionalContext context, AsyncCallback callback, object cookie); /// <summary> /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_id(Dictionary<string, string> context__, AsyncCallback cb__, object cookie__); + AsyncResult<Callback_Object_ice_id> begin_ice_id(OptionalContext context = new OptionalContext()); /// <summary> /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. /// </summary> - /// <param name="r__">The asynchronous result object returned by <code>begin_ice_id</code>.</param> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_id</code>.</param> /// <returns>The Slice type ID of the most-derived interface.</returns> - string end_ice_id(AsyncResult r__); - - /// <summary> - /// Invokes an operation dynamically. - /// </summary> - /// <param name="operation">The name of the operation to invoke.</param> - /// <param name="mode">The operation mode (normal or idempotent).</param> - /// <param name="inEncaps">The encoded in-parameters for the operation.</param> - /// <param name="outEncaps">The encoded out-paramaters and return value - /// for the operation. The return value follows any out-parameters.</param> - /// <returns>If the operation completed successfully, the return value - /// is true. If the operation raises a user exception, - /// the return value is false; in this case, outEncaps - /// contains the encoded user exception. If the operation raises a run-time exception, - /// it throws it directly.</returns> - bool ice_invoke(string operation, OperationMode mode, byte[] inEncaps, out byte[] outEncaps); + string end_ice_id(AsyncResult result); /// <summary> /// Invokes an operation dynamically. @@ -293,14 +313,14 @@ namespace Ice /// <param name="inEncaps">The encoded in-parameters for the operation.</param> /// <param name="outEncaps">The encoded out-paramaters and return value /// for the operation. The return value follows any out-parameters.</param> - /// <param name="context__">The context dictionary for the invocation.</param> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>If the operation completed successfully, the return value /// is true. If the operation raises a user exception, /// the return value is false; in this case, outEncaps /// contains the encoded user exception. If the operation raises a run-time exception, /// it throws it directly.</returns> bool ice_invoke(string operation, OperationMode mode, byte[] inEncaps, out byte[] outEncaps, - Dictionary<string, string> context__); + OptionalContext context = new OptionalContext()); /// <summary> /// Invokes an operation dynamically. @@ -308,9 +328,17 @@ namespace Ice /// <param name="operation">The name of the operation to invoke.</param> /// <param name="mode">The operation mode (normal or idempotent).</param> /// <param name="inEncaps">The encoded in-parameters for the operation.</param> - /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_invoke> begin_ice_invoke(string operation, OperationMode mode, - byte[] inEncaps); + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + Task<Object_Ice_invokeResult> + ice_invokeAsync(string operation, + OperationMode mode, + byte[] inEncaps, + OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()); /// <summary> /// Invokes an operation dynamically. @@ -318,11 +346,14 @@ namespace Ice /// <param name="operation">The name of the operation to invoke.</param> /// <param name="mode">The operation mode (normal or idempotent).</param> /// <param name="inEncaps">The encoded in-parameters for the operation.</param> - /// <param name="context__">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_invoke> begin_ice_invoke(string operation, OperationMode mode, - byte[] inEncaps, - Dictionary<string, string> context__); + AsyncResult begin_ice_invoke(string operation, + OperationMode mode, + byte[] inEncaps, + AsyncCallback callback, + object cookie); /// <summary> /// Invokes an operation dynamically. @@ -330,11 +361,16 @@ namespace Ice /// <param name="operation">The name of the operation to invoke.</param> /// <param name="mode">The operation mode (normal or idempotent).</param> /// <param name="inEncaps">The encoded in-parameters for the operation.</param> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_invoke(string operation, OperationMode mode, byte[] inEncaps, AsyncCallback cb__, - object cookie__); + AsyncResult begin_ice_invoke(string operation, + OperationMode mode, + byte[] inEncaps, + OptionalContext context, + AsyncCallback callback, + object cookie); /// <summary> /// Invokes an operation dynamically. @@ -342,24 +378,24 @@ namespace Ice /// <param name="operation">The name of the operation to invoke.</param> /// <param name="mode">The operation mode (normal or idempotent).</param> /// <param name="inEncaps">The encoded in-parameters for the operation.</param> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_invoke(string operation, OperationMode mode, byte[] inEncaps, - Dictionary<string, string> context__, AsyncCallback cb__, object cookie__); + AsyncResult<Callback_Object_ice_invoke> begin_ice_invoke(string operation, + OperationMode mode, + byte[] inEncaps, + OptionalContext context = new OptionalContext()); /// <summary> /// Completes a dynamic invocation. /// </summary> /// <param name="outEncaps">The encoded out parameters or user exception.</param> - /// <param name="r__">The asynchronous result object returned by <code>begin_ice_invoke</code>.</param> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_invoke</code>.</param> /// <returns>If the operation completed successfully, the return value /// is true. If the operation raises a user exception, /// the return value is false; in this case, outEncaps /// contains the encoded user exception. If the operation raises a run-time exception, /// it throws it directly.</returns> - bool end_ice_invoke(out byte[] outEncaps, AsyncResult r__); + bool end_ice_invoke(out byte[] outEncaps, AsyncResult result); /// <summary> /// Returns the identity embedded in this proxy. @@ -500,11 +536,11 @@ namespace Ice /// </summary> /// <param name="e">The encoding version to use to marshal requests parameters.</param> /// <returns>The new proxy with the specified encoding version.</returns> - ObjectPrx ice_encodingVersion(Ice.EncodingVersion e); + ObjectPrx ice_encodingVersion(EncodingVersion e); /// <summary>Returns the encoding version used to marshal requests parameters.</summary> /// <returns>The encoding version.</returns> - Ice.EncodingVersion ice_getEncodingVersion(); + EncodingVersion ice_getEncodingVersion(); /// <summary> /// Returns whether this proxy prefers secure endpoints. @@ -527,27 +563,27 @@ namespace Ice /// </summary> /// <returns>The router for the proxy. If no router is configured for the proxy, the return value /// is null.</returns> - Ice.RouterPrx ice_getRouter(); + RouterPrx ice_getRouter(); /// <summary> /// Creates a new proxy that is identical to this proxy, except for the router. /// </summary> /// <param name="router">The router for the new proxy.</param> /// <returns>The new proxy with the specified router.</returns> - ObjectPrx ice_router(Ice.RouterPrx router); + ObjectPrx ice_router(RouterPrx router); /// <summary> /// Returns the locator for this proxy. /// </summary> /// <returns>The locator for this proxy. If no locator is configured, the return value is null.</returns> - Ice.LocatorPrx ice_getLocator(); + LocatorPrx ice_getLocator(); /// <summary> /// Creates a new proxy that is identical to this proxy, except for the locator. /// </summary> /// <param name="locator">The locator for the new proxy.</param> /// <returns>The new proxy with the specified locator.</returns> - ObjectPrx ice_locator(Ice.LocatorPrx locator); + ObjectPrx ice_locator(LocatorPrx locator); /// <summary> /// Returns whether this proxy uses collocation optimization. @@ -662,23 +698,32 @@ namespace Ice /// <summary> /// Asynchronously gets the connection for this proxy. /// </summary> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + Task<Connection> ice_getConnectionAsync(IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()); + + /// <summary> + /// Asynchronously gets the connection for this proxy. + /// </summary> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult<Callback_Object_ice_getConnection> begin_ice_getConnection(); + AsyncResult begin_ice_getConnection(AsyncCallback callback, object cookie); /// <summary> /// Asynchronously gets the connection for this proxy. /// </summary> - /// <param name="cb__">A callback to be invoked when the invocation completes.</param> - /// <param name="cookie__">Application-specific data to be stored in the result.</param> /// <returns>An asynchronous result object.</returns> - AsyncResult begin_ice_getConnection(AsyncCallback cb__, object cookie__); + AsyncResult<Callback_Object_ice_getConnection> begin_ice_getConnection(); /// <summary> /// Asynchronously gets the connection for this proxy. /// </summary> - /// <param name="r__">The asynchronous result object returned by <code>begin_ice_getConnection</code>.</param> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_getConnection</code>.</param> /// <returns>The connection.</returns> - Connection end_ice_getConnection(AsyncResult r__); + Connection end_ice_getConnection(AsyncResult result); /// <summary> /// Returns the cached Connection for this proxy. If the proxy does not yet have an established @@ -691,19 +736,61 @@ namespace Ice Connection ice_getCachedConnection(); /// <summary> - /// Flushes any pending batched requests for this communicator. The call blocks until the flush is complete. + /// Flushes any pending batched requests for this proxy. The call blocks until the flush is complete. /// </summary> void ice_flushBatchRequests(); - AsyncResult begin_ice_flushBatchRequests(); - AsyncResult begin_ice_flushBatchRequests(AsyncCallback cb__, object cookie__); + /// <summary> + /// Asynchronously flushes any pending batched requests for this proxy. + /// </summary> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + Task ice_flushBatchRequestsAsync(IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()); + + /// <summary> + /// Asynchronously flushes any pending batched requests for this proxy. + /// </summary> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + AsyncResult begin_ice_flushBatchRequests(AsyncCallback callback = null, object cookie = null); - void end_ice_flushBatchRequests(AsyncResult r__); + /// <summary> + /// Flushes any pending batched requests for this proxy. The call blocks until the flush is complete. + /// </summary> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_getConnection</code>.</param> + void end_ice_flushBatchRequests(AsyncResult result); + /// <summary> + /// Write a proxy to the output stream. + /// </summary> + /// <param name="os">Output stream object to write the proxy.</param> void write__(OutputStream os); } /// <summary> + /// Represent the result of the ice_invokeAsync operation + /// </summary> + public struct Object_Ice_invokeResult + { + /// <summary> + /// If the operation completed successfully, the return value + /// is true. If the operation raises a user exception, + /// the return value is false; in this case, outEncaps + /// contains the encoded user exception. + /// </summary> + public bool returnValue; + + /// <summary> + /// The encoded out-paramaters and return value for the operation. + /// The return value follows any out-parameters. If returnValue is + /// false it contains the encoded user exception. + /// </summary> + public byte[] outEncaps; + }; + + /// <summary> /// Base class of all object proxies. /// </summary> public class ObjectPrxHelperBase : ObjectPrx @@ -738,553 +825,452 @@ namespace Ice /// <summary> /// Tests whether this object supports a specific Slice interface. /// </summary> - /// <param name="id__">The type ID of the Slice interface to test against.</param> - /// <returns>True if the target object has the interface specified by id__ or derives - /// from the interface specified by id__.</returns> - public bool ice_isA(string id__) + /// <param name="id">The type ID of the Slice interface to test against.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <returns>True if the target object has the interface specified by id or derives + /// from the interface specified by id.</returns> + public bool ice_isA(string id, OptionalContext context = new OptionalContext()) { - return ice_isA(id__, null, false); + try + { + return ice_isAAsync(id, context, null, CancellationToken.None, true).Result; + } + catch(AggregateException ex) + { + throw ex.InnerException; + } } /// <summary> /// Tests whether this object supports a specific Slice interface. /// </summary> - /// <param name="id__">The type ID of the Slice interface to test against.</param> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <returns>True if the target object has the interface specified by id__ or derives - /// from the interface specified by id__.</returns> - public bool ice_isA(string id__, Dictionary<string, string> context__) - { - return ice_isA(id__, context__, true); - } - - private bool ice_isA(string id__, Dictionary<string, string> context__, bool explicitCtx__) + /// <param name="id">The type ID of the Slice interface to test against.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + public Task<bool> ice_isAAsync(string id, + OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()) { - checkTwowayOnly__(__ice_isA_name); - return end_ice_isA(begin_ice_isA(id__, context__, explicitCtx__, true, null, null)); + return ice_isAAsync(id, context, progress, cancel, false); } - public AsyncResult<Callback_Object_ice_isA> begin_ice_isA(string id) + private Task<bool> + ice_isAAsync(string id, OptionalContext context, IProgress<bool> progress, CancellationToken cancel, + bool synchronous) { - return begin_ice_isA(id, null, false, false, null, null); + var completed = new OperationTaskCompletionCallback<bool>(progress, cancel); + ice_isA_invoke__(id, context, completed, synchronous); + return completed.Task; } - public AsyncResult<Callback_Object_ice_isA> begin_ice_isA(string id, Dictionary<string, string> context__) + /// <summary> + /// Tests whether this object supports a specific Slice interface. + /// </summary> + /// <param name="id">The type ID of the Slice interface to test against.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult begin_ice_isA(string id, AsyncCallback callback, object cookie) { - return begin_ice_isA(id, context__, true, false, null, null); + return begin_ice_isA(id, new OptionalContext(), callback, cookie, false); } - public AsyncResult begin_ice_isA(string id, AsyncCallback cb__, object cookie__) + /// <summary> + /// Tests whether this object supports a specific Slice interface. + /// </summary> + /// <param name="id">The type ID of the Slice interface to test against.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult begin_ice_isA(string id, OptionalContext context, AsyncCallback callback, object cookie) { - return begin_ice_isA(id, null, false, false, cb__, cookie__); + return begin_ice_isA(id, context, callback, cookie, false); } - public AsyncResult begin_ice_isA(string id, Dictionary<string, string> context__, AsyncCallback cb__, - object cookie__) + /// <summary> + /// Tests whether this object supports a specific Slice interface. + /// </summary> + /// <param name="id">The type ID of the Slice interface to test against.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult<Callback_Object_ice_isA> + begin_ice_isA(string id, OptionalContext context = new OptionalContext()) { - return begin_ice_isA(id, context__, true, false, cb__, cookie__); + return begin_ice_isA(id, context, null, null, false); } internal const string __ice_isA_name = "ice_isA"; - public bool end_ice_isA(AsyncResult r__) + /// <summary> + /// Tests whether this object supports a specific Slice interface. + /// </summary> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_isA</code>.</param> + /// <returns>True if the object supports the Slice interface, false otherwise.</returns> + public bool end_ice_isA(AsyncResult result) { - IceInternal.OutgoingAsync outAsync__ = IceInternal.OutgoingAsync.check(r__, this, __ice_isA_name); - try - { - if(!outAsync__.wait()) - { - try - { - outAsync__.throwUserException(); - } - catch(Ice.UserException ex__) - { - throw new Ice.UnknownUserException(ex__.ice_id(), ex__); - } - } - bool ret__; - InputStream is__ = outAsync__.startReadParams(); - ret__ = is__.readBool(); - outAsync__.endReadParams(); - return ret__; - } - finally - { - if(outAsync__ != null) - { - outAsync__.cacheMessageBuffers(); - } - } + var resultI = AsyncResultI.check(result, this, __ice_isA_name); + return ((OutgoingAsyncT<bool>)resultI.OutgoingAsync).result__(resultI.wait()); } - private AsyncResult<Callback_Object_ice_isA> begin_ice_isA(string id, - Dictionary<string, string> context__, - bool explicitCtx__, - bool synchronous__, - Ice.AsyncCallback cb__, - object cookie__) + private AsyncResult<Callback_Object_ice_isA> + begin_ice_isA(string id, Dictionary<string, string> context, AsyncCallback callback, object cookie, + bool synchronous) { - checkAsyncTwowayOnly__(__ice_isA_name); - - IceInternal.TwowayOutgoingAsync<Callback_Object_ice_isA> result__ = - getTwowayOutgoingAsync<Callback_Object_ice_isA>(__ice_isA_name, ice_isA_completed__, cookie__); - if(cb__ != null) - { - result__.whenCompletedWithAsyncCallback(cb__); - } - - try - { - result__.prepare(__ice_isA_name, OperationMode.Nonmutating, context__, explicitCtx__, synchronous__); - OutputStream os__ = result__.startWriteParams(FormatType.DefaultFormat); - os__.writeString(id); - result__.endWriteParams(); - result__.invoke(); - } - catch(Ice.Exception ex__) - { - result__.abort(ex__); - } - return result__; + var completed = new OperationAsyncResultCompletionCallback<Callback_Object_ice_isA, bool>( + (Callback_Object_ice_isA cb, bool result) => + { + cb?.Invoke(result); + }, this, __ice_isA_name, cookie, callback); + ice_isA_invoke__(id, context, completed, synchronous); + return completed; } - protected IceInternal.TwowayOutgoingAsync<T> - getTwowayOutgoingAsync<T>(string operation, IceInternal.ProxyTwowayCallback<T> cb, object cookie) + private void ice_isA_invoke__(string id, + Dictionary<string, string> context, + OutgoingAsyncCompletionCallback completed, + bool synchronous) { - bool haveEntry = false; - InputStream iss = null; - OutputStream os = null; - - if(_reference.getInstance().cacheMessageBuffers() > 0) - { - lock(this) - { - if(_streamCache != null && _streamCache.Count > 0) - { - haveEntry = true; - iss = _streamCache.First.Value.iss; - os = _streamCache.First.Value.os; - - _streamCache.RemoveFirst(); - } - } - } - if(!haveEntry) - { - return new IceInternal.TwowayOutgoingAsync<T>(this, operation, cb, cookie); - } - else - { - return new IceInternal.TwowayOutgoingAsync<T>(this, operation, cb, cookie, iss, os); - } + checkAsyncTwowayOnly__(__ice_isA_name); + getOutgoingAsync<bool>(completed).invoke(__ice_isA_name, + OperationMode.Nonmutating, + FormatType.DefaultFormat, + context, + synchronous, + (OutputStream os) => { os.writeString(id); }, + null, + (InputStream iss) => { return iss.readBool(); }); } - protected IceInternal.OnewayOutgoingAsync<T> - getOnewayOutgoingAsync<T>(string operation, IceInternal.ProxyOnewayCallback<T> cb, object cookie) + /// <summary> + /// Tests whether the target object of this proxy can be reached. + /// </summary> + /// <param name="context">The context dictionary for the invocation.</param> + public void ice_ping(OptionalContext context = new OptionalContext()) { - bool haveEntry = false; - InputStream iss = null; - OutputStream os = null; - - if(_reference.getInstance().cacheMessageBuffers() > 0) - { - lock(this) - { - if(_streamCache != null && _streamCache.Count > 0) - { - haveEntry = true; - iss = _streamCache.First.Value.iss; - os = _streamCache.First.Value.os; - _streamCache.RemoveFirst(); - } - } - } - if(!haveEntry) + try { - return new IceInternal.OnewayOutgoingAsync<T>(this, operation, cb, cookie); + ice_pingAsync(context, null, CancellationToken.None, true).Wait(); } - else + catch(AggregateException ex) { - return new IceInternal.OnewayOutgoingAsync<T>(this, operation, cb, cookie, iss, os); + throw ex.InnerException; } } - public void - cacheMessageBuffers(InputStream iss, OutputStream os) + /// <summary> + /// Tests whether the target object of this proxy can be reached. + /// </summary> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + public Task ice_pingAsync(OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()) { - lock(this) - { - if(_streamCache == null) - { - _streamCache = new LinkedList<StreamCacheEntry>(); - } - StreamCacheEntry cacheEntry; - cacheEntry.iss = iss; - cacheEntry.os = os; - _streamCache.AddLast(cacheEntry); - } + return ice_pingAsync(context, progress, cancel, false); } - private void ice_isA_completed__(AsyncResult r__, Callback_Object_ice_isA cb__, Ice.ExceptionCallback excb__) + private Task + ice_pingAsync(OptionalContext context, IProgress<bool> progress, CancellationToken cancel, bool synchronous) { - bool ret__; - try - { - ret__ = end_ice_isA(r__); - } - catch(Ice.Exception ex__) - { - if(excb__ != null) - { - excb__(ex__); - } - return; - } - if(cb__ != null) - { - cb__(ret__); - } + var completed = new OperationTaskCompletionCallback<object>(progress, cancel); + ice_ping_invoke__(context, completed, synchronous); + return completed.Task; } /// <summary> /// Tests whether the target object of this proxy can be reached. /// </summary> - public void ice_ping() + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult begin_ice_ping(AsyncCallback callback, object cookie) { - ice_ping(null, false); + return begin_ice_ping(new OptionalContext(), callback, cookie, false); } /// <summary> /// Tests whether the target object of this proxy can be reached. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> - public void ice_ping(Dictionary<string, string> context__) - { - ice_ping(context__, true); - } - - private void ice_ping(Dictionary<string, string> context__, bool explicitCtx__) - { - end_ice_ping(begin_ice_ping(context__, explicitCtx__, true, null, null)); - } - - public AsyncResult<Callback_Object_ice_ping> begin_ice_ping() - { - return begin_ice_ping(null, false, false, null, null); - } - - public AsyncResult<Callback_Object_ice_ping> begin_ice_ping(Dictionary<string, string> context__) - { - return begin_ice_ping(context__, true, false, null, null); - } - - public AsyncResult begin_ice_ping(AsyncCallback cb__, object cookie__) + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult begin_ice_ping(OptionalContext context, AsyncCallback callback, object cookie) { - return begin_ice_ping(null, false, false, cb__, cookie__); + return begin_ice_ping(context, callback, cookie, false); } - public AsyncResult begin_ice_ping(Dictionary<string, string> context__, AsyncCallback cb__, object cookie__) + /// <summary> + /// Tests whether the target object of this proxy can be reached. + /// </summary> + /// <param name="context">The context dictionary for the invocation.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult<Callback_Object_ice_ping> + begin_ice_ping(OptionalContext context = new OptionalContext()) { - return begin_ice_ping(null, false, false, cb__, cookie__); + return begin_ice_ping(context, null, null, false); } internal const string __ice_ping_name = "ice_ping"; - public void end_ice_ping(AsyncResult r__) + /// <summary> + /// Tests whether the target object of this proxy can be reached. + /// </summary> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_ping</code>.</param> + public void end_ice_ping(AsyncResult result) { - end__(r__, __ice_ping_name); + var resultI = AsyncResultI.check(result, this, __ice_ping_name); + ((OutgoingAsyncT<object>)resultI.OutgoingAsync).result__(resultI.wait()); } - private AsyncResult<Callback_Object_ice_ping> begin_ice_ping(Dictionary<string, string> context__, - bool explicitCtx__, - bool synchronous__, - Ice.AsyncCallback cb__, - object cookie__) + private AsyncResult<Callback_Object_ice_ping> begin_ice_ping(Dictionary<string, string> context, + AsyncCallback callback, + object cookie, + bool synchronous) { - IceInternal.OnewayOutgoingAsync<Callback_Object_ice_ping> result__ = - getOnewayOutgoingAsync<Callback_Object_ice_ping>(__ice_ping_name, ice_ping_completed__, cookie__); - if(cb__ != null) - { - result__.whenCompletedWithAsyncCallback(cb__); - } - - try - { - result__.prepare(__ice_ping_name, OperationMode.Nonmutating, context__, explicitCtx__, synchronous__); - result__.writeEmptyParams(); - result__.invoke(); - } - catch(Ice.Exception ex__) - { - result__.abort(ex__); - } - return result__; + var completed = new OperationAsyncResultCompletionCallback<Callback_Object_ice_ping, object>( + (Callback_Object_ice_ping cb, object result) => + { + cb?.Invoke(); + }, this, __ice_ping_name, cookie, callback); + ice_ping_invoke__(context, completed, synchronous); + return completed; } - private void ice_ping_completed__(Callback_Object_ice_ping cb) + private void ice_ping_invoke__(Dictionary<string, string> context, OutgoingAsyncCompletionCallback completed, + bool synchronous) { - if(cb != null) - { - cb(); - } + getOutgoingAsync<object>(completed).invoke(__ice_ping_name, + OperationMode.Nonmutating, + FormatType.DefaultFormat, + context, + synchronous); } /// <summary> /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. /// </summary> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>The Slice type IDs of the interfaces supported by the target object, in base-to-derived /// order. The first element of the returned array is always ::Ice::Object.</returns> - public string[] ice_ids() + public string[] ice_ids(OptionalContext context = new OptionalContext()) { - return ice_ids(null, false); + try + { + return ice_idsAsync(context, null, CancellationToken.None, true).Result; + } + catch(AggregateException ex) + { + throw ex.InnerException; + } } /// <summary> /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <returns>The Slice type IDs of the interfaces supported by the target object, in base-to-derived - /// order. The first element of the returned array is always ::Ice::Object.</returns> - public string[] ice_ids(Dictionary<string, string> context__) - { - return ice_ids(context__, true); - } - - private string[] ice_ids(Dictionary<string, string> context__, bool explicitCtx__) + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + public Task<string[]> + ice_idsAsync(OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()) { - - checkTwowayOnly__(__ice_ids_name); - return end_ice_ids(begin_ice_ids(context__, explicitCtx__, true, null, null)); + return ice_idsAsync(context, progress, cancel, false); } - public AsyncResult<Callback_Object_ice_ids> begin_ice_ids() + private Task<string[]> ice_idsAsync(OptionalContext context, IProgress<bool> progress, CancellationToken cancel, + bool synchronous) { - return begin_ice_ids(null, false, false, null, null); + var completed = new OperationTaskCompletionCallback<string[]>(progress, cancel); + ice_ids_invoke__(context, completed, false); + return completed.Task; } - public AsyncResult<Callback_Object_ice_ids> begin_ice_ids(Dictionary<string, string> context__) + /// <summary> + /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + /// </summary> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult begin_ice_ids(AsyncCallback callback, object cookie) { - return begin_ice_ids(context__, true, false, null, null); + return begin_ice_ids(new OptionalContext(), callback, cookie, false); } - public AsyncResult begin_ice_ids(AsyncCallback cb__, object cookie__) + /// <summary> + /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + /// </summary> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult + begin_ice_ids(OptionalContext context, AsyncCallback callback, object cookie) { - return begin_ice_ids(null, false, false, cb__, cookie__); + return begin_ice_ids(context, callback, cookie, false); } - public AsyncResult begin_ice_ids(Dictionary<string, string> context__, AsyncCallback cb__, object cookie__) + public AsyncResult<Callback_Object_ice_ids> + begin_ice_ids(OptionalContext context = new OptionalContext()) { - return begin_ice_ids(null, false, false, cb__, cookie__); + return begin_ice_ids(context, null, null, false); } internal const string __ice_ids_name = "ice_ids"; - public string[] end_ice_ids(AsyncResult r__) + private AsyncResult<Callback_Object_ice_ids> + begin_ice_ids(Dictionary<string, string> context, AsyncCallback callback, object cookie, bool synchronous) { - IceInternal.OutgoingAsync outAsync__ = IceInternal.OutgoingAsync.check(r__, this, __ice_ids_name); - try - { - if(!outAsync__.wait()) - { - try - { - outAsync__.throwUserException(); - } - catch(Ice.UserException ex__) - { - throw new Ice.UnknownUserException(ex__.ice_id(), ex__); - } - } - string[] ret__; - InputStream is__ = outAsync__.startReadParams(); - ret__ = is__.readStringSeq(); - outAsync__.endReadParams(); - return ret__; - } - finally - { - if(outAsync__ != null) + var completed = new OperationAsyncResultCompletionCallback<Callback_Object_ice_ids, string[]>( + (Callback_Object_ice_ids cb, string[] result) => { - outAsync__.cacheMessageBuffers(); - } - } + cb?.Invoke(result); + }, this, __ice_ids_name, cookie, callback); + ice_ids_invoke__(context, completed, synchronous); + return completed; } - private AsyncResult<Callback_Object_ice_ids> begin_ice_ids(Dictionary<string, string> context__, - bool explicitCtx__, - bool synchronous__, - Ice.AsyncCallback cb__, - object cookie__) + /// <summary> + /// Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + /// </summary> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_ids</code>.</param> + /// <returns>The Slice type IDs of the interfaces supported by the target object, in base-to-derived + /// order. The first element of the returned array is always ::Ice::Object.</returns> + public string[] end_ice_ids(AsyncResult result) { - checkAsyncTwowayOnly__(__ice_ids_name); - - IceInternal.TwowayOutgoingAsync<Callback_Object_ice_ids> result__ = - getTwowayOutgoingAsync<Callback_Object_ice_ids>(__ice_ids_name, ice_ids_completed__, cookie__); - if(cb__ != null) - { - result__.whenCompletedWithAsyncCallback(cb__); - } - - try - { - result__.prepare(__ice_ids_name, OperationMode.Nonmutating, context__, explicitCtx__, synchronous__); - result__.writeEmptyParams(); - result__.invoke(); - } - catch(Ice.Exception ex__) - { - result__.abort(ex__); - } - return result__; + var resultI = AsyncResultI.check(result, this, __ice_ids_name); + return ((OutgoingAsyncT<string[]>)resultI.OutgoingAsync).result__(resultI.wait()); } - private void ice_ids_completed__(AsyncResult r__, Callback_Object_ice_ids cb__, Ice.ExceptionCallback excb__) + private void ice_ids_invoke__(Dictionary<string, string> context, OutgoingAsyncCompletionCallback completed, + bool synchronous) { - string[] ret__; - try - { - ret__ = end_ice_ids(r__); - } - catch(Ice.Exception ex__) - { - if(excb__ != null) - { - excb__(ex__); - } - return; - } - if(cb__ != null) - { - cb__(ret__); - } + checkAsyncTwowayOnly__(__ice_ids_name); + getOutgoingAsync<string[]>(completed).invoke(__ice_ids_name, + OperationMode.Nonmutating, + FormatType.DefaultFormat, + context, + synchronous, + read: (InputStream iss) => { return iss.readStringSeq(); }); } /// <summary> /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. /// </summary> /// <returns>The Slice type ID of the most-derived interface.</returns> - public string ice_id() + public string ice_id(OptionalContext context = new OptionalContext()) { - return ice_id(null, false); + try + { + return ice_idAsync(context, null, CancellationToken.None, true).Result; + } + catch(AggregateException ex) + { + throw ex.InnerException; + } } /// <summary> /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. /// </summary> - /// <param name="context__">The context dictionary for the invocation.</param> - /// <returns>The Slice type ID of the most-derived interface.</returns> - public string ice_id(Dictionary<string, string> context__) - { - return ice_id(context__, true); - } - - private string ice_id(Dictionary<string, string> context__, bool explicitCtx__) + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + public Task<string> ice_idAsync(OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()) { - checkTwowayOnly__(__ice_id_name); - return end_ice_id(begin_ice_id(context__, explicitCtx__, true, null, null)); + return ice_idAsync(context, progress, cancel, false); } - public AsyncResult<Callback_Object_ice_id> begin_ice_id() + private Task<string> + ice_idAsync(OptionalContext context, IProgress<bool> progress, CancellationToken cancel, bool synchronous) { - return begin_ice_id(null, false, false, null, null); + var completed = new OperationTaskCompletionCallback<string>(progress, cancel); + ice_id_invoke__(context, completed, synchronous); + return completed.Task; } - public AsyncResult<Callback_Object_ice_id> begin_ice_id(Dictionary<string, string> context__) + /// <summary> + /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + /// </summary> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult begin_ice_id(AsyncCallback callback, object cookie) { - return begin_ice_id(context__, true, false, null, null); + return begin_ice_id(new OptionalContext(), callback, cookie, false); } - public AsyncResult begin_ice_id(AsyncCallback cb__, object cookie__) + /// <summary> + /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + /// </summary> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult + begin_ice_id(OptionalContext context, AsyncCallback callback, object cookie) { - return begin_ice_id(null, false, false, cb__, cookie__); + return begin_ice_id(context, callback, cookie, false); } - public AsyncResult begin_ice_id(Dictionary<string, string> context__, AsyncCallback cb__, object cookie__) + /// <summary> + /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + /// </summary> + /// <param name="context">The context dictionary for the invocation.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult<Callback_Object_ice_id> + begin_ice_id(OptionalContext context = new OptionalContext()) { - return begin_ice_id(null, false, false, cb__, cookie__); + return begin_ice_id(context, null, null, false); } internal const string __ice_id_name = "ice_id"; - public string end_ice_id(AsyncResult r__) + private AsyncResult<Callback_Object_ice_id> + begin_ice_id(Dictionary<string, string> context, AsyncCallback callback, object cookie, bool synchronous) { - IceInternal.OutgoingAsync outAsync__ = IceInternal.OutgoingAsync.check(r__, this, __ice_id_name); - try - { - if(!outAsync__.wait()) + var completed = new OperationAsyncResultCompletionCallback<Callback_Object_ice_id, string>( + (Callback_Object_ice_id cb, string result) => { - try - { - outAsync__.throwUserException(); - } - catch(Ice.UserException ex__) - { - throw new Ice.UnknownUserException(ex__.ice_id(), ex__); - } - } - string ret__; - InputStream is__ = outAsync__.startReadParams(); - ret__ = is__.readString(); - outAsync__.endReadParams(); - return ret__; - } - finally - { - if(outAsync__ != null) - { - outAsync__.cacheMessageBuffers(); - } - } + cb?.Invoke(result); + }, this, __ice_id_name, cookie, callback); + ice_id_invoke__(context, completed, synchronous); + return completed; } - private AsyncResult<Callback_Object_ice_id> begin_ice_id(Dictionary<string, string> context__, - bool explicitCtx__, - bool synchronous__, - Ice.AsyncCallback cb__, - object cookie__) + /// <summary> + /// Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + /// </summary> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_id</code>.</param> + /// <returns>The Slice type ID of the most-derived interface.</returns> + public string end_ice_id(AsyncResult result) { - checkAsyncTwowayOnly__(__ice_id_name); - - IceInternal.TwowayOutgoingAsync<Callback_Object_ice_id> result__ = - getTwowayOutgoingAsync<Callback_Object_ice_id>(__ice_id_name, ice_id_completed__, cookie__); - if(cb__ != null) - { - result__.whenCompletedWithAsyncCallback(cb__); - } - - try - { - result__.prepare(__ice_id_name, OperationMode.Nonmutating, context__, explicitCtx__, synchronous__); - result__.writeEmptyParams(); - result__.invoke(); - } - catch(Ice.Exception ex__) - { - result__.abort(ex__); - } - return result__; + var resultI = AsyncResultI.check(result, this, __ice_id_name); + return ((OutgoingAsyncT<string>)resultI.OutgoingAsync).result__(resultI.wait()); } - private void ice_id_completed__(AsyncResult r__, Callback_Object_ice_id cb__, Ice.ExceptionCallback excb__) + private void ice_id_invoke__(Dictionary<string, string> context, + OutgoingAsyncCompletionCallback completed, + bool synchronous) { - string ret__; - try - { - ret__ = end_ice_id(r__); - } - catch(Ice.Exception ex__) - { - if(excb__ != null) - { - excb__(ex__); - } - return; - } - if(cb__ != null) - { - cb__(ret__); - } + checkAsyncTwowayOnly__(__ice_id_name); + getOutgoingAsync<string>(completed).invoke(__ice_id_name, + OperationMode.Nonmutating, + FormatType.DefaultFormat, + context, + synchronous, + read: (InputStream iss) => { return iss.readString(); }); } /// <summary> @@ -1295,14 +1281,28 @@ namespace Ice /// <param name="inEncaps">The encoded in-parameters for the operation.</param> /// <param name="outEncaps">The encoded out-paramaters and return value /// for the operation. The return value follows any out-parameters.</param> + /// <param name="context">The context dictionary for the invocation.</param> /// <returns>If the operation completed successfully, the return value /// is true. If the operation raises a user exception, /// the return value is false; in this case, outEncaps /// contains the encoded user exception. If the operation raises a run-time exception, /// it throws it directly.</returns> - public bool ice_invoke(string operation, OperationMode mode, byte[] inEncaps, out byte[] outEncaps) + public bool ice_invoke(string operation, + OperationMode mode, + byte[] inEncaps, + out byte[] outEncaps, + OptionalContext context = new OptionalContext()) { - return ice_invoke(operation, mode, inEncaps, out outEncaps, null, false); + try + { + var result = ice_invokeAsync(operation, mode, inEncaps, context, null, CancellationToken.None, true).Result; + outEncaps = result.outEncaps; + return result.returnValue; + } + catch(AggregateException ex) + { + throw ex.InnerException; + } } /// <summary> @@ -1311,132 +1311,134 @@ namespace Ice /// <param name="operation">The name of the operation to invoke.</param> /// <param name="mode">The operation mode (normal or idempotent).</param> /// <param name="inEncaps">The encoded in-parameters for the operation.</param> - /// <param name="outEncaps">The encoded out-paramaters and return value - /// for the operation. The return value follows any out-parameters.</param> /// <param name="context">The context dictionary for the invocation.</param> - /// <returns>If the operation completed successfully, the return value - /// is true. If the operation raises a user exception, - /// the return value is false; in this case, outEncaps - /// contains the encoded user exception. If the operation raises a run-time exception, - /// it throws it directly.</returns> - public bool ice_invoke(string operation, OperationMode mode, byte[] inEncaps, out byte[] outEncaps, - Dictionary<string, string> context) + /// <param name="progress">Sent progress provider.</param> + /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> + /// <returns>The task object representing the asynchronous operation.</returns> + public Task<Object_Ice_invokeResult> + ice_invokeAsync(string operation, + OperationMode mode, + byte[] inEncaps, + OptionalContext context = new OptionalContext(), + IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()) { - return ice_invoke(operation, mode, inEncaps, out outEncaps, context, true); + return ice_invokeAsync(operation, mode, inEncaps, context, progress, cancel, false); } - private bool ice_invoke(string operation, OperationMode mode, byte[] inEncaps, out byte[] outEncaps, - Dictionary<string, string> context, bool explicitCtx) + private Task<Object_Ice_invokeResult> + ice_invokeAsync(string operation, + OperationMode mode, + byte[] inEncaps, + OptionalContext context, + IProgress<bool> progress, + CancellationToken cancel, + bool synchronous) { - return end_ice_invoke(out outEncaps, begin_ice_invoke(operation, mode, inEncaps, context, explicitCtx, true, null, null)); + var completed = new InvokeTaskCompletionCallback(progress, cancel); + ice_invoke_invoke__(operation, mode, inEncaps, context, completed, synchronous); + return completed.Task; } - public AsyncResult<Callback_Object_ice_invoke> begin_ice_invoke(string operation, - OperationMode mode, - byte[] inEncaps) - { - return begin_ice_invoke(operation, mode, inEncaps, null, false, false, null, null); - } - - public AsyncResult<Callback_Object_ice_invoke> begin_ice_invoke(string operation, - OperationMode mode, - byte[] inEncaps, - Dictionary<string, string> context__) + /// <summary> + /// Invokes an operation dynamically. + /// </summary> + /// <param name="operation">The name of the operation to invoke.</param> + /// <param name="mode">The operation mode (normal or idempotent).</param> + /// <param name="inEncaps">The encoded in-parameters for the operation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult + begin_ice_invoke(string operation, + OperationMode mode, + byte[] inEncaps, + AsyncCallback callback, + object cookie) { - return begin_ice_invoke(operation, mode, inEncaps, context__, true, false, null, null); + return begin_ice_invoke(operation, mode, inEncaps, new OptionalContext(), callback, cookie, false); } - public AsyncResult begin_ice_invoke(string operation, OperationMode mode, byte[] inEncaps, AsyncCallback cb__, - object cookie__) + /// <summary> + /// Invokes an operation dynamically. + /// </summary> + /// <param name="operation">The name of the operation to invoke.</param> + /// <param name="mode">The operation mode (normal or idempotent).</param> + /// <param name="inEncaps">The encoded in-parameters for the operation.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <param name="callback">A callback to be invoked when the invocation completes.</param> + /// <param name="cookie">Application-specific data to be stored in the result.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult + begin_ice_invoke(string operation, + OperationMode mode, + byte[] inEncaps, + OptionalContext context, + AsyncCallback callback, + object cookie) { - return begin_ice_invoke(operation, mode, inEncaps, null, false, false, cb__, cookie__); + return begin_ice_invoke(operation, mode, inEncaps, context, callback, cookie, false); } - public AsyncResult begin_ice_invoke(string operation, OperationMode mode, byte[] inEncaps, - Dictionary<string, string> context__, AsyncCallback cb__, object cookie__) + /// <summary> + /// Invokes an operation dynamically. + /// </summary> + /// <param name="operation">The name of the operation to invoke.</param> + /// <param name="mode">The operation mode (normal or idempotent).</param> + /// <param name="inEncaps">The encoded in-parameters for the operation.</param> + /// <param name="context">The context dictionary for the invocation.</param> + /// <returns>An asynchronous result object.</returns> + public AsyncResult<Callback_Object_ice_invoke> + begin_ice_invoke(string operation, + OperationMode mode, + byte[] inEncaps, + OptionalContext context = new OptionalContext()) { - return begin_ice_invoke(operation, mode, inEncaps, null, false, false, cb__, cookie__); + return begin_ice_invoke(operation, mode, inEncaps, context, null, null, false); } internal const string __ice_invoke_name = "ice_invoke"; - public bool end_ice_invoke(out byte[] outEncaps, AsyncResult r__) + /// <summary> + /// Completes a dynamic invocation. + /// </summary> + /// <param name="outEncaps">The encoded out parameters or user exception.</param> + /// <param name="result">The asynchronous result object returned by <code>begin_ice_invoke</code>.</param> + /// <returns>If the operation completed successfully, the return value + /// is true. If the operation raises a user exception, + /// the return value is false; in this case, outEncaps + /// contains the encoded user exception. If the operation raises a run-time exception, + /// it throws it directly.</returns> + public bool end_ice_invoke(out byte[] outEncaps, AsyncResult result) { - IceInternal.OutgoingAsync outAsync__ = IceInternal.OutgoingAsync.check(r__, this, __ice_invoke_name); - try - { - bool ok = outAsync__.wait(); - if(_reference.getMode() == IceInternal.Reference.Mode.ModeTwoway) - { - outEncaps = outAsync__.readParamEncaps(); - } - else - { - outEncaps = null; // Satisfy compiler - } - return ok; - } - finally - { - if(outAsync__ != null) - { - outAsync__.cacheMessageBuffers(); - } - } - + var resultI = AsyncResultI.check(result, this, __ice_invoke_name); + var r = ((InvokeOutgoingAsyncT)resultI.OutgoingAsync).result__(resultI.wait()); + outEncaps = r.outEncaps; + return r.returnValue; } - private AsyncResult<Callback_Object_ice_invoke> begin_ice_invoke(string operation, - OperationMode mode, - byte[] inEncaps, - Dictionary<string, string> context__, - bool explicitCtx__, - bool synchronous__, - Ice.AsyncCallback cb__, - object cookie__) + private AsyncResult<Callback_Object_ice_invoke> + begin_ice_invoke(string operation, + OperationMode mode, + byte[] inEncaps, + Dictionary<string, string> context, + AsyncCallback callback, + object cookie, + bool synchronous) { - IceInternal.TwowayOutgoingAsync<Callback_Object_ice_invoke> result__ = - getTwowayOutgoingAsync<Callback_Object_ice_invoke>(__ice_invoke_name, ice_invoke_completed__, cookie__); - if(cb__ != null) - { - result__.whenCompletedWithAsyncCallback(cb__); - } - - try - { - result__.prepare(operation, mode, context__, explicitCtx__, synchronous__); - result__.writeParamEncaps(inEncaps); - result__.invoke(); - } - catch(Ice.Exception ex__) - { - result__.abort(ex__); - } - return result__; + var completed = new InvokeAsyncResultCompletionCallback(this, __ice_invoke_name, cookie, callback); + ice_invoke_invoke__(operation, mode, inEncaps, context, completed, synchronous); + return completed; } - private void ice_invoke_completed__(AsyncResult r__, - Callback_Object_ice_invoke cb__, - Ice.ExceptionCallback excb__) + private void ice_invoke_invoke__(string operation, + OperationMode mode, + byte[] inEncaps, + Dictionary<string, string> context, + OutgoingAsyncCompletionCallback completed, + bool synchronous) { - byte[] outEncaps; - bool ret__; - try - { - ret__ = end_ice_invoke(out outEncaps, r__); - } - catch(Ice.Exception ex__) - { - if(excb__ != null) - { - excb__(ex__); - } - return; - } - if(cb__ != null) - { - cb__(ret__, outEncaps); - } + getInvokeOutgoingAsync(completed).invoke(operation, mode, inEncaps, context, synchronous); } /// <summary> @@ -1465,7 +1467,7 @@ namespace Ice } else { - ObjectPrxHelperBase proxy = new ObjectPrxHelperBase(); + var proxy = new ObjectPrxHelperBase(); proxy.setup(_reference.changeIdentity(newIdentity)); return proxy; } @@ -1519,7 +1521,7 @@ namespace Ice } else { - ObjectPrxHelperBase proxy = new ObjectPrxHelperBase(); + var proxy = new ObjectPrxHelperBase(); proxy.setup(_reference.changeFacet(newFacet)); return proxy; } @@ -1579,10 +1581,10 @@ namespace Ice } else { - IceInternal.EndpointI[] endpts = new IceInternal.EndpointI[newEndpoints.Length]; + var endpts = new EndpointI[newEndpoints.Length]; for(int i = 0; i < newEndpoints.Length; ++i) { - endpts[i] = (IceInternal.EndpointI)newEndpoints[i]; + endpts[i] = (EndpointI)newEndpoints[i]; } return newInstance(_reference.changeEndpoints(endpts)); } @@ -1605,7 +1607,7 @@ namespace Ice { if(newTimeout < -1) { - throw new System.ArgumentException("invalid value passed to ice_locatorCacheTimeout: " + newTimeout); + throw new ArgumentException("invalid value passed to ice_locatorCacheTimeout: " + newTimeout); } if(newTimeout == _reference.getLocatorCacheTimeout()) { @@ -1634,7 +1636,7 @@ namespace Ice { if(newTimeout < 1 && newTimeout != -1 && newTimeout != -2) { - throw new System.ArgumentException("invalid value passed to ice_invocationTimeout: " + newTimeout); + throw new ArgumentException("invalid value passed to ice_invocationTimeout: " + newTimeout); } if(newTimeout == _reference.getInvocationTimeout()) { @@ -1732,7 +1734,7 @@ namespace Ice /// </summary> /// <param name="e">The encoding version to use to marshal requests parameters.</param> /// <returns>The new proxy with the specified encoding version.</returns> - public ObjectPrx ice_encodingVersion(Ice.EncodingVersion e) + public ObjectPrx ice_encodingVersion(EncodingVersion e) { if(e.Equals(_reference.getEncoding())) { @@ -1746,7 +1748,7 @@ namespace Ice /// <summary>Returns the encoding version used to marshal requests parameters.</summary> /// <returns>The encoding version.</returns> - public Ice.EncodingVersion ice_getEncodingVersion() + public EncodingVersion ice_getEncodingVersion() { return _reference.getEncoding(); } @@ -1785,9 +1787,9 @@ namespace Ice /// </summary> /// <returns>The router for the proxy. If no router is configured for the proxy, the return value /// is null.</returns> - public Ice.RouterPrx ice_getRouter() + public RouterPrx ice_getRouter() { - IceInternal.RouterInfo ri = _reference.getRouterInfo(); + RouterInfo ri = _reference.getRouterInfo(); return ri != null ? ri.getRouter() : null; } @@ -1798,7 +1800,7 @@ namespace Ice /// <returns>The new proxy with the specified router.</returns> public ObjectPrx ice_router(RouterPrx router) { - IceInternal.Reference @ref = _reference.changeRouter(router); + Reference @ref = _reference.changeRouter(router); if(@ref.Equals(_reference)) { return this; @@ -1813,9 +1815,9 @@ namespace Ice /// Returns the locator for this proxy. /// </summary> /// <returns>The locator for this proxy. If no locator is configured, the return value is null.</returns> - public Ice.LocatorPrx ice_getLocator() + public LocatorPrx ice_getLocator() { - IceInternal.LocatorInfo li = _reference.getLocatorInfo(); + var li = _reference.getLocatorInfo(); return li != null ? li.getLocator() : null; } @@ -1826,7 +1828,7 @@ namespace Ice /// <returns>The new proxy with the specified locator.</returns> public ObjectPrx ice_locator(LocatorPrx locator) { - IceInternal.Reference @ref = _reference.changeLocator(locator); + var @ref = _reference.changeLocator(locator); if(@ref.Equals(_reference)) { return this; @@ -1869,13 +1871,13 @@ namespace Ice /// <returns>A new proxy that uses twoway invocations.</returns> public ObjectPrx ice_twoway() { - if(_reference.getMode() == IceInternal.Reference.Mode.ModeTwoway) + if(_reference.getMode() == Reference.Mode.ModeTwoway) { return this; } else { - return newInstance(_reference.changeMode(IceInternal.Reference.Mode.ModeTwoway)); + return newInstance(_reference.changeMode(Reference.Mode.ModeTwoway)); } } @@ -1885,7 +1887,7 @@ namespace Ice /// <returns>True if this proxy uses twoway invocations; false, otherwise.</returns> public bool ice_isTwoway() { - return _reference.getMode() == IceInternal.Reference.Mode.ModeTwoway; + return _reference.getMode() == Reference.Mode.ModeTwoway; } /// <summary> @@ -1894,13 +1896,13 @@ namespace Ice /// <returns>A new proxy that uses oneway invocations.</returns> public ObjectPrx ice_oneway() { - if(_reference.getMode() == IceInternal.Reference.Mode.ModeOneway) + if(_reference.getMode() == Reference.Mode.ModeOneway) { return this; } else { - return newInstance(_reference.changeMode(IceInternal.Reference.Mode.ModeOneway)); + return newInstance(_reference.changeMode(Reference.Mode.ModeOneway)); } } @@ -1910,7 +1912,7 @@ namespace Ice /// <returns>True if this proxy uses oneway invocations; false, otherwise.</returns> public bool ice_isOneway() { - return _reference.getMode() == IceInternal.Reference.Mode.ModeOneway; + return _reference.getMode() == Reference.Mode.ModeOneway; } /// <summary> @@ -1919,13 +1921,13 @@ namespace Ice /// <returns>A new proxy that uses batch oneway invocations.</returns> public ObjectPrx ice_batchOneway() { - if(_reference.getMode() == IceInternal.Reference.Mode.ModeBatchOneway) + if(_reference.getMode() == Reference.Mode.ModeBatchOneway) { return this; } else { - return newInstance(_reference.changeMode(IceInternal.Reference.Mode.ModeBatchOneway)); + return newInstance(_reference.changeMode(Reference.Mode.ModeBatchOneway)); } } @@ -1935,7 +1937,7 @@ namespace Ice /// <returns>True if this proxy uses batch oneway invocations; false, otherwise.</returns> public bool ice_isBatchOneway() { - return _reference.getMode() == IceInternal.Reference.Mode.ModeBatchOneway; + return _reference.getMode() == Reference.Mode.ModeBatchOneway; } /// <summary> @@ -1944,13 +1946,13 @@ namespace Ice /// <returns>A new proxy that uses datagram invocations.</returns> public ObjectPrx ice_datagram() { - if(_reference.getMode() == IceInternal.Reference.Mode.ModeDatagram) + if(_reference.getMode() == Reference.Mode.ModeDatagram) { return this; } else { - return newInstance(_reference.changeMode(IceInternal.Reference.Mode.ModeDatagram)); + return newInstance(_reference.changeMode(Reference.Mode.ModeDatagram)); } } @@ -1960,7 +1962,7 @@ namespace Ice /// <returns>True if this proxy uses datagram invocations; false, otherwise.</returns> public bool ice_isDatagram() { - return _reference.getMode() == IceInternal.Reference.Mode.ModeDatagram; + return _reference.getMode() == Reference.Mode.ModeDatagram; } /// <summary> @@ -1969,13 +1971,13 @@ namespace Ice /// <returns>A new proxy that uses batch datagram invocations.</returns> public ObjectPrx ice_batchDatagram() { - if(_reference.getMode() == IceInternal.Reference.Mode.ModeBatchDatagram) + if(_reference.getMode() == Reference.Mode.ModeBatchDatagram) { return this; } else { - return newInstance(_reference.changeMode(IceInternal.Reference.Mode.ModeBatchDatagram)); + return newInstance(_reference.changeMode(Reference.Mode.ModeBatchDatagram)); } } @@ -1985,7 +1987,7 @@ namespace Ice /// <returns>True if this proxy uses batch datagram invocations; false, otherwise.</returns> public bool ice_isBatchDatagram() { - return _reference.getMode() == IceInternal.Reference.Mode.ModeBatchDatagram; + return _reference.getMode() == Reference.Mode.ModeBatchDatagram; } /// <summary> @@ -1995,7 +1997,7 @@ namespace Ice /// <returns>A new proxy with the specified compression setting.</returns> public ObjectPrx ice_compress(bool co) { - IceInternal.Reference @ref = _reference.changeCompress(co); + var @ref = _reference.changeCompress(co); if(@ref.Equals(_reference)) { return this; @@ -2015,9 +2017,9 @@ namespace Ice { if(t < 1 && t != -1) { - throw new System.ArgumentException("invalid value passed to ice_timeout: " + t); + throw new ArgumentException("invalid value passed to ice_timeout: " + t); } - IceInternal.Reference @ref = _reference.changeTimeout(t); + var @ref = _reference.changeTimeout(t); if(@ref.Equals(_reference)) { return this; @@ -2036,7 +2038,7 @@ namespace Ice /// <returns>A new proxy with the specified connection ID.</returns> public ObjectPrx ice_connectionId(string connectionId) { - IceInternal.Reference @ref = _reference.changeConnectionId(connectionId); + var @ref = _reference.changeConnectionId(connectionId); if(@ref.Equals(_reference)) { return this; @@ -2065,74 +2067,109 @@ namespace Ice /// collocated object.</exception> public Connection ice_getConnection() { - return end_ice_getConnection(begin_ice_getConnection()); + try + { + return ice_getConnectionAsync().Result; + } + catch(AggregateException ex) + { + throw ex.InnerException; + } } - public AsyncResult<Callback_Object_ice_getConnection> begin_ice_getConnection() + private class ProxyGetConnectionAsyncCallback : ProxyAsyncResultCompletionCallback<Callback_Object_ice_getConnection> { - return begin_ice_getConnectionInternal(null, null); - } - - internal const string __ice_getConnection_name = "ice_getConnection"; + public ProxyGetConnectionAsyncCallback(ObjectPrxHelperBase proxy, string operation, object cookie, + AsyncCallback cb) : + base(proxy, operation, cookie, cb) + { + } - public AsyncResult begin_ice_getConnection(Ice.AsyncCallback cb, object cookie) - { - return begin_ice_getConnectionInternal(cb, cookie); + protected override AsyncCallback getCompletedCallback() + { + return (AsyncResult result) => + { + try + { + result.throwLocalException(); + responseCallback_?.Invoke(getProxy().ice_getCachedConnection()); + } + catch(Exception ex) + { + exceptionCallback_?.Invoke(ex); + } + }; + } } - public Connection end_ice_getConnection(Ice.AsyncResult r) + public class GetConnectionTaskCompletionCallback : TaskCompletionCallback<Connection> { - IceInternal.ProxyGetConnection outAsync = - IceInternal.ProxyGetConnection.check(r, this, __ice_getConnection_name); - outAsync.wait(); - return ice_getCachedConnection(); - } + public GetConnectionTaskCompletionCallback(ObjectPrx proxy, + IProgress<bool> progress, + CancellationToken cancellationToken) : + base(progress, cancellationToken) + { + _proxy = proxy; + } - private AsyncResult<Callback_Object_ice_getConnection> begin_ice_getConnectionInternal(Ice.AsyncCallback cb, - object cookie) - { - IceInternal.ProxyGetConnection result = new IceInternal.ProxyGetConnection(this, - __ice_getConnection_name, - ice_getConnection_completed__, - cookie); - if(cb != null) + public override bool handleResponse(bool ok, OutgoingAsyncBase og) { - result.whenCompletedWithAsyncCallback(cb); + SetResult(_proxy.ice_getCachedConnection()); + return false; } + + private ObjectPrx _proxy; + } + + public Task<Connection> ice_getConnectionAsync(IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()) + { + var completed = new GetConnectionTaskCompletionCallback(this, progress, cancel); + var outgoing = new ProxyGetConnection(this, completed); try { - result.invoke(); + outgoing.invoke(__ice_getConnection_name); } - catch(Ice.Exception ex) + catch(Exception ex) { - result.abort(ex); + outgoing.abort(ex); } - return result; + return completed.Task; } + public AsyncResult<Callback_Object_ice_getConnection> begin_ice_getConnection() + { + return begin_ice_getConnectionInternal(null, null); + } + + internal const string __ice_getConnection_name = "ice_getConnection"; + + public AsyncResult begin_ice_getConnection(AsyncCallback cb, object cookie) + { + return begin_ice_getConnectionInternal(cb, cookie); + } + public Connection end_ice_getConnection(AsyncResult r) + { + var resultI = AsyncResultI.check(r, this, __ice_getConnection_name); + resultI.wait(); + return ice_getCachedConnection(); + } - private void ice_getConnection_completed__(AsyncResult r, - Callback_Object_ice_getConnection cb, - Ice.ExceptionCallback excb) + private AsyncResult<Callback_Object_ice_getConnection> begin_ice_getConnectionInternal(AsyncCallback callback, + object cookie) { - Connection ret; + var completed = new ProxyGetConnectionAsyncCallback(this, __ice_getConnection_name, cookie, callback); + var outgoing = new ProxyGetConnection(this, completed); try { - ret = end_ice_getConnection(r); + outgoing.invoke(__ice_getConnection_name); } - catch(Ice.Exception ex) + catch(Exception ex) { - if(excb != null) - { - excb(ex); - } - return; - } - if(cb != null) - { - cb(ret); + outgoing.abort(ex); } + return completed; } /// <summary> @@ -2145,7 +2182,7 @@ namespace Ice /// collocated object.</exception> public Connection ice_getCachedConnection() { - IceInternal.RequestHandler handler; + RequestHandler handler; lock(this) { handler = _requestHandler; @@ -2169,41 +2206,88 @@ namespace Ice /// </summary> public void ice_flushBatchRequests() { - end_ice_flushBatchRequests(begin_ice_flushBatchRequests()); + try + { + ice_flushBatchRequestsAsync().Wait(); + } + catch(AggregateException ex) + { + throw ex.InnerException; + } } internal const string __ice_flushBatchRequests_name = "ice_flushBatchRequests"; - public AsyncResult begin_ice_flushBatchRequests() + public Task ice_flushBatchRequestsAsync(IProgress<bool> progress = null, + CancellationToken cancel = new CancellationToken()) { - return begin_ice_flushBatchRequests(null, null); + var completed = new FlushBatchTaskCompletionCallback(progress, cancel); + var outgoing = new ProxyFlushBatchAsync(this, completed); + try + { + outgoing.invoke(__ice_flushBatchRequests_name); + } + catch(Exception ex) + { + outgoing.abort(ex); + } + return completed.Task; } - public AsyncResult begin_ice_flushBatchRequests(Ice.AsyncCallback cb, object cookie) + private class ProxyFlushBatchRequestsAsyncCallback : AsyncResultCompletionCallback { - IceInternal.ProxyFlushBatch result = new IceInternal.ProxyFlushBatch(this, - __ice_flushBatchRequests_name, - cookie); - if(cb != null) + public ProxyFlushBatchRequestsAsyncCallback(ObjectPrx proxy, + string operation, + object cookie, + AsyncCallback callback) : + base(proxy.ice_getCommunicator(), ((ObjectPrxHelperBase)proxy).reference__().getInstance(), + operation, cookie, callback) { - result.whenCompletedWithAsyncCallback(cb); + _proxy = proxy; } + + public override ObjectPrx getProxy() + { + return _proxy; + } + + protected override AsyncCallback getCompletedCallback() + { + return (AsyncResult result) => + { + try + { + result.throwLocalException(); + } + catch(Exception ex) + { + exceptionCallback_?.Invoke(ex); + } + }; + } + + private ObjectPrx _proxy; + } + + public AsyncResult begin_ice_flushBatchRequests(AsyncCallback cb = null, object cookie = null) + { + var completed = new ProxyFlushBatchRequestsAsyncCallback(this, __ice_flushBatchRequests_name, cookie, cb); + var outgoing = new ProxyFlushBatchAsync(this, completed); try { - result.invoke(); + outgoing.invoke(__ice_flushBatchRequests_name); } - catch(Ice.Exception ex) + catch(Exception ex) { - result.abort(ex); + outgoing.abort(ex); } - return result; + return completed; } - public void end_ice_flushBatchRequests(Ice.AsyncResult r) + public void end_ice_flushBatchRequests(AsyncResult r) { - IceInternal.ProxyFlushBatch outAsync = - IceInternal.ProxyFlushBatch.check(r, this, __ice_flushBatchRequests_name); - outAsync.wait(); + var resultI = AsyncResultI.check(r, this, __ice_flushBatchRequests_name); + resultI.wait(); } /// <summary> @@ -2214,8 +2298,8 @@ namespace Ice /// <returns>True if this proxy is equal to r; false, otherwise.</returns> public override bool Equals(object r) { - ObjectPrxHelperBase rhs = r as ObjectPrxHelperBase; - return object.ReferenceEquals(rhs, null) ? false : _reference.Equals(rhs._reference); + var rhs = r as ObjectPrxHelperBase; + return ReferenceEquals(rhs, null) ? false : _reference.Equals(rhs._reference); } /// <summary> @@ -2227,7 +2311,7 @@ namespace Ice /// <returns>True if the proxies are equal; false, otherwise.</returns> public static bool Equals(ObjectPrxHelperBase lhs, ObjectPrxHelperBase rhs) { - return object.ReferenceEquals(lhs, null) ? object.ReferenceEquals(rhs, null) : lhs.Equals(rhs); + return ReferenceEquals(lhs, null) ? ReferenceEquals(rhs, null) : lhs.Equals(rhs); } /// <summary> @@ -2260,7 +2344,7 @@ namespace Ice _reference.streamWrite(os); } - public IceInternal.Reference reference__() + public Reference reference__() { return _reference; } @@ -2269,13 +2353,13 @@ namespace Ice { lock(from) { - ObjectPrxHelperBase h = (ObjectPrxHelperBase)from; + var h = (ObjectPrxHelperBase)from; _reference = h._reference; _requestHandler = h._requestHandler; } } - public int handleException__(Exception ex, IceInternal.RequestHandler handler, OperationMode mode, bool sent, + public int handleException__(Exception ex, RequestHandler handler, OperationMode mode, bool sent, ref int cnt) { updateRequestHandler__(handler, null); // Clear the request handler @@ -2320,21 +2404,6 @@ namespace Ice } } - public void checkTwowayOnly__(string name) - { - // - // No mutex lock necessary, there is nothing mutable in this - // operation. - // - - if(!ice_isTwoway()) - { - TwowayOnlyException ex = new TwowayOnlyException(); - ex.operation = name; - throw ex; - } - } - public void checkAsyncTwowayOnly__(string name) { // @@ -2344,43 +2413,11 @@ namespace Ice if(!ice_isTwoway()) { - throw new System.ArgumentException("`" + name + "' can only be called with a twoway proxy"); - } - } - - public void end__(AsyncResult r, string operation) - { - IceInternal.ProxyOutgoingAsyncBase result = IceInternal.ProxyOutgoingAsyncBase.check(r, this, operation); - try - { - bool ok = result.wait(); - if(_reference.getMode() == IceInternal.Reference.Mode.ModeTwoway) - { - IceInternal.OutgoingAsync outAsync = (IceInternal.OutgoingAsync)result; - if(!ok) - { - try - { - outAsync.throwUserException(); - } - catch(Ice.UserException ex) - { - throw new Ice.UnknownUserException(ex.ice_id(), ex); - } - } - outAsync.readEmptyParams(); - } - } - finally - { - if(result != null) - { - result.cacheMessageBuffers(); - } + throw new ArgumentException("`" + name + "' can only be called with a twoway proxy"); } } - public IceInternal.RequestHandler getRequestHandler__() + public RequestHandler getRequestHandler__() { if(_reference.getCacheConnection()) { @@ -2395,7 +2432,7 @@ namespace Ice return _reference.getRequestHandler(this); } - public IceInternal.BatchRequestQueue + public BatchRequestQueue getBatchRequestQueue__() { lock(this) @@ -2408,8 +2445,8 @@ namespace Ice } } - public IceInternal.RequestHandler - setRequestHandler__(IceInternal.RequestHandler handler) + public RequestHandler + setRequestHandler__(RequestHandler handler) { if(_reference.getCacheConnection()) { @@ -2425,7 +2462,7 @@ namespace Ice return handler; } - public void updateRequestHandler__(IceInternal.RequestHandler previous, IceInternal.RequestHandler handler) + public void updateRequestHandler__(RequestHandler previous, RequestHandler handler) { if(_reference.getCacheConnection() && previous != null) { @@ -2446,32 +2483,226 @@ namespace Ice } } - // - // Only for use by IceInternal.ProxyFactory - // - public void setup(IceInternal.Reference @ref) + protected OutgoingAsyncT<T> + getOutgoingAsync<T>(OutgoingAsyncCompletionCallback completed) + { + bool haveEntry = false; + InputStream iss = null; + OutputStream os = null; + + if(_reference.getInstance().cacheMessageBuffers() > 0) + { + lock(this) + { + if(_streamCache != null && _streamCache.Count > 0) + { + haveEntry = true; + iss = _streamCache.First.Value.iss; + os = _streamCache.First.Value.os; + + _streamCache.RemoveFirst(); + } + } + } + if(!haveEntry) + { + return new OutgoingAsyncT<T>(this, completed); + } + else + { + return new OutgoingAsyncT<T>(this, completed, os, iss); + } + } + + private class InvokeOutgoingAsyncT : OutgoingAsync + { + public InvokeOutgoingAsyncT(ObjectPrxHelperBase prx, + OutgoingAsyncCompletionCallback completionCallback, + OutputStream os = null, + InputStream iss = null) : base(prx, completionCallback, os, iss) + { + } + + public void invoke(string operation, OperationMode mode, byte[] inParams, + Dictionary<string, string> context, bool synchronous) + { + try + { + prepare(operation, mode, context, synchronous); + if(inParams == null || inParams.Length == 0) + { + os_.writeEmptyEncapsulation(encoding_); + } + else + { + os_.writeEncapsulation(inParams); + } + invoke(operation); + } + catch(Exception ex) + { + abort(ex); + } + } + + public Object_Ice_invokeResult + result__(bool ok) + { + try + { + var ret__ = new Object_Ice_invokeResult(); + EncodingVersion encoding; + if(proxy_.reference__().getMode() == Reference.Mode.ModeTwoway) + { + ret__.outEncaps = is_.readEncapsulation(out encoding); + } + else + { + ret__.outEncaps = null; + } + ret__.returnValue = ok; + return ret__; + } + finally + { + cacheMessageBuffers(); + } + } + } + + public class InvokeAsyncResultCompletionCallback : ProxyAsyncResultCompletionCallback<Callback_Object_ice_invoke> + { + public InvokeAsyncResultCompletionCallback(ObjectPrxHelperBase proxy, + string operation, + object cookie, + AsyncCallback callback) : + base(proxy, operation, cookie, callback) + { + } + + override protected AsyncCallback getCompletedCallback() + { + return (AsyncResult r) => + { + Debug.Assert(r == this); + try + { + Object_Ice_invokeResult result = ((InvokeOutgoingAsyncT)outgoing_).result__(wait()); + try + { + responseCallback_?.Invoke(result.returnValue, result.outEncaps); + } + catch(Exception ex) + { + throw new AggregateException(ex); + } + } + catch(Exception ex) + { + exceptionCallback_?.Invoke(ex); + } + }; + } + }; + + private class InvokeTaskCompletionCallback : TaskCompletionCallback<Object_Ice_invokeResult> + { + public InvokeTaskCompletionCallback(IProgress<bool> progress, CancellationToken cancellationToken) : + base(progress, cancellationToken) + { + } + + public override bool handleSent(bool done, bool alreadySent) + { + if(done) + { + var result = new Object_Ice_invokeResult(); + result.returnValue = true; + SetResult(result); + } + return base.handleSent(false, alreadySent); + } + + public override bool handleResponse(bool ok, OutgoingAsyncBase og) + { + SetResult(((InvokeOutgoingAsyncT)og).result__(ok)); + return false; + } + } + + private InvokeOutgoingAsyncT + getInvokeOutgoingAsync(OutgoingAsyncCompletionCallback completed) + { + bool haveEntry = false; + InputStream iss = null; + OutputStream os = null; + + if(_reference.getInstance().cacheMessageBuffers() > 0) + { + lock(this) + { + if(_streamCache != null && _streamCache.Count > 0) + { + haveEntry = true; + iss = _streamCache.First.Value.iss; + os = _streamCache.First.Value.os; + + _streamCache.RemoveFirst(); + } + } + } + if(!haveEntry) + { + return new InvokeOutgoingAsyncT(this, completed); + } + else + { + return new InvokeOutgoingAsyncT(this, completed, os, iss); + } + } + + public void + cacheMessageBuffers(InputStream iss, OutputStream os) + { + lock(this) + { + if(_streamCache == null) + { + _streamCache = new LinkedList<StreamCacheEntry>(); + } + StreamCacheEntry cacheEntry; + cacheEntry.iss = iss; + cacheEntry.os = os; + _streamCache.AddLast(cacheEntry); + } + } + + /// <summary> + /// Only for internal use by ProxyFactory + /// </summary> + /// <param name="ref"></param> + public void setup(Reference @ref) { // // No need to synchronize, as this operation is only called // upon initial initialization. // - Debug.Assert(_reference == null); Debug.Assert(_requestHandler == null); _reference = @ref; } - private ObjectPrxHelperBase newInstance(IceInternal.Reference @ref) + private ObjectPrxHelperBase newInstance(Reference @ref) { - ObjectPrxHelperBase proxy = (ObjectPrxHelperBase)Activator.CreateInstance(GetType()); + var proxy = (ObjectPrxHelperBase)Activator.CreateInstance(GetType()); proxy.setup(@ref); return proxy; } - private IceInternal.Reference _reference; - private IceInternal.RequestHandler _requestHandler; - private IceInternal.BatchRequestQueue _batchRequestQueue; + private Reference _reference; + private RequestHandler _requestHandler; + private BatchRequestQueue _batchRequestQueue; private struct StreamCacheEntry { public InputStream iss; @@ -2527,14 +2758,14 @@ namespace Ice { try { - ObjectPrx bb = b.ice_facet(f); - bool ok = bb.ice_isA("::Ice::Object"); + var bb = b.ice_facet(f); + var ok = bb.ice_isA("::Ice::Object"); Debug.Assert(ok); ObjectPrxHelper h = new ObjectPrxHelper(); h.copyFrom__(bb); d = h; } - catch(Ice.FacetNotExistException) + catch(FacetNotExistException) { } } @@ -2558,14 +2789,14 @@ namespace Ice { try { - ObjectPrx bb = b.ice_facet(f); - bool ok = bb.ice_isA("::Ice::Object", ctx); + var bb = b.ice_facet(f); + var ok = bb.ice_isA("::Ice::Object", ctx); Debug.Assert(ok); ObjectPrxHelper h = new ObjectPrxHelper(); h.copyFrom__(bb); d = h; } - catch(Ice.FacetNotExistException) + catch(FacetNotExistException) { } } @@ -2595,8 +2826,8 @@ namespace Ice ObjectPrx d = null; if(b != null) { - ObjectPrx bb = b.ice_facet(f); - ObjectPrxHelper h = new ObjectPrxHelper(); + var bb = b.ice_facet(f); + var h = new ObjectPrxHelper(); h.copyFrom__(bb); d = h; } @@ -2611,7 +2842,7 @@ namespace Ice /// <returns>The type id, "::Ice::Object".</returns> public static string ice_staticId() { - return Ice.ObjectImpl.ice_staticId(); + return ObjectImpl.ice_staticId(); } } } diff --git a/csharp/src/Ice/RequestHandler.cs b/csharp/src/Ice/RequestHandler.cs index 37471ceec04..c334c9b246c 100644 --- a/csharp/src/Ice/RequestHandler.cs +++ b/csharp/src/Ice/RequestHandler.cs @@ -18,7 +18,7 @@ namespace IceInternal { RequestHandler update(RequestHandler previousHandler, RequestHandler newHandler); - bool sendAsyncRequest(ProxyOutgoingAsyncBase @out, out Ice.AsyncCallback cb); + int sendAsyncRequest(ProxyOutgoingAsyncBase @out); Reference getReference(); diff --git a/csharp/src/Ice/RetryQueue.cs b/csharp/src/Ice/RetryQueue.cs index f1788b49fd7..3d1bbaba137 100644 --- a/csharp/src/Ice/RetryQueue.cs +++ b/csharp/src/Ice/RetryQueue.cs @@ -41,13 +41,12 @@ namespace IceInternal { if(_instance.traceLevels().retry >= 1) { - string s = "operation retry canceled\n" + ex; - _instance.initializationData().logger.trace(_instance.traceLevels().retryCat, s); + _instance.initializationData().logger.trace(_instance.traceLevels().retryCat, + string.Format("operation retry canceled\n{0}", ex)); } - Ice.AsyncCallback cb = _outAsync.completed(ex); - if(cb != null) + if(_outAsync.exception(ex)) { - _outAsync.invokeCompletedAsync(cb); + _outAsync.invokeExceptionAsync(); } } } diff --git a/csharp/src/Ice/msbuild/ice.csproj b/csharp/src/Ice/msbuild/ice.csproj index 1733415bb67..c59d690e7a7 100644 --- a/csharp/src/Ice/msbuild/ice.csproj +++ b/csharp/src/Ice/msbuild/ice.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\Assemblies\Ice.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{7CB4715E-DD8B-48F8-B478-27B8BD4008C7}</ProjectGuid> @@ -469,6 +473,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file diff --git a/csharp/src/IceBox/msbuild/icebox/icebox.csproj b/csharp/src/IceBox/msbuild/icebox/icebox.csproj index c5aab43de26..610e58abb42 100644 --- a/csharp/src/IceBox/msbuild/icebox/icebox.csproj +++ b/csharp/src/IceBox/msbuild/icebox/icebox.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\..\bin\iceboxnet.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{30ED316B-AA69-4A88-A1A3-DB27A425D6BD}</ProjectGuid> @@ -55,6 +59,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file diff --git a/csharp/src/IceBox/msbuild/iceboxlib/iceboxlib.csproj b/csharp/src/IceBox/msbuild/iceboxlib/iceboxlib.csproj index 6da06194595..45db2dfc66f 100644 --- a/csharp/src/IceBox/msbuild/iceboxlib/iceboxlib.csproj +++ b/csharp/src/IceBox/msbuild/iceboxlib/iceboxlib.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\..\Assemblies\IceBox.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{FF25599C-3654-4DF3-8078-B8235341DF83}</ProjectGuid> @@ -43,6 +47,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file diff --git a/csharp/src/IceDiscovery/msbuild/icediscovery.csproj b/csharp/src/IceDiscovery/msbuild/icediscovery.csproj index 0758e6ebde6..8bdc63d7c2f 100644 --- a/csharp/src/IceDiscovery/msbuild/icediscovery.csproj +++ b/csharp/src/IceDiscovery/msbuild/icediscovery.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\Assemblies\IceDiscovery.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{CFFB222B-19D5-499E-B833-B0F7E523B16F}</ProjectGuid> @@ -52,6 +56,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file diff --git a/csharp/src/IceGrid/msbuild/icegrid.csproj b/csharp/src/IceGrid/msbuild/icegrid.csproj index eb856276f44..002fb61aaaf 100644 --- a/csharp/src/IceGrid/msbuild/icegrid.csproj +++ b/csharp/src/IceGrid/msbuild/icegrid.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\Assemblies\IceGrid.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{1153F70C-80E9-469A-952F-5117DAEE71A9}</ProjectGuid> @@ -76,6 +80,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file diff --git a/csharp/src/IceLocatorDiscovery/msbuild/icelocatordiscovery.csproj b/csharp/src/IceLocatorDiscovery/msbuild/icelocatordiscovery.csproj index 831824a572c..aaf34cdcd45 100644 --- a/csharp/src/IceLocatorDiscovery/msbuild/icelocatordiscovery.csproj +++ b/csharp/src/IceLocatorDiscovery/msbuild/icelocatordiscovery.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\Assemblies\IceLocatorDiscovery.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{8D8AA726-3A35-407B-BD38-BEA828EEE727}</ProjectGuid> @@ -46,6 +50,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file diff --git a/csharp/src/IcePatch2/msbuild/icepatch2.csproj b/csharp/src/IcePatch2/msbuild/icepatch2.csproj index eb02e7113d4..fc0a1ae1270 100644 --- a/csharp/src/IcePatch2/msbuild/icepatch2.csproj +++ b/csharp/src/IcePatch2/msbuild/icepatch2.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\Assemblies\IcePatch2.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{6479EE9D-5730-44BC-B564-97211E1B54C5}</ProjectGuid> @@ -47,6 +51,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file diff --git a/csharp/src/IceSSL/msbuild/icessl.csproj b/csharp/src/IceSSL/msbuild/icessl.csproj index 7ab53eff4e4..1f99b3021f1 100644 --- a/csharp/src/IceSSL/msbuild/icessl.csproj +++ b/csharp/src/IceSSL/msbuild/icessl.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\Assemblies\IceSSL.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{B763DADE-440B-46BC-9CC0-BF0CF9D43182}</ProjectGuid> @@ -80,6 +84,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file diff --git a/csharp/src/IceStorm/msbuild/icestorm.csproj b/csharp/src/IceStorm/msbuild/icestorm.csproj index 699299f35e6..92c00048f93 100644 --- a/csharp/src/IceStorm/msbuild/icestorm.csproj +++ b/csharp/src/IceStorm/msbuild/icestorm.csproj @@ -4,6 +4,10 @@ <IceBuilderCsharpProps Condition="!Exists('$(IceBuilderCsharpProps)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.props', SearchOption.AllDirectories))</IceBuilderCsharpProps> <IceBuilderCsharpTargets Condition="!Exists('$(IceBuilderCsharpTargets)')">$([System.IO.Directory]::GetFiles('$(LocalAppData)\Microsoft\VisualStudio\$(VisualStudioVersion)\Extensions', 'IceBuilder.Csharp.targets', SearchOption.AllDirectories))</IceBuilderCsharpTargets> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> + <DocumentationFile>..\..\..\Assemblies\IceStorm.XML</DocumentationFile> + <NoWarn>1591</NoWarn> + </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <ProjectGuid>{A77D65F6-31CF-4BFD-A7DF-E7F509B98573}</ProjectGuid> @@ -47,6 +51,7 @@ <PropertyGroup Label="IceBuilder"> <IceBuilderIncludeDirectories>$(IceHome)\slice</IceBuilderIncludeDirectories> <IceBuilderAllowIcePrefix>yes</IceBuilderAllowIcePrefix> + <IceBuilderAdditionalOptions>--compat</IceBuilderAdditionalOptions> </PropertyGroup> <Import Project="$(IceBuilderCsharpTargets)" Condition="Exists('$(IceBuilderCsharpTargets)')" /> </Project>
\ No newline at end of file |