コード例 #1
0
        /**
         * <summary>
         * Wraps cache request into a protocol message.</summary>
         *
         * <param name="req">Cache request that need to be wrapped.</param>
         * <returns>Wrapped message.</returns>
         */
        private static GridClientCacheRequest WrapCacheRequest(ProtoRequest req)
        {
            ProtoCacheRequest data = ProtoCacheRequest.ParseFrom(req.Body);

            GridClientCacheRequest bean = new GridClientCacheRequest((GridClientCacheRequestOperation)data.Operation, Guid.Empty);

            if (data.HasCacheName)
            {
                bean.CacheName = data.CacheName;
            }

            if (data.HasKey)
            {
                bean.Key = WrapObject(data.Key);
            }

            if (data.HasValue)
            {
                bean.Value = WrapObject(data.Value);
            }

            if (data.HasValue2)
            {
                bean.Value2 = WrapObject(data.Value2);
            }

            if (data.HasValues)
            {
                bean.Values = WrapMap(data.Values);
            }

            return(WrapRequest(bean, req));
        }
コード例 #2
0
        public StaticFileContext(ProtoContext context, StaticFileOptions options, PathString matchUrl, ILogger logger, IFileProvider fileProvider, IContentTypeProvider contentTypeProvider)
        {
            _context             = context;
            _options             = options;
            _matchUrl            = matchUrl;
            _request             = context.Request;
            _response            = context.Response;
            _logger              = logger;
            _requestHeaders      = _request.GetTypedHeaders();
            _responseHeaders     = _response.GetTypedHeaders();
            _fileProvider        = fileProvider;
            _contentTypeProvider = contentTypeProvider;

            _method                 = null;
            _isGet                  = false;
            _isHead                 = false;
            _subPath                = PathString.Empty;
            _contentType            = null;
            _fileInfo               = null;
            _length                 = 0;
            _lastModified           = new DateTimeOffset();
            _etag                   = null;
            _ifMatchState           = PreconditionState.Unspecified;
            _ifNoneMatchState       = PreconditionState.Unspecified;
            _ifModifiedSinceState   = PreconditionState.Unspecified;
            _ifUnmodifiedSinceState = PreconditionState.Unspecified;
            _range                  = null;
            _isRangeRequest         = false;
        }
コード例 #3
0
        /**
         * <summary>
         * Wraps authentication request into a protocol message.</summary>
         *
         * <param name="req">Authentication request that need to be wrapped.</param>
         * <returns>Wrapped message.</returns>
         */
        private static GridClientAuthenticationRequest WrapAuthRequest(ProtoRequest req)
        {
            var data = ProtoAuthenticationRequest.ParseFrom(req.Body);
            var bean = new GridClientAuthenticationRequest(Guid.Empty);

            bean.Credentials = WrapObject(data.Credentials);

            return(WrapRequest(bean, req));
        }
コード例 #4
0
        /**
         * <summary>
         * Wraps task request into a protocol message.</summary>
         *
         * <param name="req">Task request that need to be wrapped.</param>
         * <returns>Wrapped message.</returns>
         */
        private static GridClientTaskRequest WrapTaskRequest(ProtoRequest req)
        {
            ProtoTaskRequest data = ProtoTaskRequest.ParseFrom(req.Body);

            GridClientTaskRequest bean = new GridClientTaskRequest(Guid.Empty);

            bean.TaskName = data.TaskName;
            bean.Argument = WrapObject(data.Argument);

            return(WrapRequest(bean, req));
        }
コード例 #5
0
        /**
         * <summary>
         * Wraps any request into a protocol message.</summary>
         *
         * <param name="req">Request service information (headers).</param>
         * <param name="bean">Data bean to send.</param>
         * <returns>Wrapped message.</returns>
         */
        private static T WrapRequest <T>(T bean, ProtoRequest req) where T : GridClientRequest
        {
            //bean.RequestId = req.RequestId;
            //bean.ClientId = WrapGuid(req.ClientId);

            if (req.HasSessionToken)
            {
                bean.SessionToken = req.SessionToken.ToByteArray();
            }

            return(bean);
        }
コード例 #6
0
ファイル: FormFeature.cs プロジェクト: bclnet/GameNetCore
        public FormFeature(ProtoRequest request, FormOptions options)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _request = request;
            _options = options;
        }
