Example #1
0
        void ParseServiceMessage(ServiceMessage message)
        {
            switch (message.Name)
            {
            case ServiceMessageNames.SetVariable.Name:
                var variableName  = message.GetValue(ServiceMessageNames.SetVariable.NameAttribute);
                var variableValue = message.GetValue(ServiceMessageNames.SetVariable.ValueAttribute);

                if (!string.IsNullOrWhiteSpace(variableName))
                {
                    outputVariables.Set(variableName, variableValue);
                }
                break;

            case ServiceMessageNames.CalamariFoundPackage.Name:
                CalamariFoundPackage = true;
                break;

            case ServiceMessageNames.FoundPackage.Name:
                var foundPackageId            = message.GetValue(ServiceMessageNames.FoundPackage.IdAttribute);
                var foundPackageVersion       = message.GetValue(ServiceMessageNames.FoundPackage.VersionAttribute);
                var foundPackageVersionFormat = message.GetValue(ServiceMessageNames.FoundPackage.VersionFormat);
                var foundPackageHash          = message.GetValue(ServiceMessageNames.FoundPackage.HashAttribute);
                var foundPackageRemotePath    = message.GetValue(ServiceMessageNames.FoundPackage.RemotePathAttribute);
                var fileExtension             = message.GetValue(ServiceMessageNames.FoundPackage.FileExtensionAttribute);
                if (foundPackageId != null && foundPackageVersion != null)
                {
                    FoundPackage = new FoundPackage(foundPackageId,
                                                    foundPackageVersion,
                                                    foundPackageVersionFormat,
                                                    foundPackageRemotePath,
                                                    foundPackageHash,
                                                    fileExtension);
                }
                break;

            case ServiceMessageNames.PackageDeltaVerification.Name:
                var pdvHash       = message.GetValue(ServiceMessageNames.PackageDeltaVerification.HashAttribute);
                var pdvSize       = message.GetValue(ServiceMessageNames.PackageDeltaVerification.SizeAttribute);
                var pdvRemotePath =
                    message.GetValue(ServiceMessageNames.PackageDeltaVerification.RemotePathAttribute);
                DeltaError = message.GetValue(ServiceMessageNames.PackageDeltaVerification.Error);
                if (pdvRemotePath != null && pdvHash != null)
                {
                    DeltaVerification = new DeltaPackage(pdvRemotePath, pdvHash, long.Parse(pdvSize));
                }

                break;
            }
        }
