예제 #1
0
파일: NOPApplication.cs 프로젝트: cyecp/nfx
        protected NOPApplication()
        {
            m_Configuration = new MemoryConfiguration();
            m_Configuration.Create();

            m_StartTime = DateTime.Now;
        }
예제 #2
0
파일: ManifestUtils.cs 프로젝트: zhabis/nfx
        /// <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);
        }
예제 #3
0
파일: MiscUtils.cs 프로젝트: mjaric/nfx
        /// <summary>
        ///  Evaluates variables in a context of optional variable resolver and macro runner
        /// </summary>
        public static string EvaluateVars(this string line, IEnvironmentVariableResolver envResolver = null, IMacroRunner macroRunner = null)
        {
            var config = new MemoryConfiguration();

            config.Create();
            config.EnvironmentVarResolver = envResolver;
            config.MacroRunner            = macroRunner;
            return(EvaluateVarsInConfigScope(line, config));
        }
예제 #4
0
        protected NOPApplication()
        {
            ApplicationModel.ExecutionContext.__SetApplicationLevelContext(this, null, null, NOPSession.Instance);

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

            m_StartTime = DateTime.Now;
        }
예제 #5
0
파일: MiscUtils.cs 프로젝트: mjaric/nfx
        /// <summary>
        ///  Evaluates variables in a context of optional configuration supplied as config object
        /// </summary>
        public static string EvaluateVarsInConfigScope(this string line, Configuration scopeConfig = null)
        {
            if (scopeConfig == null)
            {
                scopeConfig = new MemoryConfiguration();
                scopeConfig.Create();
            }

            return(scopeConfig.Root.EvaluateValueVariables(line));
        }
예제 #6
0
        protected NOPApplication()
        {
            m_Configuration = new MemoryConfiguration();
            m_Configuration.Create();

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

            m_StartTime = DateTime.Now;
            m_Realm     = new ApplicationRealmBase();
        }
예제 #7
0
파일: MiscUtils.cs 프로젝트: mjaric/nfx
        /// <summary>
        /// Converts dictionary into configuration where every original node gets represented as an attribute of config's root
        /// </summary>
        public static Configuration ToConfigAttributes(this IDictionary <string, object> dict)
        {
            var result = new MemoryConfiguration();

            result.Create();
            foreach (var pair in dict)
            {
                result.Root.AddAttributeNode(pair.Key, pair.Value);
            }

            return(result);
        }
예제 #8
0
        public IConfigSectionNode GetUserLogArchiveDimensions(IIdentityDescriptor identity)
        {
            if (identity == null)
            {
                return(null);
            }

            var cfg = new MemoryConfiguration();

            cfg.Create("ad");
            cfg.Root.AddAttributeNode("un", identity.IdentityDescriptorName);

            return(cfg.Root);
        }
예제 #9
0
        public IConfigSectionNode GetUserLogArchiveDimensions(User user)
        {
            if (user == null)
            {
                return(null);
            }
            if (user.Status == UserStatus.Invalid)
            {
                return(null);
            }
            var cfg = new MemoryConfiguration();

            cfg.Create("ad");
            cfg.Root.AddAttributeNode("un", user.Name);
            return(cfg.Root);
        }
예제 #10
0
        public MessageAddressBuilder(string config, MessageBuilderChangeEventHandler onChange = null)
        {
            if (config.IsNullOrWhiteSpace())
            {
                var c = new MemoryConfiguration();
                c.Create(CONFIG_ROOT_SECT);
                m_Config = c.Root;
            }
            else
            {
                m_Config = config.AsLaconicConfig(handling: ConvertErrorHandling.Throw);
            }

            if (onChange != null)
            {
                MessageBuilderChange += onChange;
            }
        }
예제 #11
0
        public void Memory_Create_Modify()
        {
            var cfg = new MemoryConfiguration();

            Aver.IsFalse(cfg.Root.Exists, "root does not exist on newly create conf");
            Aver.IsFalse(cfg.IsReadOnly, "newly created config is not read only");

            cfg.Create("meduza");
            Aver.IsTrue(cfg.Root.Exists, "root.Exists after create");
            Aver.AreEqual("meduza", cfg.Root.Name, "root name is set per create");

            Aver.IsNull(cfg.Root.Value, "empty node value is null");
            cfg.Root.Value = "abc";
            Aver.AreEqual("abc", cfg.Root.Value, "value not is gotten");

            Aver.IsTrue(cfg.Root.Modified, "root is modified after value set");
            cfg.Root.ResetModified();
            Aver.IsFalse(cfg.Root.Modified, "root is not modified after resetModified()");
        }
