コード例 #1
0
ファイル: FileModule.cs プロジェクト: RainsSoft/HttpWebServer
        /// <summary>
        /// Process a request.
        /// </summary>
        /// <param name="context">Request information</param>
        /// <returns>What to do next.</returns>
        /// <exception cref="InternalServerException">Failed to find file extension</exception>
        /// <exception cref="ForbiddenException">Forbidden file type.</exception>
        public ProcessingResult Process(RequestContext context)
        {
            Resource resource = _resourceManager.Get(context.Request.Uri.LocalPath);

            if (resource == null)
            {
                return(ProcessingResult.Continue);
            }

            IRequest  request  = context.Request;
            IResponse response = context.Response;

            try
            {
                string fileExtension = Path.GetExtension(request.Uri.AbsolutePath).TrimStart('.');

                ContentTypeHeader header;
                if (!ContentTypes.TryGetValue(fileExtension, out header))
                {
                    return(ProcessingResult.Continue);
                }

                response.ContentType = header;
                //说明: 在某些系统上,总是会出现页面刷不出来的情况,不知道和这个有没有关系?
                //暂时先注释了。
                // Only send file if it has not been modified.
                //var browserCacheDate = request.Headers["If-Modified-Since"] as DateHeader;
                //if (browserCacheDate != null)
                //{
                //    DateTime since = browserCacheDate.Value.ToUniversalTime();
                //    DateTime modified = resource.ModifiedAt;

                //    // Allow for file systems with subsecond time stamps
                //    modified = new DateTime(modified.Year, modified.Month, modified.Day, modified.Hour, modified.Minute, modified.Second, modified.Kind);
                //    if (since >= modified)
                //    {
                //        response.Status = HttpStatusCode.NotModified;
                //        return ProcessingResult.SendResponse;
                //    }
                //}

                using (resource.Stream)
                {
                    response.Add(new DateHeader("Last-Modified", resource.ModifiedAt));

                    // Send response and tell server to do nothing more with the request.
                    SendFile(context.HttpContext, response, resource.Stream);
                    return(ProcessingResult.Abort);
                }
            }
            catch (FileNotFoundException err)
            {
                throw new InternalServerException("Failed to process file '" + request.Uri + "'.", err);
            }
        }
コード例 #2
0
ファイル: SliceDisplay.cs プロジェクト: GlebDev/Slices
        public void DrawSlice(SliceSet sliceSet)
        {
            var bitmap = (int)sliceSet.Value;
            //Set the start angle
            var angle = -_angle / 2f;

            while (bitmap > 0)
            {
                //Get the first bit from the bitmap
                if ((bitmap & 1) != 0)
                {
                    var obj = _resourceProvider.Get <SingleSlice>(Vector3.zero, Quaternion.Euler(0f, 0f, angle),
                                                                  this.transform);
                    obj.transform.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;

                    _slicePrefabs.Add(obj);
                }

                angle   -= _angle;
                bitmap >>= 1;
            }
        }
コード例 #3
0
ファイル: GameWindowView.cs プロジェクト: GlebDev/Slices
 public void ShowDestroyParticle(int index)
 {
     _resourceProvider.Get <DestroyParticle>(this.receiverBtn[index].transform);
 }
コード例 #4
0
ファイル: ResourceManager.cs プロジェクト: kblwxl/Larva
 public Stream Get(string resourceKey)
 {
     return(provider.Get(resourceKey));
 }