Ejemplo n.º 1
0
        public void BasicMerge()
        {
            var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1);
            var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml2);
            var conf3 = NFX.Environment.XMLConfiguration.CreateFromXML(xml4);

            var conf = new NFX.Environment.MemoryConfiguration();

            conf.CreateFromMerge(conf1.Root, conf2.Root);

            var conf4 = new NFX.Environment.MemoryConfiguration();

            conf4.CreateFromMerge(conf.Root, conf3.Root);

            Aver.AreEqual("Sub Value 1", conf.Root["section-a"]["sub1"].Value);
            Aver.AreEqual("Sub Value 2 ammended", conf.Root["section-a"]["sub2"].Value);
            Aver.AreEqual("Sub Value 3", conf.Root["section-a"]["sub3"].Value);

            Aver.AreEqual("CSVFile", conf.Root["section-a"].Children.FirstOrDefault(n => n.IsSameName("destination") && n.AttrByName("name").Value == "A").AttrByName("type").Value);
            Aver.AreEqual("Clock", conf.Root["section-a"].Children.FirstOrDefault(n => n.IsSameName("destination") && n.AttrByName("name").Value == "B").AttrByName("type").Value);
            Aver.AreEqual("SMTPMail", conf1.Root["section-a"].Children.FirstOrDefault(n => n.IsSameName("destination") && n.AttrByName("name").Value == "B").AttrByName("type").Value);

            Aver.IsTrue(conf4.Root["section-b"].AttrCount == 1);
            Aver.IsTrue(!conf4.Root["section-a"].Exists);
        }
Ejemplo n.º 2
0
      /// <summary>
      /// Takes optional args[] and root configuration. If configuration is null then
      ///  application is configured from a file co-located with entry-point assembly and
      ///   called the same name as assembly with '.config' extension, unless args are specified and "/config file"
      ///   switch is used in which case 'file' has to be locatable and readable.
      /// </summary>
      public BaseApplication(string[] args, ConfigSectionNode rootConfig)
      {
        lock(typeof(BaseApplication))
        {
          if (s_Instance != null) throw new WFormsException(StringConsts.APP_INSTANCE_ALREADY_CREATED_ERROR);

          try
          {  
            Configuration argsConfig;
            if (args != null)
              argsConfig = new CommandArgsConfiguration(args);
            else
              argsConfig = new MemoryConfiguration();

            m_CommandArgs = argsConfig.Root;

            m_ConfigRoot = rootConfig ?? GetConfiguration().Root;

            InitApplication();
        
            s_Instance = this;

          }
          catch
          {
              Destructor();
              throw;
          }

        }
      }
Ejemplo n.º 3
0
     protected NOPApplication()
     {
        ApplicationModel.ExecutionContext.__SetApplicationLevelContext(this, null, null, NOPSession.Instance);

        m_Configuration = new MemoryConfiguration();
        m_Configuration.Create();

        m_StartTime = DateTime.Now;
     }
Ejemplo n.º 4
0
        public void MergeStop()
        {
            var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1);
            var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml2);

            var conf = new NFX.Environment.MemoryConfiguration();

            conf.CreateFromMerge(conf1.Root, conf2.Root);


            Assert.AreEqual("This can not be overridden and no exception will be thrown", conf.Root["section-d"].Value);
            Assert.AreEqual(1, conf.Root["section-d"].Attributes.Count());
            Assert.AreEqual(OverrideSpec.Stop, NodeOverrideRules.Default.StringToOverrideSpec(conf.Root["section-d"].AttrByName("_override").Value));
        }
Ejemplo n.º 5
0
        public void ExpectOverrideException()
        {
            var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1);
            var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml3);

            var conf = new NFX.Environment.MemoryConfiguration();

            try
            {
                conf.CreateFromMerge(conf1.Root, conf2.Root);
            }
            catch (Exception error)
            {
                Console.WriteLine("Expected and got: " + error.Message);
                throw error;
            }
        }
Ejemplo n.º 6
0
        public void Performance()
        {
            const int CNT = 10000;

            var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(largexml1);
            var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(largexml2);

            var clock = System.Diagnostics.Stopwatch.StartNew();

            for (var i = 0; i < CNT; i++)
            {
                var conf = new NFX.Environment.MemoryConfiguration();
                conf.CreateFromMerge(conf1.Root, conf2.Root);
            }
            clock.Stop();

            Console.WriteLine("Config merge performance. Merged {0} times in {1} ms", CNT, clock.ElapsedMilliseconds);
        }
