public IntermediateFileObject AddNewParent(EvaluatedFilesRule parent)
        {
            var ofo = new IntermediateFileObject(parent, OutputSubPath, File, ParentRules);

            //AddToAncestorEvaluatedFileRules(ofo);
            return ofo;
        }
 private IntermediateFileObject(EvaluatedFilesRule parent, string currentSubPath,  string originalFile, IEnumerable<EvaluatedFilesRule> currentStack )
 {
     _parentRules = new Stack<EvaluatedFilesRule>(currentStack);
     _parentRules.Push(parent);
     OutputSubPath = parent.CreateChildPath(currentSubPath);
     File = originalFile;
     //parent.AddDescendentOFO(this);
 }
 public bool IsThisMyRoot(EvaluatedFilesRule parent)
 {
     return _parentRules.Last() == parent;
 }
 public bool IsThisMyParent(EvaluatedFilesRule parent)
 {
     return _parentRules.Peek() == parent;
 }
 public IntermediateFileObject(EvaluatedFilesRule parent, string currentSubPath, string originalFile)
     : this(parent, currentSubPath, originalFile, Enumerable.Empty<EvaluatedFilesRule>())
 {
 }
        private void EvalFileRule(FilesRule r)
        {
            var exceptions = Enumerable.Empty<Exception>();
            var files = Enumerable.Empty<IntermediateFileObject>();

            var tempFileRule = new EvaluatedFilesRule(r.Name, r.Destination);
            var inclSplit = from i in r.IncludeDefs
                            group i by i.GetType()
                            into g
                            select g;

            foreach (var g in inclSplit)
            {
                if (g.Key == typeof(LiteralInclExclDef))
                {

                    //get the all the files

                    var actualFiles = g.Aggregate(Enumerable.Empty<string>(), (current, def) =>
                                                                              current.Concat(
                                                                                  def.Value.FindFilesSmarterComplex(
                                                                                      r.Root)));
                    var localMinimalPaths = actualFiles.GetMinimalPaths();

                    var fileToMinimalPaths = actualFiles.Zip(localMinimalPaths,
                                                             (actual, minimal) =>
                                                             new {Actual = actual, Minimal = minimal});

                    files = files.Concat(fileToMinimalPaths.Aggregate((IList<IntermediateFileObject>)new List<IntermediateFileObject>(),
                        (currentFiles, file) =>
                                        currentFiles.LAdd(
                                            new IntermediateFileObject
                                                (tempFileRule,
                                                file.Minimal,
                                                file.Actual))));
                }
                else if (g.Key == typeof(FilesRuleInclExclDef))
                {
                    foreach (var fr in g)
                    {

                        if (!_evaluatedFilesRules.ContainsKey(fr.Value))
                                //Exception; !!!!
                            return;

                        files = files.Concat(_evaluatedFilesRules[fr.Value].Files.Select((i) => i.AddNewParent(tempFileRule)));
                    }
                }
            }

            /*
             *we exclude all the files that AREN'T allowed
             */

            var excludeSplit = from e in r.ExcludeDefs
                               group e by e.GetType()
                               into g
                               select g;

            foreach (var g in excludeSplit) {
                if (g.Key == typeof(LiteralInclExclDef))
                {
                    //for literals, we need to work from the current root and see if the literal matches
                    // a wildcard

                    var g1 = g;
                    files = from f in files
                            where g1.All((e) => !f.File.IsWildcardMatch(e.Value, r.Root.GetFullPath() + Path.DirectorySeparatorChar))
                            select f;
                }
                else if (g.Key == typeof(FilesRuleInclExclDef)) {

                    //for these we just match the original paths straight

                    //get all files in evals
                    var allFiles = from fr in g
                                   from f in _evaluatedFilesRules[fr.Value].Files
                                   select f.File;

                    files = from f in files
                            where !allFiles.Contains(f.File)
                            select f;

                }
            }
            // we've excluded everything, now we have to add the damn prefixes
            files = PerformPathTrimming(files, tempFileRule, r.TrimPath);
            tempFileRule.Files = files;
               // var output = tempFileRule.Files.ToArray();
            _evaluatedFilesRules[r.Name] = tempFileRule;
        }
        private IEnumerable<IntermediateFileObject> PerformPathTrimming(IEnumerable<IntermediateFileObject> files, EvaluatedFilesRule parent, TrimPathType trimType)
        {
            if (trimType == TrimPathType.minimal) {

                //DO NOT REORDER ANYTHING HERE. IF YOU DO, EVERYTHING WILL FAIL!!!
                return files.Zip(files.Select(i => i.File).GetMinimalPaths(),
                         (o, s) => {
                             o.OutputSubPath = parent.CreateChildPath(s);
                             return o;
                         });
            }
            else if (trimType == TrimPathType.all) {
                return files.Select(i => {
                    i.OutputSubPath = parent.CreateChildPath(Path.GetFileName(i.File));
                    return i;
                });
            }

            //we did the local_minimal path trimming before
            //TODO: we actually need to move this back down here
            return files;
        }