Esempio n. 1
0
        public static EntryPointNode Create(
            IHostEnvironment env,
            string entryPointName,
            object arguments,
            ModuleCatalog catalog,
            RunContext context,
            Dictionary <string, List <ParameterBinding> > inputBindingMap,
            Dictionary <ParameterBinding, VariableBinding> inputMap,
            Dictionary <string, string> outputMap,
            bool checkpoint = false,
            string stageId  = "",
            float cost      = float.NaN)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckNonEmpty(entryPointName, nameof(entryPointName));
            env.CheckValue(arguments, nameof(arguments));
            env.CheckValue(catalog, nameof(catalog));
            env.CheckValue(context, nameof(context));
            env.CheckValue(inputBindingMap, nameof(inputBindingMap));
            env.CheckValue(inputMap, nameof(inputMap));
            env.CheckValue(outputMap, nameof(outputMap));
            ModuleCatalog.EntryPointInfo info;
            bool success = catalog.TryFindEntryPoint(entryPointName, out info);

            env.Assert(success);

            var inputBuilder = new InputBuilder(env, info.InputType, catalog);
            var outputHelper = new OutputHelper(env, info.OutputType);

            var entryPointNode = new EntryPointNode(env, catalog, context, context.GenerateId(entryPointName), entryPointName,
                                                    inputBuilder.GetJsonObject(arguments, inputBindingMap, inputMap),
                                                    outputHelper.GetJsonObject(outputMap), checkpoint, stageId, cost);

            return(entryPointNode);
        }
Esempio n. 2
0
        public static List <EntryPointNode> ValidateNodes(IHostEnvironment env, RunContext context, JArray nodes, ModuleCatalog moduleCatalog)
        {
            Contracts.AssertValue(env);
            env.AssertValue(context);
            env.AssertValue(nodes);
            env.AssertValue(moduleCatalog);

            var result = new List <EntryPointNode>(nodes.Count);

            using (var ch = env.Start("Validating graph nodes"))
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    var node = nodes[i] as JObject;
                    if (node == null)
                    {
                        throw env.Except("Unexpected node token: '{0}'", nodes[i]);
                    }

                    string name   = node[FieldNames.Name].Value <string>();
                    var    inputs = node[FieldNames.Inputs] as JObject;
                    if (inputs == null && node[FieldNames.Inputs] != null)
                    {
                        throw env.Except("Unexpected {0} token: '{1}'", FieldNames.Inputs, node[FieldNames.Inputs]);
                    }

                    var outputs = node[FieldNames.Outputs] as JObject;
                    if (outputs == null && node[FieldNames.Outputs] != null)
                    {
                        throw env.Except("Unexpected {0} token: '{1}'", FieldNames.Outputs, node[FieldNames.Outputs]);
                    }

                    var id = context.GenerateId(name);
                    var unexpectedFields = node.Properties().Where(
                        x => x.Name != FieldNames.Name && x.Name != FieldNames.Inputs && x.Name != FieldNames.Outputs &&
                        x.Name != FieldNames.StageId && x.Name != FieldNames.Checkpoint && x.Name != FieldNames.Cost);

                    var stageId    = node[FieldNames.StageId] == null ? "" : node[FieldNames.StageId].Value <string>();
                    var checkpoint = node[FieldNames.Checkpoint] == null ? false : node[FieldNames.Checkpoint].Value <bool>();
                    var cost       = node[FieldNames.Cost] == null ? float.NaN : node[FieldNames.Cost].Value <float>();

                    if (unexpectedFields.Any())
                    {
                        // REVIEW: consider throwing an exception.
                        ch.Warning("Node '{0}' has unexpected fields that are ignored: {1}", id, string.Join(", ", unexpectedFields.Select(x => x.Name)));
                    }

                    result.Add(new EntryPointNode(env, moduleCatalog, context, id, name, inputs, outputs, checkpoint, stageId, cost));
                }
            }
            return(result);
        }