Esempio n. 1
0
        private static void printIdentityFacetOperation(System.IO.StringWriter s, Ice.InputStream str)
        {
            try
            {
                Ice.ToStringMode toStringMode = str.Communicator()?.ToStringMode ?? Ice.ToStringMode.Unicode;

                Ice.Identity identity = new Ice.Identity();
                identity.ice_readMembers(str);
                s.Write("\nidentity = " + identity.ToString(toStringMode));

                string[] facet = str.ReadStringSeq();
                s.Write("\nfacet = ");
                if (facet.Length > 0)
                {
                    s.Write(IceUtilInternal.StringUtil.escapeString(facet[0], "", toStringMode));
                }

                string operation = str.ReadString();
                s.Write("\noperation = " + operation);
            }
            catch (System.IO.IOException)
            {
                Debug.Assert(false);
            }
        }
Esempio n. 2
0
        public void invoke(ServantManager servantManager, Ice.InputStream stream)
        {
            _is = stream;

            int start = _is.pos();
            //
            // Read the current.
            //
            var id = new Ice.Identity();

            id.ice_readMembers(_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 = "";
            }

            string operation = _is.ReadString();
            byte   mode      = _is.ReadByte();
            Dictionary <string, string> context = new Dictionary <string, string>();
            int sz = _is.ReadSize();

            while (sz-- > 0)
            {
                string first  = _is.ReadString();
                string second = _is.ReadString();
                context[first] = second;
            }
            _current = new Ice.Current(_adapter, id, facet, operation, (Ice.OperationMode)mode, context, _requestId, _connection);
            Ice.Instrumentation.CommunicatorObserver?obsv = _communicator.Observer;
            if (obsv != null)
            {
                // Read the encapsulation size.
                int size = _is.ReadInt();
                _is.pos(_is.pos() - 4);

                _observer = obsv.getDispatchObserver(_current, _is.pos() - start + size);
                if (_observer != null)
                {
                    _observer.attach();
                }
            }

            //
            // Don't put the code above into the try block below. Exceptions
            // in the code above are considered fatal, and must propagate to
            // the caller of this operation.
            //

            if (servantManager != null)
            {
                _servant = servantManager.findServant(_current.Id, _current.Facet);
                if (_servant == null)
                {
                    _locator = servantManager.findServantLocator(_current.Id.category);
                    if (_locator == null && _current.Id.category.Length > 0)
                    {
                        _locator = servantManager.findServantLocator("");
                    }

                    if (_locator != null)
                    {
                        Debug.Assert(_locator != null);
                        try
                        {
                            _servant = _locator.locate(_current, out _cookie);
                        }
                        catch (Exception ex)
                        {
                            skipReadParams(); // Required for batch requests.
                            handleException(ex, false);
                            return;
                        }
                    }
                }
            }

            if (_servant == null)
            {
                try
                {
                    if (servantManager != null && servantManager.hasServant(_current.Id))
                    {
                        throw new Ice.FacetNotExistException(_current.Id, _current.Facet, _current.Operation);
                    }
                    else
                    {
                        throw new Ice.ObjectNotExistException(_current.Id, _current.Facet, _current.Operation);
                    }
                }
                catch (Exception ex)
                {
                    skipReadParams(); // Required for batch requests
                    handleException(ex, false);
                    return;
                }
            }

            try
            {
                Task <Ice.OutputStream>?task = _servant(this, _current);
                if (task == null)
                {
                    completed(null, false);
                }
                else
                {
                    if (task.IsCompleted)
                    {
                        _os = task.GetAwaiter().GetResult(); // Get the response
                        completed(null, false);
                    }
                    else
                    {
                        task.ContinueWith((Task <Ice.OutputStream> t) =>
                        {
                            try
                            {
                                _os = t.GetAwaiter().GetResult();
                                completed(null, true); // true = asynchronous
                            }
                            catch (Exception ex)
                            {
                                completed(ex, true); // true = asynchronous
                            }
                        },
                                          CancellationToken.None,
                                          TaskContinuationOptions.ExecuteSynchronously,
                                          scheduler: TaskScheduler.Current);
                    }
                }
            }
            catch (Exception ex)
            {
                completed(ex, false);
            }
        }