示例#1
0
        private string GetMasterHHC(IList <TopicEntry> hhcTopics)
        {
            string sRet = "";

            if ((hhcTopics != null) && (hhcTopics.Count > 0))
            {
                if (hhcTopics.Count == 1)
                {
                    sRet = hhcTopics[0].Locale;
                }
                else
                {
                    foreach (TopicEntry curEntry in hhcTopics)
                    {
                        ITStorageWrapper iw = null;
                        // Open the internal chm system files and parse their content
                        FileObject fileObject = null;

                        if (_associatedFile.CurrentStorageWrapper == null)
                        {
                            iw = new ITStorageWrapper(_associatedFile.ChmFilePath, false);
                        }
                        else
                        {
                            iw = _associatedFile.CurrentStorageWrapper;
                        }

                        fileObject = iw.OpenUCOMStream(null, curEntry.Locale);
                        if (fileObject != null)
                        {
                            string fileString = fileObject.ReadFromFile(_associatedFile.TextEncoding);
                            fileObject.Close();

                            if (HHCParser.HasGlobalObjectTag(fileString, _associatedFile))
                            {
                                sRet = curEntry.Locale;
                                break;
                            }
                        }
                    }
                }
            }

            return(sRet);
        }
示例#2
0
		static void Main(string[] args)
		{
			// Create Instance of ITStorageWrapper.
			// During initialization constructor will process CHM file 
			// and create collection of file objects stored inside CHM file.
			ITStorageWrapper iw = new ITStorageWrapper(@"I:\apps\abslog.chm");

			// Loop through collection of objects stored inside IStorage
			foreach(IBaseStorageWrapper.FileObjects.FileObject fileObject in iw.foCollection)
			{
				// Check to make sure we can READ stream of an individual file object
				if (fileObject.CanRead)
				{
					// We only want to extract HTM files in this example
					// fileObject is our representation of internal file stored in IStorage
					if (fileObject.FileName.EndsWith(".htm"))
					{
						Console.WriteLine("Path: " + fileObject.FilePath);
						Console.WriteLine("File: " + fileObject.FileName);

						// FileUrl - is a external reference to the internal object
						// allows you to display content of single file in Internet Explorer
						// without extracting content from the archive
						Console.WriteLine("Url: " + fileObject.FileUrl);
			
						string fileString = fileObject.ReadFromFile();
						Console.WriteLine("Text: " + fileString);

						// Direct Extraction sample
						fileObject.Save(@"i:\apps\test1\" + fileObject.FileName);

						// Read first and then save later example
						StreamWriter sw = File.CreateText(@"i:\apps\test1\" + "1" + fileObject.FileName);
						sw.WriteLine(fileString);
						sw.Close();

						Console.ReadLine();
					}
				}
			}
			Console.ReadLine();
		}
示例#3
0
        static void Main(string[] args)
        {
            // Create Instance of ITStorageWrapper.
            // During initialization constructor will process CHM file
            // and create collection of file objects stored inside CHM file.
            ITStorageWrapper iw = new ITStorageWrapper(@"I:\apps\abslog.chm");

            // Loop through collection of objects stored inside IStorage
            foreach (IBaseStorageWrapper.FileObjects.FileObject fileObject in iw.foCollection)
            {
                // Check to make sure we can READ stream of an individual file object
                if (fileObject.CanRead)
                {
                    // We only want to extract HTM files in this example
                    // fileObject is our representation of internal file stored in IStorage
                    if (fileObject.FileName.EndsWith(".htm"))
                    {
                        Console.WriteLine("Path: " + fileObject.FilePath);
                        Console.WriteLine("File: " + fileObject.FileName);

                        // FileUrl - is a external reference to the internal object
                        // allows you to display content of single file in Internet Explorer
                        // without extracting content from the archive
                        Console.WriteLine("Url: " + fileObject.FileUrl);

                        string fileString = fileObject.ReadFromFile();
                        Console.WriteLine("Text: " + fileString);

                        // Direct Extraction sample
                        fileObject.Save(@"i:\apps\test1\" + fileObject.FileName);

                        // Read first and then save later example
                        StreamWriter sw = File.CreateText(@"i:\apps\test1\" + "1" + fileObject.FileName);
                        sw.WriteLine(fileString);
                        sw.Close();

                        Console.ReadLine();
                    }
                }
            }
            Console.ReadLine();
        }
示例#4
0
        public ResultISBN ExtractISBN(string path)
        {
            try
            {
                int i = 0;
                ITStorageWrapper iw = new ITStorageWrapper(path);

                foreach (IBaseStorageWrapper.FileObjects.FileObject fileObject in iw.foCollection)
                {
                    if (fileObject.CanRead)
                    {
                        if (fileObject.FileName.EndsWith(".hhc"))
                        {
                            Regex exp = new Regex(@"[0-9]{9}[0-9xX]", RegexOptions.IgnoreCase);
                            string filtriran = fileObject.FileName.Replace(":", "").Replace(" ", "").Replace("-", "").Trim();
                            Match m = exp.Match(filtriran);
                            if (m.Success) return (new ResultISBN(m.Value,null));
                        }
                        if (fileObject.FileName.EndsWith(".html") || fileObject.FileName.EndsWith(".htm") || fileObject.FileName.StartsWith("#"))
                        {
                            string rezult = fileObject.ReadFromFile();
                            string isbn = (new ISBN()).getISBNFromContent(rezult);
                            switch (isbn)
                            {
                                case null:
                                    break;
                                case "nomatch":
                                    return (new ResultISBN("nomatch", rezult));
                                default:
                                    return (new ResultISBN(isbn, rezult));
                            }
                            if (i < 11) i++; else return (new ResultISBN(isbn, rezult));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                File.AppendAllText("log_chm.txt", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ": " + path +" ::: " +e.Message + Environment.NewLine);
            }
            return (new ResultISBN(null,null));
        }
示例#5
0
        public override string ReadToEnd()
        {
            StringBuilder stringBuilder = new StringBuilder();

            ITStorageWrapper iw = new ITStorageWrapper(fileName);

            foreach (IBaseStorageWrapper.FileObjects.FileObject fileObject in iw.foCollection)
            {
                if (fileObject.CanRead)
                {
                    if (fileObject.FileName.EndsWith(".htm") || fileObject.FileName.EndsWith(".html"))
                    {
                        string fileString = fileObject.ReadFromFile();
                        stringBuilder.Append(RemoveHtml(fileString));
                    }
                }
            }

            return stringBuilder.ToString();
        }