globals.cs

来自「微软的.NET论坛的源代码(COOL!!!)」· CS 代码 · 共 1,022 行 · 第 1/3 页

CS
1,022
字号
            // Attempt to load header template from Cache
            if ((Cache[virtualPathToTemplate] == null) && (Cache[templateKey] != "TemplateNotFound")) {

                try {

                    // Create a file dependency
                    fileDep = new CacheDependency(page.Server.MapPath(virtualPathToTemplate));

                    // Load the template
                    _template = page.LoadTemplate(virtualPathToTemplate);

                    // Add to cache
                    Cache.Insert(templateKey, _template, fileDep);

                } catch (FileNotFoundException fileNotFound) {

                    // Add a marker we can check for to skip this in the future
                    Cache.Insert(templateKey, "FileNotFound");

                    return null;
                } catch (HttpException httpException) {

                    // Add a marker we can check for to skip this in the future
                    if (httpException.ErrorCode == -2147467259)
                        Cache.Insert(templateKey, "FileNotFound");
                    else
                        throw httpException;

                    return null;
                }


            } else {
                return null;
            }

            // return the template
            return (ITemplate) Cache[templateKey];

        }

        public static string FormatSignature(string userSignature) {
            if (userSignature != String.Empty)
                return "<hr size=\"1\" align=\"left\" width=\"15%\">" + Globals.FormatPostBody(userSignature);

            return null;
        }

        /// <summary>
        /// Converts the raw, database form of a post's body to an HTML-friendly formatted version.
        /// </summary>
        /// <param name="RawPostBody">The raw format of the post body text.</param>
        /// <returns>The formatted version of the raw text.</returns>
        /// <remarks>When a post is saved into a database, it is the raw text that is saved.  (The literal
        /// text entered by the user.)  However, due to the way a browser views certain text characters,
        /// we need to format this text before we display it to the user.  This method removes breaking
        /// HTML characters and applies the text transformations specified by the transformation file.</remarks>
        public static String FormatPostBody(String stringToTransform) {
            return Transforms.TransformString(stringToTransform);
        }


        /// <summary>
        /// Converts a prepared subject line back into a raw text subject line.
        /// </summary>
        /// <param name="FormattedMessageSubject">The prepared subject line.</param>
        /// <returns>A raw text subject line.</returns>
        /// <remarks>This function is only needed when editing an existing message or when replying to
        /// a message - it turns the HTML escaped characters back into their pre-escaped status.</remarks>
        public static String HtmlDecode(String FormattedMessageSubject) {		
            String strSubject = FormattedMessageSubject;
			
		
            // strip the HTML - i.e., turn < into &lt;, > into &gt;
            strSubject = HttpContext.Current.Server.HtmlDecode(strSubject);
			
            return strSubject;
        } 

        /// <summary>
        /// Converts a prepared subject line back into a raw text subject line.
        /// </summary>
        /// <param name="FormattedMessageSubject">The prepared subject line.</param>
        /// <returns>A raw text subject line.</returns>
        /// <remarks>This function is only needed when editing an existing message or when replying to
        /// a message - it turns the HTML escaped characters back into their pre-escaped status.</remarks>
        public static String HtmlEncode(String FormattedMessageSubject) {		
            String strSubject = FormattedMessageSubject;
		
            // strip the HTML - i.e., turn < into &lt;, > into &gt;
            strSubject = HttpContext.Current.Server.HtmlEncode(strSubject);
			
            return strSubject;
        } 

        /************ PROPERTY SET/GET STATEMENTS **************/
        /// <summary>
        /// Returns the default view to use for viewing the forum posts, as specified in the AspNetForumsSettings
        /// section of Web.config.
        /// </summary>
        static public int DefaultForumView {
            get {
                const int _defaultForumView = 2;
                const String _settingName = "defaultForumView";

                String _str = (String) HttpContext.Current.Cache.Get("webForums." + _settingName);
                int iValue = _defaultForumView;
                if (_str == null) {
                    // we need to get the string and place it in the cache
                    String prefix = "";
                    NameValueCollection context = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                    if (context == null) {
                        // get the appSettings context
                        prefix = Globals._appSettingsPrefix;;
                        context = (NameValueCollection)ConfigurationSettings.GetConfig("appSettings");
                    }

                    _str = context[prefix + _settingName];

                    // determine what forum view to show
                    if (_str == null)
                        // choose the default
                        iValue = _defaultForumView;
                    else
                        switch(_str.ToUpper()) {
                            case "THREADED":
                                iValue = 2;
                                break;

                            case "MIXED":
                                iValue = 1;
                                break;

                            case "FLAT":
                                iValue = 0;
                                break;

                            default:
                                iValue = _defaultForumView;
                                break;
                        }
					
                    _str = iValue.ToString();
                    HttpContext.Current.Cache.Insert("webForums." + _settingName, _str);
                }

                return Convert.ToInt32(_str);
            }
        }


        /// <summary>
        /// Returns a boolean value indicating whether or not duplicate posts are allowed on the forum.
        /// </summary>
        static public bool AllowDuplicatePosts {
            get {
                NameValueCollection configSettings = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return Convert.ToBoolean(configSettings["allowDuplicatePosts"]);
            }
        }

        /// <summary>
        /// Specifies the SMTP Mail Server to use to send email information.  If no value is specified, or
        /// a value of "default" is specified, the default SMTP Mail Server is used.
        /// </summary>
        static public String SmtpServer {
            get {
                NameValueCollection configSettings = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                string smtpServer = configSettings["smtpServer"];

                if (smtpServer.Length == 0 || smtpServer.ToUpper() == "DEFAULT")
                    smtpServer = "";

                return smtpServer;
            }
        }

        /// <summary>
        /// Returns the Url to view a User's information
        /// </summary>
        static public String WebSiteUrl {
            get {
                NameValueCollection configSettings = (NameValueCollection) ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["webSiteUrl"];
            }
        }

        /// <summary>
        /// A read-only property that determines if WebForums.NET should send automated email messages
        /// or not.  Simply, this property returns false if the smtpServer property is set to NONE, true
        /// otherwise.
        /// </summary>
        static public bool SendEmail {
            get { return SmtpServer.ToUpper() != "NONE"; }
        }
		
        /// <summary>
        /// Url path to the page implementing search features
        /// </summary>
        static public String UrlSearch {
            get {
                NameValueCollection configSettings = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["urlSearch"];
            }
        }

        /// <summary>
        /// Url path to the page used for new user registration
        /// </summary>
        static public String UrlRegister {
            get {
                NameValueCollection configSettings = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["urlRegister"];
            }
        }
        
        /// <summary>
        /// Url path to the user profile page
        /// </summary>
        static public String UrlEditUserProfile {
            get {
                NameValueCollection configSettings = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["urlEditUserProfile"];
            }
        }

        /// <summary>
        /// Name of the skin to be applied
        /// </summary>
        static public String Skin {
            get {
                NameValueCollection configSettings = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["Skin"];
            }
        }

        /// <summary>
        /// Name of the default style to be applied
        /// </summary>
        static public String SiteStyle {
            get {
                NameValueCollection configSettings = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["Style"];
            }
        }

        /// <summary>
        /// Available styles that can be used
        /// </summary>
        static public String[] SiteStyles {
            get {
                NameValueCollection configSettings = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["AvailableStyles"].Split(';');
            }
        }

        /// <summary>
        /// TODO: Necessary?
        /// </summary>
        static public String ApplicationVRoot {
            get {
                NameValueCollection configSettings = (NameValueCollection)ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["ApplicationRoot"];
            }
        }
        
        /// <summary>
        /// Returns the database connection string
        /// </summary>
        static public String DatabaseConnectionString {
            get {
                NameValueCollection configSettings = (NameValueCollection) ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["connectionString"];
            }
        }

        /// <summary>
        /// Returns the default page size used in paging
        /// </summary>
        static public int PageSize {
            get {
                NameValueCollection configSettings = (NameValueCollection) ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return Convert.ToInt32(configSettings["pageSize"]);
            }
        }

        /// <summary>
        /// Default date format
        /// </summary>
        static public string DateFormat {
            get {
                NameValueCollection configSettings = (NameValueCollection) ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["defaultDateFormat"];
            }
        }

        /// <summary>
        /// Default time format
        /// </summary>
        static public string TimeFormat {
            get {
                NameValueCollection configSettings = (NameValueCollection) ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["defaultTimeFormat"];
            }
        }

        /// <summary>
        /// Returns the path to the images directory
        /// </summary>
        static public String ImagePath {
            get {
                NameValueCollection configSettings = (NameValueCollection) ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["imagesPath"];
            }
        }
		
        /// <summary>
        /// Returns the offset of the timezone of the database server
        /// </summary>
        static public int DBTimezone {
            get {
                NameValueCollection configSettings = (NameValueCollection) ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return Convert.ToInt32(configSettings["dbTimeZoneOffset"]);
            }
        }
		
        /// <summary>
        /// Returns the Url to view a User's information
        /// </summary>
        static public String UrlUserProfile {
            get {
                NameValueCollection configSettings = (NameValueCollection) ConfigurationSettings.GetConfig("AspNetForumsSettings");
                return configSettings["urlShowUserProfile"].Replace("^", "&");
            }
        }

        /// <summary>
        /// Returns the Url to the home of the forums app
        /// </summary>
        static public String UrlHome {
            get {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?