コード例 #7
0
        /**
         * <summary>
         * Wraps any request into a protocol message.</summary>
         *
         * <param name="req">Request service information (headers).</param>
         * <param name="bean">Data bean to send.</param>
         * <returns>Wrapped message.</returns>
         */
        private static ProtoRequest WrapRequest(GridClientRequest req, IMessage bean)
        {
            var builder = ProtoRequest.CreateBuilder()
                          //.SetRequestId(req.RequestId)
                          //.SetClientId(WrapGuid(req.ClientId))
                          .SetBody(bean.ToByteString());

            if (req.SessionToken != null)
            {
                builder.SetSessionToken(ByteString.CopyFrom(req.SessionToken));
            }

            return(builder.Build());
        }
コード例 #8
0
        public static string GetMultipartBoundary(this ProtoRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            MediaTypeHeaderValue mediaType;

            if (!MediaTypeHeaderValue.TryParse(request.ContentType, out mediaType))
            {
                return(string.Empty);
            }
            return(HeaderUtilities.RemoveQuotes(mediaType.Boundary).ToString());
        }
コード例 #9
0
ファイル: BufferingHelper.cs プロジェクト: bclnet/GameNetCore
        public static ProtoRequest EnableRewind(this ProtoRequest request, int bufferThreshold = DefaultBufferThreshold, long?bufferLimit = null)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var body = request.Body;

            if (!body.CanSeek)
            {
                var fileStream = new FileBufferingReadStream(body, bufferThreshold, bufferLimit, _getTempDirectory);
                request.Body = fileStream;
                request.ProtoContext.Response.RegisterForDispose(fileStream);
            }
            return(request);
        }
コード例 #10
0
        /**
         * <summary>
         * Wraps topology request into a protocol message.</summary>
         *
         * <param name="req">Topology request that need to be wrapped.</param>
         * <returns>Wrapped message.</returns>
         */
        private static GridClientTopologyRequest WrapTopologyRequest(ProtoRequest req)
        {
            ProtoTopologyRequest data = ProtoTopologyRequest.ParseFrom(req.Body);

            GridClientTopologyRequest bean = new GridClientTopologyRequest(Guid.Empty);

            bean.IncludeAttributes = data.IncludeAttributes;
            bean.IncludeMetrics    = data.IncludeMetrics;

            if (data.HasNodeId)
            {
                bean.NodeId = Guid.Parse(data.NodeId);
            }

            if (data.HasNodeIp)
            {
                bean.NodeIP = data.NodeIp;
            }

            return(WrapRequest(bean, req));
        }
コード例 #11
0
        /// <summary>
        /// Returns the combined components of the request URL in a fully un-escaped form (except for the QueryString)
        /// suitable only for display. This format should not be used in HTTP headers or other HTTP operations.
        /// </summary>
        /// <param name="request">The request to assemble the uri pieces from.</param>
        /// <returns></returns>
        public static string GetDisplayUrl(this ProtoRequest request)
        {
            var scheme      = request.Scheme ?? string.Empty;
            var host        = request.Host.Value ?? string.Empty;
            var pathBase    = request.PathBase.Value ?? string.Empty;
            var path        = request.Path.Value ?? string.Empty;
            var queryString = request.QueryString.Value ?? string.Empty;

            // PERF: Calculate string length to allocate correct buffer size for StringBuilder.
            var length = scheme.Length + SchemeDelimiter.Length + host.Length
                         + pathBase.Length + path.Length + queryString.Length;

            return(new StringBuilder(length)
                   .Append(scheme)
                   .Append(SchemeDelimiter)
                   .Append(host)
                   .Append(pathBase)
                   .Append(path)
                   .Append(queryString)
                   .ToString());
        }
コード例 #12
0
        /**
         * <summary>
         * Wraps log request into a protocol message.</summary>
         *
         * <param name="req">Log request that need to be wrapped.</param>
         * <returns>Wrapped message.</returns>
         */
        private static GridClientLogRequest WrapLogRequest(ProtoRequest req)
        {
            ProtoLogRequest data = ProtoLogRequest.ParseFrom(req.Body);

            GridClientLogRequest bean = new GridClientLogRequest(Guid.Empty);

            if (data.HasPath)
            {
                bean.Path = data.Path;
            }

            if (data.HasFrom)
            {
                bean.From = data.From;
            }

            if (data.HasTo)
            {
                bean.To = data.To;
            }

            return(WrapRequest(bean, req));
        }
