Exemple #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;
        }
Exemple #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;
        }
        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;
        }
Exemple #4
0
 private static FileCollection GetFileCollectionFromFileMapping(string baseDirectory, DocumentType type, FileMapping files)
 {
     var result = new FileCollection(baseDirectory);
     foreach (var mapping in files.Items)
     {
         result.Add(type, mapping.Files, mapping.SourceFolder, mapping.DestinationFolder);
     }
     return result;
 }
Exemple #5
0
 private static IEnumerable<string> GetFilesFromFileMapping(FileMapping mapping)
 {
     if (mapping == null)
     {
         return Enumerable.Empty<string>();
     }
     return from file in mapping.Items
            from item in file.Files
            select Path.Combine(file.SourceFolder ?? Directory.GetCurrentDirectory(), item);
 }
Exemple #6
0
 private static IEnumerable<string> GetFilesFromFileMapping(FileMapping mapping)
 {
     if (mapping == null) yield break;
     foreach (var file in mapping.Items)
     {
         foreach (var item in file.Files)
         {
             yield return Path.Combine(file.CurrentWorkingDirectory ?? Environment.CurrentDirectory, item);
         }
     }
 }