예제 #1
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                Log.DebugFormat("Processing request for [{0}]", context.Request.Url);

                var cpa = (IContainerProviderAccessor)HttpContext.Current.ApplicationInstance;
                var cp = cpa.ContainerProvider;
                BootstrapperService _service = cp.RequestLifetime.Resolve<BootstrapperService>();

                var action = context.Request["action"];

                Log.DebugFormat("Processing action [{0}]", action);
                switch (action)
                {
                    case "GetFileInfos":
                        var fileInfoArray = new FileInfoArray() { Files = _service.GetFileInfos() };
                        context.Response.StatusCode = 200;
                        context.Response.ContentType = "text/xml";
                        Log.DebugFormat("Sending [{0}] file infos", fileInfoArray.Files.Length);
                        fileInfoArray.ToXmlStream(context.Response.OutputStream);
                        break;
                    case "GetFile":
                        var probe = _service.GetFilePath(context.Request["path"]);
                        if (File.Exists(probe))
                        {
                            context.Response.ContentType = "application/octet-stream";
                            Log.DebugFormat("Sending file [{0}]", probe);
                            using (var fs = File.OpenRead(probe))
                            {
                                var buf = new byte[1024];
                                int read = 0, offset = 0;
                                while (0 < (read = fs.Read(buf, 0, buf.Length)))
                                {
                                    context.Response.OutputStream.Write(buf, 0, read);
                                    offset += buf.Length;
                                }
                            }
                        }
                        else
                        {
                            Log.DebugFormat("file [{0}] not found", probe);
                            context.Response.StatusCode = 404;
                        }
                        break;
                    default:
                        Log.DebugFormat("Unknown action [{0}]", action);
                        context.Response.StatusCode = 400;
                        break;
                }
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Error while processing request for [{0}]", context.Request.Url), ex);
                throw;
            }
        }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                Log.DebugFormat("Processing request for [{0}]", context.Request.Url);

                var cpa = (IContainerProviderAccessor)HttpContext.Current.ApplicationInstance;
                var cp  = cpa.ContainerProvider;
                BootstrapperService _service = cp.RequestLifetime.Resolve <BootstrapperService>();

                var action = context.Request["action"];

                Log.DebugFormat("Processing action [{0}]", action);
                switch (action)
                {
                case "GetFileInfos":
                    var fileInfoArray = new FileInfoArray()
                    {
                        Files = _service.GetFileInfos()
                    };
                    context.Response.StatusCode  = 200;
                    context.Response.ContentType = "text/xml";
                    Log.DebugFormat("Sending [{0}] file infos", fileInfoArray.Files.Length);
                    fileInfoArray.ToXmlStream(context.Response.OutputStream);
                    break;

                case "GetFile":
                    var probe = _service.GetFilePath(context.Request["path"]);
                    if (File.Exists(probe))
                    {
                        Log.DebugFormat("Sending file [{0}]", probe);
                        context.Response.TransmitFile(probe);
                    }
                    else
                    {
                        Log.DebugFormat("file [{0}] not found", probe);
                        context.Response.StatusCode = 404;
                    }
                    break;

                default:
                    Log.DebugFormat("Unknown action [{0}]", action);
                    context.Response.StatusCode = 400;
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Error while processing request for [{0}]", context.Request.Url), ex);
                throw;
            }
        }