コード例 #1
0
ファイル: Extensions.cs プロジェクト: pollination/csharp-sdk
        public static object GetDefaultValue(this Interface.Io.Inputs.IDag inputDag)
        {
            // use this dummy is for future-proofing. Just in case "Default" is changed in the future
            DAGStringInput dummy;

            return(inputDag.GetPropertyValue(nameof(dummy.Default)));
        }
コード例 #2
0
        public static Interface.Io.Inputs.IStep ToStepInput(this Interface.Io.Inputs.IDag dag, object value)
        {
            if (value == null)
            {
                throw new System.ArgumentNullException($"Required input {dag.Name}'s value cannot be null for step input");
            }
            Interface.Io.Inputs.IStep step = null;
            //AnyOf<DAGGenericInput,DAGStringInput,DAGIntegerInput,DAGNumberInput,DAGBooleanInput,DAGFolderInput,DAGFileInput,DAGPathInput,DAGArrayInput,DAGJSONObjectInput>
            switch (dag)
            {
            case DAGStringInput s:
                step = new StepStringInput(s.Name, value.ToString(), s.Annotations, s.Description, s.Default, s.Alias, s.Required, s.Spec);
                break;

            case DAGIntegerInput s:
                step = new StepIntegerInput(s.Name, int.Parse(value.ToString()), s.Annotations, s.Description, s.Default, s.Alias, s.Required, s.Spec);
                break;

            case DAGNumberInput s:
                step = new StepNumberInput(s.Name, double.Parse(value.ToString()), s.Annotations, s.Description, s.Default, s.Alias, s.Required, s.Spec);
                break;

            case DAGBooleanInput s:
                step = new StepBooleanInput(s.Name, bool.Parse(value.ToString()), s.Annotations, s.Description, s.Default, s.Alias, s.Required, s.Spec);
                break;

            case DAGFolderInput s:
                step = new StepFolderInput(s.Name, new ProjectFolder(path: value.ToString()), s.Annotations, s.Description, s.Default, s.Alias, s.Required, s.Spec);
                break;

            case DAGFileInput s:
                step = new StepFileInput(s.Name, new ProjectFolder(path: value.ToString()), s.Annotations, s.Description, s.Default, s.Alias, s.Required, s.Spec, extensions: s.Extensions);
                break;

            case DAGPathInput s:
                step = new StepPathInput(s.Name, new ProjectFolder(path: value.ToString()), s.Annotations, s.Description, s.Default, s.Alias, s.Required, s.Spec, extensions: s.Extensions);
                break;

            case DAGArrayInput s:
                //["room", "hallway"]
                var list = value.ToString().Trim(new char[] { '[', ']', ' ' }).Split(',').Select(_ => _.Trim(new char[] { '"', ' ' }) as object).ToList();
                step = new StepArrayInput(s.Name, list, s.Annotations, s.Description, s.Default, s.Alias, s.Required, s.Spec, s.ItemsType);
                break;

            case DAGJSONObjectInput g:
                step = new StepJSONObjectInput(g.Name, value, g.Annotations, g.Description, g.Default, g.Alias, g.Required, g.Spec);
                break;

            case DAGGenericInput g:
                step = new StepStringInput(g.Name, value.ToString(), g.Annotations, g.Description, g.Default, g.Alias, g.Required, g.Spec);
                break;

            default:
                throw new System.ArgumentException($"{dag.GetType().Name} is not supported to be converted to step input");
                break;
            }

            return(step);
        }
コード例 #3
0
ファイル: Extensions.cs プロジェクト: pollination/csharp-sdk
 /// <summary>
 /// Check if a Dag input is a DAGFileInput, DAGFolderInput, or DAGPathInput
 /// </summary>
 /// <param name="inputDag"></param>
 /// <returns></returns>
 public static bool IsPathType(this Interface.Io.Inputs.IDag inputDag)
 {
     if (inputDag is DAGFileInput)
     {
         return(true);
     }
     if (inputDag is DAGFolderInput)
     {
         return(true);
     }
     if (inputDag is DAGPathInput)
     {
         return(true);
     }
     return(false);
 }
コード例 #4
0
ファイル: Extensions.cs プロジェクト: pollination/csharp-sdk
 /// <summary>
 /// Get an alias for a platform (rhino, grasshopper, revit, etc)
 /// </summary>
 /// <param name="inputDag"></param>
 /// <param name="platform">platform name (rhino, grasshopper, revit, etc)</param>
 /// <returns></returns>
 public static Interface.Io.Inputs.IAlias GetAlias(this Interface.Io.Inputs.IDag inputDag, string platform)
 {
     return(inputDag.Alias?.OfType <Interface.Io.Inputs.IAlias>()?.FirstOrDefault(_ => _.Platform.Contains(platform)));
 }