コード例 #13
0
ファイル: FormFeature.cs プロジェクト: bclnet/GameNetCore
 public FormFeature(ProtoRequest request)
     : this(request, FormOptions.Default)
 {
 }
コード例 #14
0
        /**
         * <summary>
         * Converts protocol object into object.</summary>
         *
         * <param name="val">Protocol message object to convert into value.</param>
         * <returns>Recovered object.</returns>
         */
        public static Object WrapObject(ObjectWrapper val)
        {
            byte[] bin = val.Binary.ToByteArray();

            // Primitives.

            switch (val.Type)
            {
            case ObjectWrapperType.NONE:
                return(null);

            case ObjectWrapperType.BOOL:
                Dbg.Assert(bin.Length == 1, "bin.Length == 1");

                return(bin[0] != 0);

            case ObjectWrapperType.BYTE:
                Dbg.Assert(bin.Length == 1, "bin.Length == 1");

                return(bin[0]);

            case ObjectWrapperType.SHORT:
                Dbg.Assert(bin.Length == 2, "bin.Length == 2");

                return(U.BytesToInt16(bin, 0));

            case ObjectWrapperType.INT32:
                Dbg.Assert(bin.Length == 4, "bin.Length == 4");

                return(U.BytesToInt32(bin, 0));

            case ObjectWrapperType.INT64:
                Dbg.Assert(bin.Length == 8, "bin.Length == 8");

                return(U.BytesToInt64(bin, 0));

            case ObjectWrapperType.FLOAT:
                Dbg.Assert(bin.Length == 4, "bin.Length == 4");

                return(U.BytesToSingle(bin, 0));

            case ObjectWrapperType.DOUBLE:
                Dbg.Assert(bin.Length == 8, "bin.Length == 8");

                return(U.BytesToDouble(bin, 0));

            case ObjectWrapperType.BYTES:
                return(bin);

            case ObjectWrapperType.UUID:
                return(WrapGuid(val.Binary));

            case ObjectWrapperType.STRING:
                return(val.Binary.ToStringUtf8());

            case ObjectWrapperType.COLLECTION:
                return(WrapCollection(Collection.ParseFrom(bin)));

            case ObjectWrapperType.MAP:
                return(WrapMap(Map.ParseFrom(bin)));

            case ObjectWrapperType.AUTH_REQUEST:
                return(WrapAuthRequest(ProtoRequest.ParseFrom(bin)));

            case ObjectWrapperType.CACHE_REQUEST:
                return(WrapCacheRequest(ProtoRequest.ParseFrom(bin)));

            case ObjectWrapperType.TASK_REQUEST:
                return(WrapTaskRequest(ProtoRequest.ParseFrom(bin)));

            case ObjectWrapperType.LOG_REQUEST:
                return(WrapLogRequest(ProtoRequest.ParseFrom(bin)));

            case ObjectWrapperType.TOPOLOGY_REQUEST:
                return(WrapTopologyRequest(ProtoRequest.ParseFrom(bin)));

            case ObjectWrapperType.RESPONSE:
                return(WrapResponse(ProtoResponse.ParseFrom(bin)));

            case ObjectWrapperType.NODE_BEAN:
                return(WrapNode(ProtoNodeBean.ParseFrom(bin)));

            case ObjectWrapperType.TASK_BEAN:
                return(WrapTaskResult(ProtoTaskBean.ParseFrom(bin)));

            default:
                throw new ArgumentException("Failed to deserialize object (object deserialization" +
                                            " of given type is not supported): " + val.Type);
            }
        }
コード例 #15
0
 /// <summary>
 /// Returns the relative url
 /// </summary>
 /// <param name="request">The request to assemble the uri pieces from.</param>
 /// <returns></returns>
 public static string GetEncodedPathAndQuery(this ProtoRequest request)
 {
     return(BuildRelative(request.PathBase, request.Path, request.QueryString));
 }
コード例 #16
0
 /// <summary>
 /// Returns the combined components of the request URL in a fully escaped form suitable for use in HTTP headers
 /// and other HTTP operations.
 /// </summary>
 /// <param name="request">The request to assemble the uri pieces from.</param>
 /// <returns></returns>
 public static string GetEncodedUrl(this ProtoRequest request)
 {
     return(BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path, request.QueryString));
 }