Add() public method

Should not merge FileMappingItems even if they are using the same name, because other propertes also matters, e.g. src, exclude.
public Add ( Microsoft.DocAsCode.FileMappingItem item ) : void
item Microsoft.DocAsCode.FileMappingItem
return void
Exemplo n.º 1
0
        public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping)
        {
            if (fileMapping == null)
            {
                return null;
            }

            if (fileMapping.Expanded) return fileMapping;

            var expandedFileMapping = new FileMapping();
            foreach (var item in fileMapping.Items)
            {
                // Use local variable to avoid different items influencing each other
                var src = Path.Combine(baseDirectory, item.SourceFolder ?? string.Empty);
                var options = GetMatchOptionsFromItem(item);
                var files = FileGlob.GetFiles(src, item.Files, item.Exclude, options).ToArray();
                if (files.Length == 0)
                {
                    var currentSrcFullPath = string.IsNullOrEmpty(src) ? Environment.CurrentDirectory : Path.GetFullPath(src);
                    Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under directory \"{currentSrcFullPath}\"");
                }
                expandedFileMapping.Add(
                    new FileMappingItem
                    {
                        SourceFolder = src,
                        Files = new FileItems(files),
                        DestinationFolder = item.DestinationFolder
                    });
            }

            expandedFileMapping.Expanded = true;
            return expandedFileMapping;
        }
Exemplo n.º 2
0
        public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping)
        {
            if (fileMapping == null)
            {
                return(null);
            }

            if (fileMapping.Expanded)
            {
                return(fileMapping);
            }

            var expandedFileMapping = new FileMapping();

            foreach (var item in fileMapping.Items)
            {
                // Use local variable to avoid different items influencing each other
                var cwd     = Path.Combine(baseDirectory, item.CurrentWorkingDirectory ?? string.Empty);
                var options = GetMatchOptionsFromItem(item);
                var files   = FileGlob.GetFiles(cwd, item.Files, item.Exclude, options).ToArray();
                if (files.Length == 0)
                {
                    Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under working directory {baseDirectory ?? "<current>"}");
                }
                expandedFileMapping.Add(
                    new FileMappingItem
                {
                    CurrentWorkingDirectory = cwd,
                    Files = new FileItems(files),
                });
            }

            expandedFileMapping.Expanded = true;
            return(expandedFileMapping);
        }
Exemplo n.º 3
0
        public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping)
        {
            if (fileMapping == null)
            {
                return null;
            }

            if (fileMapping.Expanded) return fileMapping;

            var expandedFileMapping = new FileMapping();
            foreach (var item in fileMapping.Items)
            {
                // Use local variable to avoid different items influencing each other
                var cwd = Path.Combine(baseDirectory, item.CurrentWorkingDirectory ?? string.Empty);
                var options = GetMatchOptionsFromItem(item);
                var files = FileGlob.GetFiles(cwd, item.Files, item.Exclude, options).ToArray();
                if (files.Length == 0)
                {
                    Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under working directory {baseDirectory ?? "<current>"}");
                }
                expandedFileMapping.Add(
                    new FileMappingItem
                    {
                        CurrentWorkingDirectory = cwd,
                        Files = new FileItems(files),
                    });
            }

            expandedFileMapping.Expanded = true;
            return expandedFileMapping;
        }
Exemplo n.º 4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var model = new FileMapping();
            var value = reader.Value;
            IEnumerable <JToken> jItems;

            if (reader.TokenType == JsonToken.StartArray)
            {
                jItems = JArray.Load(reader);
            }
            else if (reader.TokenType == JsonToken.String)
            {
                jItems = JRaw.Load(reader);
            }
            else
            {
                jItems = JObject.Load(reader);
            }

            if (jItems is JValue)
            {
                model.Add(FileModelParser.ParseItem(jItems.ToString()));
            }
            else if (jItems is JObject)
            {
                model.Add(FileModelParser.ParseItem((JToken)jItems));
            }
            else
            {
                foreach (var item in jItems)
                {
                    FileMappingItem itemModel = FileModelParser.ParseItem(item);
                    model.Add(itemModel);
                }
            }

            return(model);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        /// <exception cref="JsonReaderException"></exception>
        public static FileMapping Parse(string input, string key)
        {
            FileMapping model = new FileMapping();

            var value = JObject.Parse(input)[key];

            foreach (var item in value)
            {
                var itemModel = ParseItem(item);
                model.Add(itemModel);
            }

            return(model);
        }
