示例#1
0
		/// <summary>
		/// Writes reflected metadata combined with the /doc comments to the 
		/// specified file.
		/// </summary>
		/// <remarks>
		/// This is performed in a separate <see cref="AppDomain" />.
		/// </remarks>
		protected void MakeXmlFile(Project project, string fileName)
		{
			//if this.rep.UseNDocXmlFile is set, 
			//copy it to the temp file and return.
			string xmlFile = MyConfig.UseNDocXmlFile;
			if (xmlFile.Length > 0)
			{
				Trace.WriteLine("Loading pre-compiled XML information from: " + xmlFile);
				File.Copy(xmlFile, fileName, true);
				return;
			}

            AppDomain appDomain = null;
			try 
			{
				appDomain = AppDomain.CreateDomain("NDocReflection", 
					AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);
                appDomain.SetupInformation.ShadowCopyFiles = "true"; //only required for managed c++ assemblies
                ReflectionEngine re = (ReflectionEngine)   
                    appDomain.CreateInstanceAndUnwrap(typeof(ReflectionEngine).Assembly.FullName, 
                    typeof(ReflectionEngine).FullName, false, BindingFlags.Public | BindingFlags.Instance, 
                    null, new object[0], CultureInfo.InvariantCulture, new object[0], 
                    AppDomain.CurrentDomain.Evidence);
				ReflectionEngineParameters rep = new ReflectionEngineParameters(
					project, MyConfig);
				re.MakeXmlFile(rep, fileName);
			} 
			finally 
			{
				if (appDomain != null) AppDomain.Unload(appDomain);
			}
		}
示例#2
0
		/// <summary>
		/// Gets the namespaces from assembly.
		/// </summary>
		/// <param name="rep">ReflectionEngine Parameters.</param>
		/// <param name="assemblyFile">Assembly file name.</param>
		/// <returns></returns>
		public SortedList GetNamespacesFromAssembly(ReflectionEngineParameters rep, string assemblyFile)
		{
			this.rep = rep;
			assemblyLoader = SetupAssemblyLoader();
			try
			{
				Assembly a = assemblyLoader.LoadAssembly(assemblyFile);
				SortedList namespaces = new SortedList();

				foreach (Type t in a.GetTypes())
				{
					string ns = t.Namespace;
				{
					if (ns == null)
					{
						if ((!namespaces.ContainsKey("(global)")))
							namespaces.Add("(global)", null);
					}
					else
					{
						if ((!namespaces.ContainsKey(ns)))
							namespaces.Add(ns, null);
					}
				}
				}

				return namespaces;
			}
			catch (ReflectionTypeLoadException rtle)
			{
				StringBuilder sb = new StringBuilder();
				if (assemblyLoader.UnresolvedAssemblies.Count > 0)
				{
					sb.Append("One or more required assemblies could not be located : \n");
					foreach (string ass in assemblyLoader.UnresolvedAssemblies)
					{
						sb.AppendFormat("   {0}\n", ass);
					}
					sb.Append("\nThe following directories were searched, \n");
					foreach (string dir in assemblyLoader.SearchedDirectories)
					{
						sb.AppendFormat("   {0}\n", dir);
					}
				}
				else
				{
					Hashtable fileLoadExceptions = new Hashtable();
					foreach (Exception loaderEx in rtle.LoaderExceptions)
					{
						System.IO.FileLoadException fileLoadEx = loaderEx as System.IO.FileLoadException;
						if (fileLoadEx != null)
						{
							if (!fileLoadExceptions.ContainsKey(fileLoadEx.FileName))
							{
								fileLoadExceptions.Add(fileLoadEx.FileName, null);
								sb.Append("Unable to load: " + fileLoadEx.FileName + "\r\n");
							}
						}
						sb.Append(loaderEx.Message + Environment.NewLine);
						sb.Append(loaderEx.StackTrace + Environment.NewLine);
						sb.Append("--------------------" + Environment.NewLine + Environment.NewLine);
					}
				}
				throw new DocumenterException(sb.ToString());
			}
			finally
			{
				assemblyLoader.Deinstall();
			}
		}
示例#3
0
		/// <summary>Builds an Xml string combining the reflected metadata with the /doc comments.</summary>
		/// <remarks>This now evidently writes the string in utf-16 format (and 
		/// says so, correctly I suppose, in the xml text) so if you write this string to a file with 
		/// utf-8 encoding it will be unparseable because the file will claim to be utf-16
		/// but will actually be utf-8.</remarks>
		/// <returns>XML string</returns>
		internal string MakeXml(ReflectionEngineParameters rep)
		{
			this.rep = rep;

			StringWriter swriter = new StringWriter();
			XmlWriter writer = new XmlTextWriter(swriter);

			try
			{
				BuildXml(writer);
				return swriter.ToString();
			}
			finally
			{
				if (writer != null)  writer.Close();
				if (swriter != null) swriter.Close();
			}

		}
示例#4
0
		/// <summary>Builds an Xml file combining the reflected metadata with the /doc comments.</summary>
		/// <returns>full pathname of XML file</returns>
		/// <remarks>The caller is responsible for deleting the xml file after use...</remarks>
		internal void MakeXmlFile(ReflectionEngineParameters rep, string xmlFile)
		{
			this.rep = rep;

			XmlTextWriter writer = null;
			try
			{
				writer = new XmlTextWriter(xmlFile, Encoding.UTF8);
				BuildXml(writer);
			}
			finally
			{
				if (writer != null)  writer.Close();
			}			
		}
