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

            return(inputStep.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>
 /// Get the value of non-path type Stet input. Returns null if inputStep is a path type
 /// </summary>
 /// <param name="inputStep"></param>
 /// <returns></returns>
 public static object GetValue(this Interface.Io.Inputs.IStep inputStep)
 {
     if (inputStep.IsValueType())
     {
         StepStringInput dummy;
         return(inputStep.GetPropertyValue(nameof(dummy.Value)));
     }
     else
     {
         return(null);
     }
 }
コード例 #4
0
ファイル: Extensions.cs プロジェクト: pollination/csharp-sdk
 /// <summary>
 /// Get the source of a path type Step input. Returns null if inputStep is not path type
 /// </summary>
 /// <param name="inputStep"></param>
 /// <returns></returns>
 public static AnyOf <HTTP, S3, ProjectFolder> GetPathSource(this Interface.Io.Inputs.IStep inputStep)
 {
     if (inputStep.IsPathType())
     {
         StepFileInput dummy;
         return(inputStep.GetPropertyValue(nameof(dummy.Source)) as AnyOf <HTTP, S3, ProjectFolder>);
     }
     else
     {
         return(null);
     }
 }
コード例 #5
0
ファイル: Extensions.cs プロジェクト: pollination/csharp-sdk
 /// <summary>
 /// Check if a Step input is a StepFileInput, StepFolderInput, or StepPathInput
 /// </summary>
 /// <param name="inputStep"></param>
 /// <returns></returns>
 public static bool IsPathType(this Interface.Io.Inputs.IStep inputStep)
 {
     if (inputStep is StepFileInput)
     {
         return(true);
     }
     if (inputStep is StepFolderInput)
     {
         return(true);
     }
     if (inputStep is StepPathInput)
     {
         return(true);
     }
     return(false);
 }
コード例 #6
0
ファイル: Extensions.cs プロジェクト: pollination/csharp-sdk
        /// <summary>
        /// Get asset path of ProjectFolder type to be downloaded
        /// </summary>
        /// <param name="inputStep"></param>
        /// <returns>return empty if it is not a path type input</returns>
        public static string GetInputPath(this Interface.Io.Inputs.IStep inputStep)
        {
            var value = string.Empty;

            if (inputStep.IsPathType())
            {
                var pathSource = inputStep.GetPathSource();
                if (pathSource.Obj is ProjectFolder file)
                {
                    value = file.Path;
                }
                else
                {
                    throw new System.ArgumentException($"The source of {inputStep.Name} is {pathSource.Obj.GetType()}, which is not supported ProjectFolder type");
                }
            }
            return(value);
        }
コード例 #7
0
ファイル: Extensions.cs プロジェクト: pollination/csharp-sdk
        /// <summary>
        /// Get user's argument of value type inputs (string, int, double, etc)
        /// </summary>
        /// <param name="inputStep"></param>
        /// <returns>return an empty list if inputStep is a path type, which need to be downloaded</returns>
        public static List <object> GetInputValue(this Interface.Io.Inputs.IStep inputStep)
        {
            var value = new List <object>();

            if (inputStep.IsPathType())
            {
                return(value);
            }

            if (inputStep is StepArrayInput s)
            {
                value.AddRange(s.Value);
            }
            else
            {
                var v = inputStep.GetValue();
                value.Add(v);
            }

            return(value);
        }
コード例 #8
0
        public RunInputAsset(Interface.Io.Inputs.IStep dagInput, string runSource = default)
        {
            if (dagInput == null)
            {
                return;
            }

            // get name
            this.Name        = dagInput.Name;
            this.Description = dagInput.Description;

            // check path type
            this.RelativePath = dagInput.GetInputPath();


            // value type
            this.Value = dagInput.GetInputValue();

            // cloud source: CLOUD:mingbo/demo/1D725BD1-44E1-4C3C-85D6-4D98F558DE7C
            // local source: LOCAL:C\Users\mingo\simulaiton\1D725BD1
            this.RunSource = runSource;
        }
コード例 #9
0
ファイル: Extensions.cs プロジェクト: pollination/csharp-sdk
 public static bool IsValueType(this Interface.Io.Inputs.IStep inputStep)
 {
     return(!inputStep.IsPathType());
 }