Beispiel #1
0
        protected static void OutputLog(CodeActivityContext context, List <KeyValuePair <string, string> > log, bool outputAllAsInfo = false)
        {
            if (log != null)
            {
                foreach (var message in log)
                {
                    if (outputAllAsInfo)
                    {
                        context.TrackBuildMessage(message.Value);
                    }
                    else
                    {
                        switch (message.Key)
                        {
                        case "Info":
                            context.TrackBuildMessage(message.Value);
                            break;

                        case "Warning":
                            context.TrackBuildWarning(message.Value);
                            break;

                        case "Error":
                            context.TrackBuildError(message.Value);
                            break;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        protected override void Execute(CodeActivityContext context)
        {
            #region Mapeamento dos parametros para variaveis:
            Uri    tfsCollection      = context.GetValue(this.TFSCollection);
            string tfsProjectName     = context.GetValue(this.TFSProjectName);
            string tfsUser            = context.GetValue(this.TFSUser);
            string tfsPassword        = context.GetValue(this.TFSPassword);
            string tfsDomain          = context.GetValue(this.TFSDomain);
            string envMachineName     = context.GetValue(this.EnvMachineName);
            string envMachineRoles    = context.GetValue(this.EnvMachineRoles);
            string envEnvironmentName = context.GetValue(this.EnvEnvironmentName);
            string envTestController  = context.GetValue(this.EnvTestController);
            TfsTeamProjectCollection currentTfsTeamProjectCollection = context.GetValue(this.CurrentTfsTeamProjectCollection);
            bool runAsInteractive = true;
            #endregion

            try
            {
                #region Carregamento do serviço de LAB

                System.Net.NetworkCredential credentials =
                    new System.Net.NetworkCredential(tfsUser, tfsPassword, tfsDomain);

                LabService labService = GetLabService(currentTfsTeamProjectCollection, credentials);

                if (labService == null)
                {
                    throw new System.ArgumentOutOfRangeException("Lab Service não encontrado.");
                }

                #endregion

                #region Configura o ambiente

                //Remove ambiente atual com o mesmo nome
                RemoveLabEnvironment(labService, tfsProjectName, envEnvironmentName);

                //Cria novo ambiente
                CreateNewLabEnvironment(labService, runAsInteractive, envEnvironmentName, envTestController, tfsProjectName, envMachineName, envMachineRoles, credentials);

                //Refresh do ambiente
                UpdateLabEnvironment(labService, envMachineName, tfsProjectName, envEnvironmentName);

                Console.WriteLine("Ambiente Criado com Sucesso!");


                #endregion
            }
            catch (Exception ex)
            {
                context.TrackBuildError("Criação do Ambiente falhou:  " + ex.ToString() + ".");
            }
        }
Beispiel #3
0
        protected override void Execute(CodeActivityContext context)
        {
            string folder    = Folder.Get(context);
            bool   recursive = Recursive.Get(context);

            var xpoList = Client.XPOLabelCheck.FindTempLabels(folder, recursive);

            foreach (var xpo in xpoList)
            {
                // Tracking error without exception will cause "partially succeeded"
                context.TrackBuildError(string.Format("Temporary label(s) found in XPO {0}", xpo));
            }
        }
Beispiel #4
0
        protected override void Execute(CodeActivityContext context)
        {
            // Mapeamento dos parametros para variaveis:
            string tfsServer          = context.GetValue(this.TFSServer);
            string tfsCollection      = context.GetValue(this.TFSCollection);
            string tfsProject         = context.GetValue(this.TFSProject);
            string tfsUser            = context.GetValue(this.TFSUser);
            string tfsPassword        = context.GetValue(this.TFSPassword);
            string tfsDomain          = context.GetValue(this.TFSDomain);
            string envEnvironmentName = context.GetValue(this.EnvEnvironmentName);

            try
            {
                #region Client do TFS e Lab Service

                System.Net.NetworkCredential administratorCredentials =
                    new System.Net.NetworkCredential(tfsUser, tfsPassword, tfsDomain);

                string tfsName = tfsServer + "/" + tfsCollection;
                Uri    uri     = new Uri(tfsName);
                TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(uri, administratorCredentials);

                LabService lab = tfs.GetService <LabService>();

                if (lab == null)
                {
                    throw new System.ArgumentOutOfRangeException("Lab Service não encontrado.");
                }

                #endregion

                #region Obtém o ambiente

                var env = lab.GetLabEnvironments(tfsProject).FirstOrDefault(c => c.Name == envEnvironmentName);

                if (env != null)
                {
                    context.TrackBuildMessage("Ambiente encontrado sob URI: '" + env.Uri.ToString() + "'.", BuildMessageImportance.High);
                    context.SetValue(this.Result, env);
                    context.SetValue(this.ResultUri, env.Uri.ToString());
                }

                #endregion
            }
            catch (Exception ex)
            {
                context.TrackBuildError("Ambiente não pode ser obtido:  " + ex.ToString() + ".");
            }
        }
Beispiel #5
0
        public static void ReportCompileMessages(CodeActivityContext context, CodeCrib.AX.Client.CompileOutput output)
        {
            bool hasErrors = false;

            foreach (var item in output.Output)
            {
                string compileMessage = String.Format("{0}, line {1}, column {2} : {3}", item.TreeNodePath, item.LineNumber, item.ColumnNumber, item.Message);
                switch (item.Severity)
                {
                // Compile Errors
                case 0:
                    context.TrackBuildError(compileMessage);
                    hasErrors = true;
                    break;

                // Compile Warnings
                case 1:
                case 2:
                case 3:
                    context.TrackBuildWarning(compileMessage);
                    break;

                // Best practices
                case 4:
                    context.TrackBuildMessage(string.Format("BP: {0}", compileMessage), BuildMessageImportance.Low);
                    break;

                // TODOs
                case 254:
                case 255:
                    context.TrackBuildWarning(string.Format("TODO: {0}", compileMessage));
                    break;

                // "Other"
                default:
                    context.TrackBuildMessage(compileMessage);
                    break;
                }
            }
            if (hasErrors)
            {
                throw new Exception("Compile error(s) found");
            }
        }
        private void RunCommand(string command, CodeActivityContext context)
        {
            LogMessage("@@@@@@@@@@@@", context);
            LogMessage("Apprenda: Executing command <<" + command + ">> as " + Environment.UserDomainName + @"\" + Environment.UserName, context);
            using (System.Diagnostics.Process process = new System.Diagnostics.Process())
            {
                process.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"PowerShell.exe");
                process.StartInfo.Arguments = " " + command;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.ErrorDialog = false;
                process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.Start();
                
                string msTestOutput = process.StandardOutput.ReadToEnd();
                string msErrOutput = process.StandardError.ReadToEnd();
                LogMessage("Standard Output: " + msTestOutput, context);
                LogMessage("Error output: " + msErrOutput, context);
                    
                process.WaitForExit();

                if (process.ExitCode != 0)
                {
                    bool verboseLogging = context.GetValue(this.VerboseLogging);
                    // verboselogging would have printed out the process output already
                    if (!verboseLogging)
                    {
                        LogMessage("Apprenda: Executing command <<" + command + ">> as " + Environment.UserDomainName + @"\" + Environment.UserName, context);
                        LogMessage("Standard Output: " + msTestOutput, context, true);
                        LogMessage("Error output: " + msErrOutput, context, true);
                    }
                    context.TrackBuildError("Apprenda: Fail the Apprenda custom build activity because ACS failed with exit code " + process.ExitCode);
                }            
            }
            LogMessage("@@@@@@@@@@@@", context);
        }
 /// <summary>
 /// Logs the the specified error message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Error(string message)
 {
     _context.TrackBuildError(message);
 }
        private int RunProcess(CodeActivityContext context, string fullPath, string workingDirectory, string arguments)
        {
            context.TrackBuildMessage("fullPath: " + fullPath, BuildMessageImportance.Low);
            context.TrackBuildMessage("workingDir: " + workingDirectory, BuildMessageImportance.Low);
            context.TrackBuildMessage("arguments: " + arguments, BuildMessageImportance.Low);
            using (Process proc = new Process())
            {
                proc.StartInfo.FileName = fullPath;

                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.Arguments = arguments;
                context.TrackBuildMessage("Running " + proc.StartInfo.FileName + " " + proc.StartInfo.Arguments, BuildMessageImportance.High);

                if (!string.IsNullOrEmpty(workingDirectory))
                {
                    proc.StartInfo.WorkingDirectory = workingDirectory;
                }

                proc.Start();

                string outputStream = proc.StandardOutput.ReadToEnd();
                if (outputStream.Length > 0)
                {
                    context.TrackBuildMessage(outputStream, BuildMessageImportance.Normal);
                }

                string errorStream = proc.StandardError.ReadToEnd();
                if (errorStream.Length > 0)
                {
                    context.TrackBuildError(errorStream);
                }

                proc.WaitForExit();
                context.TrackBuildMessage("Exit Code: " + proc.ExitCode, BuildMessageImportance.Low);
                return proc.ExitCode;
            }
        }
        private void TransformNUnitToMSTest(CodeActivityContext context, string nunitResultFile, string mstestResultFile)
        {
            context.TrackBuildMessage("input file: " + nunitResultFile);
            context.TrackBuildMessage("output file: " + mstestResultFile);
            Stream s = this.GetType().Assembly.GetManifestResourceStream("CustomBuildActivities.NUnitToMSTest.xslt");
            if (s == null)
            {
                context.TrackBuildError("Could not load NUnitToMSTest.xslt from embedded resources");
                return;
            }

            using (var reader = new XmlTextReader(s))
            {
                XslCompiledTransform transform = new XslCompiledTransform();
                transform.Load(reader);
                transform.Transform(nunitResultFile, mstestResultFile);
            }
        }