Ejemplo n.º 1
0
        private bool CalculateIsActiveStatus(Dictionary <string, string> variables, string expr)
        {
            // Update selector active status. Note that the first selector cannot use variables (there are none),
            // and each subsequent selector can only reference variables from previous selectors.
            var normVars     = this.CreateBooleanNormalizedList(variables);
            var expandedExpr = TemplateExpander.ExpandTemplate(normVars, expr, null);

            expandedExpr = TemplateExpander.ReplaceUnresolved(expandedExpr, "false");
            return(ExpressionEvaluator.Evaluate(expandedExpr));
        }
Ejemplo n.º 2
0
 internal void Expand(Dictionary <string, string> variables)
 {
     this.unresolvedVariables.Clear();
     this.Content  = TemplateExpander.ExpandTemplate(variables, this.ContentTemplate, this.unresolvedVariables);
     this.FileName = TemplateExpander.ExpandTemplate(variables, this.FileNameTemplate, this.unresolvedVariables);
     this.OnPropertyChanged("UnresolvedVariables");
     this.OnPropertyChanged("UnresolvedVariablesList");
     this.OnPropertyChanged("IsResolved");
     this.OnPropertyChanged("IsIncomplete");
 }
Ejemplo n.º 3
0
        internal void NotifySelectionChanged()
        {
            // The first round is used to determine which selectors are active now.
            var variables = new Dictionary <string, string>();

            foreach (var selector in this.Selectors)
            {
                // Update selector active status. Note that the first selector cannot use variables (there are none),
                // and each subsequent selector can only reference variables from previous selectors.
                selector.IsActive = this.CalculateIsActiveStatus(variables, selector.IsActiveExpr ?? "false");

                // Inactive selector cannot influence variables.
                if (!selector.IsActive)
                {
                    continue;
                }

                var v = selector.SelectedChoice;
                if (v != null)
                {
                    foreach (var variable in v.Variables)
                    {
                        if (variable.Value.IsExpression)
                        {
                            variables[variable.Key] = TemplateExpander.ExpandTemplate(
                                variables,
                                variable.Value.Value,
                                null);
                        }
                        else
                        {
                            variables[variable.Key] = variable.Value.Value;
                        }
                    }
                }
            }

            foreach (var tpl in this.Templates)
            {
                tpl.IsActive = this.CalculateIsActiveStatus(variables, tpl.IsActiveExpr);
                tpl.Expand(variables);
            }

            if (this.SelectedTemplate == null || !this.SelectedTemplate.IsActive)
            {
                this.SelectedTemplate = this.Templates.FirstOrDefault();
            }

            this.saveAllCommand.RaiseCanExecuteChanged();
            this.runCommand.RaiseCanExecuteChanged();
        }