Пример #1
0
        void Events_GetFilesRequestFinished(IFileHandler sender, Backload.Contracts.Eventing.IGetFilesRequestEventArgs e)
        {
            // Backload component has finished the internal GET handler method.
            // Results can be found in e.Param.FileStatus or sender.FileStatus

            IFileStatus status = e.Param.FileStatus;
        }
Пример #2
0
        public async Task <ActionResult> FileHandler()
        {
            IBackloadResult result = null;
            IFileStatus     status = null;

            try
            {
                // Create and initialize the handler
                IFileHandler handler = Backload.FileHandler.Create();
                handler.Init(HttpContext.Request);


                // This demo calls high level API methods.
                // Http methhod related API methods are in handler.Services.[HttpMethod].
                // Low level API methods are in handler.Services.Core
                if (handler.Context.HttpMethod == "GET")
                {
                    status = await handler.Services.GET.Execute();
                }
                else if (handler.Context.HttpMethod == "POST")
                {
                    status = await handler.Services.POST.Execute();
                }
                else if (handler.Context.HttpMethod == "DELETE")
                {
                    status = await handler.Services.DELETE.Execute();
                }


                // Create a client plugin specific result.
                // In this example we could simply call CreateResult(), because handler.FilesStatus also has the IFileStatus object
                result = handler.Services.Core.CreatePluginResult(status, Backload.Contracts.Context.Config.PluginType.JQueryFileUpload);


                // Helper to create an ActionResult object from the IBackloadResult instance
                return(ResultCreator.Create(result));
            }
            catch
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
Пример #3
0
        // DELETE api/<controller>?fileName=[name]
        public async Task <IClientPluginResultCore> Delete(string fileName)
        {
            try
            {
                IFileHandler handler = GetHandler();

                // Call the DELETE execution method and get the result
                IFileStatus status = await handler.Services.DELETE.Execute();

                // Create plugin specific result
                IFileStatusResult result = handler.Services.Core.CreatePluginResult();

                // return Json
                return(result.ClientStatus);
            }
            catch
            {
                HttpContext.Current.Response.StatusCode = 500;
            }
            return(null);
        }
Пример #4
0
        // GET api/<controller>?fileName=[name]
        public async Task <HttpResponseMessage> Get(string fileName)
        {
            try
            {
                IFileHandler handler = GetHandler();

                // Call the GET execution method and get the result
                IFileStatus status = await handler.Services.GET.Execute();

                // Create plugin specific result
                IFileDataResult result = handler.Services.Core.CreateFileResult();

                // FIle data (bytes) requested
                HttpResponseMessage data = new HttpResponseMessage(HttpStatusCode.OK);
                data.Content = new ByteArrayContent(result.FileData);
                data.Content.Headers.ContentType = new MediaTypeHeaderValue(result.ContentType);

                return(data);
            }
            catch
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }