Exemplo n.º 1
0
        protected override void Execute(CodeActivityContext context)
        {
            string configurationFile = ConfigurationFile.Get(context);
            var    serverConfig      = Helper.GetServerConfig(configurationFile);
            string sourcePath        = ReferencesFolder.Get(context);

            context.TrackBuildMessage("Deploying references to client and server");

            if (System.IO.Directory.Exists(sourcePath))
            {
                string clientBasePath        = string.Format(@"{0}\Microsoft\Dynamics Ax", System.Environment.GetEnvironmentVariable("localappdata"));
                IEnumerable <string> folders = System.IO.Directory.EnumerateDirectories(clientBasePath, "VSAssemblies*");
                string serverPath            = string.Format(@"{0}\VSAssemblies", serverConfig.AlternateBinDirectory);

                if (!System.IO.Directory.Exists(serverPath))
                {
                    System.IO.Directory.CreateDirectory(serverPath);
                }

                IEnumerable <string> files = System.IO.Directory.EnumerateFiles(sourcePath, "*");
                foreach (string file in files)
                {
                    foreach (string folder in folders)
                    {
                        System.IO.File.Copy(file, string.Format(@"{0}\{1}", folder, System.IO.Path.GetFileName(file)));
                    }
                    System.IO.File.Copy(file, string.Format(@"{0}\{1}", serverPath, System.IO.Path.GetFileName(file)));
                }
            }
            else
            {
                context.TrackBuildWarning(string.Format("Folder '{0}' containing reference files does not exist", sourcePath));
            }
        }
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            string text     = context.GetValue(this.Size);
            string name     = context.GetValue(this.Name);
            String filePath = Path.Combine(Path.GetDirectoryName(FilePath.Get(context)), "ServiceDefinition.csdef");

            context.TrackBuildWarning("File Path: " + filePath, BuildMessageImportance.High);
//            context.TrackBuildWarning(string.Join("\n", Directory.GetFiles(Path.GetDirectoryName(FilePath.Get(context)), "*.csdef", SearchOption.AllDirectories)), BuildMessageImportance.High);

            var        doc = XDocument.Load(filePath);
            XNamespace ab  = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition";

            foreach (var element in doc.Root.Elements(ab + "WebRole"))
            {
                FixSize(ab, element, name, text);
            }
            foreach (var element in doc.Root.Elements(ab + "WorkerRole"))
            {
                FixSize(ab, element, name, text);
            }
            //  doc.Root.Element(ab + "WebRole").SetAttributeValue("vmsize", text);

            doc.Save(filePath);
        }
Exemplo n.º 3
0
        protected override void Execute(CodeActivityContext context)
        {
            String[]     dirty       = context.GetValue(this.TfsProjectAndBuildDefinition);
            IBuildDetail buildDetail = context.GetValue(this.BuildDetail);

            var pds = Parse(dirty);
            //var workspace = buildDetail.BuildDefinition.Workspace;
            IBuildServer buildServer = buildDetail.BuildServer;

            foreach (var pd in pds)
            {
                try
                {
                    string message = string.Format("Queue new build \"{0}\"-\"{1}\"", pd.TfsProject, pd.BuildDefinition);
                    context.TrackBuildMessage(message);

                    IBuildDefinition buildDef = buildServer.GetBuildDefinition(pd.TfsProject, pd.BuildDefinition);
                    buildServer.QueueBuild(buildDef);
                }
                catch (Exception ex)
                {
                    string message = string.Format("Queue new build error \"{0}\"-\"{1}\", Exception : \"{2}\"",
                                                   pd.TfsProject, pd.BuildDefinition, ex.Message);
                    context.TrackBuildWarning(message);
                }
            }
        }
Exemplo n.º 4
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;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Executes the activity
        /// </summary>
        /// <param name="context">The activity's context</param>
        protected override void Execute(CodeActivityContext context)
        {
            //context.Track(new CustomTrackingRecord("olalá", TraceLevel.Info));
            context.TrackBuildMessage("Starting", BuildMessageImportance.High);
            //context.TrackBuildError("Starting");
            WorkingFolder workingFolder =
                Workspace.Get(context).GetWorkingFolderForServerItem(SourcesDirectory.Get(context));

            var sourcesDirectory = workingFolder.LocalItem;

            context.TrackBuildWarning(string.Format("Getting js files from {0}", sourcesDirectory), BuildMessageImportance.High);
            var jsFiles = Directory.GetFiles(sourcesDirectory, "*.js");

            foreach (var jsFile in jsFiles)
            {
                context.TrackBuildWarning(string.Format("Passing tests from {0}", jsFile), BuildMessageImportance.High);
            }
        }
