/// <summary>Add a source dependency from an input spec.</summary>
        /// <param name="inputSpec">The input spec.</param>
        public void AddSourceDependency(InputSpec inputSpec)
        {
            this.isUnsaved = true;
            var key = inputSpec.ToJson(true);

            Safe.UniqueKeyLock(
                key,
                Safe.MaxLockTimeout,
                () =>
            {
                if (!this.sourceDependencies.ContainsKey(key))
                {
                    this.sourceDependencies.Add(
                        key,
                        CacheSourceDependency.Create(
                            this.context,
                            new InputSpec
                    {
                        IsOptional    = inputSpec.IsOptional,
                        Path          = inputSpec.Path,
                        SearchOption  = inputSpec.SearchOption,
                        SearchPattern = inputSpec.SearchPattern
                    }));
                }
            });
        }
示例#2
0
        /// <summary>Creates a source dependency.</summary>
        /// <param name="context">The context.</param>
        /// <param name="inputSpec">The input spec.</param>
        /// <returns>The <see cref="CacheSourceDependency"/>.</returns>
        internal static CacheSourceDependency Create(IWebGreaseContext context, InputSpec inputSpec)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (inputSpec == null)
            {
                throw new ArgumentNullException("inputSpec");
            }

            var csd = new CacheSourceDependency();

            if (Directory.Exists(inputSpec.Path))
            {
                inputSpec.Path.EnsureEndSeparator();
            }

            csd.InputSpecHash = GetInputSpecHash(context, inputSpec);
            inputSpec.Path    = inputSpec.Path.MakeRelativeToDirectory(context.Configuration.SourceDirectory);
            csd.InputSpec     = inputSpec;

            return(csd);
        }