protected override void Execute()
        {
            var projectsFilter = new string[0];
            if (projects.Count > 0)
            {
                Log.Debug("Loading projects...");
                projectsFilter = Repository.Projects.FindByNames(projects.ToArray()).Select(p => p.Id).ToArray();
            }

            var environmentsById = new Dictionary<string, string>();
            if (environments.Count > 0)
            {
                Log.Debug("Loading environments...");
                environmentsById.AddRange(Repository.Environments.FindByNames(environments.ToArray()).Select(p => new KeyValuePair<string, string>(p.Id, p.Name)));
            }
            else
            {
                environmentsById.AddRange(Repository.Environments.FindAll().Select(p => new KeyValuePair<string, string>(p.Id, p.Name)));
            }

            var deployments = Repository.Deployments.FindAll(projectsFilter, environments.Count > 0 ? environmentsById.Keys.ToArray() : new string[] { });

            foreach (var deployment in deployments.Items)
            {
                LogDeploymentInfo(deployment, environmentsById);
            }
        }
        public void AddRangeTest_ShouldAddAllElement_IfDistinctDictionaryIsPassed()
        {
            // Arrange
            var dictionary = new Dictionary<string, int>();
            dictionary.Add("a", 1);
            dictionary.Add("d", 4);
            dictionary.Add("b", 2);
            dictionary.Add("c", 3);
            dictionary.Add("e", 5);
            var target = new Dictionary<string, int>();

            // Act
            target.AddRange(dictionary);

            // Assert
            CollectionAssert.AreEqual(
                new int[] { 1, 2, 3, 4, 5 }.AsEnumerable(),
                target.Union(dictionary, (_1, _2) => _1.Is(_2)).
                       OrderBy(_ => _.Key).
                       Select(_=>_.Value)
            );
        }
Exemple #3
0
        /// <summary>
        ///     Sets up the data bindings to the combo box and the text box
        ///     Refreshes also -by deleting and rebinding
        /// </summary>
        private void CategryDataBinding()
        {
            // Clears any old data bindings
            cmbIncomeCategories.DataSource = null;
            txtIncomeCategoryTotal.DataBindings.Clear();
            cmbExpenseCategories.DataSource = null;
            txtExpenseCategoryTotal.DataBindings.Clear();

            // Intializes the category total dictionarys
            IncomeCategoriesTotals = new Dictionary<string, decimal>();
            ExpenseCategoriesTotals = new Dictionary<string, decimal>();

            ExpenseCategoriesTotals.Add("Total Expenses", _expenseService.GetMonthTotal(dtPick.Value));
            ExpenseCategoriesTotals.AddRange(_expenseService.GetAllCategoryTotals(dtPick.Value));

            IncomeCategoriesTotals.Add("Total Income", _incomeService.GetMonthTotal(dtPick.Value));
            IncomeCategoriesTotals.AddRange(_incomeService.GetTotalIncomeByCategories(dtPick.Value));

            // Sets the bindings for the controls
            cmbIncomeCategories.DataSource = new ArrayList(IncomeCategoriesTotals);
            cmbIncomeCategories.DisplayMember = "KEY";
            txtIncomeCategoryTotal.DataBindings.Add("Text", cmbIncomeCategories.DataSource, "VALUE");

            cmbExpenseCategories.DataSource = new ArrayList(ExpenseCategoriesTotals);
            cmbExpenseCategories.DisplayMember = "KEY";
            txtExpenseCategoryTotal.DataBindings.Add("Text", cmbExpenseCategories.DataSource, "VALUE");
        }
        /// <summary>
        /// Gather all windows system variables and their values
        /// </summary>
        /// <returns></returns>
        private static void AddSystemVariables(ArtifactoryConfig artifactoryConfig, Build build)
        {
            if (artifactoryConfig.PropertyGroup.EnvironmentVariables == null)
                return;

            string enable = artifactoryConfig.PropertyGroup.EnvironmentVariables.EnabledEnvVariable;
            if (string.IsNullOrWhiteSpace(enable) || !enable.ToLower().Equals("true"))
                return;

            // includePatterns = new List<Pattern>();
            //List<Pattern> excludePatterns = new List<Pattern>();
            List<Pattern> includePatterns = artifactoryConfig.PropertyGroup.EnvironmentVariables.IncludePatterns.Pattern;
            List<Pattern> excludePatterns = artifactoryConfig.PropertyGroup.EnvironmentVariables.ExcludePatterns.Pattern;

            StringBuilder includeRegexUnion = new StringBuilder();
            StringBuilder excludeRegexUnion = new StringBuilder();

            if (includePatterns != null && includePatterns.Count > 0) 
            {
                includePatterns.ForEach(pattern => includeRegexUnion.Append(WildcardToRegex(pattern.key)).Append("|"));
                includeRegexUnion.Remove(includeRegexUnion.Length - 1, 1);
            }

            if (excludePatterns != null && excludePatterns.Count > 0) 
            {
                excludePatterns.ForEach(pattern => excludeRegexUnion.Append(WildcardToRegex(pattern.key)).Append("|"));
                excludeRegexUnion.Remove(excludeRegexUnion.Length - 1, 1);
            }

            Regex includeRegex = new Regex(includeRegexUnion.ToString(), RegexOptions.IgnoreCase);
            Regex excludeRegex = new Regex(excludeRegexUnion.ToString(), RegexOptions.IgnoreCase);

            //System.Environment.GetEnvironmentVariables()
            //EnvironmentVariableTarget
            IDictionary sysVariables = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process);
            var dicVariables = new Dictionary<string, string>();

            var environmentVariables = build.agent.BuildAgentEnvironment();

            foreach(string key in sysVariables.Keys)
            {
                if (!environmentVariables.ContainsKey(string.Concat(Agent.PRE_FIX_ENV, key)) && !PathConflicts(includePatterns, excludePatterns, includeRegex, excludeRegex, key)) 
                {
                    dicVariables.Add(key, (string)sysVariables[key]);
                }
            }

            dicVariables.AddRange(environmentVariables);

            build.properties = dicVariables;
        }