Пример #1
0
        public ProcessOpTransaction Write(object value, string name, string prop, ProcessFlags flags)
        {
            var op       = new WriteConfigOp(value, name, prop, flags);
            var settings = Settings.IfNone(Map <string, object> .Empty).AddOrUpdate($"{name}@{prop}", value);

            return(new ProcessOpTransaction(ProcessId, Ops.Enqueue(op), settings));
        }
Пример #2
0
        private S GetState()
        {
            var res = state.IfNone(InitState);

            state = res;
            return(res);
        }
Пример #3
0
        /// <summary>
        /// Process system configuration initialisation
        /// This will parse the configuration text, you should call this
        /// function from within Application_BeginRequest of Global.asax.  It can run multiple times, once the config
        /// has loaded the system won't re-load the config until you call ProcessConfig.unload() followed by
        /// ProcessConfig.initialiseFileSystem(...), so it's safe to not surround it with ifs.
        ///
        /// NOTE: If a cluster is specified in the cluster.conf and its 'node-name' matches nodeName, then those settings
        /// will be used to connect to the cluster.  This allows for different staging environments to be setup.
        /// </summary>
        /// <param name="nodeName">If a cluster is specified in the cluster.conf and its 'node-name' matches nodeName, then
        /// those settings will be used to connect to the cluster.  This allows for different staging environments to be
        /// setup.</param>
        /// <param name="setup">A setup function to call on successful loading of the configuration files - this will
        /// happen once only.</param>
        /// <param name="strategyFuncs">Plugin extra strategy behaviours by passing in a list of FuncSpecs.</param>
        public static AppProfile initialise(string configText, Option <string> nodeName, Action <AppProfile> setup = null, IEnumerable <FuncSpec> strategyFuncs = null)
        {
            if (appProfile != null)
            {
                return(appProfile);
            }
            lock (sync)
            {
                if (appProfile != null)
                {
                    return(appProfile);
                }

                config = new ProcessSystemConfig(nodeName.IfNone(""), strategyFuncs);
                config.ParseConfigText(configText);

                appProfile = AppProfile.NonClustered;

                nodeName.Iter(node =>
                {
                    var provider    = config.GetClusterSetting("provider", "value", "redis");
                    var role        = config.GetClusterSetting("role", "value", name => clusterSettingMissing <string>(name));
                    var clusterConn = config.GetClusterSetting("connection", "value", "localhost");
                    var clusterDb   = config.GetClusterSetting("database", "value", "0");
                    var env         = config.GetClusterSetting <string>("env", "value");
                    var userEnv     = config.GetClusterSetting <string>("user-env", "value");

                    appProfile = new AppProfile(
                        node,
                        role,
                        clusterConn,
                        clusterDb,
                        env,
                        userEnv
                        );

                    Cluster.connect(provider, node, clusterConn, clusterDb, role);
                });

                config.PostConnect();

                setup(appProfile);
                return(appProfile);
            }
        }
        /// <summary>
        /// Process system configuration initialisation
        /// This will parse the configuration text, It can run multiple times, once the config has loaded the system won't
        /// re-load the config until you call ProcessConfig.unload() followed by ProcessConfig.initialise(...), so it's safe
        /// to not surround it with ifs.
        ///
        /// NOTE: If a cluster is specified in config text and its 'node-name' matches nodeName, then those settings
        /// will be used to connect to the cluster.  This allows for different staging environments to be setup.
        /// </summary>
        /// <param name="nodeName">If a cluster is specified in the cluster.conf and its 'node-name' matches nodeName, then
        /// those settings will be used to connect to the cluster.  This allows for different staging environments to be
        /// setup.</param>
        /// <param name="setup">A setup function to call on successful loading of the configuration files - this will
        /// happen once only.</param>
        /// <param name="strategyFuncs">Plugin extra strategy behaviours by passing in a list of FuncSpecs.</param>
        public static Unit initialise(string configText, Option <string> nodeName, Action setup = null, IEnumerable <FuncSpec> strategyFuncs = null)
        {
            lock (sync)
            {
                var parser  = new ProcessSystemConfigParser(nodeName.IfNone(""), new Types(), strategyFuncs);
                var configs = String.IsNullOrWhiteSpace(configText)
                    ? Map.create(Tuple(new SystemName(""), ProcessSystemConfig.Empty))
                    : parser.ParseConfigText(configText);

                nodeName.Map(_ => configs.Filter(c => c.NodeName == nodeName).Iter(StartFromConfig))
                .IfNone(() => configs.Filter(c => c.NodeName == "root").Iter(StartFromConfig));

                if (setup != null)
                {
                    setup();
                }
                return(unit);
            }
        }
Пример #5
0
 public static T ifNone <T>(Option <T> option, T noneValue) =>
 option.IfNone(noneValue);
Пример #6
0
 public static T ifNone <T>(Option <T> option, Func <T> None) =>
 option.IfNone(None);
Пример #7
0
 /// <summary>
 /// Sum the bound value
 /// </summary>
 /// <remarks>This is a legacy method for backwards compatibility</remarks>
 /// <param name="a">Option of int</param>
 /// <returns>The bound value or 0 if None</returns>
 public static int Sum(this Option <int> a) =>
 a.IfNone(0);