Ejemplo n.º 1
0
        /// <summary>
        /// Deploys the repositories that have been recently updated and built.
        /// </summary>
        /// <returns>
        ///   <c>true</c> if all repositories were deployed successfully; <c>false</c> if at least one repository failed to deploy.
        /// </returns>
        /// <seealso cref="BuildRepositories" />
        /// <seealso cref="RepositoriesToDeploy" />
        /// <remarks>
        /// This method will not build the updated repositories. To do so, call <see cref="BuildRepositories" />.
        /// The list of repositories that will be deployed by this method is available through <see cref="RepositoriesToDeploy" />.
        /// </remarks>
        public bool DeployRepositories()
        {
            bool result = true;

            if (_deploymentManager != null && _repositories != null && _repositories.Any(r => r.IsNeedingDeployment))
            {
                foreach (RepositoryEntity repository in _repositories.Where(r => r.IsNeedingDeployment))
                {
                    IDictionary <string, string> replacementsTable = BuildReplacementsTable(repository);
                    foreach (DeploymentActionEntity deploymentAction in repository.DeploymentActions)
                    {
                        // Replaces tokens in action parameters.
                        for (int i = 0; i < deploymentAction.ActionParameters.Count; i++)
                        {
                            foreach (KeyValuePair <string, string> replacement in replacementsTable)
                            {
                                deploymentAction.ActionParameters[i] = deploymentAction.ActionParameters[i].Replace(replacement.Key, replacement.Value);
                            }
                        }

                        // Executes deployment action.
                        bool currentActionResult = _exceptionManager.Process(() => _deploymentManager.ExecuteDeploymentAction(deploymentAction.ActionType, deploymentAction.ActionParameters.ToArray()), false, Resources.DefaultExceptionHandlingPolicyName);
                        result = result && currentActionResult;
                    }

                    repository.IsNeedingDeployment = !result;

                    // Saves current configuration to file so that changes to the IsNeedingDeployment flag are not lost if the application exits.
                    SaveConfigurationToFile();
                }
            }

            return(result);
        }