Ejemplo n.º 7
0
            public Schema(Configuration source,  IEnumerable<string> includePaths = null, bool runScript = true, ScriptRunner runner = null)
            {
                m_SourceOriginal = source;
                m_IncludePaths = includePaths ?? Enumerable.Empty<string>();

                processIncludes(source.Root, new HashSet<string>());

                if (runScript)
                {
                    m_SourceScriptRunner = runner ?? new ScriptRunner();
                    
                    m_Source = new MemoryConfiguration();

                    m_SourceScriptRunner.Execute(m_SourceOriginal, m_Source);
                }
                else
                    m_Source = m_SourceOriginal;

                
            }
Ejemplo n.º 8
0
      /// <summary>
      /// Generates packaging manifest for the specified directory. Optionally may specify root node name
      /// </summary>
      /// <param name="directory">Source directory to generate manifest for</param>
      /// <param name="rootNodeName">Name of root manifest node, if omitted then 'package' is defaulted</param>
      /// <param name="packageName">Optional 'name' attribute value under root node</param>
      /// <param name="packageLocalPath">Optional 'local-path' attribute value under root node</param>
      public static ConfigSectionNode GeneratePackagingManifest(this FileSystemDirectory directory,
                                                                string rootNodeName = null,
                                                                string packageName = null,
                                                                string packageLocalPath = null)
      {
        if (directory==null)
         throw new NFXIOException(StringConsts.ARGUMENT_ERROR + "GeneratePackagingManifest(directory==null)");

        var conf = new MemoryConfiguration();
        conf.Create(rootNodeName.IsNullOrWhiteSpace()?CONFIG_PACKAGE_SECTION : rootNodeName); 
        var root = conf.Root; 
        if (packageName.IsNotNullOrWhiteSpace())
          root.AddAttributeNode(CONFIG_NAME_ATTR, packageName);
        
        if (packageLocalPath.IsNotNullOrWhiteSpace())
          root.AddAttributeNode(CONFIG_LOCAL_PATH_ATTR, packageLocalPath);
        
        buildDirLevel(root, directory);

        root.ResetModified();

        return root;
      }
Ejemplo n.º 9
0
            public User Authenticate(Credentials credentials)
            {
              var sect = m_Config ?? App.ConfigRoot[CommonApplicationLogic.CONFIG_SECURITY_SECTION];
              if (sect.Exists && credentials is IDPasswordCredentials)
              { 
                  var idpass = (IDPasswordCredentials)credentials;
                  
                  var usern = findUserNode(sect, idpass);

                  if (usern.Exists)
                  {
                      var name = usern.AttrByName(CONFIG_NAME_ATTR).ValueAsString(string.Empty);
                      var descr = usern.AttrByName(CONFIG_DESCRIPTION_ATTR).ValueAsString(string.Empty);
                      var status = usern.AttrByName(CONFIG_STATUS_ATTR).ValueAsEnum<UserStatus>(UserStatus.Invalid);
                      
                      var rights = Rights.None;
                      
                      var rightsn = usern[CONFIG_RIGHTS_SECTION];
                      
                      if (rightsn.Exists)
                      {
                        var data = new MemoryConfiguration();
                        data.CreateFromNode(rightsn);
                        rights = new Rights(data);
                      } 
                      
                      return new User(credentials,
                                      credToAuthToken(idpass),
                                      status,
                                      name,
                                      descr,
                                      rights);
                  }
              }
                
              return new User(credentials, 
                              new AuthenticationToken(),
                              UserStatus.Invalid, 
                              StringConsts.SECURITY_NON_AUTHENTICATED,
                              StringConsts.SECURITY_NON_AUTHENTICATED,
                              Rights.None); 
            }
Ejemplo n.º 10
0
      protected virtual Configuration GetConfiguration()
      {
          //try to read from  /config file
          var configFile = m_CommandArgs[CONFIG_SWITCH].AttrByIndex(0).Value;

          if (string.IsNullOrEmpty(configFile))
              configFile = GetDefaultConfigFileName();
                  

          Configuration conf;

          if (File.Exists(configFile))
              conf = Configuration.ProviderLoadFromFile(configFile);
          else
              conf = new MemoryConfiguration();

          return conf;
      }
