示例#1
0
 /// <summary>
 /// Creates a new instance of the <see cref="SetMetadataStep"/> class.
 /// </summary>
 /// <param name="stepGroup">The step group containing the newly initialized step.</param>
 public SetMetadataStep(StepGroup stepGroup)
     : base(stepGroup)
 {
 }
示例#2
0
    private static void OnConfirm(string chunkName)
    {
        List <Step> StepList = new List <Step>();
        Level       level    = null;

        foreach (GameObject go in Selection.gameObjects)
        {
            Step step = go.GetComponent <Step>();
            if (step && !StepList.Contains(step))
            {
                if (level == null)
                {
                    level = step.GetComponentInParent <Level>();
                }

                StepList.Add(step);
            }
        }

        if (StepList.Count == 0)
        {
            return;
        }

        if (level != null)
        {
            foreach (StepGroup stepGroup in level.StepGroupList)
            {
                stepGroup.StepList.RemoveNull();
                List <Step> removeStepList = new List <Step>();
                foreach (Step step in stepGroup.StepList)
                {
                    if (StepList.Contains(step))
                    {
                        removeStepList.Add(step);
                    }
                }

                foreach (Step step in removeStepList)
                {
                    if (step.PreviousStep && step.NextStep)
                    {
                        step.PreviousStep.NextStep = step.NextStep;
                        step.NextStep.PreviousStep = step.PreviousStep;
                    }

                    if (step.PreviousStep)
                    {
                        step.PreviousStep.NextStep = null;
                    }
                    if (step.NextStep)
                    {
                        step.NextStep.PreviousStep = null;
                    }
                    step.PreviousStep = null;
                    step.NextStep     = null;
                    stepGroup.StepList.Remove(step);
                }
            }

            StepGroup newStepGroup = new StepGroup();
            if (string.IsNullOrWhiteSpace(chunkName))
            {
                for (int i = 1; i < 999; i++)
                {
                    chunkName = $"Chunk_{i}";
                    bool found = true;
                    foreach (StepGroup sg in level.StepGroupList)
                    {
                        if (sg.GroupName.Equals(chunkName))
                        {
                            found = false;
                            break;
                        }
                    }

                    if (found)
                    {
                        break;
                    }
                }
            }

            newStepGroup.GroupName = chunkName;
            newStepGroup.Material  = level.DefaultStepMaterial;
            level.StepGroupList.Add(newStepGroup);
            newStepGroup.StepList      = StepList;
            newStepGroup.ColorGradient = StepList[0].ColorGradient;
            newStepGroup.Initialize();

            level.RefreshStep();
        }
    }