Exemplo n.º 6
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var model = new FileMapping();
            var value = reader.Value;
            IEnumerable<JToken> jItems;
            if (reader.TokenType == JsonToken.StartArray)
            {
                jItems = JArray.Load(reader);
            }
            else if (reader.TokenType == JsonToken.StartObject)
            {
                jItems = JContainer.Load(reader);
            }
            else if (reader.TokenType == JsonToken.String)
            {
                jItems = JRaw.Load(reader);
            }
            else
            {
                jItems = JObject.Load(reader);
            }

            if (jItems is JValue)
            {
                model.Add(FileModelParser.ParseItem(jItems.ToString()));
            }
            else
            {
                foreach (var item in jItems)
                {
                    FileMappingItem itemModel = FileModelParser.ParseItem(item);
                    model.Add(itemModel);
                }
            }

            return model;
        }
Exemplo n.º 7
0
        public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping)
        {
            if (fileMapping == null)
            {
                return(null);
            }
            if (fileMapping.Expanded)
            {
                return(fileMapping);
            }

            var expandedFileMapping = new FileMapping();

            foreach (var item in fileMapping.Items)
            {
                var src       = Path.Combine(baseDirectory, item.SourceFolder ?? string.Empty);
                var options   = GetMatchOptionsFromItem(item);
                var fileItems = new FileItems(FileGlob.GetFiles(src, item.Files, item.Exclude, options));
                if (fileItems.Count == 0)
                {
                    var currentSrcFullPath = string.IsNullOrEmpty(src) ? Directory.GetCurrentDirectory() : Path.GetFullPath(src);
                    Logger.LogInfo($"No files are found with glob pattern {StringExtension.ToDelimitedString(item.Files) ?? "<none>"}, excluding {StringExtension.ToDelimitedString(item.Exclude) ?? "<none>"}, under directory \"{currentSrcFullPath}\"");
                    CheckPatterns(item.Files);
                }
                if (item.Exclude != null)
                {
                    CheckPatterns(item.Exclude);
                }
                expandedFileMapping.Add(
                    new FileMappingItem
                {
                    SourceFolder      = src,
                    Files             = fileItems,
                    DestinationFolder = item.DestinationFolder
                });
            }

            expandedFileMapping.Expanded = true;
            return(expandedFileMapping);
        }
Exemplo n.º 8
0
        public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping)
        {
            if (fileMapping == null)
            {
                return(null);
            }

            if (fileMapping.Expanded)
            {
                return(fileMapping);
            }

            var expandedFileMapping = new FileMapping();

            foreach (var item in fileMapping.Items)
            {
                // Use local variable to avoid different items influencing each other
                var src     = Path.Combine(baseDirectory, item.SourceFolder ?? string.Empty);
                var options = GetMatchOptionsFromItem(item);
                var files   = FileGlob.GetFiles(src, item.Files, item.Exclude, options).ToArray();
                if (files.Length == 0)
                {
                    var currentSrcFullPath = string.IsNullOrEmpty(src) ? Directory.GetCurrentDirectory() : Path.GetFullPath(src);
                    Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under directory \"{currentSrcFullPath}\"");
                    CheckPatterns(item.Files);
                }
                expandedFileMapping.Add(
                    new FileMappingItem
                {
                    SourceFolder      = src,
                    Files             = new FileItems(files),
                    DestinationFolder = item.DestinationFolder
                });
            }

            expandedFileMapping.Expanded = true;
            return(expandedFileMapping);
        }