Ejemplo n.º 11
0
        protected override void DoCompileTemplateSource(CompileUnit unit)
        {
            var text = unit.TemplateSource.GetSourceContent().ToString().Trim();
             var icname = unit.TemplateSource.InferClassName();

             Configuration conf = new MemoryConfiguration();

             var confLineCount = 0;
             if (text.StartsWith(CONFIG_START))
             {
               var i = text.IndexOf(CONFIG_END);
               if (i<CONFIG_START.Length) throw new TemplateParseException(StringConsts.TEMPLATE_CS_COMPILER_CONFIG_CLOSE_TAG_ERROR);

               var confText = text.Substring(CONFIG_START.Length, i - CONFIG_START.Length);

               confLineCount = confText.Count(c=>c=='\n');

               //cut configuration out of template
               text = text.Substring(i + CONFIG_END.Length);

               try
               {
                 conf = XMLConfiguration.CreateFromXML("<config>"+confText+"</config>");
               }
               catch(Exception error)
               {
                 throw new TemplateParseException(StringConsts.TEMPLATE_CS_COMPILER_CONFIG_ERROR + error.Message, error);
               }
             }else//20140103 DKh add Laconic support
             if (text.StartsWith(LACONFIG_START))
             {
               var i = text.IndexOf(LACONFIG_END);
               if (i<LACONFIG_START.Length) throw new TemplateParseException(StringConsts.TEMPLATE_CS_COMPILER_CONFIG_CLOSE_TAG_ERROR);

               var confText = text.Substring(LACONFIG_START.Length, i - LACONFIG_START.Length);

               confLineCount = confText.Count(c=>c=='\n');

               //cut configuration out of template
               text = text.Substring(i + LACONFIG_END.Length);

               try
               {
                 conf = LaconicConfiguration.CreateFromString("config{"+confText+"}");
               }
               catch(Exception error)
               {
                 throw new TemplateParseException(StringConsts.TEMPLATE_CS_COMPILER_CONFIG_ERROR + error.Message, error);
               }
             }

             var compilerNode = conf.Root[CONFIG_COMPILER_SECTION];

             //add referenced assemblies
             foreach(var anode in compilerNode.Children.Where(cn=> cn.IsSameName(CONFIG_REF_ASSEMBLY_SECTION)))
               this.ReferenceAssembly(anode.AttrByName(CONFIG_REF_ASSEMBLY_NAME_ATTR).Value);

             //add usings
             var usings = new HashSet<string>();

             RegisterDefaultUsings(usings);

             foreach(var unode in compilerNode.Children.Where(cn=> cn.IsSameName(CONFIG_USING_SECTION)))
               usings.Add(unode.AttrByName(CONFIG_USING_NS_ATTR).Value);

             //add attributes
             var attributes = new List<string>();
              foreach(var anode in compilerNode.Children.Where(cn=> cn.IsSameName(CONFIG_ATTRIBUTE_SECTION)))
               attributes.Add(anode.AttrByName(CONFIG_ATTRIBUTE_DECL_ATTR).Value);

             unit.CompiledSource = new FSM(){Compiler = this,
                                             Unit = unit,
                                             InferredClassName = icname,
                                             ConfigNode = conf.Root,
                                             Source = text,
                                             Usings = usings,
                                             Attributes = attributes,
                                             LineNo = confLineCount+1}.Build().ToString();
        }
Ejemplo n.º 12
0
        public void Performance()
        {
            const int CNT = 10000;

              var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(largexml1);
              var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(largexml2);

              var clock = System.Diagnostics.Stopwatch.StartNew();
              for(var i=0; i<CNT; i++)
              {
            var conf = new NFX.Environment.MemoryConfiguration();
            conf.CreateFromMerge(conf1.Root, conf2.Root);
              }
              clock.Stop();

              Console.WriteLine("Config merge performance. Merged {0} times in {1} ms", CNT, clock.ElapsedMilliseconds);
        }
Ejemplo n.º 13
0
        public void MergeStop()
        {
            var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1);
              var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml2);

              var conf = new NFX.Environment.MemoryConfiguration();
              conf.CreateFromMerge(conf1.Root, conf2.Root);

              Assert.AreEqual("This can not be overridden and no exception will be thrown", conf.Root["section-d"].Value);
              Assert.AreEqual(1, conf.Root["section-d"].Attributes.Count());
              Assert.AreEqual(OverrideSpec.Stop, NodeOverrideRules.Default.StringToOverrideSpec(conf.Root["section-d"].AttrByName("_override").Value));
        }
