Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> Get(HttpRequestMessage request, [FromUri(Name = "objectContext")] string userId)
        {
            try
            {
                // Call the execution pipeline and get the result
                IBackloadResult result = await _handler.Execute();

                // Get the client plugin specific result
                var clientResult = ((IFileStatusResult)result).ClientStatus;

                // return result object and status code
                return(request.CreateResponse(result.HttpStatusCode, clientResult));


                #region Optional: Use Backload Api (Services namespace. Pro/Enterprise only)

                //// Simple demo: Call the GET execution method and get the result
                //IFileStatus status = await _handler.Services.GET.Execute();

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

                //// return plugin specific result object
                //return request.CreateResponse(HttpStatusCode.OK, result.ClientStatus);

                #endregion Optional: Use backload Api (Services namespace. Pro/Enterprise only)
            }
            catch (Exception e)
            {
                return(request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Upload()
        {
            try
            {
                IFileHandler handler = Backload.FileHandler.Create();

                using (var provider = new BackloadDataProvider(this.Request))
                {
                    var name = provider.Files[0].FileName;
                    provider.Files[0].FileName = string.Format("{0}.{1}", Guid.NewGuid(), "xlsx");

                    handler.Init(provider);
                    IBackloadResult result = await handler.Execute();

                    result.ContentType = "Content-Type: application/json; charset=utf-8";

                    return(ResultCreator.Create(result));
                }
            }
            catch (Exception ex)
            {
                MvcApplication.log.Error(ex, "Не удалось загрузить файл контактов");
            }

            return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> FileHandler()
        {
            try
            {
                // Create and initialize the handler
                IFileHandler handler = Backload.FileHandler.Create();


                // Attach event handlers to events
                handler.Events.IncomingRequestStarted  += Events_IncomingRequestStarted;
                handler.Events.GetFilesRequestStarted  += Events_GetFilesRequestStarted;
                handler.Events.GetFilesRequestFinished += Events_GetFilesRequestFinished;


                // Init Backloads execution environment and execute the request
                handler.Init(HttpContext.Request);
                IBackloadResult result = await handler.Execute();


                // Helper to create an ActionResult object from the IBackloadResult instance
                return(ResultCreator.Create(result));
            }
            catch
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// File handler demo for classic Asp.Net or HTML.
        /// To access it in an Javascript ajax request use: <code>var url = "/Handler/FileHandler.ashx";</code>.
        /// </summary>
        /// <remarks>
        /// NOTE. Edit the web.config file to allow the DELETE method in the system.webServer.handlers section
        /// </remarks>
        public override async Task ProcessRequestAsync(HttpContext context)
        {
            try
            {
                // Wrap the request into a HttpRequestBase type
                HttpRequestBase request = new HttpRequestWrapper(context.Request);


                // Create and initialize the handler
                IFileHandler handler = Backload.FileHandler.Create();
                handler.Init(request);


                // Call the execution pipeline and get the result
                IBackloadResult result = await handler.Execute();


                // Write result to the response and flush
                ResultCreator.Write(context.Response, result);
                context.Response.Flush();
            }
            catch
            {
                context.Response.StatusCode = 500;
            }
        }
        public async Task <ActionResult> FileHandler()
        {
            try
            {
                IFileHandler handler = Backload.FileHandler.Create();
                handler.Init(HttpContext.Request);

                IBackloadResult result = await handler.Execute(false);

                return(ResultCreator.Create(result));
            }
            catch
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
        public async Task <ActionResult> Upload()
        {
            try
            {
                IFileHandler handler = Backload.FileHandler.Create();

                handler.Events.IncomingRequestStarted += Events_IncomingRequestStarted;

                handler.Init(this.HttpContext, _hosting);
                IBackloadResult result = await handler.Execute();

                return(ResultCreator.Create(result));
            }
            catch
            {
                return(new StatusCodeResult((int)HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 7
0
        public ActionResult FileHandler()
        {
            try
            {
                // Create and initialize the handler
                IFileHandler handler = Backload.FileHandler.Create();
                handler.Init(HttpContext.Request);


                // Call the execution pipeline and get the result
                IBackloadResult result = handler.Execute();


                // Helper to create an ActionResult object from the IBackloadResult instance
                return(ResultCreator.Create(result));
            }
            catch
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> Create(NewMicropost newMP)
        {
            var currentUser = await UserManager.FindByIdAsync(User.Identity.GetUserId <int>());

            if (ModelState.IsValid)
            {
                _newMPId = MicropostRepository.Create(newMP.TweetContent, currentUser);

                IFileHandler handler = Backload.FileHandler.Create();
                handler.Events.StoreFileRequestStarted += Events_StoreFileRequestStarted;
                handler.Init(HttpContext.Request);
                var result = await handler.Execute();

                if (handler.FileStatus.Files[0].Success)
                {
                    var request      = HttpContext.Request;
                    var absoluteRoot = request.Url.AbsoluteUri.Replace(request.Url.AbsolutePath, String.Empty);
                    var relativeURL  = handler.FileStatus.Files[0].FileUrl.Replace(absoluteRoot, "");

                    MicropostRepository.AttachPicture(_newMPId, relativeURL);
                }
                else
                {
                    TempData["error"]      = handler.FileStatus.Files[0].ErrorMessage;
                    ViewBag.FeedItems      = Enumerable.Empty <Micropost>().ToPagedList(1, 25);;
                    ViewBag.MicropostCount = currentUser.Microposts.Count;
                    return(View("../StaticPages/Home", newMP));
                }

                MicropostRepository.Save();
                TempData.Add("success", "Micropost created.");
                return(RedirectToRoute("Default"));
            }
            else
            {
                ViewBag.FeedItems      = Enumerable.Empty <Micropost>().ToPagedList(1, 25);;
                ViewBag.MicropostCount = currentUser.Microposts.Count;
                return(View("../StaticPages/Home", newMP));
            }
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> FileHandler()
        {
            try
            {
                // Create and initialize the handler
                IFileHandler handler = Backload.FileHandler.Create();
                handler.Init(HttpContext.Request);


                // Call the execution pipeline and get the result
                IBackloadResult result = await handler.Execute();

                return(RedirectToAction("Index", "Home"));


                // Helper to create an ActionResult object from the IBackloadResult instance
                //return ResultCreator.Create(result);
            }
            catch
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }