Exemple #1
0
        public static int Main(string[] argv)
        {
            #if TEST
            AutoTest.TestSuite();
            #endif
            int result = 1;
            StringCollection parameters = new StringCollection();
            parameters.AddRange(argv);

            AppDomain.CurrentDomain.AppendPrivatePath(Environment.CurrentDirectory);
            AppDomain.CurrentDomain.AppendPrivatePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            try {
                EntryPoint entryPoint = new EntryPoint();

                if (parameters.Contains(DebugOption)) { // Handle debug mode
                    AspectDngConfig.Instance.debug = true;
                    parameters.Remove(DebugOption);
                }

                if (parameters.Contains(QueryOption) && parameters.Count >= 3) { // Handle query mode
                    parameters.Remove(QueryOption);
                    Cil.Init(parameters[0], parameters[0]);
                    parameters.RemoveAt(0);

                    string[] array = new string[parameters.Count];
                    parameters.CopyTo(array, 0);
                    string xpath = string.Join(" ", array);
                    Console.WriteLine("\nReal XPath query:\n{0}", xpath);

                    ICollection results = Cil.TargetNavigator.SelectList(xpath);
                    Console.WriteLine("{0} results", results.Count);
                    foreach (Navigator nav in results) {
                        Console.WriteLine("[" + nav.Name + "] " + nav);
                    }
                } else if (parameters.Contains(IlmlDumpOption) && parameters.Count == 3) { // Handle ilml mode
                    parameters.Remove(IlmlDumpOption);
                    Cil.Init(parameters[0], parameters[0]);
                    parameters.RemoveAt(0);

                    // Apply XSLT to Assembly
                    XslTransform ilmlDump = new XslTransform();
                    ilmlDump.Load(new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("IlmlDump.xsl")), null, null);
                    XmlTextWriter writer = new XmlTextWriter(parameters[0], Encoding.Unicode);
                    writer.Formatting = Formatting.Indented;
                    ilmlDump.Transform(new Navigator(Cil.TargetAssembly), null, writer, null);
                    writer.Close();
                } else { // Handle weave mode
                    long Start = DateTime.Now.Ticks;
                    // Interpret parameters
                    if (parameters.Count > 0) {
                        string firstArg = parameters[0];
                        if (firstArg.EndsWith(".xml")) {
                            Log.Debug("Weaving as specified in " + firstArg);
                            entryPoint.Weave(firstArg);
                            result = 0;
                        } else if (firstArg.EndsWith(".dll") || firstArg.EndsWith(".exe")) {
                            if (parameters.Count == 1)
                                entryPoint.DirectWeave(firstArg);
                            else if (parameters.Count == 2) {
                                string secondArg = parameters[1];
                                entryPoint.DirectWeave(firstArg, secondArg);
                            }
                            result = 0;
                        } else entryPoint.PrintUsage();
                    } else entryPoint.PrintUsage();

                    if (result == 0) {
                        Log.Debug("aspectdng took in {0} millis to weave {1} aspects", (DateTime.Now.Ticks - Start) / 10000, AspectDngConfig.Instance.Advice.Count);
                        Log.Save();
                    }
                }
            } catch (ConfigurationException e) {
                Log.Error(e.Message);
            } catch (AdviceException e) {
                Log.Error(e.Message);
            } catch (Exception e) {
                Log.Error(e.Message);
                Log.Error(e.StackTrace);
            }
            return result;
        }