Esempio n. 1
0
        public void Resolve(Func <IItemContainer, bool> solutionItemFilter = null)
        {
            tracer.Verbose(
                Resources.PathResolver_TraceResolveInitial, Path ?? string.Empty, FileName ?? string.Empty);

            if (!string.IsNullOrEmpty(this.Path) &&
                !Regex.IsMatch(this.Path, PathRegExpression, RegexOptions.IgnoreCase))
            {
                throw new InvalidOperationException(string.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Resources.PathResolver_ErrorPathInvalidFormat,
                                                        this.Path));
            }

            if (solutionItemFilter == null)
            {
                solutionItemFilter = item => true;
            }

            // Navigate the path and resolve the link (if any)
            ResolveArtifactLinkInPath(solutionItemFilter);

            if (!string.IsNullOrEmpty(this.Path))
            {
                tracer.Verbose(
                    Resources.PathResolver_TraceResolveApplyingExpression, this.Path, ((IProductElement)this.Context).GetSafeInstanceName());

                var evaluatedPath = ExpressionEvaluator.Evaluate(this.Context, this.Path);

                if (string.IsNullOrEmpty(evaluatedPath))
                {
                    tracer.Verbose(
                        Resources.PathResolver_TraceResolveFailedExpressionEvaluation);

                    throw new InvalidOperationException(string.Format(
                                                            CultureInfo.CurrentCulture,
                                                            Resources.PathResolver_PathEvaluatedEmpty,
                                                            this.Path));
                }

                evaluatedPath = PathResolver.Normalize(evaluatedPath);
                tracer.Verbose(
                    Resources.PathResolver_TraceResolveEvaluatedPath, evaluatedPath);

                // Ensure item name does not contain any invalid file chars
                if (!DataFormats.IsValidSolutionPathName(evaluatedPath))
                {
                    evaluatedPath = DataFormats.MakeValidSolutionPathName(evaluatedPath);
                }

                tracer.Verbose(Resources.PathResolver_TraceEvaluatedPath, this.Path, evaluatedPath);

                evaluatedPath = evaluatedPath.Trim('\\');

                this.Path = evaluatedPath;
            }

            tracer.Verbose(
                Resources.PathResolver_TraceResolvePath, this.Path ?? string.Empty);

            if (!string.IsNullOrEmpty(this.FileName))
            {
                tracer.Verbose(
                    Resources.PathResolver_TraceResolveApplyingExpression, this.FileName, ((IProductElement)this.Context).GetSafeInstanceName());

                var evaluatedName = ExpressionEvaluator.Evaluate(this.Context, this.FileName);

                if (string.IsNullOrEmpty(evaluatedName))
                {
                    tracer.Verbose(
                        Resources.PathResolver_TraceResolveFailedExpressionEvaluation);

                    throw new InvalidOperationException(string.Format(
                                                            CultureInfo.CurrentCulture,
                                                            Resources.PathResolver_ErrorFileNameEvaluatedEmpty,
                                                            this.FileName));
                }

                tracer.Verbose(
                    Resources.PathResolver_TraceResolveEvaluatedFileName2, evaluatedName);

                // Ensure item name does not contain any invalid file chars
                if (!DataFormats.IsValidSolutionItemName(evaluatedName))
                {
                    evaluatedName = DataFormats.MakeValidSolutionItemName(evaluatedName);
                }

                tracer.Info(
                    Resources.PathResolver_TraceEvaluatedFileName, this.FileName, evaluatedName);

                this.FileName = evaluatedName;
            }

            tracer.Verbose(
                Resources.PathResolver_TraceResolveResolvedFileName, this.FileName ?? string.Empty);
        }