// ********************************************************************************** // CassiniDev - http://cassinidev.codeplex.com // // Copyright (c) Microsoft Corporation. All rights reserved. // // This source code is subject to terms and conditions of the Microsoft Public // License (Ms-PL). A copy of the license can be found in the license.txt file // included in this distribution. // // You must not remove this notice, or any other, from this software. // // ********************************************************************************** #region using System.IO; using System.Text; using System.Web; #endregion namespace CassiniDev { /// /// TODO: get this into resources /// internal static class Messages { private const string _dirListingDirFormat = @"{0,38:dddd, MMMM dd, yyyy hh:mm tt} <dir> {2} "; private const string _dirListingFileFormat = @"{0,38:dddd, MMMM dd, yyyy hh:mm tt} {1,12:n0} {3} "; private const string _dirListingFormat1 = @" Directory Listing -- {0} "; private const string _dirListingFormat2 = @"

Directory Listing -- {0}


";

        private const string _dirListingParentFormat =
            @"[To Parent Directory]

";

        private const string _httpErrorFormat1 =
            @"
    
        {0}
";

        private const string _httpStyle =
            @"        
";

        private static readonly string _dirListingTail =
            @"

Version Information: Cassini Web Server " + VersionString + @" "; private static readonly string _httpErrorFormat2 = @"

Server Error in '{0}' Application.

HTTP Error {1} - {2}.


Version Information: Cassini Web Server " + VersionString + @" "; public static string VersionString = typeof (Server).Assembly.GetName().Version.ToString(); public static string FormatDirectoryListing(string dirPath, string parentPath, FileSystemInfo[] elements) { StringBuilder sb = new StringBuilder(); sb.Append(string.Format(_dirListingFormat1, dirPath)); sb.Append(_httpStyle); sb.Append(string.Format(_dirListingFormat2, dirPath)); if (parentPath != null) { if (!parentPath.EndsWith("/")) { parentPath += "/"; } sb.Append(string.Format(_dirListingParentFormat, parentPath)); } if (elements != null) { for (int i = 0; i < elements.Length; i++) { if (elements[i] is FileInfo) { FileInfo fi = (FileInfo) elements[i]; sb.Append(string.Format(_dirListingFileFormat, fi.LastWriteTime, fi.Length, fi.Name, fi.Name)); } else if (elements[i] is DirectoryInfo) { DirectoryInfo di = (DirectoryInfo) elements[i]; sb.Append(string.Format(_dirListingDirFormat, di.LastWriteTime, di.Name, di.Name)); } } } sb.Append(_dirListingTail); return sb.ToString(); } public static string FormatErrorMessageBody(int statusCode, string appName) { string desc = HttpWorkerRequest.GetStatusDescription(statusCode); return string.Format(_httpErrorFormat1, desc) + _httpStyle + string.Format(_httpErrorFormat2, appName, statusCode, desc); } } }