Example #2
0
        void ServiceMessage(ServiceMessage serviceMessage)
        {
            serviceMessages.Add(serviceMessage);

            switch (serviceMessage.Name)
            {
            case ScriptServiceMessageNames.StdErrBehavior.Ignore:
                errorTarget = nullTarget;
                break;

            case ScriptServiceMessageNames.StdErrBehavior.Default:
            case ScriptServiceMessageNames.StdErrBehavior.Error:
                errorTarget = log.Error;
                break;

            case ScriptServiceMessageNames.StdErrBehavior.Progress:
                errorTarget = log.Verbose;
                break;

            case ScriptServiceMessageNames.SetVariable.Name:
            {
                var name  = serviceMessage.GetValue(ScriptServiceMessageNames.SetVariable.NameAttribute);
                var value = serviceMessage.GetValue(ScriptServiceMessageNames.SetVariable.ValueAttribute);
                bool.TryParse(serviceMessage.GetValue(ScriptServiceMessageNames.SetVariable.SensitiveAttribute), out var isSensitive);

                if (name != null && value != null)
                {
                    testOutputVariables[name] = new TestOutputVariable(name, value, isSensitive);

                    if (isSensitive)
                    {
                        // If we're adding a sensitive output-variable we need to add it to the log-context
                        // so it will be masked.
                        logContext.WithSensitiveValue(value);
                    }
                }

                break;
            }

            case ScriptServiceMessageNames.Progress.Name:
            {
                var message = serviceMessage.GetValue(ScriptServiceMessageNames.Progress.Message);
                if (message != null && int.TryParse(serviceMessage.GetValue(ScriptServiceMessageNames.Progress.Percentage), out int percentage))
                {
                    using (log.WithinBlock(logContext))
                        progressTarget(percentage, message);
                }

                break;
            }

            case ScriptServiceMessageNames.CreateArtifact.Name:
            {
                var name = serviceMessage.GetValue(ScriptServiceMessageNames.CreateArtifact.NameAttribute);
                var path = serviceMessage.GetValue(ScriptServiceMessageNames.CreateArtifact.PathAttribute);
                long.TryParse(serviceMessage.GetValue(ScriptServiceMessageNames.CreateArtifact.LengthAttribute), out long length);

                if (name != null)
                {
                    artifacts.Add(new CollectedArtifact(name, path)
                        {
                            Length = length
                        });
                }

                break;
            }

            case ScriptServiceMessageNames.ResultMessage.Name:
                ResultMessage = serviceMessage.GetValue(ScriptServiceMessageNames.ResultMessage.MessageAttribute);
                break;

            case ScriptServiceMessageNames.CalamariFoundPackage.Name:
                CalamariFoundPackage = true;
                break;

            case ScriptServiceMessageNames.FoundPackage.Name:
                var id            = serviceMessage.GetValue(ScriptServiceMessageNames.FoundPackage.IdAttribute);
                var version       = serviceMessage.GetValue(ScriptServiceMessageNames.FoundPackage.VersionAttribute);
                var versionFormat = serviceMessage.GetValue(ScriptServiceMessageNames.FoundPackage.VersionFormat);
                var hash          = serviceMessage.GetValue(ScriptServiceMessageNames.FoundPackage.HashAttribute);
                var remotePath    = serviceMessage.GetValue(ScriptServiceMessageNames.FoundPackage.RemotePathAttribute);
                var fileExtension = serviceMessage.GetValue(ScriptServiceMessageNames.FoundPackage.FileExtensionAttribute);
                if (id != null && version != null)
                {
                    foundPackages.Add(new FoundPackage(id, version, versionFormat, remotePath, hash, fileExtension));
                }
                break;

            case ScriptServiceMessageNames.PackageDeltaVerification.Name:
                var deltaVerificationRemotePath = serviceMessage.GetValue(ScriptServiceMessageNames.PackageDeltaVerification.RemotePathAttribute);
                var deltaVerificationHash       = serviceMessage.GetValue(ScriptServiceMessageNames.PackageDeltaVerification.HashAttribute);
                var deltaVerificationSize       = serviceMessage.GetValue(ScriptServiceMessageNames.PackageDeltaVerification.SizeAttribute);
                DeltaPackageError = serviceMessage.GetValue(ScriptServiceMessageNames.PackageDeltaVerification.Error);
                if (deltaVerificationRemotePath != null && deltaVerificationHash != null)
                {
                    DeltaPackageVerifcation = new DeltaPackage(deltaVerificationRemotePath, deltaVerificationHash, long.Parse(deltaVerificationSize));
                }
                break;

            case ScriptServiceMessageNames.StdOutBehaviour.Default:
                outputTarget = log.Info;
                break;

            case ScriptServiceMessageNames.StdOutBehaviour.Error:
                outputTarget = log.Error;
                break;

            case ScriptServiceMessageNames.StdOutBehaviour.Ignore:
                outputTarget = nullTarget;
                break;

            case ScriptServiceMessageNames.StdOutBehaviour.Verbose:
                outputTarget = log.Verbose;
                break;

            case ScriptServiceMessageNames.StdOutBehaviour.Warning:
                outputTarget = log.Warn;
                break;

            case ScriptServiceMessageNames.StdOutBehaviour.Highlight:
                outputTarget = s => log.Write(LogCategory.Highlight, s);
                break;

            case ScriptServiceMessageNames.StdOutBehaviour.Wait:
                outputTarget = s => log.Write(LogCategory.Wait, s);
                break;

            default:
                // check to see if it is a support action name
                if (supportedScriptActionNames.Contains(serviceMessage.Name))
                {
                    actions.Add(new TestScriptOutputAction(serviceMessage.Name, serviceMessage.Properties));
                }
                break;
            }
        }