Example #1
0
        /// <summary>
        /// Returns NanoContext stuff.
        /// </summary>
        /// <param name="nanoContext">The nano context.</param>
        /// <returns>NanoContext stuff.</returns>
        public static object GetContext(NanoContext nanoContext)
        {
            Func <System.Collections.Specialized.NameValueCollection, Dictionary <string, object> > nameValueCollectionToDictionary = collection =>
            {
                Dictionary <string, object> dictionary = new Dictionary <string, object>();

                foreach (string parameterName in collection)
                {
                    dictionary.Add(parameterName, collection[parameterName]);
                }

                return(dictionary);
            };

            return(new
            {
                Request = new
                {
                    nanoContext.Request.HttpMethod,
                    QueryStringParameters = nameValueCollectionToDictionary(nanoContext.Request.QueryStringParameters),
                    FormBodyParameters = nameValueCollectionToDictionary(nanoContext.Request.FormBodyParameters),
                    HeaderParameters = nameValueCollectionToDictionary(nanoContext.Request.HeaderParameters)
                },
                NanoConfiguration = new
                {
                    nanoContext.NanoConfiguration.ApplicationRootFolderPath,
                    BackgroundTasks = nanoContext.NanoConfiguration.BackgroundTasks.Select(task => task == null ? null : new
                    {
                        task.Name,
                        task.AllowOverlappingRuns,
                        task.MillisecondInterval,
                        BackgroundTaskRunHistory = task.BackgroundTaskRunHistory.Select(context => context == null ? null : new
                        {
                            context.StartDateTime,
                            context.EndDateTime,
                            context.TaskResult
                        })
                    }),
                    RequestHandlers = nanoContext.NanoConfiguration.RequestHandlers.Select(handler => new
                    {
                        handler.UrlPath,
                        Type = handler.GetType().Name,
                        PreInvokeHandlers = handler.EventHandler.PreInvokeHandlers.Select(invokeHandler => new
                        {
                            invokeHandler.Method.Name
                        }),
                        PostInvokeHandlers = handler.EventHandler.PostInvokeHandlers.Select(invokeHandler => new
                        {
                            invokeHandler.Method.Name
                        }),
                        UnhandledExceptionHandlers = handler.EventHandler.UnhandledExceptionHandlers.Select(invokeHandler => new
                        {
                            invokeHandler.Method.Name
                        })
                    }),
                }
            });
        }
Example #2
0
        /// <summary>
        /// Echos back the uploaded file to the client.
        /// </summary>
        /// <param name="nanoContext">The Nano context.</param>
        public static void EchoUploadedFile(NanoContext nanoContext)
        {
            if (nanoContext.Request.Files.Count == 0)
            {
                throw new Exception("No file uploaded");
            }

            var file = nanoContext.Request.Files.FirstOrDefault();

            if (file == null)
            {
                throw new Exception("No file uploaded");
            }

            nanoContext.Response.ContentType = file.ContentType;
            nanoContext.Response.HeaderParameters.Add("Content-Disposition", "attachment; filename=" + file.FileName);
            nanoContext.Response.ResponseStreamWriter = stream =>
            {
                file.Value.CopyTo(stream);
            };
        }
Example #3
0
        /// <summary>
        /// Returns the details of the files uploaded.
        /// </summary>
        /// <param name="nanoContext">The Nano context.</param>
        /// <returns>Uploaded file details.</returns>
        public static dynamic GetUploadedFilesDetails(NanoContext nanoContext)
        {
            if (nanoContext.Request.Files.Count == 0)
            {
                throw new Exception("No file uploaded");
            }

            var results = new List <object>();

            foreach (var file in nanoContext.Request.Files)
            {
                results.Add(new
                {
                    file.ContentType,
                    file.FileName,
                    file.Name,
                    FileLength = file.Value.Length
                });
            }

            return(results);
        }
Example #4
0
        /// <summary>
        /// Returns the details of the files uploaded.
        /// </summary>
        /// <param name="nanoContext">The Nano context.</param>
        /// <returns>Uploaded file details.</returns>
        public static dynamic GetUploadedFilesDetails( NanoContext nanoContext )
        {
            if ( nanoContext.Request.Files.Count == 0 )
                throw new Exception( "No file uploaded" );

            var results = new List<object>();

            foreach ( var file in nanoContext.Request.Files )
            {
                results.Add( new
                {
                    file.ContentType,
                    file.FileName,
                    file.Name,
                    FileLength = file.Value.Length
                } );
            }

            return results;
        }
Example #5
0
        /// <summary>
        /// Echos back the uploaded file to the client.
        /// </summary>
        /// <param name="nanoContext">The Nano context.</param>
        public static void EchoUploadedFile( NanoContext nanoContext )
        {
            if ( nanoContext.Request.Files.Count == 0 )
                throw new Exception( "No file uploaded" );

            var file = nanoContext.Request.Files.FirstOrDefault();

            if ( file == null )
                throw new Exception( "No file uploaded" );

            nanoContext.Response.ContentType = file.ContentType;
            nanoContext.Response.HeaderParameters.Add( "Content-Disposition", "attachment; filename=" + file.FileName );
            nanoContext.Response.ResponseStreamWriter = stream =>
            {
                file.Value.CopyTo( stream );
            };
        }