示例#3
0
        internal static IStep ReadStep(IParser parser, Boolean simpleOnly = false)
        {
            IStep result;

            parser.Expect <MappingStart>();
            var scalar = parser.Expect <Scalar>();

            if (String.Equals(scalar.Value, YamlConstants.Task, StringComparison.Ordinal))
            {
                var task = new TaskStep {
                    Enabled = true
                };
                scalar = parser.Expect <Scalar>();
                String[] refComponents = (scalar.Value ?? String.Empty).Split('@');
                Int32    version;
                if (refComponents.Length != 2 ||
                    String.IsNullOrEmpty(refComponents[0]) ||
                    String.IsNullOrEmpty(refComponents[1]) ||
                    !Int32.TryParse(refComponents[1], NumberStyles.None, CultureInfo.InvariantCulture, out version))
                {
                    throw new SyntaxErrorException(scalar.Start, scalar.End, $"Task reference must be in the format <NAME>@<VERSION>. For example MyTask@2. The following task reference format is invalid: '{scalar.Value}'");
                }

                task.Reference = new TaskReference
                {
                    Name    = refComponents[0],
                    Version = refComponents[1],
                };
                while (parser.Allow <MappingEnd>() == null)
                {
                    scalar = parser.Expect <Scalar>();
                    switch (scalar.Value ?? String.Empty)
                    {
                    case YamlConstants.Inputs:
                        task.Inputs = ReadMappingOfStringString(parser, StringComparer.OrdinalIgnoreCase);
                        break;

                    default:
                        SetTaskControlProperty(parser, task, scalar);
                        break;
                    }
                }

                result = task;
            }
            else if (String.Equals(scalar.Value, YamlConstants.Script, StringComparison.Ordinal))
            {
                var task = new TaskStep
                {
                    Enabled   = true,
                    Reference = new TaskReference
                    {
                        Name    = "CmdLine",
                        Version = "2",
                    },
                    Inputs = new Dictionary <String, String>(StringComparer.OrdinalIgnoreCase),
                };

                task.Inputs["script"] = parser.Expect <Scalar>().Value ?? String.Empty;
                while (parser.Allow <MappingEnd>() == null)
                {
                    scalar = parser.Expect <Scalar>();
                    switch (scalar.Value ?? String.Empty)
                    {
                    case YamlConstants.FailOnStderr:
                        task.Inputs["failOnStderr"] = parser.Expect <Scalar>().Value ?? String.Empty;
                        break;

                    case YamlConstants.WorkingDirectory:
                        task.Inputs["workingDirectory"] = parser.Expect <Scalar>().Value ?? String.Empty;
                        break;

                    default:
                        SetTaskControlProperty(parser, task, scalar);
                        break;
                    }
                }

                result = task;
            }
            else if (String.Equals(scalar.Value, YamlConstants.Bash, StringComparison.Ordinal))
            {
                var task = new TaskStep
                {
                    Enabled   = true,
                    Reference = new TaskReference
                    {
                        Name    = "Bash",
                        Version = "3",
                    },
                    Inputs = new Dictionary <String, String>(StringComparer.OrdinalIgnoreCase),
                };

                task.Inputs["targetType"] = "inline";
                task.Inputs["script"]     = parser.Expect <Scalar>().Value ?? String.Empty;
                while (parser.Allow <MappingEnd>() == null)
                {
                    scalar = parser.Expect <Scalar>();
                    switch (scalar.Value ?? String.Empty)
                    {
                    case YamlConstants.FailOnStderr:
                        task.Inputs["failOnStderr"] = parser.Expect <Scalar>().Value ?? String.Empty;
                        break;

                    case YamlConstants.WorkingDirectory:
                        task.Inputs["workingDirectory"] = parser.Expect <Scalar>().Value ?? String.Empty;
                        break;

                    default:
                        SetTaskControlProperty(parser, task, scalar);
                        break;
                    }
                }

                result = task;
            }
            else if (String.Equals(scalar.Value, YamlConstants.PowerShell, StringComparison.Ordinal))
            {
                var task = new TaskStep
                {
                    Enabled   = true,
                    Reference = new TaskReference
                    {
                        Name    = "PowerShell",
                        Version = "2",
                    },
                    Inputs = new Dictionary <String, String>(StringComparer.OrdinalIgnoreCase),
                };

                task.Inputs["targetType"] = "inline";
                task.Inputs["script"]     = parser.Expect <Scalar>().Value ?? String.Empty;
                while (parser.Allow <MappingEnd>() == null)
                {
                    scalar = parser.Expect <Scalar>();
                    switch (scalar.Value ?? String.Empty)
                    {
                    case YamlConstants.ErrorActionPreference:
                        task.Inputs["errorActionPreference"] = parser.Expect <Scalar>().Value ?? String.Empty;
                        break;

                    case YamlConstants.FailOnStderr:
                        task.Inputs["failOnStderr"] = parser.Expect <Scalar>().Value ?? String.Empty;
                        break;

                    case YamlConstants.IgnoreLASTEXITCODE:
                        task.Inputs["ignoreLASTEXITCODE"] = parser.Expect <Scalar>().Value ?? String.Empty;
                        break;

                    case YamlConstants.WorkingDirectory:
                        task.Inputs["workingDirectory"] = parser.Expect <Scalar>().Value ?? String.Empty;
                        break;

                    default:
                        SetTaskControlProperty(parser, task, scalar);
                        break;
                    }
                }

                result = task;
            }
            else if (String.Equals(scalar.Value, YamlConstants.Checkout, StringComparison.Ordinal))
            {
                var checkoutStep = new CheckoutStep();
                scalar            = parser.Expect <Scalar>();
                checkoutStep.Name = scalar.Value ?? String.Empty;
                if (String.Equals(checkoutStep.Name, YamlConstants.Self, StringComparison.Ordinal))
                {
                    while (parser.Allow <MappingEnd>() == null)
                    {
                        scalar = parser.Expect <Scalar>();
                        switch (scalar.Value ?? String.Empty)
                        {
                        case YamlConstants.Clean:
                            checkoutStep.Clean = ReadNonEmptyString(parser);
                            break;

                        case YamlConstants.FetchDepth:
                            checkoutStep.FetchDepth = ReadNonEmptyString(parser);
                            break;

                        case YamlConstants.Lfs:
                            checkoutStep.Lfs = ReadNonEmptyString(parser);
                            break;
                        }
                    }
                }
                else if (String.Equals(checkoutStep.Name, YamlConstants.None, StringComparison.Ordinal))
                {
                    parser.Expect <MappingEnd>();
                }
                else
                {
                    throw new SyntaxErrorException(scalar.Start, scalar.End, $"Unexpected resource name '{scalar.Value}'. The '{YamlConstants.Checkout}' step currently can only be used with the resource name '{YamlConstants.Self}' or '{YamlConstants.None}'.");
                }

                result = checkoutStep;
            }
            else if (String.Equals(scalar.Value, YamlConstants.Group, StringComparison.Ordinal))
            {
                if (simpleOnly)
                {
                    throw new SyntaxErrorException(scalar.Start, scalar.End, $"A step '{YamlConstants.Group}' cannot be nested within a step group or steps template.");
                }

                var stepGroup = new StepGroup()
                {
                    Name = ReadNonEmptyString(parser)
                };
                while (parser.Allow <MappingEnd>() == null)
                {
                    scalar = parser.Expect <Scalar>();
                    if (String.Equals(scalar.Value, YamlConstants.Steps, StringComparison.Ordinal))
                    {
                        stepGroup.Steps = ReadSteps(parser, simpleOnly: true).Cast <ISimpleStep>().ToList();
                    }
                    else
                    {
                        throw new SyntaxErrorException(scalar.Start, scalar.End, $"Unexpected property: '{scalar.Value}'");
                    }
                }

                result = stepGroup;
            }
            else if (String.Equals(scalar.Value, YamlConstants.Template, StringComparison.Ordinal))
            {
                if (simpleOnly)
                {
                    throw new SyntaxErrorException(scalar.Start, scalar.End, $"Steps '{YamlConstants.Template}' cannot be nested within a step group or steps template.");
                }

                var templateReference = new StepsTemplateReference {
                    Name = ReadNonEmptyString(parser)
                };
                while (parser.Allow <MappingEnd>() == null)
                {
                    scalar = parser.Expect <Scalar>();
                    switch (scalar.Value ?? String.Empty)
                    {
                    case YamlConstants.Parameters:
                        templateReference.Parameters = ReadMapping(parser);
                        break;

                    case YamlConstants.Steps:
                        templateReference.StepOverrides = ReadStepOverrides(parser);
                        break;

                    default:
                        throw new SyntaxErrorException(scalar.Start, scalar.End, $"Unexpected property: '{scalar.Value}'");
                    }
                }

                result = templateReference;
            }
            else
            {
                throw new SyntaxErrorException(scalar.Start, scalar.End, $"Unknown step type: '{scalar.Value}'");
            }

            return(result);
        }