internal void FoundAdapter(string adapterId, string requestId, IObjectPrx proxy, bool isReplicaGroup) { lock (this) { AdapterRequest request; if (_adapterRequests.TryGetValue(adapterId, out request) && request.getRequestId() == requestId) { if (request.response(proxy, isReplicaGroup)) { _timer.cancel(request); _adapterRequests.Remove(request.getId()); } } // else ignore responses from old requests } }
/// <summary>Sends a request synchronously.</summary> /// <param name="proxy">The proxy for the target Ice object.</param> /// <param name="request">The outgoing request frame for this invocation. Usually this request frame should have /// been created using the same proxy, however some differences are acceptable, for example proxy can have /// different endpoints.</param> /// <param name="oneway">When true, the request is sent as a oneway request. When false, it is sent as a /// two-way request.</param> /// <returns>The response frame.</returns> public static IncomingResponseFrame Invoke(this IObjectPrx proxy, OutgoingRequestFrame request, bool oneway = false) { try { var completed = new IObjectPrx.InvokeTaskCompletionCallback(null, default); new OutgoingAsync(proxy, completed, request, oneway: oneway).Invoke(request.Operation, request.Context, synchronous: true); return(completed.Task.Result); } catch (AggregateException ex) { Debug.Assert(ex.InnerException != null); throw ex.InnerException; } }
/// <summary>Creates a clone of this proxy, with a new facet and optionally other options. The clone is /// identical to this proxy except for its facet and other options set through parameters.</summary> /// <param name="prx">The source proxy.</param> /// <param name="facet">The facet of the clone.</param> /// <param name="factory">The proxy factory used to manufacture the clone.</param> /// <param name="adapterId">The adapter ID of the clone (optional).</param> /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param> /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional). /// </param> /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional). /// </param> /// <param name="compress">Determines whether or not the clone compresses requests (optional).</param> /// <param name="connectionId">The connection ID of the clone (optional).</param> /// <param name="connectionTimeout">The connection timeout of the clone (optional).</param> /// <param name="context">The context of the clone (optional).</param> /// <param name="encoding">The encoding of the clone (optional).</param> /// <param name="endpointSelection">The encoding selection policy of the clone (optional).</param> /// <param name="endpoints">The endpoints of the clone (optional).</param> /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param> /// <param name="invocationMode">The invocation mode of the clone (optional).</param> /// <param name="invocationTimeout">The invocation timeout of the clone (optional).</param> /// <param name="locator">The locator proxy of the clone (optional).</param> /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param> /// <param name="oneway">Determines whether the clone is oneway or twoway (optional). This is a simplified /// version of the invocationMode parameter.</param> /// <param name="preferNonSecure">Determines whether the clone prefers non-secure connections over secure /// connections (optional).</param> /// <param name="protocol">The Ice protocol of the clone (optional).</param> /// <param name="router">The router proxy of the clone (optional).</param> /// <returns>A new proxy manufactured by the proxy factory (see factory parameter).</returns> public static T Clone <T>(this IObjectPrx prx, string facet, ProxyFactory <T> factory, string?adapterId = null, bool?cacheConnection = null, bool clearLocator = false, bool clearRouter = false, bool?compress = null, string?connectionId = null, int?connectionTimeout = null, IReadOnlyDictionary <string, string>?context = null, Encoding?encoding = null, EndpointSelectionType?endpointSelection = null, IEnumerable <Endpoint>?endpoints = null, Connection?fixedConnection = null, InvocationMode?invocationMode = null, int?invocationTimeout = null, ILocatorPrx?locator = null, TimeSpan?locatorCacheTimeout = null, bool?oneway = null, bool?preferNonSecure = null, Protocol?protocol = null, IRouterPrx?router = null) where T : class, IObjectPrx { return(factory(prx.IceReference.Clone(adapterId, cacheConnection, clearLocator, clearRouter, compress, connectionId, connectionTimeout, context, encoding, endpointSelection, endpoints, facet, fixedConnection, identity: null, invocationMode, invocationTimeout, locator, locatorCacheTimeout, oneway, preferNonSecure, protocol, router))); }
/// Compares two proxies using the object identity and facet for comparison. /// <param name="obj1">A proxy to compare.</param> /// <param name="obj2">A proxy to compare.</param> /// <returns>< 0 if obj1 is less than obj2; > 0 if obj1 is greater than obj2; /// 0, otherwise.</returns> public int Compare(object obj1, object obj2) { IObjectPrx proxy1 = obj1 as IObjectPrx; if (obj1 != null && proxy1 == null) { throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(obj1)); } IObjectPrx proxy2 = obj2 as IObjectPrx; if (obj2 != null && proxy2 == null) { throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(obj2)); } return(Util.proxyIdentityAndFacetCompare(proxy1, proxy2)); }
internal IObjectPrx FindObject(Identity id) { lock (this) { if (id.name.Length == 0) { return(null); } IObjectPrx prx = _wellKnownProxy.Clone(id); List <string> adapterIds = new List <string>(); foreach (KeyValuePair <string, HashSet <string> > entry in _replicaGroups) { try { prx.Clone(adapterId: entry.Key).IcePing(); adapterIds.Add(entry.Key); } catch (Ice.Exception) { } } if (adapterIds.Count == 0) { foreach (KeyValuePair <string, IObjectPrx> entry in _adapters) { try { prx.Clone(adapterId: entry.Key).IcePing(); adapterIds.Add(entry.Key); } catch (Exception) { } } } if (adapterIds.Count == 0) { return(null); } //adapterIds.Suffle(); return(prx.Clone(adapterId: adapterIds[0])); } }
public void Destroy() { if (_replyAdapter != null) { _replyAdapter.Destroy(); } if (_locatorAdapter != null) { _locatorAdapter.Destroy(); } if (IObjectPrx.Equals(_communicator.GetDefaultLocator(), _locatorPrx)) { // Restore original default locator proxy, if the user didn't change it in the meantime _communicator.SetDefaultLocator(_defaultLocator); } }
public Task <TReturnValue> InvokeAsync( IObjectPrx prx, TParamList paramList, IReadOnlyDictionary <string, string>?context, IProgress <bool>?progress, CancellationToken cancel) => InvokeAsync(prx, OutgoingRequestFrame.WithParamList(prx, _operationName, _idempotent, _compress, _format, context, paramList, _writer), progress, cancel);
/// <summary>Creates a clone of this proxy, with a new identity and optionally other options. The clone /// is identical to this proxy except for its identity and other options set through parameters.</summary> /// <param name="prx">The source proxy.</param> /// <param name="factory">The proxy factory used to manufacture the clone.</param> /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param> /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional). /// </param> /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional). /// </param> /// <param name="connectionId">The connection ID of the clone (optional).</param> /// <param name="context">The context of the clone (optional).</param> /// <param name="encoding">The encoding of the clone (optional).</param> /// <param name="endpoints">The endpoints of the clone (optional).</param> /// <param name="facet">The facet of the clone (optional).</param> /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param> /// <param name="identity">The identity of the clone.</param> /// <param name="identityAndFacet">A relative URI string [category/]identity[#facet].</param> /// <param name="invocationInterceptors">A collection of <see cref="InvocationInterceptor"/> that will be /// executed with each invocation</param> /// <param name="invocationMode">The invocation mode of the clone (optional). Applies only to ice1 proxies. /// </param> /// <param name="invocationTimeout">The invocation timeout of the clone (optional).</param> /// <param name="location">The location of the clone (optional).</param> /// <param name="locator">The locator proxy of the clone (optional).</param> /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param> /// <param name="oneway">Determines whether the clone is oneway or twoway (optional).</param> /// <param name="preferNonSecure">Determines whether the clone prefers non-secure connections over secure /// connections (optional).</param> /// <param name="relative">When true, the new proxy is a relative proxy (optional).</param> /// <param name="router">The router proxy of the clone (optional).</param> /// <returns>A new proxy manufactured by the proxy factory (see factory parameter).</returns> public static T Clone <T>( this IObjectPrx prx, ProxyFactory <T> factory, bool?cacheConnection = null, bool clearLocator = false, bool clearRouter = false, string?connectionId = null, IReadOnlyDictionary <string, string>?context = null, Encoding?encoding = null, IEnumerable <Endpoint>?endpoints = null, string?facet = null, Connection?fixedConnection = null, Identity?identity = null, string?identityAndFacet = null, IEnumerable <InvocationInterceptor>?invocationInterceptors = null, InvocationMode?invocationMode = null, TimeSpan?invocationTimeout = null, IEnumerable <string>?location = null, ILocatorPrx?locator = null, TimeSpan?locatorCacheTimeout = null, bool?oneway = null, bool?preferNonSecure = null, bool?relative = null, IRouterPrx?router = null) where T : class, IObjectPrx => factory(prx.IceReference.Clone(cacheConnection, clearLocator, clearRouter, connectionId, context, encoding, endpoints, facet, fixedConnection, identity, identityAndFacet, invocationInterceptors, invocationMode, invocationTimeout, location, locator, locatorCacheTimeout, oneway, preferNonSecure, relative, router));
public async ValueTask DisposeAsync() { if (_replyAdapter != null) { await _replyAdapter.DisposeAsync().ConfigureAwait(false); } if (_locatorAdapter != null) { await _locatorAdapter.DisposeAsync().ConfigureAwait(false); } if (IObjectPrx.Equals(_communicator.DefaultLocator, _locatorPrx)) { // Restore original default locator proxy, if the user didn't change it in the meantime _communicator.DefaultLocator = _defaultLocator; } }
/// <summary> /// Invokes an operation dynamically. /// </summary> /// <param name="prx">The proxy to invoke the operation.</param> /// <param name="operation">The name of the operation to invoke.</param> /// <param name="idempotent">True if this operation is idempotent, and false otherwise.</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 static bool Invoke(this IObjectPrx prx, string operation, bool idempotent, byte[] inEncaps, out byte[]?outEncaps, Dictionary <string, string>?context = null) { try { Object_Ice_invokeResult result = prx.IceI_ice_invokeAsync(operation, idempotent, inEncaps, context, null, CancellationToken.None, true).Result; outEncaps = result.OutEncaps; return(result.ReturnValue); } catch (AggregateException ex) { throw ex.InnerException; } }
private static Connection connect(IObjectPrx prx) { int nRetry = 10; while (--nRetry > 0) { try { prx.GetConnection(); break; } catch (ConnectTimeoutException) { // Can sporadically occur with slow machines } } return(prx.GetConnection()); }
public override async Task RunAsync(string[] args) { Dictionary <string, string> properties = CreateTestProperties(ref args); properties["Ice.Warn.Dispatch"] = "0"; properties["Ice.Warn.Connections"] = "0"; properties["Ice.IncomingFrameMaxSize"] = "10K"; await using Communicator communicator = Initialize(properties); await communicator.ActivateAsync(); communicator.SetProperty("TestAdapter.Endpoints", GetTestEndpoint(0)); communicator.SetProperty("TestAdapter2.Endpoints", GetTestEndpoint(1)); communicator.SetProperty("TestAdapter2.IncomingFrameMaxSize", "0"); communicator.SetProperty("TestAdapter3.Endpoints", GetTestEndpoint(2)); communicator.SetProperty("TestAdapter3.IncomingFrameMaxSize", "1K"); ObjectAdapter adapter = communicator.CreateObjectAdapter("TestAdapter"); ObjectAdapter adapter2 = communicator.CreateObjectAdapter("TestAdapter2"); ObjectAdapter adapter3 = communicator.CreateObjectAdapter("TestAdapter3"); var obj = new Thrower(); ZeroC.Ice.IObjectPrx prx = adapter.Add("thrower", obj, ZeroC.Ice.IObjectPrx.Factory); adapter2.Add("thrower", obj); adapter3.Add("thrower", obj); await adapter.ActivateAsync(); await adapter2.ActivateAsync(); await adapter3.ActivateAsync(); await using var communicator2 = new Communicator(properties); await communicator2.ActivateAsync(); communicator2.SetProperty("ForwarderAdapter.Endpoints", GetTestEndpoint(3)); communicator2.SetProperty("ForwarderAdapter.IncomingFrameMaxSize", "0"); ObjectAdapter forwarderAdapter = communicator2.CreateObjectAdapter("ForwarderAdapter"); forwarderAdapter.Add("forwarder", new Forwarder(IObjectPrx.Parse(GetTestProxy("thrower"), communicator2))); await forwarderAdapter.ActivateAsync(); ServerReady(); await communicator.WaitForShutdownAsync(); }
public IInvocationObserver?GetInvocationObserver( IObjectPrx prx, string operation, IReadOnlyDictionary <string, string> context) { if (_invocations.IsEnabled) { try { return(_invocations.GetObserver(new InvocationHelper(prx, operation, context), _delegate?.GetInvocationObserver(prx, operation, context))); } catch (Exception ex) { AdminFacet.Logger.Error($"unexpected exception trying to obtain observer:\n{ex}"); } } return(null); }
private protected void Invoke(IObjectPrx prx, OutgoingRequestFrame request) { try { var completed = new IObjectPrx.InvokeTaskCompletionCallback(null, default); new OutgoingAsync(prx, completed, request, oneway: prx.IsOneway).Invoke( request.Operation, request.Context, synchronous: true); IncomingResponseFrame response = completed.Task.Result; if (!prx.IsOneway) { response.ReadVoidReturnValue(); } } catch (AggregateException ex) { Debug.Assert(ex.InnerException != null); throw ex.InnerException; } }
/// <summary> /// Returns the cached Connection for this proxy. If the proxy does not yet have an established /// connection, it does not attempt to create a connection. /// </summary> /// <returns>The cached Connection for this proxy (null if the proxy does not have /// an established connection).</returns> /// <exception name="CollocationOptimizationException">If the proxy uses collocation optimization and denotes a /// collocated object.</exception> public static Connection?GetCachedConnection(this IObjectPrx prx) { IRequestHandler?handler; lock (prx) { handler = prx.RequestHandler; } if (handler != null) { try { return(handler.GetConnection()); } catch (System.Exception) { } } return(null); }
public Ice.Instrumentation.IInvocationObserver? GetInvocationObserver(IObjectPrx prx, string operation, Dictionary <string, string> ctx) { if (_invocations.IsEnabled()) { try { Ice.Instrumentation.IInvocationObserver del = null; if (_delegate != null) { del = _delegate.GetInvocationObserver(prx, operation, ctx); } return(_invocations.GetObserver(new InvocationHelper(prx, operation, ctx), del)); } catch (System.Exception ex) { _metrics.GetLogger().Error("unexpected exception trying to obtain observer:\n" + ex); } } return(null); }
/// <summary>Creates a new outgoing request frame. This frame is incomplete and its payload needs to be /// provided using StartParameters/EndParameters.</summary> /// <param name="proxy">A proxy to the target Ice object. This method uses the communicator, identity, facet, /// encoding and context of this proxy to create the request frame.</param> /// <param name="operation">The operation to invoke on the target Ice object.</param> /// <param name="idempotent">True when operation is idempotent, otherwise false.</param> /// <param name="context">An optional explicit context. When non null, it overrides both the context of the /// proxy and the communicator's current context (if any).</param> public OutgoingRequestFrame(IObjectPrx proxy, string operation, bool idempotent, IReadOnlyDictionary <string, string>?context = null) : base(proxy.Communicator) { proxy.IceReference.GetProtocol().CheckSupported(); Identity = proxy.Identity; Facet = proxy.Facet; Operation = operation; IsIdempotent = idempotent; _payloadEncoding = proxy.Encoding; WriteSpan(Ice1Definitions.RequestHeader.AsSpan()); Identity.IceWrite(this); if (Facet.Length == 0) { WriteStringSeq(Array.Empty <string>()); } else { WriteStringSeq(new string[] { Facet }); } WriteString(operation); this.Write(idempotent ? OperationMode.Idempotent : OperationMode.Normal); if (context != null) { Context = new Dictionary <string, string>(context); } else { Context = new Dictionary <string, string>(proxy.Communicator.CurrentContext); foreach ((string key, string value) in proxy.Context) { Context[key] = value; // the proxy Context entry prevails. } } ContextHelper.Write(this, Context); }
public override async Task RunAsync(string[] args) { await Communicator.ActivateAsync(); Dictionary <string, string> properties = Communicator.GetProperties(); Communicator.SetProperty("TestAdapter.Endpoints", GetTestEndpoint(0)); Communicator.SetProperty("TestAdapter2.Endpoints", GetTestEndpoint(1)); Communicator.SetProperty("TestAdapter2.IncomingFrameMaxSize", "0"); Communicator.SetProperty("TestAdapter3.Endpoints", GetTestEndpoint(2)); Communicator.SetProperty("TestAdapter3.IncomingFrameMaxSize", "1K"); ObjectAdapter adapter = Communicator.CreateObjectAdapter("TestAdapter"); ObjectAdapter adapter2 = Communicator.CreateObjectAdapter("TestAdapter2"); ObjectAdapter adapter3 = Communicator.CreateObjectAdapter("TestAdapter3"); var obj = new Thrower(); ZeroC.Ice.IObjectPrx prx = adapter.Add("thrower", obj, ZeroC.Ice.IObjectPrx.Factory); adapter2.Add("thrower", obj); adapter3.Add("thrower", obj); await adapter.ActivateAsync(); await adapter2.ActivateAsync(); await adapter3.ActivateAsync(); await using var communicator2 = new Communicator(properties); await communicator2.ActivateAsync(); communicator2.SetProperty("ForwarderAdapter.Endpoints", GetTestEndpoint(3)); communicator2.SetProperty("ForwarderAdapter.IncomingFrameMaxSize", "0"); ObjectAdapter forwarderAdapter = communicator2.CreateObjectAdapter("ForwarderAdapter"); forwarderAdapter.Add("forwarder", new Forwarder(IObjectPrx.Parse(GetTestProxy("thrower"), communicator2))); await forwarderAdapter.ActivateAsync(); ServerReady(); await Communicator.ShutdownComplete; }
/// <summary>Forwards an incoming request to another Ice object represented by the <paramref name="proxy"/> /// parameter.</summary> /// <remarks>When the incoming request frame's protocol and proxy's protocol are different, this method /// automatically bridges between these two protocols. When proxy's protocol is ice1, the resulting outgoing /// request frame is never compressed.</remarks> /// <param name="proxy">The proxy for the target Ice object.</param> /// <param name="request">The incoming request frame to forward to proxy's target.</param> /// <param name="oneway">When true, the request is sent as a oneway request. When false, it is sent as a /// two-way request.</param> /// <param name="progress">Sent progress provider.</param> /// <param name="cancel">A cancellation token that receives the cancellation requests.</param> /// <returns>A task holding the response frame.</returns> public static async ValueTask <OutgoingResponseFrame> ForwardAsync( this IObjectPrx proxy, IncomingRequestFrame request, bool oneway, IProgress <bool>?progress = null, CancellationToken cancel = default) { var forwardedRequest = new OutgoingRequestFrame(proxy, request, cancel: cancel); try { // TODO: add support for stream data forwarding. using IncomingResponseFrame response = await Reference.InvokeAsync(proxy, forwardedRequest, oneway, progress).ConfigureAwait(false); return(new OutgoingResponseFrame(request, response)); } catch (LimitExceededException exception) { return(new OutgoingResponseFrame(request, new ServerException(exception.Message, exception))); } }
internal IRequestHandler GetRequestHandler(RoutableReference rf, IObjectPrx proxy) { if (rf.GetCollocationOptimized()) { ObjectAdapter?adapter = FindObjectAdapter(proxy); if (adapter != null) { return(proxy.IceSetRequestHandler(new CollocatedRequestHandler(rf, adapter))); } } bool connect = false; ConnectRequestHandler handler; if (rf.GetCacheConnection()) { lock (_handlers) { if (!_handlers.TryGetValue(rf, out handler)) { handler = new ConnectRequestHandler(rf, proxy); _handlers.Add(rf, handler); connect = true; } } } else { handler = new ConnectRequestHandler(rf, proxy); connect = true; } if (connect) { rf.GetConnection(handler); } return(proxy.IceSetRequestHandler(handler.Connect(proxy))); }
public void FindObjectById(string domainId, Identity id, ILookupReplyPrx reply, Current current) { if (!domainId.Equals(_domainId)) { return; // Ignore } IObjectPrx proxy = _registry.FindObject(id); if (proxy != null) { // // Reply to the mulicast request using the given proxy. // try { reply.FoundObjectByIdAsync(id, proxy); } catch (LocalException) { // Ignore. } } }
// // Implementation of Reference.GetConnectionCallback // public void SetConnection(Connection connection, bool compress) { lock (this) { Debug.Assert(!_flushing && _exception == null && _connection == null); _connection = connection; _compress = compress; } // // If this proxy is for a non-local object, and we are using a router, then // add this proxy to the router info object. RouterInfo?ri = _reference.RouterInfo; if (ri != null && !ri.AddProxy(IObjectPrx.Factory(_reference), this)) { return; // The request handler will be initialized once addProxy returns. } // // We can now send the queued requests. // FlushRequests(); }
public void FindAdapterById(string domainId, string adapterId, ILookupReplyPrx reply, Current current) { if (!domainId.Equals(_domainId)) { return; // Ignore } IObjectPrx proxy = _registry.FindAdapter(adapterId, out bool isReplicaGroup); if (proxy != null) { // // Reply to the multicast request using the given proxy. // try { reply.FoundAdapterByIdAsync(adapterId, proxy, isReplicaGroup); } catch (LocalException) { // Ignore. } } }
public static IGPrx allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing Ice.Admin.Facets property... "); test(communicator.GetPropertyAsList("Ice.Admin.Facets") == null); communicator.SetProperty("Ice.Admin.Facets", "foobar"); string[]? facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets"); test(facetFilter != null && facetFilter.Length == 1 && facetFilter[0].Equals("foobar")); communicator.SetProperty("Ice.Admin.Facets", "foo\\'bar"); facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets"); test(facetFilter != null && facetFilter.Length == 1 && facetFilter[0].Equals("foo'bar")); communicator.SetProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'"); facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets"); test(facetFilter != null && facetFilter.Length == 3 && facetFilter[0].Equals("foo bar") && facetFilter[1].Equals("toto") && facetFilter[2].Equals("titi")); communicator.SetProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'"); facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets"); test(facetFilter != null && facetFilter.Length == 2 && facetFilter[0].Equals("foo bar' toto") && facetFilter[1].Equals("titi")); // communicator.SetProperty("Ice.Admin.Facets", "'foo bar' 'toto titi"); // facetFilter = communicator.Properties.getPropertyAsList("Ice.Admin.Facets"); // test(facetFilter.Length == 0); communicator.SetProperty("Ice.Admin.Facets", ""); output.WriteLine("ok"); output.Write("testing facet registration exceptions... "); communicator.SetProperty("FacetExceptionTestAdapter.Endpoints", "tcp -h *"); ObjectAdapter adapter = communicator.CreateObjectAdapter("FacetExceptionTestAdapter"); var obj = new Empty(); adapter.Add("d", obj); adapter.Add("d", "facetABCD", obj); try { adapter.Add("d", "facetABCD", obj); test(false); } catch (System.ArgumentException) { } adapter.Remove("d", "facetABCD"); adapter.Remove("d", "facetABCD"); // multiple Remove are fine as of Ice 4.0 output.WriteLine("ok"); adapter.Deactivate(); var prx = IObjectPrx.Parse($"d:{helper.getTestEndpoint(0)}", communicator); output.Write("testing unchecked cast... "); output.Flush(); var d = IDPrx.UncheckedCast(prx); test(d.Facet.Length == 0); var df = prx.Clone("facetABCD", IDPrx.Factory); test(df.Facet == "facetABCD"); var df2 = IDPrx.UncheckedCast(df); test(df2.Facet == "facetABCD"); var df3 = df.Clone(facet: "", IDPrx.Factory); test(df3.Facet.Length == 0); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); d = IDPrx.CheckedCast(prx); test(d.Facet.Length == 0); df = IDPrx.CheckedCast(prx.Clone(facet: "facetABCD", IObjectPrx.Factory)); test(df.Facet == "facetABCD"); df2 = IDPrx.CheckedCast(df); test(df2.Facet == "facetABCD"); df3 = IDPrx.CheckedCast(df.Clone(facet: "", IObjectPrx.Factory)); test(df3.Facet.Length == 0); output.WriteLine("ok"); output.Write("testing non-facets A, B, C, and D... "); output.Flush(); d = IDPrx.CheckedCast(prx); test(d != null); test(d.Equals(prx)); test(d.callA().Equals("A")); test(d.callB().Equals("B")); test(d.callC().Equals("C")); test(d.callD().Equals("D")); output.WriteLine("ok"); output.Write("testing facets A, B, C, and D... "); output.Flush(); df = IDPrx.CheckedCast(d.Clone(facet: "facetABCD", IObjectPrx.Factory)); test(df != null); test(df.callA().Equals("A")); test(df.callB().Equals("B")); test(df.callC().Equals("C")); test(df.callD().Equals("D")); output.WriteLine("ok"); output.Write("testing facets E and F... "); output.Flush(); var ff = IFPrx.CheckedCast(d.Clone(facet: "facetEF", IObjectPrx.Factory)); test(ff.callE().Equals("E")); test(ff.callF().Equals("F")); output.WriteLine("ok"); output.Write("testing facet G... "); output.Flush(); var gf = IGPrx.CheckedCast(ff.Clone(facet: "facetGH", IObjectPrx.Factory)); test(gf.callG().Equals("G")); output.WriteLine("ok"); output.Write("testing whether casting preserves the facet... "); output.Flush(); var hf = IHPrx.CheckedCast(gf); test(hf.callG().Equals("G")); test(hf.callH().Equals("H")); output.WriteLine("ok"); return(gf); }
public static void allTests(global::Test.TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); var output = helper.GetWriter(); output.Write("testing proxy endpoint information... "); output.Flush(); { var p1 = IObjectPrx.Parse( "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" + "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" + "opaque -e 1.8 -t 100 -v ABCD", communicator); var endps = p1.Endpoints; Endpoint endpoint = endps[0]; TcpEndpoint?tcpEndpoint = getTCPEndpoint(endpoint); TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert(tcpEndpoint.Host.Equals("tcphost")); TestHelper.Assert(tcpEndpoint.Port == 10000); TestHelper.Assert(tcpEndpoint.SourceAddress !.ToString().Equals("10.10.10.10")); TestHelper.Assert(tcpEndpoint.Timeout == 1200); TestHelper.Assert(tcpEndpoint.HasCompressionFlag); TestHelper.Assert(!tcpEndpoint.IsDatagram); TestHelper.Assert(tcpEndpoint.Type == EndpointType.TCP && !tcpEndpoint.IsSecure || tcpEndpoint.Type == EndpointType.SSL && tcpEndpoint.IsSecure || tcpEndpoint.Type == EndpointType.WS && !tcpEndpoint.IsSecure || tcpEndpoint.Type == EndpointType.WSS && tcpEndpoint.IsSecure); TestHelper.Assert(tcpEndpoint.Type == EndpointType.TCP && endpoint is TcpEndpoint || tcpEndpoint.Type == EndpointType.SSL && endpoint is IceSSL.Endpoint || tcpEndpoint.Type == EndpointType.WS && endpoint is WSEndpoint || tcpEndpoint.Type == EndpointType.WSS && endpoint is WSEndpoint); UdpEndpoint udpEndpoint = (UdpEndpoint)endps[1]; TestHelper.Assert(udpEndpoint.Host.Equals("udphost")); TestHelper.Assert(udpEndpoint.Port == 10001); TestHelper.Assert(udpEndpoint.McastInterface.Equals("eth0")); TestHelper.Assert(udpEndpoint.McastTtl == 5); TestHelper.Assert(udpEndpoint.SourceAddress !.ToString().Equals("10.10.10.10")); TestHelper.Assert(udpEndpoint.Timeout == -1); TestHelper.Assert(!udpEndpoint.HasCompressionFlag); TestHelper.Assert(!udpEndpoint.IsSecure); TestHelper.Assert(udpEndpoint.IsDatagram); TestHelper.Assert(udpEndpoint.Type == EndpointType.UDP); OpaqueEndpoint opaqueEndpoint = (OpaqueEndpoint)endps[2]; TestHelper.Assert(opaqueEndpoint.Bytes.Length > 0); TestHelper.Assert(opaqueEndpoint.Encoding.Equals(new Encoding(1, 8))); } output.WriteLine("ok"); ObjectAdapter adapter; output.Write("test object adapter endpoint information... "); output.Flush(); { string host = communicator.GetPropertyAsInt("Ice.IPv6") != 0 ? "::1" : "127.0.0.1"; communicator.SetProperty("TestAdapter.Endpoints", "tcp -h \"" + host + "\" -t 15000:udp -h \"" + host + "\""); adapter = communicator.CreateObjectAdapter("TestAdapter"); var endpoints = adapter.GetEndpoints(); TestHelper.Assert(endpoints.Count == 2); var publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(global::Test.Collections.Equals(endpoints, publishedEndpoints)); TcpEndpoint?tcpEndpoint = getTCPEndpoint(endpoints[0]); TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert( tcpEndpoint.Type == EndpointType.TCP || tcpEndpoint.Type == EndpointType.SSL || tcpEndpoint.Type == EndpointType.WS || tcpEndpoint.Type == EndpointType.WSS); TestHelper.Assert(tcpEndpoint.Host.Equals(host)); TestHelper.Assert(tcpEndpoint.Port > 0); TestHelper.Assert(tcpEndpoint.Timeout == 15000); UdpEndpoint udpEndpoint = (UdpEndpoint)endpoints[1]; TestHelper.Assert(udpEndpoint.Host.Equals(host)); TestHelper.Assert(udpEndpoint.IsDatagram); TestHelper.Assert(udpEndpoint.Port > 0); endpoints = new List <Endpoint> { endpoints[0] }; TestHelper.Assert(endpoints.Count == 1); adapter.SetPublishedEndpoints(endpoints); publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(Collections.Equals(endpoints, publishedEndpoints)); adapter.Destroy(); int port = helper.GetTestPort(1); communicator.SetProperty("TestAdapter.Endpoints", $"default -h * -p {port}"); communicator.SetProperty("TestAdapter.PublishedEndpoints", helper.GetTestEndpoint(1)); adapter = communicator.CreateObjectAdapter("TestAdapter"); endpoints = adapter.GetEndpoints(); TestHelper.Assert(endpoints.Count >= 1); publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(publishedEndpoints.Count == 1); foreach (var endpoint in endpoints) { tcpEndpoint = getTCPEndpoint(endpoint); TestHelper.Assert(tcpEndpoint !.Port == port); } tcpEndpoint = getTCPEndpoint(publishedEndpoints[0]); TestHelper.Assert(tcpEndpoint !.Host == "127.0.0.1"); TestHelper.Assert(tcpEndpoint !.Port == port); adapter.Destroy(); } output.WriteLine("ok"); int endpointPort = helper.GetTestPort(0); var testIntf = Test.ITestIntfPrx.Parse("test:" + helper.GetTestEndpoint(0) + ":" + helper.GetTestEndpoint(0, "udp"), communicator); string defaultHost = communicator.GetProperty("Ice.Default.Host") ?? ""; output.Write("test connection endpoint information... "); output.Flush(); { Endpoint endpoint = testIntf.GetConnection().Endpoint; TcpEndpoint?tcpEndpoint = getTCPEndpoint(endpoint); TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert(tcpEndpoint.Port == endpointPort); TestHelper.Assert(!tcpEndpoint.HasCompressionFlag); TestHelper.Assert(tcpEndpoint.Host.Equals(defaultHost)); Dictionary <string, string> ctx = testIntf.getEndpointInfoAsContext(); TestHelper.Assert(ctx["host"].Equals(tcpEndpoint.Host)); TestHelper.Assert(ctx["compress"].Equals("false")); int port = int.Parse(ctx["port"]); TestHelper.Assert(port > 0); endpoint = testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection().Endpoint; UdpEndpoint udp = (UdpEndpoint)endpoint; TestHelper.Assert(udp.Port == endpointPort); TestHelper.Assert(udp.Host.Equals(defaultHost)); } output.WriteLine("ok"); output.Write("testing connection information... "); output.Flush(); { Connection connection = testIntf.GetConnection(); connection.SetBufferSize(1024, 2048); ConnectionInfo info = connection.GetConnectionInfo(); TCPConnectionInfo ipInfo = getTCPConnectionInfo(info) !; TestHelper.Assert(!info.Incoming); TestHelper.Assert(info.AdapterName !.Length == 0); TestHelper.Assert(ipInfo.RemotePort == endpointPort); TestHelper.Assert(ipInfo.LocalPort > 0); if (defaultHost.Equals("127.0.0.1")) { TestHelper.Assert(ipInfo.LocalAddress.Equals(defaultHost)); TestHelper.Assert(ipInfo.RemoteAddress.Equals(defaultHost)); } TestHelper.Assert(ipInfo.RcvSize >= 1024); TestHelper.Assert(ipInfo.SndSize >= 2048); Dictionary <string, string> ctx = testIntf.getConnectionInfoAsContext(); TestHelper.Assert(ctx["incoming"].Equals("true")); TestHelper.Assert(ctx["adapterName"].Equals("TestAdapter")); TestHelper.Assert(ctx["remoteAddress"].Equals(ipInfo.LocalAddress)); TestHelper.Assert(ctx["localAddress"].Equals(ipInfo.RemoteAddress)); TestHelper.Assert(ctx["remotePort"].Equals(ipInfo.LocalPort.ToString())); TestHelper.Assert(ctx["localPort"].Equals(ipInfo.RemotePort.ToString())); if (testIntf.GetConnection().Type().Equals("ws") || testIntf.GetConnection().Type().Equals("wss")) { Dictionary <string, string> headers = ((WSConnectionInfo)info).Headers !; TestHelper.Assert(headers["Upgrade"].Equals("websocket")); TestHelper.Assert(headers["Connection"].Equals("Upgrade")); TestHelper.Assert(headers["Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); TestHelper.Assert(headers["Sec-WebSocket-Accept"] != null); TestHelper.Assert(ctx["ws.Upgrade"].Equals("websocket")); TestHelper.Assert(ctx["ws.Connection"].Equals("Upgrade")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Version"].Equals("13")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Key"] != null); } connection = testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection(); connection.SetBufferSize(2048, 1024); UDPConnectionInfo udpInfo = (UDPConnectionInfo)connection.GetConnectionInfo(); TestHelper.Assert(!udpInfo.Incoming); TestHelper.Assert(udpInfo.AdapterName !.Length == 0); TestHelper.Assert(udpInfo.LocalPort > 0); TestHelper.Assert(udpInfo.RemotePort == endpointPort); if (defaultHost.Equals("127.0.0.1")) { TestHelper.Assert(udpInfo.RemoteAddress.Equals(defaultHost)); TestHelper.Assert(udpInfo.LocalAddress.Equals(defaultHost)); } TestHelper.Assert(udpInfo.RcvSize >= 2048); TestHelper.Assert(udpInfo.SndSize >= 1024); } output.WriteLine("ok"); testIntf.shutdown(); communicator.Shutdown(); communicator.WaitForShutdown(); }
public override async Task RunAsync(string[] args) { Dictionary <string, string> properties = CreateTestProperties(ref args); // We must disable connection warnings, because we attempt to ping the router before session establishment, // as well as after session destruction. Both will cause a ConnectionLostException. properties["Ice.Warn.Connections"] = "0"; properties["Test.Protocol"] = "ice1"; await using Communicator communicator = Initialize(properties); IObjectPrx routerBase; { Console.Out.Write("testing stringToProxy for router... "); Console.Out.Flush(); routerBase = IObjectPrx.Parse(GetTestProxy("Glacier2/router", 50), communicator); Console.Out.WriteLine("ok"); } IRouterPrx?router; { Console.Out.Write("testing checked cast for router... "); Console.Out.Flush(); router = routerBase.CheckedCast(IRouterPrx.Factory); Assert(router != null); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing router finder... "); Console.Out.Flush(); var finder = IRouterFinderPrx.Parse(GetTestProxy("Ice/RouterFinder", 50), communicator); Assert(finder.GetRouter() !.Identity.Equals(router.Identity)); Console.Out.WriteLine("ok"); } { Console.Out.Write("installing router with communicator... "); Console.Out.Flush(); communicator.DefaultRouter = router; Console.Out.WriteLine("ok"); } { Console.Out.Write("getting the session timeout... "); Console.Out.Flush(); long sessionTimeout = router.GetSessionTimeout(); long acmTimeout = router.GetACMTimeout(); Assert(sessionTimeout == 30 && acmTimeout == 30); Console.Out.WriteLine("ok"); } ICallbackPrx twoway; { Console.Out.Write("testing stringToProxy for server object... "); Console.Out.Flush(); twoway = ICallbackPrx.Parse(GetTestProxy("c1/callback", 0), communicator); Console.Out.WriteLine("ok"); } { Console.Out.Write("trying to ping server before session creation... "); Console.Out.Flush(); try { twoway.IcePing(); Assert(false); } catch (ConnectionLostException) { Console.Out.WriteLine("ok"); } catch (TransportException) { Assert(false); } } { Console.Out.Write("trying to create session with wrong password... "); Console.Out.Flush(); try { router.CreateSession("userid", "xxx"); Assert(false); } catch (PermissionDeniedException) { Console.Out.WriteLine("ok"); } catch (CannotCreateSessionException) { Assert(false); } } { Console.Out.Write("trying to destroy non-existing session... "); Console.Out.Flush(); try { router.DestroySession(); Assert(false); } catch (SessionNotExistException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("creating session with correct password... "); Console.Out.Flush(); try { router.CreateSession("userid", "abc123"); } catch (PermissionDeniedException) { Assert(false); } catch (CannotCreateSessionException) { Assert(false); } Console.Out.WriteLine("ok"); } { Console.Out.Write("trying to create a second session... "); Console.Out.Flush(); try { router.CreateSession("userid", "abc123"); Assert(false); } catch (PermissionDeniedException) { Assert(false); } catch (CannotCreateSessionException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("pinging server after session creation... "); Console.Out.Flush(); twoway.IcePing(); Console.Out.WriteLine("ok"); } { Console.Out.Write("pinging object with client endpoint... "); var baseC = IObjectPrx.Parse(GetTestProxy("collocated", 50), communicator); try { baseC.IcePing(); } catch (ObjectNotExistException) { } Console.Out.WriteLine("ok"); } ObjectAdapter adapter; { Console.Out.Write("creating and activating callback receiver adapter... "); Console.Out.Flush(); communicator.SetProperty("Ice.PrintAdapterReady", "0"); adapter = communicator.CreateObjectAdapterWithRouter("CallbackReceiverAdapter", router); adapter.Activate(); Console.Out.WriteLine("ok"); } string category; { Console.Out.Write("getting category from router... "); Console.Out.Flush(); category = router.GetCategoryForClient(); Console.Out.WriteLine("ok"); } CallbackReceiver callbackReceiverImpl; ICallbackReceiver callbackReceiver; ICallbackReceiverPrx twowayR; ICallbackReceiverPrx fakeTwowayR; { Console.Out.Write("creating and adding callback receiver object... "); Console.Out.Flush(); callbackReceiverImpl = new CallbackReceiver(); callbackReceiver = callbackReceiverImpl; var callbackReceiverIdent = new Identity("callbackReceiver", category); twowayR = adapter.Add(callbackReceiverIdent, callbackReceiver, ICallbackReceiverPrx.Factory); var fakeCallbackReceiverIdent = new Identity("callbackReceiver", "dummy"); fakeTwowayR = adapter.Add(fakeCallbackReceiverIdent, callbackReceiver, ICallbackReceiverPrx.Factory); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing oneway callback... "); Console.Out.Flush(); ICallbackPrx oneway = twoway.Clone(oneway: true); ICallbackReceiverPrx onewayR = twowayR.Clone(oneway: true); var context = new Dictionary <string, string> { ["_fwd"] = "o" }; oneway.InitiateCallback(onewayR, context); callbackReceiverImpl.CallbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing twoway callback... "); Console.Out.Flush(); var context = new Dictionary <string, string> { ["_fwd"] = "t" }; twoway.InitiateCallback(twowayR, context); callbackReceiverImpl.CallbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("ditto, but with user exception... "); Console.Out.Flush(); var context = new Dictionary <string, string> { ["_fwd"] = "t" }; try { twoway.InitiateCallbackEx(twowayR, context); Assert(false); } catch (CallbackException ex) { Assert(ex.SomeValue == 3.14); Assert(ex.SomeString.Equals("3.14")); } callbackReceiverImpl.CallbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("trying twoway callback with fake category... "); Console.Out.Flush(); var context = new Dictionary <string, string> { ["_fwd"] = "t" }; try { twoway.InitiateCallback(fakeTwowayR, context); Assert(false); } catch (ObjectNotExistException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("testing whether other allowed category is accepted... "); Console.Out.Flush(); var context = new Dictionary <string, string> { ["_fwd"] = "t" }; ICallbackPrx otherCategoryTwoway = twoway.Clone(ICallbackPrx.Factory, identity: Identity.Parse("c2/callback")); otherCategoryTwoway.InitiateCallback(twowayR, context); callbackReceiverImpl.CallbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing whether disallowed category gets rejected... "); Console.Out.Flush(); var context = new Dictionary <string, string> { ["_fwd"] = "t" }; try { ICallbackPrx otherCategoryTwoway = twoway.Clone(ICallbackPrx.Factory, identity: Identity.Parse("c3/callback")); otherCategoryTwoway.InitiateCallback(twowayR, context); Assert(false); } catch (ObjectNotExistException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("testing whether user-id as category is accepted... "); Console.Out.Flush(); var context = new Dictionary <string, string> { ["_fwd"] = "t" }; ICallbackPrx otherCategoryTwoway = twoway.Clone(ICallbackPrx.Factory, identity: Identity.Parse("_userid/callback")); otherCategoryTwoway.InitiateCallback(twowayR, context); callbackReceiverImpl.CallbackOK(); Console.Out.WriteLine("ok"); } if (args.Length >= 1 && args[0].Equals("--shutdown")) { Console.Out.Write("testing server shutdown... "); Console.Out.Flush(); twoway.Shutdown(); // No ping, otherwise the router prints a warning message if it's // started with --Ice.Warn.Connections. Console.Out.WriteLine("ok"); /* * try * { * base.IcePing(); * Assert(false); * } * // If we use the glacier router, the exact exception reason gets * // lost. * catch(Ice.UnknownLocalException ex) * { * Console.Out.WriteLine("ok"); * } */ } { Console.Out.Write("destroying session... "); Console.Out.Flush(); try { router.DestroySession(); } catch { Assert(false); } Console.Out.WriteLine("ok"); } { Console.Out.Write("trying to ping server after session destruction... "); Console.Out.Flush(); try { twoway.IcePing(); Assert(false); } catch (ConnectionLostException) { Console.Out.WriteLine("ok"); } catch (TransportException) { Assert(false); } } if (args.Length >= 1 && args[0].Equals("--shutdown")) { { Console.Out.Write("uninstalling router with communicator... "); Console.Out.Flush(); communicator.DefaultRouter = null; Console.Out.WriteLine("ok"); } IProcessPrx process; { Console.Out.Write("testing stringToProxy for admin object... "); process = IProcessPrx.Parse(GetTestProxy("Glacier2/admin -f Process", 51), communicator); Console.Out.WriteLine("ok"); } /* * { * Console.Out.Write("uninstalling router with process object... "); * processBase.ice_router(null); * Console.Out.WriteLine("ok"); * } */ Console.Out.Write("testing Glacier2 shutdown... "); process.Shutdown(); try { process.IcePing(); Assert(false); } catch { Console.Out.WriteLine("ok"); } } }
/// <summary>Create a new OutgoingRequestFrame.</summary> /// <param name="proxy">A proxy to the target Ice object. This method uses the communicator, identity, facet, /// encoding and context of this proxy to create the request frame.</param> /// <param name="operation">The operation to invoke on the target Ice object.</param> /// <param name="idempotent">True when operation is idempotent, otherwise false.</param> /// <param name="format">The format type used to marshal classes and exceptions, when this parameter is null /// the communicator's default format is used.</param> /// <param name="context">An optional explicit context. When non null, it overrides both the context of the /// proxy and the communicator's current context (if any).</param> /// <param name="value">The parameter to marshal in the frame, when the request frame contain multiple /// parameters they must be passed as a tuple.</param> /// <param name="writer">The delegate to marshal the parameters into the frame.</param> /// <returns>A new OutgoingRequestFrame</returns> public static OutgoingRequestFrame WithParamList <T>( IObjectPrx proxy, string operation, bool idempotent, FormatType?format, IReadOnlyDictionary <string, string>?context, in T value, OutputStreamStructWriter <T> writer) where T : struct
public static Test.ITestIntfPrx allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); string sref = "test:" + helper.getTestEndpoint(0); var obj = IObjectPrx.Parse(sref, communicator); test(obj != null); var proxy = Test.ITestIntfPrx.UncheckedCast(obj); test(proxy != null); var output = helper.getWriter(); output.Write("testing enum values... "); output.Flush(); test((int)Test.ByteEnum.benum1 == 0); test((int)Test.ByteEnum.benum2 == 1); test((int)Test.ByteEnum.benum3 == Test.ByteConst1.value); test((int)Test.ByteEnum.benum4 == Test.ByteConst1.value + 1); test((int)Test.ByteEnum.benum5 == Test.ShortConst1.value); test((int)Test.ByteEnum.benum6 == Test.ShortConst1.value + 1); test((int)Test.ByteEnum.benum7 == Test.IntConst1.value); test((int)Test.ByteEnum.benum8 == Test.IntConst1.value + 1); test((int)Test.ByteEnum.benum9 == Test.LongConst1.value); test((int)Test.ByteEnum.benum10 == Test.LongConst1.value + 1); test((int)Test.ByteEnum.benum11 == Test.ByteConst2.value); test((int)Test.ShortEnum.senum1 == 3); test((int)Test.ShortEnum.senum2 == 4); test((int)Test.ShortEnum.senum3 == Test.ByteConst1.value); test((int)Test.ShortEnum.senum4 == Test.ByteConst1.value + 1); test((int)Test.ShortEnum.senum5 == Test.ShortConst1.value); test((int)Test.ShortEnum.senum6 == Test.ShortConst1.value + 1); test((int)Test.ShortEnum.senum7 == Test.IntConst1.value); test((int)Test.ShortEnum.senum8 == Test.IntConst1.value + 1); test((int)Test.ShortEnum.senum9 == Test.LongConst1.value); test((int)Test.ShortEnum.senum10 == Test.LongConst1.value + 1); test((int)Test.ShortEnum.senum11 == Test.ShortConst2.value); test((int)Test.IntEnum.ienum1 == 0); test((int)Test.IntEnum.ienum2 == 1); test((int)Test.IntEnum.ienum3 == Test.ByteConst1.value); test((int)Test.IntEnum.ienum4 == Test.ByteConst1.value + 1); test((int)Test.IntEnum.ienum5 == Test.ShortConst1.value); test((int)Test.IntEnum.ienum6 == Test.ShortConst1.value + 1); test((int)Test.IntEnum.ienum7 == Test.IntConst1.value); test((int)Test.IntEnum.ienum8 == Test.IntConst1.value + 1); test((int)Test.IntEnum.ienum9 == Test.LongConst1.value); test((int)Test.IntEnum.ienum10 == Test.LongConst1.value + 1); test((int)Test.IntEnum.ienum11 == Test.IntConst2.value); test((int)Test.IntEnum.ienum12 == Test.LongConst2.value); test((int)Test.SimpleEnum.red == 0); test((int)Test.SimpleEnum.green == 1); test((int)Test.SimpleEnum.blue == 2); output.WriteLine("ok"); output.Write("testing enum streaming... "); output.Flush(); Ice.OutputStream ostr; byte[] bytes; ostr = new OutputStream(communicator); ostr.Write(ByteEnum.benum11); bytes = ostr.ToArray(); test(bytes.Length == 1); // ByteEnum should require one byte ostr = new OutputStream(communicator); ostr.Write(ShortEnum.senum11); bytes = ostr.ToArray(); test(bytes.Length == 5); ostr = new OutputStream(communicator); ostr.Write(IntEnum.ienum11); bytes = ostr.ToArray(); test(bytes.Length == 5); ostr = new OutputStream(communicator); ostr.Write(SimpleEnum.blue); bytes = ostr.ToArray(); test(bytes.Length == 1); // SimpleEnum should require one byte output.WriteLine("ok"); output.Write("testing enum operations... "); output.Flush(); { var(r, o) = proxy.opByte(Test.ByteEnum.benum1); test(r == Test.ByteEnum.benum1 && o == Test.ByteEnum.benum1); (r, o) = proxy.opByte(Test.ByteEnum.benum11); test(r == Test.ByteEnum.benum11 && o == Test.ByteEnum.benum11); } { var(r, o) = proxy.opShort(Test.ShortEnum.senum1); test(r == Test.ShortEnum.senum1 && o == Test.ShortEnum.senum1); (r, o) = proxy.opShort(Test.ShortEnum.senum11); test(r == Test.ShortEnum.senum11 && o == Test.ShortEnum.senum11); } { var(r, o) = proxy.opInt(Test.IntEnum.ienum1); test(r == Test.IntEnum.ienum1 && o == Test.IntEnum.ienum1); (r, o) = proxy.opInt(Test.IntEnum.ienum11); test(r == Test.IntEnum.ienum11 && o == Test.IntEnum.ienum11); (r, o) = proxy.opInt(Test.IntEnum.ienum12); test(r == Test.IntEnum.ienum12 && o == Test.IntEnum.ienum12); } { var(r, o) = proxy.opSimple(Test.SimpleEnum.green); test(r == Test.SimpleEnum.green && o == Test.SimpleEnum.green); } output.WriteLine("ok"); output.Write("testing enum sequences operations... "); output.Flush(); { var b1 = new Test.ByteEnum[11] { Test.ByteEnum.benum1, Test.ByteEnum.benum2, Test.ByteEnum.benum3, Test.ByteEnum.benum4, Test.ByteEnum.benum5, Test.ByteEnum.benum6, Test.ByteEnum.benum7, Test.ByteEnum.benum8, Test.ByteEnum.benum9, Test.ByteEnum.benum10, Test.ByteEnum.benum11 }; var(b3, b2) = proxy.opByteSeq(b1); for (int i = 0; i < b1.Length; ++i) { test(b1[i] == b2[i]); test(b1[i] == b3[i]); } } { var s1 = new Test.ShortEnum[11] { Test.ShortEnum.senum1, Test.ShortEnum.senum2, Test.ShortEnum.senum3, Test.ShortEnum.senum4, Test.ShortEnum.senum5, Test.ShortEnum.senum6, Test.ShortEnum.senum7, Test.ShortEnum.senum8, Test.ShortEnum.senum9, Test.ShortEnum.senum10, Test.ShortEnum.senum11 }; var(s3, s2) = proxy.opShortSeq(s1); for (int i = 0; i < s1.Length; ++i) { test(s1[i] == s2[i]); test(s1[i] == s3[i]); } } { Test.IntEnum[] i1 = new Test.IntEnum[11] { Test.IntEnum.ienum1, Test.IntEnum.ienum2, Test.IntEnum.ienum3, Test.IntEnum.ienum4, Test.IntEnum.ienum5, Test.IntEnum.ienum6, Test.IntEnum.ienum7, Test.IntEnum.ienum8, Test.IntEnum.ienum9, Test.IntEnum.ienum10, Test.IntEnum.ienum11 }; var(i3, i2) = proxy.opIntSeq(i1); for (int i = 0; i < i1.Length; ++i) { test(i1[i] == i2[i]); test(i1[i] == i3[i]); } } { var s1 = new Test.SimpleEnum[3] { Test.SimpleEnum.red, Test.SimpleEnum.green, Test.SimpleEnum.blue }; var(s3, s2) = proxy.opSimpleSeq(s1); for (int i = 0; i < s1.Length; ++i) { test(s1[i] == s2[i]); test(s1[i] == s3[i]); } } output.WriteLine("ok"); return(proxy); }
internal Forwarder(IObjectPrx target) => _target = target;
private readonly Encoding _payloadEncoding; // TODO: move to OutputStream /// <summary>Creates a new outgoing request frame with no parameters.</summary> /// <param name="proxy">A proxy to the target Ice object. This method uses the communicator, identity, facet, /// encoding and context of this proxy to create the request frame.</param> /// <param name="operation">The operation to invoke on the target Ice object.</param> /// <param name="idempotent">True when operation is idempotent, otherwise false.</param> /// <param name="context">An optional explicit context. When non null, it overrides both the context of the /// proxy and the communicator's current context (if any).</param> public static OutgoingRequestFrame Empty(IObjectPrx proxy, string operation, bool idempotent, IReadOnlyDictionary <string, string>?context = null) => new OutgoingRequestFrame(proxy, operation, idempotent, context, ArraySegment <byte> .Empty);