コード例 #1
0
        /// <summary>
        /// Loads the Javascript file contents onto the page
        /// using the given url which must refer to this site.
        ///
        /// If the url starts with "http://" or "https://"
        /// then this method calls LoadFileReference instead.
        /// </summary>
        /// <param name="page">The page on which to load</param>
        /// <param name="url">The url of the file</param>
        /// <param name="addScriptTag">If true then add script tags</param>
        public static void LoadFileContents
            (Page page, string url, bool addScriptTag)
        {
            if (url.StartsWith(FileTools.httpStart))
            {
                LoadFileReference(page, url);
                return;
            }

            if (url.StartsWith(FileTools.httpsStart))
            {
                LoadFileReference(page, url);
                return;
            }

            ClientScriptManager clientscriptmanager = page.ClientScript;
            Type type = page.GetType();

            if (!clientscriptmanager.IsClientScriptBlockRegistered(type, url))
            {
                string filepath = page.MapPath(url);
                string contents = FileTools.GetFileAsText(filepath);
                LoadScriptString(page, url, contents, addScriptTag);
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns a list of Range objects representing
        /// the matches of the pattern in the content of
        /// a text file with the given tilde file path.
        ///
        /// If successful, returns a reference to the
        /// text file content via an out parameter.
        ///
        /// If isRegex is true,
        /// uses regular expression matching,
        /// otherwise uses plain text matching.
        ///
        /// Ignores case if ignoreCase is true.
        ///
        /// Returns null if the file is not a text file.
        ///
        /// Precondition: The page that calls this method must:
        ///
        ///   Be able to guarantee that the file is OK to serve
        ///   in context.
        /// </summary>
        /// <param name="page">
        ///     The page object that uses this method</param>
        /// <param name="tildeFilePath">
        ///     The tilde file path</param>
        /// <param name="pattern">
        ///     The search pattern</param>
        /// <param name="isRegex">
        ///     If true use regex matching</param>
        /// <param name="ignoreCase">
        ///     If true ignore case</param>
        /// <param name="content">
        ///     Out param: If the file is a text file
        ///     then returns a reference to its content;
        ///     otherwise returns null.</param>
        public static List <Range> SearchFileContent
            (Page page,
            string tildeFilePath,
            string pattern,
            bool isRegex,
            bool ignoreCase,
            out string content)
        {
            content = null;

            int category = FileTools.GetFileCategory(tildeFilePath);

            if (category != FileTools.TEXT)
            {
                return(null);
            }

            string filePath = page.MapPath(tildeFilePath);

            content = FileTools.GetFileAsText(filePath);

            return(Search(content, pattern, 0, isRegex, ignoreCase));
        }