Exemplo n.º 6
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");
            }
        }
Exemplo n.º 7
0
            /// <summary>
            /// Executes the activity and returns the data necessary to execute putty (executable + arguments)
            /// </summary>
            /// <param name="context">The context</param>
            protected override void Execute(CodeActivityContext context)
            {
                var toolsPath = PuttyHelper.GetPuttyPath(this.ToolsPath.Get(context));

                if (string.IsNullOrEmpty(toolsPath))
                {
                    context.TrackBuildWarning("can't determine PuTTy tools path. Will rely on path");
                    toolsPath = string.Empty;
                }

                this.ToolCommandPath.Set(context, Path.Combine(toolsPath, "plink.exe"));
                this.Arguments.Set(context, this.GenerateCommandLineCommands(context));
            }
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            string text = context.GetValue(this.Size);
            String filePath = Path.Combine(Path.GetDirectoryName(FilePath.Get(context)), "ServiceDefinition.csdef");
            context.TrackBuildWarning("File Path: " + filePath, BuildMessageImportance.High);
//            context.TrackBuildWarning(string.Join("\n", Directory.GetFiles(Path.GetDirectoryName(FilePath.Get(context)), "*.csdef", SearchOption.AllDirectories)), BuildMessageImportance.High);

            var doc = XDocument.Load(filePath);
            XNamespace ab = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition";
            foreach(var element in doc.Root.Elements(ab + "WebRole"))
                element.SetAttributeValue("vmsize", text);
            foreach (var element in doc.Root.Elements(ab + "WorkerRole"))
                element.SetAttributeValue("vmsize", text);
          //  doc.Root.Element(ab + "WebRole").SetAttributeValue("vmsize", text);
            
            doc.Save(filePath);

        }
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {

            string buildFullName = context.GetExtension<IEnvironmentVariableExtension>().GetEnvironmentVariable<string>(context, WellKnownEnvironmentVariables.BuildNumber);
            string buildNumber = buildFullName.Substring(buildFullName.LastIndexOf("_") + 1).Replace(".", "");
            if (buildNumber.Length > 9)
            {
                // apprenda only allows up to 9 charachers for the version alias and it has to be alphanumeric
                // in this case we are trimming the size to  max 9 characters
                buildNumber = buildNumber.Substring(buildNumber.Length - 9);
            }
            string apprendaRootURL = context.GetValue(this.ApprendaRootURL);
            string cloudAlias = context.GetValue(this.CloudAlias);
            string acsPath = context.GetValue(this.AcsPath);
            string username = context.GetValue(this.Username);
            string password = context.GetValue(this.Password);
            string devTeamAlias = context.GetValue(this.DevelopmentTeamAlias);
            string acsBuildParams = context.GetValue(this.AcsBuildParameters);
            string[] projectToBuild = context.GetValue(this.ProjectToBuild);
            string appAlias = context.GetValue(this.ApplicationAlias);
            string versionNamePrefix = context.GetValue(this.VersionNamePrefix);
            string packageName = projectToBuild[0].Substring(0, projectToBuild[0].LastIndexOf(".")).Substring(projectToBuild[0].LastIndexOf("/") + 1) + ".zip";

            // add the Fully Qualified path including the zip extension to the name of the solution for the Apprenda package
            // we will drop this ZIP file on the root folder of the build destination directory
            string zipPackageFullPath = context.GetExtension<IEnvironmentVariableExtension>().GetEnvironmentVariable<string>(
                context, WellKnownEnvironmentVariables.DropLocation) + @"\" + packageName;

            // get the path to the solution file, after eliminating the TFS root path of $/<tfs name>/
            string tfsCodeDirectory = context.GetExtension<IEnvironmentVariableExtension>().GetEnvironmentVariable<string>(
                context, WellKnownEnvironmentVariables.SourcesDirectory);
            string tfsRelativePath = projectToBuild[0].Substring(projectToBuild[0].IndexOf("/", 2)).Replace("/", @"\");
            string tfsSolutionFilePath = tfsCodeDirectory + tfsRelativePath;

            // populate the ACS path now
            acsPath = (tfsCodeDirectory.EndsWith(@"\") ? tfsCodeDirectory : tfsCodeDirectory + @"\") + (acsPath.StartsWith(@"\") ? acsPath.Substring(1) : acsPath);

            if (projectToBuild.Count() > 1)
            {
                context.TrackBuildWarning(string.Format("Apprenda: You entered more than 1 Solution in the Build Definition. The Apprenda Code Activity will only utilize the first one entered - {0}", projectToBuild[0]));
            }

            LogMessage("Apprenda: The Apprenda TFS Build Activity will now execute", context);
            LogMessage("---Code Activity Parameters---", context);
            LogMessage("ApprendaRootURL: " + apprendaRootURL, context);
            LogMessage("CloudAlias: " + cloudAlias, context);
            LogMessage("AcsPath: " + acsPath, context);
            LogMessage("Username: "******"Password: ********", context);
            LogMessage("DevelopmentTeamAlias: " + devTeamAlias, context);
            LogMessage("AcsBuildParameters: " + acsBuildParams, context);
            LogMessage("ProjectToBuild: " + projectToBuild[0], context);
            LogMessage("ApplicationAlias: " + appAlias, context);

            string acsRegisterCloudCmd = string.Format(RegisterCloud, acsPath, apprendaRootURL, cloudAlias);
            string acsConnectCloudCmd = string.Format(ConnectCloud, acsPath, cloudAlias, username, password, devTeamAlias);
            string acsNewPackageCmd = string.Format(NewPackage, acsPath, tfsSolutionFilePath, zipPackageFullPath, acsBuildParams);
            string acsNewVersionCmd = string.Format(NewVersion, acsPath, appAlias, buildNumber, "Created from Apprenda TFS Activity", zipPackageFullPath, buildFullName);
            string acsDisconnectCloudCmd = string.Format(DisconnectCloud, acsPath);

            LogMessage("---Code Activity Constructed Commands---", context);
            LogMessage("ACS command 1: " + acsRegisterCloudCmd, context);
            LogMessage("ACS command 2: " + acsConnectCloudCmd.Replace(password, "********"), context);
            LogMessage("ACS command 3: " + acsNewPackageCmd, context);
            LogMessage("ACS command 4: " + acsNewVersionCmd, context);
            LogMessage("ACS command 5: " + acsDisconnectCloudCmd, context);

            var buildDetail = context.GetExtension<IBuildDetail>();
            buildDetail.RefreshAllDetails();
            if (!buildDetail.BuildFinished)
            {
                LogMessage("Apprenda: Build is not finished yet! - " + buildDetail.Status.ToString(), context);
            }

            LogMessage("---Execute Apprenda ACS Utility Commands---", context);
            this.RunCommand(acsRegisterCloudCmd, context);
            this.RunCommand(acsConnectCloudCmd, context);
            this.RunCommand(acsNewPackageCmd, context);
            this.RunCommand(acsNewVersionCmd, context);
            this.RunCommand(acsDisconnectCloudCmd, context);
        }
 /// <summary>
 /// Logs the specified warning message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Warning(string message)
 {
     _context.TrackBuildWarning(message);
 }
Exemplo n.º 11
0
            /// <summary>
            /// Executes the activity and returns the data necessary to execute putty (executable + arguments)
            /// </summary>
            /// <param name="context">The context</param>
            protected override void Execute(CodeActivityContext context)
            {
                var toolsPath = PuttyHelper.GetPuttyPath(this.ToolsPath.Get(context));
                
                if (string.IsNullOrEmpty(toolsPath))
                {
                    context.TrackBuildWarning("can't determine PuTTy tools path. Will rely on path");
                    toolsPath = string.Empty;
                }

                this.ToolCommandPath.Set(context, Path.Combine(toolsPath, "pscp.exe"));
                this.Arguments.Set(context, this.GenerateCommandLineCommands(context));
            }