Esempio n. 1
0
        private HelpInfo LoadHelpFile(string path)
        {
            string fileName = Path.GetFileName(path);

            if (!path.EndsWith(".help.txt", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            string str2 = fileName.Substring(0, fileName.Length - 9);

            if (string.IsNullOrEmpty(str2))
            {
                return(null);
            }
            HelpInfo cache = base.GetCache(path);

            if (cache == null)
            {
                TextReader reader = new StreamReader(path);
                string     text   = null;
                try
                {
                    text = reader.ReadToEnd();
                }
                finally
                {
                    reader.Close();
                }
                this._helpFiles[path] = 0;
                cache = HelpFileHelpInfo.GetHelpInfo(str2, text, path);
                base.AddCache(path, cache);
            }
            return(cache);
        }
Esempio n. 2
0
 private HelpInfo LoadHelpFile(string path)
 {
     using (HelpFileHelpProvider.tracer.TraceMethod())
     {
         string fileName = Path.GetFileName(path);
         if (!path.EndsWith(".help.txt", StringComparison.OrdinalIgnoreCase))
         {
             return((HelpInfo)null);
         }
         string name = fileName.Substring(0, fileName.Length - 9);
         if (string.IsNullOrEmpty(name))
         {
             return((HelpInfo)null);
         }
         HelpInfo cache = this.GetCache(path);
         if (cache != null)
         {
             return(cache);
         }
         TextReader textReader = (TextReader) new StreamReader(path);
         string     text       = (string)null;
         try
         {
             text = textReader.ReadToEnd();
         }
         finally
         {
             textReader.Close();
         }
         this._helpFiles[(object)path] = (object)0;
         HelpInfo helpInfo = (HelpInfo)HelpFileHelpInfo.GetHelpInfo(name, text, path);
         this.AddCache(path, helpInfo);
         return(helpInfo);
     }
 }
        /// <summary>
        /// Load help file based on the file path.
        /// </summary>
        /// <param name="path">file path to load help from</param>
        /// <returns>Help info object loaded from the file</returns>
        private HelpInfo LoadHelpFile(string path)
        {
            string fileName = Path.GetFileName(path);

            //Bug906435: Get-help for special devices throws an exception
            //There might be situations where path does not end with .help.txt extension
            //The assumption that path ends with .help.txt is broken under special
            //conditions when user uses "get-help" with device names like "prn","com1" etc.
            //First check whether path ends with .help.txt.

            // If path does not end with ".help.txt" return.
            if (!path.EndsWith(".help.txt", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            string name = fileName.Substring(0, fileName.Length - 9 /* ".help.txt".Length */);

            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }

            HelpInfo helpInfo = GetCache(path);

            if (helpInfo != null)
            {
                return(helpInfo);
            }

            string helpText = null;

            using (TextReader tr = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                helpText = tr.ReadToEnd();
            }
            // Add this file into _helpFiles hashtable to prevent it to be loaded again.
            _helpFiles[path] = 0;
            helpInfo         = HelpFileHelpInfo.GetHelpInfo(name, helpText, path);

            AddCache(path, helpInfo);

            return(helpInfo);
        }