Exemple #1
0
 public static AdviceSpec Create(Decorator d)
 {
     AdviceSpec spec = (AdviceSpec) Activator.CreateInstance(Type.GetType(m_Namespace + d.Name));
     spec.aspectRegExp = d["@aspectRegExp"];
     spec.targetRegExp = d["@targetRegExp"];
     spec.aspectXPath = d["@aspectXPath"];
     spec.targetXPath = d["@targetXPath"];
     return spec;
 }
        public AspectDngConfig(string configFile)
        {
            m_Instance = this;

            try{
                Decorator conf = new Decorator(configFile);
                conf.GoTo("/AspectDngConfig");

                // Read variables from the main config file
                foreach(Decorator d in conf.GetDecorators("//Variable"))
                    Variables[d["@name"]] = d["@value"];

                debug = bool.Parse(conf["@debug"]);
                warnings = DereferenceVariablesIn(conf["@warnings"]);
                weaving = DereferenceVariablesIn(conf["@weaving"]);

                AspectsAssembly = DereferenceVariablesIn(conf["AspectsAssembly"]);
                TargetAssembly = DereferenceVariablesIn(conf["TargetAssembly"]);
                WeavedAssembly = DereferenceVariablesIn(conf["WeavedAssembly"]);

                PrivateLocations = conf.GetStrings("//PrivatePath");

                foreach(Decorator d in conf.GetDecorators("//Advice/*[not(self::Variable)]")){
                    AdviceSpec spec = AdviceSpec.Create(d);
                    spec.DereferenceVariables();
                    AddAdvice(spec, configFile);
                }

                foreach(string path in conf.GetStrings("//AdviceFile")){
                    Decorator otherConf = new Decorator(DereferenceVariablesIn(path));
                    foreach(Decorator otherD in otherConf.GetDecorators("//Advice/*[not(self::Variable)]")){
                        AdviceSpec spec = AdviceSpec.Create(otherD);
                        spec.DereferenceVariables();
                        AddAdvice(spec, path);
                    }
                    foreach(Decorator otherD in otherConf.GetDecorators("//Variable"))
                        Variables[otherD["@name"]] = otherD["@value"];
                }

                Log.Level = debug ? LogLevel.Debug : LogLevel.Warn;
            }
            catch(Exception e){
                if (e.GetType().FullName.StartsWith("System.Xml"))
                    throw new ConfigurationException(e);
                else
                    throw e;
            }

            foreach(AdviceSpec spec in Advice)
                spec.origin = configFile;
            Environment.CurrentDirectory = new FileInfo(configFile).Directory.FullName;
            m_Instance = this;
        }
Exemple #3
0
        public AspectDngConfig(string configFile)
        {
            m_Instance = this;

            try{
                Decorator conf = new Decorator(configFile);
                conf.GoTo("/AspectDngConfig");

                // Read variables from the main config file
                foreach (Decorator d in conf.GetDecorators("//Variable"))
                {
                    Variables[d["@name"]] = d["@value"];
                }

                debug    = bool.Parse(conf["@debug"]);
                warnings = DereferenceVariablesIn(conf["@warnings"]);
                weaving  = DereferenceVariablesIn(conf["@weaving"]);

                AspectsAssembly = DereferenceVariablesIn(conf["AspectsAssembly"]);
                TargetAssembly  = DereferenceVariablesIn(conf["TargetAssembly"]);
                WeavedAssembly  = DereferenceVariablesIn(conf["WeavedAssembly"]);

                PrivateLocations = conf.GetStrings("//PrivatePath");

                foreach (Decorator d in conf.GetDecorators("//Advice/*[not(self::Variable)]"))
                {
                    AdviceSpec spec = AdviceSpec.Create(d);
                    spec.DereferenceVariables();
                    AddAdvice(spec, configFile);
                }

                foreach (string path in conf.GetStrings("//AdviceFile"))
                {
                    Decorator otherConf = new Decorator(DereferenceVariablesIn(path));
                    foreach (Decorator otherD in otherConf.GetDecorators("//Advice/*[not(self::Variable)]"))
                    {
                        AdviceSpec spec = AdviceSpec.Create(otherD);
                        spec.DereferenceVariables();
                        AddAdvice(spec, path);
                    }
                    foreach (Decorator otherD in otherConf.GetDecorators("//Variable"))
                    {
                        Variables[otherD["@name"]] = otherD["@value"];
                    }
                }

                Log.Level = debug ? LogLevel.Debug : LogLevel.Warn;
            }
            catch (Exception e) {
                if (e.GetType().FullName.StartsWith("System.Xml"))
                {
                    throw new ConfigurationException(e);
                }
                else
                {
                    throw e;
                }
            }

            foreach (AdviceSpec spec in Advice)
            {
                spec.origin = configFile;
            }
            Environment.CurrentDirectory = new FileInfo(configFile).Directory.FullName;
            m_Instance = this;
        }