コード例 #1
0
        public IOrderedEnumerable <IContentSource> Evaluate(ResourceType resourceType)
        {
            var file = VirtualPathResolver.ResolveVirtualPathToFile(VirtualPath);

            if (file == null)
            {
                return(Enumerable.Empty <IContentSource>().OrderBy(x => x));
            }

            return(new IContentSource[] { PhysicalFileRegister.For(file, resourceType, Mode) }.OrderBy(x => x));
        }
コード例 #2
0
        public IOrderedEnumerable <IContentSource> Evaluate(ResourceType resourceType)
        {
            var physicalPath = VirtualPathResolver.ResolveVirtualPathToDirectory(FolderVirtualPath);

            if (physicalPath == null)
            {
                return(Enumerable.Empty <IContentSource>().OrderBy(x => x));
            }

            return(Directory.GetFiles(physicalPath.FullName, SearchPattern ?? "*", IsRecursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                   .Select(f => new FileInfo(f))
                   .Select(file => PhysicalFileRegister.For(file, resourceType, Mode))
                   .OfType <IContentSource>()
                   .OrderBy(x => new FileInfo(((PhysicalFileSource)x).PhysicalPath).Name));
        }
コード例 #3
0
            public void Can_Append_Action_To_Url()
            {
                // Given
                var page = new FakePage {
                    Metadata = { Url = "foo/bar/fudge" }
                };
                var resolver = new VirtualPathResolver();

                // When

                var result = resolver.Resolve(page, new RouteValueDictionary(new { action = "comment" }));

                // Then

                Assert.Equal("foo/bar/fudge/comment/", result);
            }
コード例 #4
0
            public void Can_Resolve_Virtual_Path()
            {
                // Given
                var page = new FakePage {
                    Metadata = { Url = "foo/bar/fudge" }
                };
                var resolver = new VirtualPathResolver();

                // When

                var result = resolver.Resolve(page, new RouteValueDictionary(new { action = "index" }));

                // Then

                Assert.Equal("foo/bar/fudge/", result);
            }
コード例 #5
0
        public void Can_Resolve_Virtual_Path_With_Default_Action()
        {
            // Arrange
            IPage model = new FakePage {
                Metadata = { Url = "page1/page2" }
            };
            var routeValueDictionary = new RouteValueDictionary();

            // Act

            var virtualPathResolver = new VirtualPathResolver();
            var virtualPath         = virtualPathResolver.Resolve(model, routeValueDictionary);

            // Assert

            Assert.AreEqual("page1/page2/", virtualPath);
        }
コード例 #6
0
        private static string LoadMessageBody(string bodyTemplateFileName)
        {
            if (string.IsNullOrEmpty(bodyTemplateFileName) == true)
            {
                throw new ArgumentNullException("bodyTemplateFileName");
            }

            // load the body template
            string body             = null;
            string physicalFileName = VirtualPathResolver.MapPath(bodyTemplateFileName);

            if (string.IsNullOrEmpty(physicalFileName) == false && File.Exists(physicalFileName) == true)
            {
                using (TextReader textReader = new StreamReader(physicalFileName))
                {
                    body = textReader.ReadToEnd();
                }
            }
            return(body);
        }
コード例 #7
0
ファイル: SingleFileRule.cs プロジェクト: Romhein/Rejuicer
 static SingleFileRule()
 {
     VirtualPathResolver = new VirtualPathResolver();
 }
コード例 #8
0
 static PhysicalFileRegister()
 {
     VirtualPathResolver = new VirtualPathResolver();
 }
コード例 #9
0
 static WildcardMatchFileRule()
 {
     VirtualPathResolver = new VirtualPathResolver();
 }
コード例 #10
0
ファイル: VirtualPathFileReader.cs プロジェクト: nieve/assman
        public VirtualPathFileReader()
        {
            var config = AssmanConfiguration.Current;

            _pathResolver = VirtualPathResolver.GetInstance(config.RootFilePath);
        }
コード例 #11
0
        /// <summary>
        /// Creates a new instance of a MailMessage using the specified parameters.
        /// </summary>
        /// <param name="from">Sender's e-mail address. Could be null, in which case the default sender e-mail specified via smtp configuration will be used.</param>
        /// <param name="to">Comma-separated list of e-mail addresses to send the message to.</param>
        /// <param name="cc">Comma-separated list of e-mail addresses to send a copy (CC) of the message to.</param>
        /// <param name="bcc">Comma-separated list of e-mail addresses to send a blind copy (BCC) of the message to.</param>
        /// <param name="subject">Email subject.</param>
        /// <param name="priority">Email priority.</param>
        /// <param name="htmlTemplateFileName">Html template file name.</param>
        /// <param name="plainTemplateFileName">Plain text template file name. Could be <b>null</b>.</param>
        /// <param name="styleSheetFileName">Name of a file containing styles to be added to the email.</param>
        /// <param name="replacements">Collection of replacement arguments.</param>
        /// <param name="linkedResources">Collection containing information about linked resources.</param>
        /// <param name="attachments">Collection containing information about attachments.</param>
        /// <returns>New instance of a Mail Message.</returns>
        public static MailMessage CreateMessage(
            string from,
            string to,
            string cc,
            string bcc,
            string subject,
            MailPriority priority,
            string htmlTemplateFileName,
            string plainTemplateFileName,
            string styleSheetFileName,
            IDictionary <string, string> replacements,
            IEnumerable <ILinkedResourceInfo> linkedResources,
            IEnumerable <IAttachmentInfo> attachments)
        {
            // copy replacements to our internal dictionary
            Dictionary <string, string> replacementArgs = new Dictionary <string, string>(replacements);

            // load styles, they will be automatically added to the email
            string physicalStyleSheetFileName = VirtualPathResolver.MapPath(styleSheetFileName);

            if (string.IsNullOrEmpty(physicalStyleSheetFileName) == false && File.Exists(physicalStyleSheetFileName) == true)
            {
                string styles = File.ReadAllText(physicalStyleSheetFileName);
                replacementArgs.Add("<%Styles%>", styles);
            }

            // create an instance of the MailMessage
            MailMessage message = new MailMessage();

            message.To.Add(to);
            message.Priority = priority;

            if (string.IsNullOrEmpty(from) == false)
            {
                MailAddress fromAddress = new MailAddress(from);
                message.From   = fromAddress;
                message.Sender = fromAddress;
            }
            if (string.IsNullOrEmpty(cc) == false)
            {
                message.CC.Add(cc);
            }
            if (string.IsNullOrEmpty(bcc) == false)
            {
                message.Bcc.Add(bcc);
            }
            if (string.IsNullOrEmpty(subject) == false)
            {
                message.Subject = subject;
            }

            // load html body
            string htmlBodyTemplate = MailUtility.LoadMessageBody(htmlTemplateFileName);

            message.Body       = MailUtility.BuildMessageBody(htmlBodyTemplate, replacementArgs);
            message.IsBodyHtml = true;

            // add the alternate body to the message
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(message.Body);

            htmlView.ContentType.MediaType = "text/html";
            message.AlternateViews.Add(htmlView);

            // add plain text alternate body if plain text template was provided
            if (string.IsNullOrEmpty(plainTemplateFileName) == false)
            {
                // add the alternate body to the message
                string        plainBodyTemplate = MailUtility.LoadMessageBody(plainTemplateFileName);
                string        plainBody         = MailUtility.BuildMessageBody(plainBodyTemplate, replacementArgs);
                AlternateView plainView         = AlternateView.CreateAlternateViewFromString(plainBody);
                plainView.ContentType.MediaType = "text/plain";
                message.AlternateViews.Add(plainView);
            }

            // add linked resources
            if (linkedResources != null)
            {
                foreach (ILinkedResourceInfo resourceInfo in linkedResources)
                {
                    // create the LinkedResource
                    string         physicalResourceFileName = VirtualPathResolver.MapPath(resourceInfo.FileName);
                    LinkedResource linkedResource           = new LinkedResource(physicalResourceFileName, resourceInfo.MediaType);
                    linkedResource.ContentId = resourceInfo.ContentId;
                    // add the LinkedResource to the appropriate view
                    htmlView.LinkedResources.Add(linkedResource);
                }
            }

            // add attachments
            if (attachments != null)
            {
                foreach (IAttachmentInfo attachmentInfo in attachments)
                {
                    // create the file attachment for this e-mail message
                    string     physicalAttachmentFileName = VirtualPathResolver.MapPath(attachmentInfo.FileName);
                    Attachment attachment = new Attachment(physicalAttachmentFileName, attachmentInfo.MediaType);
                    // add file information
                    attachment.ContentDisposition.CreationDate     = File.GetCreationTime(attachmentInfo.FileName);
                    attachment.ContentDisposition.ModificationDate = File.GetLastWriteTime(attachmentInfo.FileName);
                    attachment.ContentDisposition.ReadDate         = File.GetLastAccessTime(attachmentInfo.FileName);
                    // add the file attachment to this e-mail message
                    message.Attachments.Add(attachment);
                }
            }

            return(message);
        }