Esempio n. 1
0
        /// <summary>
        /// Loads binary documentation.
        /// </summary>
        /// <remarks>
        /// Don't forget to dispose the BinaryDocumentationProvider.
        /// </remarks>
        /// <param name="fileName">The name of the binary cache file.</param>
        /// <param name="fileDate">The file date of the original XML file. Loading will fail if the cached data was generated
        /// from a different file date than the original XML file.</param>
        /// <returns>
        /// The BinaryDocumentationProvider representing the file's content; or null if loading failed.
        /// </returns>
        public static BinaryDocumentationProvider Load(string fileName, DateTime fileDate)
        {
            BinaryDocumentationProvider doc = new BinaryDocumentationProvider();

            try {
                doc.fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete);
                int          len    = (int)doc.fs.Length;
                BinaryReader loader = doc.loader = new BinaryReader(doc.fs);
                if (loader.ReadInt64() != magic)
                {
                    Debug.WriteLine("Cannot load XmlDoc: wrong magic");
                    return(null);
                }
                if (loader.ReadInt16() != version)
                {
                    Debug.WriteLine("Cannot load XmlDoc: wrong version");
                    return(null);
                }
                if (loader.ReadInt64() != fileDate.Ticks)
                {
                    Debug.WriteLine("Not loading XmlDoc: file changed since cache was created");
                    return(null);
                }
                int count = loader.ReadInt32();
                int indexStartPosition = loader.ReadInt32();                 // go to start of index
                if (indexStartPosition <= 0 || indexStartPosition >= len)
                {
                    Debug.WriteLine("XmlDoc: Cannot find index, cache invalid!");
                    return(null);
                }
                doc.fs.Position = indexStartPosition;
                IndexEntry[] index = new IndexEntry[count];
                for (int i = 0; i < index.Length; i++)
                {
                    index[i] = new IndexEntry(loader.ReadInt32(), loader.ReadInt32());
                }
                doc.index = index;
                return(doc);
            } catch (IOException ex) {
                Debug.WriteLine("Cannot load from cache" + ex.ToString());
                return(null);
            }
        }
		/// <summary>
		/// Loads binary documentation.
		/// </summary>
		/// <remarks>
		/// Don't forget to dispose the BinaryDocumentationProvider.
		/// </remarks>
		/// <param name="fileName">The name of the binary cache file.</param>
		/// <param name="fileDate">The file date of the original XML file. Loading will fail if the cached data was generated
		/// from a different file date than the original XML file.</param>
		/// <returns>
		/// The BinaryDocumentationProvider representing the file's content; or null if loading failed.
		/// </returns>
		public static BinaryDocumentationProvider Load(string fileName, DateTime fileDate)
		{
			BinaryDocumentationProvider doc = new BinaryDocumentationProvider();
			try {
				doc.fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete);
				int len = (int)doc.fs.Length;
				BinaryReader loader = doc.loader = new BinaryReader(doc.fs);
				if (loader.ReadInt64() != magic) {
					Debug.WriteLine("Cannot load XmlDoc: wrong magic");
					return null;
				}
				if (loader.ReadInt16() != version) {
					Debug.WriteLine("Cannot load XmlDoc: wrong version");
					return null;
				}
				if (loader.ReadInt64() != fileDate.Ticks) {
					Debug.WriteLine("Not loading XmlDoc: file changed since cache was created");
					return null;
				}
				int count = loader.ReadInt32();
				int indexStartPosition = loader.ReadInt32(); // go to start of index
				if (indexStartPosition <= 0 || indexStartPosition >= len) {
					Debug.WriteLine("XmlDoc: Cannot find index, cache invalid!");
					return null;
				}
				doc.fs.Position = indexStartPosition;
				IndexEntry[] index = new IndexEntry[count];
				for (int i = 0; i < index.Length; i++) {
					index[i] = new IndexEntry(loader.ReadInt32(), loader.ReadInt32());
				}
				doc.index = index;
				return doc;
			} catch (IOException ex) {
				Debug.WriteLine("Cannot load from cache" + ex.ToString());
				return null;
			}
		}