コード例 #1
0
        public bool Execute(IBackloadContext context, IIncomingRequestParam param)
        {
            // Demo 2: Comment out the following line and rebuild the solution
            return(false);

            if (context.HttpMethod == "POST")
            {
                int    startIdx  = context.PipelineControl.Message.MessageCode;
                string subfolder = string.Empty;
                if (startIdx < 8)
                {
                    subfolder = DateTime.Now.ToString(datetime[startIdx]);
                }
                else
                {
                    subfolder = lorem[startIdx - 8];
                }

                if (string.IsNullOrEmpty(param.BackloadValues.UploadContext) == false)
                {
                    param.BackloadValues.UploadContext += ";";                                                                    // Seperate subfolders with a semicolon
                }
                param.BackloadValues.UploadContext += subfolder;

                // There are multiple ways sharing data between extensions. Here we use PipelineControl.Message to increase the index.
                // Note, that the ExtensionLogger logs the messages (subfolders) in PipelineControl.Message returned from the extension
                context.PipelineControl.Message.MessageText  = subfolder;
                context.PipelineControl.Message.MessageCode += 1;

                return(true); // Processed value is true, because the extension has changed properties.
            }

            return(false); // No properties have been changed, so false is returned.
        }
コード例 #2
0
        public bool Execute(IBackloadContext context, IIncomingRequestParam param)
        {
            // Demo 2: Comment out the following line and rebuild the solution
             return false;

            if (context.HttpMethod == "POST")
            {
                int startIdx = context.PipelineControl.Message.MessageCode;
                string subfolder = string.Empty;
                if (startIdx < 8) subfolder = DateTime.Now.ToString(datetime[startIdx]);
                else subfolder = lorem[startIdx - 8];

                if (string.IsNullOrEmpty(param.BackloadValues.UploadContext) == false) param.BackloadValues.UploadContext += ";"; // Seperate subfolders with a semicolon
                param.BackloadValues.UploadContext += subfolder;

                // There are multiple ways sharing data between extensions. Here we use PipelineControl.Message to increase the index.
                // Note, that the ExtensionLogger logs the messages (subfolders) in PipelineControl.Message returned from the extension
                context.PipelineControl.Message.MessageText = subfolder;
                context.PipelineControl.Message.MessageCode += 1;

                return true; // Processed value is true, because the extension has changed properties.
            }

            return false; // No properties have been changed, so false is returned.
        }
コード例 #3
0
        public bool Execute(IBackloadContext context, IIncomingRequestParam param)
        {
            if (context.HttpMethod == "POST")
            {
                // This extension validate if the artist is in the database, and returns a Bad Request status (400) if not.

                // IMPORTANT: Don't forget to rebuild the extension when you changed code. Otherwise you may use the old extensions code.
                using (var artists = new ArtistsLibrary())
                {
                    var artist = artists.Artists.FirstOrDefault(a => a.ArtistId == param.BackloadValues.ObjectContext);

                    if (artist == null)  // Artist not in list
                    {
                        // Stop further processing of the pipeline but all extensions can do their work (maybe logging, etc.).
                        // The outgoing extension will also be called, so you have the chance to change the response to the client.
                        context.PipelineControl.ExecutePipeline = false;
                        // Because we prevented the execution of the core pipeline (where the core method for executing
                        // this request is) we do not generate a FileUploadStatus which holds the status of all files this request
                        // handles. IIncomingRequest is the first extension point and FileUploadStatus is generated later in the core pipeline.
                        // This taken into account, we cannot send a message with each FileUploadStatusItem, instead we send a general error.
                        // If you want to send messages with the FileUploadStatus, do this in an extension like GetFilesRequest, StoreFileRequest
                        // or in the OutgoingResponse extension.
                        context.Request.RequestContext.HttpContext.Response.StatusCode = 400;
                        return(true); // Return value is true, because the extension has changed properties.
                    }
                }
            }
            return(false); // No properties have been changed, so false is returned.
        }
コード例 #4
0
ファイル: BadRequest.cs プロジェクト: Zoumaho/Backload
        public bool Execute(IBackloadContext context, IIncomingRequestParam param)
        {
            if (context.HttpMethod == "POST")
            {
                // This extension validate if the artist is in the database, and returns a Bad Request status (400) if not.
                
                // IMPORTANT: Don't forget to rebuild the extension when you changed code. Otherwise you may use the old extensions code.
                using (var artists = new ArtistsLibrary())
                {
                    var artist = artists.Artists.FirstOrDefault(a => a.ArtistId == param.BackloadValues.ObjectContext);

                    if (artist == null)  // Artist not in list
                    {   
                        // Stop further processing of the pipeline but all extensions can do their work (maybe logging, etc.).
                        // The outgoing extension will also be called, so you have the chance to change the response to the client.
                        context.PipelineControl.ExecutePipeline = false;
                        // Because we prevented the execution of the core pipeline (where the core method for executing
                        // this request is) we do not generate a FileUploadStatus which holds the status of all files this request 
                        // handles. IIncomingRequest is the first extension point and FileUploadStatus is generated later in the core pipeline.
                        // This taken into account, we cannot send a message with each FileUploadStatusItem, instead we send a general error.
                        // If you want to send messages with the FileUploadStatus, do this in an extension like GetFilesRequest, StoreFileRequest 
                        // or in the OutgoingResponse extension.
                        context.Request.RequestContext.HttpContext.Response.StatusCode = 400; 
                        return true; // Return value is true, because the extension has changed properties.
                    }
                }
            }
            return false; // No properties have been changed, so false is returned.
        }
コード例 #5
0
 // This extension is only for demo purposes, as we throw an exception here
 // Don't forget to rebuid your solution if you made changes to your extension, otherwise you may use the old extension assembly.
 public bool Execute(IBackloadContext context, IIncomingRequestParam param)
 {
     if (context.HttpMethod == "POST")
     {
         for (int i = 0; i < context.Request.Files.Count; i++)
         {
             var file = context.Request.Files[i];
             if (file.FileName.ToLower().Contains("badfile"))
             {
                 context.PipelineControl.Message.MessageText = "Bad file name.";
                 throw new Exception(context.PipelineControl.Message.MessageText);
             }
         }
     }
     return(false); // No properties have been changed, so we set return false.
 }
コード例 #6
0
ファイル: IncomingRequest.cs プロジェクト: Zoumaho/Backload
 // This extension is only for demo purposes, as we throw an exception here
 // Don't forget to rebuid your solution if you made changes to your extension, otherwise you may use the old extension assembly.
 public bool Execute(IBackloadContext context, IIncomingRequestParam param)
 {
     if (context.HttpMethod == "POST")
     {
         for (int i = 0; i < context.Request.Files.Count; i++)
         {
             var file = context.Request.Files[i];
             if (file.FileName.ToLower().Contains("badfile"))
             {
                 context.PipelineControl.Message.MessageText = "Bad file name.";
                 throw new Exception(context.PipelineControl.Message.MessageText);
             }
         }
     }
     return false; // No properties have been changed, so we set return false.
 }