Example #1
0
        /*
         * Creates ContentObject from filename.
         */
        static void CreateContentObjectFromFilename(
            Node contentNode,
            MimePart part,
            IStreamService streamService,
            IRootResolver rootResolver)
        {
            var filename = contentNode.GetEx <string>() ?? throw new HyperlambdaException("No [filename] value provided");

            // Checking if explicit encoding was supplied.
            ContentEncoding encoding     = ContentEncoding.Default;
            var             encodingNode = contentNode.Children.FirstOrDefault(x => x.Name == "Content-Encoding");

            if (encodingNode != null)
            {
                encoding = (ContentEncoding)Enum.Parse(typeof(ContentEncoding), encodingNode.GetEx <string>(), true);
            }

            // Checking if explicit disposition was specified.
            if (part.ContentDisposition == null)
            {
                // Defaulting Content-Disposition to; "attachment; filename=whatever.xyz"
                part.ContentDisposition = new ContentDisposition("attachment")
                {
                    FileName = Path.GetFileName(filename)
                };
            }
            part.Content = new MimeContent(
                streamService.OpenFile(
                    rootResolver.AbsolutePath(filename.TrimStart('/'))),
                encoding);
        }
        /// <summary>
        /// Implementation of slot.
        /// </summary>
        /// <param name="signaler">Signaler used to raise the signal.</param>
        /// <param name="input">Arguments to slot.</param>
        public void Signal(ISignaler signaler, Node input)
        {
            // Figuring out filename.
            var filename = PathResolver.CombinePaths(
                _rootResolver.RootFolder,
                input.GetEx <string>());

            // Opening file and returning to caller.
            input.Value = _service.OpenFile(filename);
        }