public static bool Run(XRefArguments arguments, IMessageSender logger = null) { lock (s_locker) { var success = false; s_log = logger; try { success = InternalRun(arguments); } catch (Exception ex) { Log.SendError(ex.ToString()); if (ex is ReflectionTypeLoadException) { foreach (var loaderException in ((ReflectionTypeLoadException)ex).LoaderExceptions) { Log.SendError(loaderException.ToString()); } } } s_log = null; return(success); } }
public Settings(string persistentSettingsFile, Action<XRefArguments> apply, Func<XRefArguments> get, XRefArguments defaultSettings = null) { _persistentSettingsFile = persistentSettingsFile; _apply = apply; _get = get; _defaultSettings = defaultSettings; Arguments = Load (_persistentSettingsFile) ?? defaultSettings; }
public int Run(string[] talkbackArgs, XRefArguments cmdLineArgs) { if(talkbackArgs != null) TalkBackChannel.Initialize (talkbackArgs); XRefArguments.Instance = cmdLineArgs; return TalkBackInvoke.Action (sender => XRef.Run (cmdLineArgs, sender), MessageReceived) ? 0 : 1; }
public int Run(string[] talkbackArgs, XRefArguments cmdLineArgs) { if (talkbackArgs != null) { TalkBackChannel.Initialize(talkbackArgs); } XRefArguments.Instance = cmdLineArgs; return(TalkBackInvoke.Action(sender => XRef.Run(cmdLineArgs, sender), MessageReceived) ? 0 : 1); }
public int Run(string[] talkBackArgs, XRefArguments xRefArgs, CrossAppDomainCommunicator.MessageReceivedDelegate onMessageReceived = null) { // Create new application domain and run cross referencer var appDomain = AppDomain.CurrentDomain; var setupInformation = appDomain.SetupInformation; setupInformation.ApplicationBase = xRefArgs.AssemblyDirectory; if(!string.IsNullOrEmpty(xRefArgs.AppBaseDirectory)) { setupInformation.ApplicationBase = xRefArgs.AppBaseDirectory; var appBaseDirectory = xRefArgs.AppBaseDirectory; if (!appBaseDirectory.EndsWith ("\\")) appBaseDirectory += "\\"; if(xRefArgs.AssemblyDirectory.StartsWith(appBaseDirectory)) { var relativeSearchPath = xRefArgs.AssemblyDirectory.Remove (0, appBaseDirectory.Length); if (!string.IsNullOrEmpty (relativeSearchPath)) { setupInformation.PrivateBinPath = relativeSearchPath; } } else { throw new ArgumentException ("Input directory is not a sub directory of application base directory!"); } } if (!string.IsNullOrEmpty (xRefArgs.AppConfigFile)) { if (!File.Exists (xRefArgs.AppConfigFile)) throw new ArgumentException (string.Format ("Supplied app-config file '{0}' does not exist.", xRefArgs.AppConfigFile)); setupInformation.ConfigurationFile = xRefArgs.AppConfigFile; // The PrivateBinPath needs to be read manually from the config because for some reason it does not via automatic setup. var privateBinPath = GetPrivateBinPathFromConfig (xRefArgs.AppConfigFile); if (!string.IsNullOrEmpty (privateBinPath)) { if (string.IsNullOrEmpty (setupInformation.PrivateBinPath)) setupInformation.PrivateBinPath = privateBinPath; else setupInformation.PrivateBinPath = setupInformation.PrivateBinPath + ";" + privateBinPath; } } var newAppDomain = AppDomain.CreateDomain ("XRefAppDomain", appDomain.Evidence, setupInformation, new PermissionSet(PermissionState.Unrestricted)); var crossAppDomainCommunicatorType = typeof (CrossAppDomainCommunicator); var proxy = (CrossAppDomainCommunicator) newAppDomain.CreateInstanceFromAndUnwrap (crossAppDomainCommunicatorType.Assembly.Location, crossAppDomainCommunicatorType.FullName); if(onMessageReceived != null) proxy.SetMessageReceivedDelegate(new MessageReceivedDelegateWrapper(onMessageReceived).OnMessageReceived); return proxy.Run (talkBackArgs, xRefArgs); }
private static bool CheckArguments(XRefArguments arguments) { if (string.IsNullOrEmpty(arguments.AssemblyDirectory)) { Log.SendError("Input directory missing"); return(false); } if (!File.Exists(Path.Combine(arguments.AssemblyDirectory, "Remotion.dll"))) { Log.SendError("The input directory '" + arguments.AssemblyDirectory + "' doesn't contain the remotion assembly."); return(false); } if (string.IsNullOrEmpty(arguments.OutputDirectory)) { Log.SendError("Output directory missing"); return(false); } if (arguments.ReflectorSource == ReflectorSource.Unspecified) { Log.SendError("Reflector is missing. Either provide a reflector assembly or a custom reflector."); return(false); } if (!Directory.Exists(arguments.AssemblyDirectory)) { Log.SendError("Input directory '" + arguments.AssemblyDirectory + "' does not exist"); return(false); } var invalid = arguments.OutputDirectory.Intersect(Path.GetInvalidPathChars()); if (invalid.Any()) { Log.SendError("Output directory contains invalid characters: {0}", string.Join(" ", invalid.Select(c => c.ToString()).ToArray())); return(false); } if (Directory.Exists(arguments.OutputDirectory) && !arguments.OverwriteExistingFiles) { Log.SendError("Output directory already exists. Use -f option if you are sure you want to overwrite all existing files."); return(false); } return(true); }
private static bool CreateReflector(XRefArguments arguments, out IRemotionReflector reflector) { try { switch (arguments.ReflectorSource) { case ReflectorSource.ReflectorAssembly: reflector = RemotionReflectorFactory.Create(arguments.AssemblyDirectory, arguments.ReflectorPath); return(true); case ReflectorSource.CustomReflector: var customReflector = Type.GetType(arguments.CustomReflectorAssemblyQualifiedTypeName); if (customReflector == null) { Log.SendError("Custom reflector can not be found"); reflector = null; return(false); } if (!typeof(IRemotionReflector).IsAssignableFrom(customReflector)) { Log.SendError( "Specified custom reflector {0} does not implement {1}", customReflector, typeof(IRemotionReflector).FullName); reflector = null; return(false); } reflector = RemotionReflectorFactory.Create(arguments.AssemblyDirectory, customReflector); return(true); case ReflectorSource.Unspecified: throw new IndexOutOfRangeException("Reflector source is unspecified"); } } catch (Exception ex) { Log.SendError("Error while initializing the reflector: {0}", ex.Message); reflector = null; return(false); } throw new InvalidOperationException("Unreachable codepath reached."); }
private static int CheckArguments(XRefArguments cmdLineArgs) { if (string.IsNullOrEmpty (cmdLineArgs.AssemblyDirectory)) { Console.Error.WriteLine ("Input directory missing"); return 1; } if (string.IsNullOrEmpty (cmdLineArgs.XMLOutputFileName)) { Console.Error.WriteLine ("Output file missing"); return 1; } if (cmdLineArgs.ReflectorSource == ReflectorSource.Unspecified) { Console.Error.WriteLine ("Reflector is missing. Either provide a reflector assembly or a custom reflector."); return 1; } return 0; }
public static bool Run(XRefArguments arguments, IMessageSender logger = null) { lock (s_locker) { var success = false; s_log = logger; try { success = InternalRun (arguments); } catch (Exception ex) { Log.SendError (ex.ToString ()); if (ex is ReflectionTypeLoadException) { foreach (var loaderException in ((ReflectionTypeLoadException) ex).LoaderExceptions) Log.SendError (loaderException.ToString()); } } s_log = null; return success; } }
private static void SerializeToFile(string file, XRefArguments args) { using (var stream = File.OpenWrite (file)) { var formatter = new BinaryFormatter (); formatter.Serialize (stream, args); } }
private void ApplySettings(XRefArguments settings) { assemblyPathTextBox.Text = settings.AssemblyDirectory; outputPathTextBox.Text = settings.OutputDirectory; reflectorAssemblyTextBox.Text = settings.ReflectorPath; customReflectorTextBox.Text = settings.CustomReflectorAssemblyQualifiedTypeName; forceOverrideCheckBox.Checked = settings.OverwriteExistingFiles; appBaseDirectory.Text = settings.AppBaseDirectory; appConfigFile.Text = settings.AppConfigFile; switch (settings.ReflectorSource) { case ReflectorSource.ReflectorAssembly: reflectorAssemblyRadioButton.Checked = true; break; case ReflectorSource.CustomReflector: customReflectorRadioButton.Checked = true; break; } }
private static bool CheckArguments(XRefArguments arguments) { if (string.IsNullOrEmpty (arguments.AssemblyDirectory)) { Log.SendError ("Input directory missing"); return false; } if (!File.Exists (Path.Combine (arguments.AssemblyDirectory, "Remotion.dll"))) { Log.SendError("The input directory '" + arguments.AssemblyDirectory + "' doesn't contain the remotion assembly."); return false; } if (string.IsNullOrEmpty (arguments.OutputDirectory)) { Log.SendError ("Output directory missing"); return false; } if (arguments.ReflectorSource == ReflectorSource.Unspecified) { Log.SendError ("Reflector is missing. Either provide a reflector assembly or a custom reflector."); return false; } if (!Directory.Exists (arguments.AssemblyDirectory)) { Log.SendError ("Input directory '" + arguments.AssemblyDirectory + "' does not exist"); return false; } var invalid = arguments.OutputDirectory.Intersect (Path.GetInvalidPathChars ()); if (invalid.Any ()) { Log.SendError ("Output directory contains invalid characters: {0}", string.Join (" ", invalid.Select (c => c.ToString ()).ToArray ())); return false; } if (Directory.Exists (arguments.OutputDirectory) && !arguments.OverwriteExistingFiles) { Log.SendError ("Output directory already exists. Use -f option if you are sure you want to overwrite all existing files."); return false; } return true; }
private static bool InternalRun(XRefArguments arguments) { var argsOk = CheckArguments (arguments); if (!argsOk) return false; IRemotionReflector reflector; if (!CreateReflector(arguments, out reflector)) return false; var assemblyResolver = AssemblyResolver.Create(); AppDomain.CurrentDomain.AssemblyResolve += assemblyResolver.HandleAssemblyResolve; reflector.InitializeLogging (); var typeDiscoveryService = reflector.GetTypeDiscoveryService(); ICollection allTypes; try { allTypes = typeDiscoveryService.GetTypes (null, true); } catch (Exception ex) { Log.SendError (ex.ToString()); return false; } var allAssemblies = allTypes.Cast<Type>().Select (t => t.Assembly) .Distinct() .Where (a => !reflector.IsRelevantAssemblyForConfiguration (a) || !reflector.IsNonApplicationAssembly (a)) .ToArray(); if (!allAssemblies.Any()) { Log.SendError ("\"{0}\" contains no assemblies or only assemblies on the ignore list", arguments.AssemblyDirectory); return false; } var mixinConfiguration = reflector.BuildConfigurationFromAssemblies (allAssemblies); var outputFormatter = new OutputFormatter (); var configurationErrors = new ErrorAggregator<Exception> (); var validationErrors = new ErrorAggregator<Exception> (); var involvedTypes = new InvolvedTypeFinder (mixinConfiguration, allAssemblies, configurationErrors, validationErrors, reflector).FindInvolvedTypes (); var reportGenerator = new FullReportGenerator (involvedTypes, configurationErrors, validationErrors, reflector, outputFormatter); var outputDocument = reportGenerator.GenerateXmlDocument (); var xmlFile = Path.Combine (arguments.OutputDirectory, !string.IsNullOrEmpty (arguments.XMLOutputFileName) ? arguments.XMLOutputFileName : "MixinXRef.xml"); outputDocument.Save (xmlFile); reportGenerator = null; GC.Collect (); allAssemblies = null; GC.Collect (); GC.WaitForPendingFinalizers (); if (!arguments.SkipHTMLGeneration) { var transformerExitCode = new XRefTransformer (xmlFile, arguments.OutputDirectory).GenerateHtmlFromXml (); if (transformerExitCode != 0) { Log.SendError ("Error applying XSLT (code {0})", transformerExitCode); return false; } // copy resources folder var xRefPath = Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location); new DirectoryInfo (Path.Combine (xRefPath, @"xml_utilities\resources")).CopyTo (Path.Combine (arguments.OutputDirectory, "resources")); Log.SendInfo ("Mixin Documentation successfully generated to '{0}'.", arguments.OutputDirectory); } else { Log.SendInfo (" Skipping HTML generation"); } return true; }
private static bool CreateReflector(XRefArguments arguments, out IRemotionReflector reflector) { try { switch (arguments.ReflectorSource) { case ReflectorSource.ReflectorAssembly: reflector = RemotionReflectorFactory.Create (arguments.AssemblyDirectory, arguments.ReflectorPath); return true; case ReflectorSource.CustomReflector: var customReflector = Type.GetType (arguments.CustomReflectorAssemblyQualifiedTypeName); if (customReflector == null) { Log.SendError ("Custom reflector can not be found"); reflector = null; return false; } if (!typeof (IRemotionReflector).IsAssignableFrom (customReflector)) { Log.SendError ( "Specified custom reflector {0} does not implement {1}", customReflector, typeof (IRemotionReflector).FullName); reflector = null; return false; } reflector = RemotionReflectorFactory.Create (arguments.AssemblyDirectory, customReflector); return true; case ReflectorSource.Unspecified: throw new IndexOutOfRangeException ("Reflector source is unspecified"); } } catch (Exception ex) { Log.SendError ("Error while initializing the reflector: {0}", ex.Message); reflector = null; return false; } throw new InvalidOperationException ("Unreachable codepath reached."); }
public int Run(string[] talkBackArgs, XRefArguments xRefArgs, CrossAppDomainCommunicator.MessageReceivedDelegate onMessageReceived = null) { // Create new application domain and run cross referencer var appDomain = AppDomain.CurrentDomain; var setupInformation = appDomain.SetupInformation; setupInformation.ApplicationBase = xRefArgs.AssemblyDirectory; if (!string.IsNullOrEmpty(xRefArgs.AppBaseDirectory)) { setupInformation.ApplicationBase = xRefArgs.AppBaseDirectory; var appBaseDirectory = xRefArgs.AppBaseDirectory; if (!appBaseDirectory.EndsWith("\\")) { appBaseDirectory += "\\"; } if (xRefArgs.AssemblyDirectory.StartsWith(appBaseDirectory)) { var relativeSearchPath = xRefArgs.AssemblyDirectory.Remove(0, appBaseDirectory.Length); if (!string.IsNullOrEmpty(relativeSearchPath)) { setupInformation.PrivateBinPath = relativeSearchPath; } } else { throw new ArgumentException("Input directory is not a sub directory of application base directory!"); } } if (!string.IsNullOrEmpty(xRefArgs.AppConfigFile)) { if (!File.Exists(xRefArgs.AppConfigFile)) { throw new ArgumentException(string.Format("Supplied app-config file '{0}' does not exist.", xRefArgs.AppConfigFile)); } setupInformation.ConfigurationFile = xRefArgs.AppConfigFile; // The PrivateBinPath needs to be read manually from the config because for some reason it does not via automatic setup. var privateBinPath = GetPrivateBinPathFromConfig(xRefArgs.AppConfigFile); if (!string.IsNullOrEmpty(privateBinPath)) { if (string.IsNullOrEmpty(setupInformation.PrivateBinPath)) { setupInformation.PrivateBinPath = privateBinPath; } else { setupInformation.PrivateBinPath = setupInformation.PrivateBinPath + ";" + privateBinPath; } } } var newAppDomain = AppDomain.CreateDomain("XRefAppDomain", appDomain.Evidence, setupInformation, new PermissionSet(PermissionState.Unrestricted)); var crossAppDomainCommunicatorType = typeof(CrossAppDomainCommunicator); var proxy = (CrossAppDomainCommunicator)newAppDomain.CreateInstanceFromAndUnwrap(crossAppDomainCommunicatorType.Assembly.Location, crossAppDomainCommunicatorType.FullName); if (onMessageReceived != null) { proxy.SetMessageReceivedDelegate(new MessageReceivedDelegateWrapper(onMessageReceived).OnMessageReceived); } return(proxy.Run(talkBackArgs, xRefArgs)); }
private static bool InternalRun(XRefArguments arguments) { var argsOk = CheckArguments(arguments); if (!argsOk) { return(false); } IRemotionReflector reflector; if (!CreateReflector(arguments, out reflector)) { return(false); } var assemblyResolver = AssemblyResolver.Create(); AppDomain.CurrentDomain.AssemblyResolve += assemblyResolver.HandleAssemblyResolve; reflector.InitializeLogging(); var typeDiscoveryService = reflector.GetTypeDiscoveryService(); ICollection allTypes; try { allTypes = typeDiscoveryService.GetTypes(null, true); } catch (Exception ex) { Log.SendError(ex.ToString()); return(false); } var allAssemblies = allTypes.Cast <Type>().Select(t => t.Assembly) .Distinct() .Where(a => !reflector.IsRelevantAssemblyForConfiguration(a) || !reflector.IsNonApplicationAssembly(a)) .ToArray(); if (!allAssemblies.Any()) { Log.SendError("\"{0}\" contains no assemblies or only assemblies on the ignore list", arguments.AssemblyDirectory); return(false); } var mixinConfiguration = reflector.BuildConfigurationFromAssemblies(allAssemblies); var outputFormatter = new OutputFormatter(); var configurationErrors = new ErrorAggregator <Exception> (); var validationErrors = new ErrorAggregator <Exception> (); var involvedTypes = new InvolvedTypeFinder(mixinConfiguration, allAssemblies, configurationErrors, validationErrors, reflector).FindInvolvedTypes(); var reportGenerator = new FullReportGenerator(involvedTypes, configurationErrors, validationErrors, reflector, outputFormatter); var outputDocument = reportGenerator.GenerateXmlDocument(); var xmlFile = Path.Combine(arguments.OutputDirectory, !string.IsNullOrEmpty(arguments.XMLOutputFileName) ? arguments.XMLOutputFileName : "MixinXRef.xml"); outputDocument.Save(xmlFile); reportGenerator = null; GC.Collect(); allAssemblies = null; GC.Collect(); GC.WaitForPendingFinalizers(); if (!arguments.SkipHTMLGeneration) { var transformerExitCode = new XRefTransformer(xmlFile, arguments.OutputDirectory).GenerateHtmlFromXml(); if (transformerExitCode != 0) { Log.SendError("Error applying XSLT (code {0})", transformerExitCode); return(false); } // copy resources folder var xRefPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); new DirectoryInfo(Path.Combine(xRefPath, @"xml_utilities\resources")).CopyTo(Path.Combine(arguments.OutputDirectory, "resources")); Log.SendInfo("Mixin Documentation successfully generated to '{0}'.", arguments.OutputDirectory); } else { Log.SendInfo(" Skipping HTML generation"); } return(true); }
private void RunXRef(XRefArguments options) { try { AppendTextToLogTextBoxAsync ("Running MixinXRef..."); CrossAppDomainCommunicator.MessageReceivedDelegate onMessageReceived = (severity, message) => AppendTextToLogTextBoxAsync (message); new XRefInAppDomainRunner ().Run(null, options, onMessageReceived); } catch (ArgumentException ex) { Action messageBoxDisplayer = () => MessageBox.Show (this, ex.Message, "Configuration error", MessageBoxButtons.OK, MessageBoxIcon.Error); BeginInvoke(messageBoxDisplayer); } }