Exemplo n.º 1
0
        private void Weave(string configFile)
        {
            AspectDngConfig conf = new AspectDngConfig(configFile);

            if (!File.Exists(conf.TargetAssembly))
            {
                throw new ConfigurationException("File doesn't exist: " + conf.TargetAssembly);
            }
            if (!File.Exists(conf.AspectsAssembly))
            {
                throw new ConfigurationException("File doesn't exist: " + conf.AspectsAssembly);
            }

            string backup = CopyToBackup(conf.TargetAssembly);

            if (conf.TargetAssembly == conf.AspectsAssembly || conf.AspectsAssembly == null || conf.AspectsAssembly == "")
            {
                Cil.Init(backup, backup);
            }
            else
            {
                Cil.Init(backup, conf.AspectsAssembly);
            }

            PerformWeave();
            Cil.SaveTo(conf.WeavedAssembly);
        }
Exemplo n.º 2
0
        private void DirectWeave(string targetAssemblyPath)
        {
            if (!File.Exists(targetAssemblyPath))
            {
                throw new ConfigurationException("File doesn't exist: " + targetAssemblyPath);
            }

            string backup = CopyToBackup(targetAssemblyPath);

            Cil.Init(backup, backup);
            PerformWeave();
            Cil.SaveTo(targetAssemblyPath);
        }
Exemplo n.º 3
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);
        }