Exemple #1
0
        /// <summary>
        /// Automatically defined record-type constructor
        /// </summary>
        /// <param name="type"></param>
        /// <param name="ctor"></param>
        /// <param name="assembly"></param>
        /// <param name="name"></param>
        /// <param name="nodeName"></param>
        public TypeDef(
            Type type,
            Func <Lst <NamedValueToken>, object> ctor,
            Types assembly,
            int order,
            string name     = null,
            string nodeName = ""
            )
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var info = type.GetTypeInfo();

            Order               = order;
            Ctor                = ctor ?? (x => x);
            MapsTo              = type;
            Name                = name ?? MakeName(info.Name);
            BinaryOperators     = LanguageExt.Map.empty <string, Func <ValueToken, ValueToken, ValueToken> >();
            PrefixOperators     = LanguageExt.Map.empty <string, Func <ValueToken, ValueToken> >();
            PostfixOperators    = LanguageExt.Map.empty <string, Func <ValueToken, ValueToken> >();
            ConversionOperators = LanguageExt.Map.empty <string, Func <object, object> >();
            ToLstValues         = x => x;
            ToMapValues         = x => x;
            GenericType         = null;
            NodeName            = nodeName;

            var props = from p in type.GetTypeInfo().GetProperties()
                        where assembly.Exists(p.PropertyType)
                        select FuncSpec.Property(MakeName(p.Name), () => assembly.Get(p.PropertyType));

            var fields = from p in type.GetTypeInfo().GetFields()
                         where assembly.Exists(p.FieldType)
                         select FuncSpec.Property(MakeName(p.Name), () => assembly.Get(p.FieldType));

            var methods = from m in type.GetTypeInfo().GetMethods()
                          where m.IsStatic &&
                          assembly.Exists(m.ReturnType) &&
                          m.GetParameters().Map(p => p.ParameterType).ForAll(assembly.Exists)
                          let ps = m.GetParameters().Map(p => new FieldSpec(p.Name, () => assembly.Get(p.ParameterType))).ToArray()
                                   select FuncSpec.Attrs(MakeName(m.Name), () => assembly.Get(m.ReturnType), locals => m.Invoke(null, locals.Values.ToArray()), ps);

            FuncSpecs = List.append(props, fields, methods).ToArray();


            ValueParser = BuildObjectParser(FuncSpecs).Memo();
        }
Exemple #2
0
 private TypeDef BuildClusterType() =>
 new TypeDef(
     "cluster",
     typeof(ClusterToken),
     (alias, nvs) => new ClusterToken(alias, (Lst <NamedValueToken>)nvs),
     20,
     FuncSpec.Property("node-name", () => types.String),
     FuncSpec.Property("role", () => types.String),
     FuncSpec.Property("provider", () => types.String),
     FuncSpec.Property("connection", () => types.String),
     FuncSpec.Property("database", () => types.String),
     FuncSpec.Property("env", () => types.String),
     FuncSpec.Property("user-env", () => types.String),
     FuncSpec.Property("default", () => types.Bool)
     );
Exemple #3
0
 private TypeDef BuildRouterType() =>
 new TypeDef(
     "router",
     typeof(ProcessToken),
     (_, nvs) => new ProcessToken((Lst <NamedValueToken>)nvs),
     20,
     FuncSpec.Property("pid", () => types.ProcessId),
     FuncSpec.Property("flags", () => types.ProcessFlags),
     FuncSpec.Property("mailbox-size", () => types.Int),
     FuncSpec.Property("dispatch", () => types.DispatcherType),
     FuncSpec.Property("route", () => types.DispatcherType),
     FuncSpec.Property("workers", () => TypeDef.Array(() => processType)),
     FuncSpec.Property("worker-count", () => types.Int),
     FuncSpec.Property("worker-name", () => types.String),
     FuncSpec.Property("strategy", () => strategyType));
        Parser <Lst <NamedValueToken> > InitialiseParser(string nodeName, IEnumerable <FuncSpec> strategyFuncs)
        {
            strategyFuncs = strategyFuncs ?? new FuncSpec[0];

            clusterType = new TypeDef(
                "cluster",
                nvs => new ClusterToken(nvs),
                20,
                FuncSpec.Property("node-name", () => types.String),
                FuncSpec.Property("role", () => types.String),
                FuncSpec.Property("provider", () => types.String),
                FuncSpec.Property("connection", () => types.String),
                FuncSpec.Property("database", () => types.String),
                FuncSpec.Property("env", () => types.String),
                FuncSpec.Property("user-env", () => types.String));

            types.Register(clusterType);

            processType = new TypeDef(
                "process",
                nvs => new ProcessToken(nvs),
                20,
                FuncSpec.Property("pid", () => types.ProcessId),
                FuncSpec.Property("flags", () => types.ProcessFlags),
                FuncSpec.Property("mailbox-size", () => types.Int),
                FuncSpec.Property("dispatch", () => types.DispatcherType),
                FuncSpec.Property("route", () => types.DispatcherType),
                FuncSpec.Property("workers", () => TypeDef.Array(() => processType)),
                FuncSpec.Property("worker-count", () => types.Int),
                FuncSpec.Property("worker-name", () => types.String),
                FuncSpec.Property("strategy", () => strategyType));

            types.Register(processType);

            strategyType = BuildStrategySpec(types, strategyFuncs);

            types.Register(strategyType);

            var sys = new ProcessSystemConfigParser(
                nodeName,
                types
                );

            return(sys.Settings);
        }