示例#1
0
        public DeploymentActionResource AddOrUpdateScriptAction(string name, ScriptAction scriptAction, ScriptTarget scriptTarget)
        {
            var action = AddOrUpdateAction(name);

            action.ActionType = "Octopus.Script";
            action.Properties.Clear();
            action.Properties["Octopus.Action.RunOnServer"]         = scriptTarget == ScriptTarget.Server ? "true" : "false";
            action.Properties["Octopus.Action.Script.Syntax"]       = scriptAction.Syntax.ToString();
            action.Properties["Octopus.Action.Script.ScriptSource"] = scriptAction.Source.ToString();

            RequiresPackagesToBeAcquired = scriptAction.Source == ScriptSource.Package;

            switch (scriptAction.Source)
            {
            case ScriptSource.Inline:
                string scriptBody   = null;
                var    inlineScript = scriptAction as InlineScriptAction;
                if (inlineScript != null)
                {
                    scriptBody = inlineScript.GetScriptBody();
                }
                var inlineScriptFromFileInAssembly = scriptAction as InlineScriptActionFromFileInAssembly;
                if (inlineScriptFromFileInAssembly != null)
                {
                    scriptBody = inlineScriptFromFileInAssembly.GetScriptBody();
                }

                if (scriptBody == null)
                {
                    throw new NotSupportedException($"{scriptAction.GetType().Name} is not a supported Script Action type yet...");
                }

                action.Properties.Add("Octopus.Action.Script.ScriptBody", scriptBody);
                break;

            case ScriptSource.Package:
                var packageScript = (ScriptActionFromFileInPackage)scriptAction;
                action.Properties.Add("Octopus.Action.Package.PackageId", packageScript.PackageId);
                action.Properties.Add("Octopus.Action.Package.FeedId", packageScript.PackageFeedId);
                action.Properties.Add("Octopus.Action.Script.ScriptFileName", packageScript.ScriptFilePath);
                break;
            }

            return(action);
        }
示例#2
0
        private void ProcessCoroutine()
        {
            if (!_account.Scripts.Running)
            {
                return;
            }

            try
            {
                var result = _currentCoroutine.Coroutine.Resume();
                _account.Logger.LogDebug("Scripts", $"Processing coroutine: (last action: {_currentAction?.GetType().Name}, result: {result}).");

                // Check if the custom function ended
                if (result.Type == DataType.Void)
                {
                    //_account.Logger.LogDebug("", "Ending coroutine.");
                    OnCustomHandled();
                }
            }
            catch (Exception ex)
            {
                _account.Scripts.StopScript(ex.ToString());
            }
        }