예제 #12
0
        ///reads supported configuration file taking file path relative to file system root
        private Configuration getConfigFromFile(FileSystemSession session, string path, bool require = true)
        {
            try
            {
                var fnwe = m_FS.CombinePaths(m_FSRootPath, path);
                foreach (var fmt in Configuration.AllSupportedFormats)
                {
                    var fn   = "{0}.{1}".Args(fnwe, fmt); // filename.<format>
                    var file = session[fn] as FileSystemFile;
                    if (file == null)
                    {
                        continue;
                    }
                    using (file)
                    {
                        var text   = file.ReadAllText();
                        var result = Configuration.ProviderLoadFromString(text, fmt);
                        result.Application = App;
                        return(result);
                    }
                }
                if (require)
                {
                    throw new MetabaseException(StringConsts.METABASE_FILE_NOT_FOUND_ERROR.Args(path));
                }
                else
                {
                    var result = new MemoryConfiguration();

                    result.Create(SysConsts.DEFAULT_APP_CONFIG_ROOT);
                    result.Application = App;
                    result.Root.ResetModified();
                    return(result);
                }
            }
            catch (Exception error)
            {
                throw new MetabaseException(StringConsts.METABASE_CONFIG_LOAD_ERROR.Args(path ?? SysConsts.UNKNOWN_ENTITY, error.ToMessageWithType()), error);
            }
        }
예제 #13
0
        protected NOPApplication()
        {
            m_Configuration = new MemoryConfiguration();
            m_Configuration.Create();

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

            m_StartTime          = DateTime.Now;
            m_Singletons         = new NOPApplicationSingletonManager();
            m_DependencyInjector = new ApplicationDependencyInjector(this);
            m_Realm = new ApplicationRealmBase(this);

            m_Log             = new NOPLog(this);
            m_Instrumentation = new NOPInstrumentation(this);
            m_ObjectStore     = new NOPObjectStore(this);
            m_Glue            = new NOPGlue(this);
            m_DataStore       = new NOPDataStore(this);
            m_SecurityManager = new NOPSecurityManager(this);
            m_Module          = new NOPModule(this);
            m_TimeSource      = new DefaultTimeSource(this);
            m_EventTimer      = new EventTimer(this);
        }
예제 #14
0
        public void Memory_Set_Get_Values()
        {
            var cfg = new MemoryConfiguration();

            cfg.Create();
            cfg.Root.AddAttributeNode("a", "1");
            cfg.Root.AddAttributeNode("b").Value = "2";

            Aver.AreEqual("1", cfg.Root.AttrByName("a").Value);
            Aver.AreEqual("1", cfg.Root.AttrByName("a").VerbatimValue);

            Aver.AreEqual(1, cfg.Root.AttrByName("a").ValueAsInt());
            Aver.AreEqual(true, cfg.Root.AttrByName("a").ValueAsBool());

            Aver.AreEqual(1f, cfg.Root.AttrByName("a").ValueAsFloat());
            Aver.AreEqual(1d, cfg.Root.AttrByName("a").ValueAsDouble());
            Aver.AreEqual(1m, cfg.Root.AttrByName("a").ValueAsDecimal());
            Aver.AreEqual((byte)1, cfg.Root.AttrByName("a").ValueAsByte());
            Aver.AreEqual((sbyte)1, cfg.Root.AttrByName("a").ValueAsSByte());
            Aver.AreEqual(1L, cfg.Root.AttrByName("a").ValueAsLong());
            Aver.AreEqual(1UL, cfg.Root.AttrByName("a").ValueAsULong());
            Aver.AreEqual((short)1, cfg.Root.AttrByName("a").ValueAsShort());
            Aver.AreEqual((ushort)1, cfg.Root.AttrByName("a").ValueAsUShort());

            Aver.AreEqual(0, cfg.Root.AttrByName("dont exist").ValueAsInt());
            Aver.AreEqual(-100, cfg.Root.AttrByName("dont exist").ValueAsInt(-100));

            Aver.AreEqual("2", cfg.Root.AttrByName("b").Value);
            Aver.AreEqual("2", cfg.Root.AttrByName("b").VerbatimValue);

            Aver.AreEqual(null, cfg.Root.AttrByName("c").Value);
            Aver.AreEqual(null, cfg.Root.AttrByName("c").VerbatimValue);

            cfg.Root.AttrByName("c", autoCreate: true).Value = "$(/$b)-$(/$a)";//<-- auto create attribute
            Aver.AreEqual("2-1", cfg.Root.AttrByName("c").Value);
            Aver.AreEqual("$(/$b)-$(/$a)", cfg.Root.AttrByName("c").VerbatimValue);
        }