示例#5
0
		/// <summary>
		/// Returns reflected metadata combined with the /doc comments.
		/// </summary>
		/// <remarks>This now evidently writes the string in utf-16 format (and 
		/// says so, correctly I suppose, in the xml text) so if you write this string to a file with 
		/// utf-8 encoding it will be unparseable because the file will claim to be utf-16
		/// but will actually be utf-8.</remarks>
		/// <returns>XML string</returns>
		/// <remarks>
		/// This is performed in a separate <see cref="AppDomain" />.
		/// </remarks>
		protected string MakeXml(Project project)
		{
			//if MyConfig.UseNDocXmlFile is set, 
			//load the XmlBuffer from the file and return.
			string xmlFile = MyConfig.UseNDocXmlFile;
			if (xmlFile.Length > 0)
			{
				Trace.WriteLine("Loading pre-compiled XML information from: " + xmlFile);
				using (TextReader reader = new StreamReader(xmlFile, Encoding.UTF8))
				{
					return reader.ReadToEnd();
				}
			}

			AppDomain appDomain = null;

			try 
			{
				appDomain = AppDomain.CreateDomain("NDocReflection", 
					AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);
				appDomain.SetupInformation.ShadowCopyFiles = "true"; //only required for managed c++ assemblies
				ReflectionEngine re = (ReflectionEngine)   
                    appDomain.CreateInstanceAndUnwrap(typeof(ReflectionEngine).Assembly.FullName, 
                    typeof(ReflectionEngine).FullName, false, BindingFlags.Public | BindingFlags.Instance, 
                    null, new object[0], CultureInfo.InvariantCulture, new object[0], 
                    AppDomain.CurrentDomain.Evidence);
                ReflectionEngineParameters rep = new ReflectionEngineParameters(
					project, MyConfig);
				return re.MakeXml(rep);
			} 
			finally 
			{
				if (appDomain != null) AppDomain.Unload(appDomain);
			}
		}
示例#6
0
		/// <summary>
		/// Loads the namespaces from assemblies.
		/// </summary>
		/// <param name="project">Project.</param>
		public void LoadNamespacesFromAssemblies(Project project)
		{
			//let's try to create this in a new AppDomain
			AppDomain appDomain = null;
			try
			{
				appDomain = AppDomain.CreateDomain("NDocNamespaces");
				ReflectionEngine re = (ReflectionEngine)   
					appDomain.CreateInstanceAndUnwrap(typeof(ReflectionEngine).Assembly.FullName, 
					typeof(ReflectionEngine).FullName, false, BindingFlags.Public | BindingFlags.Instance, 
					null, new object[0], CultureInfo.InvariantCulture, new object[0], 
					AppDomain.CurrentDomain.Evidence);
				ReflectionEngineParameters rep = new ReflectionEngineParameters(project);
				foreach (AssemblySlashDoc assemblySlashDoc in project.AssemblySlashDocs)
				{
					if (assemblySlashDoc.Assembly.Path.Length > 0)
					{
						string assemblyFullPath = assemblySlashDoc.Assembly.Path;
						if (File.Exists(assemblyFullPath))
						{
							SortedList namespaces = re.GetNamespacesFromAssembly(rep, assemblyFullPath);
							foreach (string ns in namespaces.GetKeyList())
							{
								if (_namespaces == null)
									_namespaces = new SortedList();
								if ((!_namespaces.ContainsKey(ns)))
								{
									_namespaces.Add(ns, null);
								}
							}
						}
					}
				}
			}
			finally
			{
				if (appDomain != null) AppDomain.Unload(appDomain);
			}
		}
示例#7
0
		/// <summary>
		/// Writes reflected metadata combined with the /doc comments to the 
		/// specified file.
		/// </summary>
		/// <remarks>
		/// This is performed in a separate <see cref="AppDomain" />.
		/// </remarks>
		protected void MakeXmlFile(Project project, string fileName)
		{
			//if this.rep.UseNDocXmlFile is set, 
			//copy it to the temp file and return.
			string xmlFile = MyConfig.UseNDocXmlFile;
			if (xmlFile.Length > 0)
			{
				Trace.WriteLine("Loading pre-compiled XML information from: " + xmlFile);
				File.Copy(xmlFile, fileName, true);
				return;
			}

            AppDomain appDomain = null;
			try 
			{
				appDomain = AppDomain.CreateDomain("NDocReflection", 
				    AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);
				appDomain.SetShadowCopyFiles(); //only required for managed c++ assemblies
                ReflectionEngine re = null;
                try {
                    //re = (ReflectionEngine)
                    //    appDomain.CreateInstanceAndUnwrap(typeof(ReflectionEngine).Assembly.FullName,
                    //    typeof(ReflectionEngine).FullName, false, BindingFlags.Public | BindingFlags.Instance,
                    //    null, new object[0], CultureInfo.InvariantCulture, new object[0],
                    //    //AppDomain.CurrentDomain.Evidence);
                    //    new System.Security.Policy.Evidence());
                    re = new ReflectionEngine();
                }
                catch (System.Security.SecurityException e) {
                    System.Windows.Forms.MessageBox.Show(
                        e.Message + "\n" + 
                        e.ToString() + "\n" + 
                        e.PermissionState + "\n" + 
                        e.PermissionType.ToString() + "\n" + 
                        e.RefusedSet + "\n" + 
                        e.Source + "\n" + 
                        e.Url + "\n" + 
                        e.Zone.ToString() + "\n" + 
                        string.Empty
                        );
                }
				ReflectionEngineParameters rep = new ReflectionEngineParameters(
					project, MyConfig);
				re.MakeXmlFile(rep, fileName);
			} 
			finally 
			{
				if (appDomain != null) AppDomain.Unload(appDomain);
			}
		}