Ejemplo n.º 14
0
        public void ExpectOverrideException()
        {
            var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1);
              var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml3);

              var conf = new NFX.Environment.MemoryConfiguration();

              try
              {
            conf.CreateFromMerge(conf1.Root, conf2.Root);
              }
              catch(Exception error)
              {
            Console.WriteLine("Expected and got: "+error.Message);
            throw error;
              }
        }
Ejemplo n.º 15
0
        public void BasicMerge()
        {
            var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1);
              var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml2);

              var conf = new NFX.Environment.MemoryConfiguration();
              conf.CreateFromMerge(conf1.Root, conf2.Root);

              Assert.AreEqual("Sub Value 1", conf.Root["section-a"]["sub1"].Value);
              Assert.AreEqual("Sub Value 2 ammended", conf.Root["section-a"]["sub2"].Value);
              Assert.AreEqual("Sub Value 3", conf.Root["section-a"]["sub3"].Value);

              Assert.AreEqual("CSVFile", conf.Root["section-a"].Children.FirstOrDefault(n=>n.IsSameName("destination") && n.AttrByName("name").Value=="A").AttrByName("type").Value);
              Assert.AreEqual("Clock", conf.Root["section-a"].Children.FirstOrDefault(n=>n.IsSameName("destination") && n.AttrByName("name").Value=="B").AttrByName("type").Value);
              Assert.AreEqual("SMTPMail", conf1.Root["section-a"].Children.FirstOrDefault(n=>n.IsSameName("destination") && n.AttrByName("name").Value=="B").AttrByName("type").Value);
        }
Ejemplo n.º 16
0
        public void Configure(IConfigSectionNode node)
        {
            var appRoot = node.NavigateSection("/" + ErlConsts.ERLANG_CONFIG_SECTION);

              if (appRoot == null)
            throw new ErlException(
              StringConsts.CONFIGURATION_NAVIGATION_SECTION_REQUIRED_ERROR,
              ErlConsts.ERLANG_CONFIG_SECTION);

              // Configure global node variables

              ErlAbstractNode.s_DefaultCookie = new ErlAtom(
            appRoot.AttrByName(ErlConsts.ERLANG_COOKIE_ATTR)
            .ValueAsString(ErlAbstractNode.s_DefaultCookie.Value));

              ErlAbstractNode.s_UseShortNames =
            appRoot.AttrByName(ErlConsts.ERLANG_SHORT_NAME_ATTR)
            .ValueAsBool(ErlAbstractNode.s_UseShortNames);

              ErlAbstractConnection.ConnectTimeout =
            appRoot.AttrByName(ErlConsts.ERLANG_CONN_TIMEOUT_ATTR)
            .ValueAsInt(ErlAbstractConnection.ConnectTimeout);

              // Configure local node and remote connections

              var cfg = new MemoryConfiguration();
              cfg.CreateFromNode(appRoot);

              var root  = cfg.Root;
              var nodes = root.Children
                      .Where(n => n.Name.EqualsIgnoreCase(ErlConsts.ERLANG_NODE_SECTION));

              var localNodes = nodes.Where(n => n.AttrByName(ErlConsts.CONFIG_IS_LOCAL_ATTR).ValueAsBool()).ToArray();
              if (localNodes.Length != 1)
            throw new ErlException(StringConsts.ERL_CONFIG_SINGLE_NODE_ERROR, localNodes.Length);

              var localNode = localNodes[0];

              // Create and configure local node

              s_Node = new ErlLocalNode(localNode.Value, localNode);

              // Configure connections to all remote nodes

              //m_AllNodes = nodes.Where(n => !n.AttrByName(ErlConsts.CONFIG_IS_LOCAL_ATTR).ValueAsBool());
              m_AllNodes = root;
        }
Ejemplo n.º 17
0
        private void btnMerge_Click(object sender, EventArgs e)
        {
            try
            {
                var confA = LaconicConfiguration.CreateFromString(this.confMergeA.Text);
                var confB = LaconicConfiguration.CreateFromString(this.confMergeB.Text);
                var conf = new MemoryConfiguration();

                conf.CreateFromMerge(confA.Root, confB.Root);

                this.resultMerge.Text = conf.ToLaconicString();
            }
            catch (Exception ex)
            {
                this.resultMerge.Text = ex.ToMessageWithType();
            }
        }