Esempio n. 1
0
 public static PathMatch Combine(PathMatch first, PathMatch second)
 {
     return(new PathMatch(
                first.Success && second.Success,
                first.Length + second.Length
                ));
 }
Esempio n. 2
0
        public static string[] FindAllRecur(string Input, Parser a)
        {
            PathMatch     Pm      = GetPathMatch(Input);
            string        Pathc   = Pm.Path;
            string        Mat     = Pm.Match;
            string        Dir     = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, Pathc)).FullName;
            Regex         Re      = GenericRegex(Mat, a);
            List <string> Matched = new List <string>();
            List <string> Final   = new List <string>();

            foreach (string F in AllEntries(Dir))
            {
                FileInfo fi = new FileInfo(F);
                if (Re.IsMatch(fi.Name))
                {
                    Matched.Add(F);
                }
            }
            Action <IEnumerable <string> > Recur = null;

            Recur = (l) =>
            {
                foreach (string F in l)
                {
                    Final.Add(F);
                    if (Directory.Exists(F))
                    {
                        Recur(AllEntries(F));
                    }
                }
            };
            Recur(Matched);
            return(Final.ToArray());
        }
Esempio n. 3
0
        private void CreateEntries(Mapping mapping)
        {
            Entries.Clear();

            if (mapping == null)
            {
                return;
            }

            DcTable sourceTable = mapping.SourceSet;
            DcTable targetTable = mapping.TargetSet;

            foreach (DcColumn sourceColumn in sourceTable.Columns)
            {
                if (sourceColumn.IsSuper)
                {
                    continue;
                }
                if (!sourceColumn.IsPrimitive)
                {
                    continue;
                }
                if (sourceColumn == Column)
                {
                    continue;                         // Do not include the generating/projection column
                }
                ColumnMappingEntry entry = new ColumnMappingEntry(sourceColumn);

                PathMatch match = mapping.GetMatchForSource(new DimPath(sourceColumn));

                if (match != null)
                {
                    entry.Target     = match.TargetPath.FirstSegment;
                    entry.TargetType = entry.Target.Output;

                    entry.IsKey = entry.Target.IsKey;

                    entry.IsMatched = true;
                }
                else
                {
                    entry.Target     = null;
                    entry.TargetType = null;

                    if (IsImport)
                    {
                        entry.IsKey = false;
                    }
                    else
                    {
                        entry.IsKey = true;
                    }

                    entry.IsMatched = false;
                }

                Entries.Add(entry);
            }
        }
Esempio n. 4
0
        private static bool TryMatch(string path, PathPatterns pathPatterns, out PathMatch match)
        {
            var ignoreCache = pathPatterns.IgnoreCache;

            // Try first to get a previously match from the cache
            lock (ignoreCache)
            {
                return(ignoreCache.TryGetValue(path, out match));
            }
        }
        public void Matches_CallsMatchesOnFirstDefinitionStep()
        {
            var definitionStep = new StepDefinitionMock(PathMatch.Succeed(0));
            var definition     = PathDefinition.Empty.Append(definitionStep);

            definition.Matches(Path.Empty);

            Assert.AreEqual(
                1,
                definitionStep.InvocationCount,
                "The PathDefinition did not call the first PathDefinitionStep."
                );
        }
Esempio n. 6
0
        /// <summary>
        /// Primary: does not do anything (or calls the same method of the secondary tree).
        /// Secondary: takes the currently selected primary node and this secondary node and adds this match to the list. Previous match is deleted. Contradictory matches are removed. Match status of nodes needs to be redrawn.
        /// </summary>
        public PathMatch AddMatch()
        {
            if (SourceTree.SelectedPath == null || TargetTree.SelectedPath == null)
            {
                return(null);
            }

            PathMatch match = new PathMatch(SourceTree.SelectedPath, TargetTree.SelectedPath, 1.0);

            Mapping.AddMatch(match); // Some existing matches (which contradict to the added one) will be removed

            return(match);
        }
Esempio n. 7
0
            private static PathDefinitionStep CreateStepStub(bool success, int matchLength = 0)
            {
                var mock = new Mock <PathDefinitionStep>();

                var result = success ?
                             PathMatch.Succeed(matchLength) :
                             PathMatch.Fail(matchLength);

                mock
                .Setup(x => x.Matches(It.IsAny <PathDefinitionIterator>(), It.IsAny <PathIterator>()))
                .Returns(result);

                return(mock.Object);
            }
        public void Matches_CallingMatchesNextOnPassedIteratorCallsNext()
        {
            var firstDefinitionStep  = new StepDefinitionMock(PathMatch.Succeed(0));
            var secondDefinitionStep = new StepDefinitionMock(PathMatch.Succeed(0));

            var definition = PathDefinition.Empty
                             .Append(firstDefinitionStep)
                             .Append(secondDefinitionStep);

            definition.Matches(Path.Empty);
            Assert.AreEqual(0, secondDefinitionStep.InvocationCount);

            firstDefinitionStep.DefinitionIterator.MatchesNext(Path.Empty.GetIterator());
            Assert.AreEqual(1, secondDefinitionStep.InvocationCount);
        }
        public void Matches_PassesPathIteratorAtFirstElementToFirstDefinitionStep()
        {
            var firstPathStep = new ViewModelStub();
            var path          = Path.Empty.Append(firstPathStep);

            var definitionStep = new StepDefinitionMock(PathMatch.Succeed(0));
            var definition     = PathDefinition.Empty.Append(definitionStep);

            definition.Matches(path);

            Assert.AreEqual(
                firstPathStep,
                definitionStep.PathIterator.ViewModel,
                "The PathIterator was not positioned at the first step."
                );
        }
Esempio n. 10
0
        private static void Match(string path, PathPatterns pathPatterns, ref PathMatch match)
        {
            var ignoreCache = pathPatterns.IgnoreCache;

            foreach (var pathPattern in pathPatterns)
            {
                if (pathPattern.Ignore.IsPathIgnored(path))
                {
                    match = new PathMatch(true, pathPattern);
                    break;
                }
            }
            lock (ignoreCache)
            {
                ignoreCache.Add(path, match);
            }
        }
Esempio n. 11
0
 public async Task Run(IOwinContext context, PathMatch match)
 {
     using (Container.BeginExecutionContextScope())
     {
         try
         {
             var cancellationToken = new CancellationToken();
             var currentContext    = Container.GetInstance <ICurrentContext>();
             currentContext.Setup(context, this);
             await match.Path.Invoke(match.PathParts, currentContext, cancellationToken);
         }
         catch (Exception e)
         {
             Console.Error.Write(e.ToString());
             throw;
         }
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Does this entry match the request
        /// </summary>
        /// <param name="request">The request</param>
        /// <returns>True if it matches</returns>
        public bool IsMatch(HttpRequestHeader request)
        {
            bool ret = true;

            if (request != null)
            {
                if (!PathMatch.IsMatch(request.Path))
                {
                    ret = false;
                }

                if (MethodMatch.IsMatch(request.Method))
                {
                    ret = false;
                }
            }

            return(ret);
        }
Esempio n. 13
0
        public static string[] Search(string Input, Parser a, int Level = 3)
        {
            PathMatch              Pm      = GetPathMatch(Input);
            Regex                  Re      = GenericRegex(Pm.Match, a);
            DirectoryInfo          Dir     = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, Pm.Path));
            HashSet <string>       Results = new HashSet <string>();
            Action <DirectoryInfo> Recur   = null;

            Recur = (d) =>
            {
                try
                {
                    foreach (FileInfo Entry in d.GetFiles())
                    {
                        if (Re.IsMatch(Entry.Name))
                        {
                            Results.Add(Entry.FullName);
                            Terminal.CWriteLine("$a{0}", Entry.FullName);
                        }
                    }
                }
                catch (Exception) { }
                try
                {
                    foreach (DirectoryInfo Entry in d.GetDirectories())
                    {
                        if (Re.IsMatch(Entry.Name))
                        {
                            Results.Add(Entry.FullName);
                            Terminal.CWriteLine("$a{0}", Entry.FullName);
                        }
                        Recur(Entry);
                    }
                }
                catch (Exception) { }
            };
            Recur(Dir);
            return(Results.ToArray());
        }
Esempio n. 14
0
        public bool IsMatchedTarget(ColumnPath path)
        {
            PathMatch match = Mapping.GetMatchForTarget(path);

            if (match == null)
            {
                return(false);
            }

            if (TargetTree.IsPrimary)
            {
                return(true);
            }
            else
            {
                if (SourceTree.SelectedPath == null)
                {
                    return(false);
                }
                return(match.MatchesSource(SourceTree.SelectedPath));
            }
        }
Esempio n. 15
0
 public JsonParse(string match, string extentId = null)
 {
     pathStack      = new PathStack();
     this.pathMatch = new PathMatch(match);
     this.extentId  = extentId;
 }
Esempio n. 16
0
        private void OkCommand_Executed(object state)
        {
            Mapping mapping;

            if (IsNew)
            {
                mapping = new Mapping(Column.Input, Column.Output);
            }
            else
            {
                mapping = Column.Definition.Mapping;
            }

            // For each entry decide what to do with the corresponding 1. match in the mapping 2. target column, depending on the comparision with the existing 1. match, target column
            foreach (var entry in SourceColumnEntries)
            {
                DcColumn sourceColumn = entry.Source;

                PathMatch match = mapping.GetMatchForSource(new DimPath(sourceColumn));

                DcColumn targetColumn;

                if (entry.IsMatched && match == null) // Newly added. Creation
                {
                    DcTable targetType       = entry.TargetType;
                    string  targetColumnName = sourceColumn.Name;
                    targetColumn = TargetSchema.CreateColumn(targetColumnName, Column.Output, targetType, entry.IsKey);
                    targetColumn.Add();

                    mapping.AddMatch(new PathMatch(new DimPath(sourceColumn), new DimPath(targetColumn)));
                }
                else if (!entry.IsMatched && match != null) // Newly removed. Deletion.
                {
                    targetColumn = match.TargetPath.FirstSegment;
                    targetColumn.Remove();

                    mapping.RemoveMatch(match.SourcePath, match.TargetPath);
                }
                else if (entry.IsMatched) // Remains included. Update properties (name, key, type etc.)
                {
                    targetColumn = match.TargetPath.FirstSegment;
                    if (targetColumn.Output != entry.TargetType) // Type has been changed
                    {
                        targetColumn.Remove();
                        targetColumn.Output = entry.TargetType;
                        targetColumn.Add();
                    }
                }
                else // Remains excluded
                {
                }
            }

            Column.Name        = NewColumnName;
            Column.Output.Name = NewTableName;

            if (IsNew)
            {
                Column.Definition.DefinitionType = DcColumnDefinitionType.LINK;
                Column.Definition.Mapping        = mapping;
                Column.Definition.IsAppendData   = true;
                Column.Add();

                Column.Output.Definition.DefinitionType = DcTableDefinitionType.PROJECTION;
                TargetSchema.AddTable(Column.Output, null, null);
            }

            this.DialogResult = true;
        }
Esempio n. 17
0
        private void Initialize() // Initialize dialog after context change (source table or column)
        {
            NewTableName = Column.Output.Name;

            NewColumnName = Column.Name;

            SourceColumnEntries.Clear();

            if (Column.Input == null)
            {
                return; // Empty list if no source table
            }

            // Find a mapping
            Mapping mapping;

            if (IsNew)
            {
                if (Column.Definition.Mapping != null)
                {
                    mapping = Column.Definition.Mapping;
                }
                else
                {
                    Mapper mapper = new Mapper();
                    mapping = mapper.CreatePrimitive(Column.Input, Column.Output, TargetSchema); // Complete mapping (all to all)
                }
            }
            else // Edit
            {
                mapping = Column.Definition.Mapping;
                if (mapping == null)
                {
                    mapping = new Mapping(Column.Input, Column.Output);
                }
            }

            // Initialize a list of entries

            List <DcTable> targetTypes = new List <DcTable>();

            targetTypes.Add(TargetSchema.GetPrimitive("Integer"));
            targetTypes.Add(TargetSchema.GetPrimitive("Double"));
            targetTypes.Add(TargetSchema.GetPrimitive("String"));

            foreach (DcColumn sourceColumn in mapping.SourceSet.Columns)
            {
                if (sourceColumn.IsSuper)
                {
                    continue;
                }
                if (!sourceColumn.IsPrimitive)
                {
                    continue;
                }
                if (sourceColumn == Column)
                {
                    continue;                         // Do not include the generating/projection column
                }
                ImportMappingEntry entry = new ImportMappingEntry(sourceColumn);

                PathMatch match = mapping.GetMatchForSource(new DimPath(sourceColumn));

                entry.TargetTypes = targetTypes;

                if (match != null)
                {
                    entry.Target    = match.TargetPath.FirstSegment;
                    entry.IsMatched = true;
                    entry.IsKey     = entry.Target.IsKey;

                    entry.TargetType = entry.Target.Output;
                }
                else
                {
                    entry.Target    = null;
                    entry.IsMatched = false;

                    entry.IsKey = false;

                    // Recommend a type
                    if (sourceColumn.Output.Name == "Integer")
                    {
                        entry.TargetType = TargetSchema.GetPrimitive("Integer");
                    }
                    else if (sourceColumn.Output.Name == "Double")
                    {
                        entry.TargetType = TargetSchema.GetPrimitive("Double");
                    }
                    else if (sourceColumn.Output.Name == "String")
                    {
                        entry.TargetType = TargetSchema.GetPrimitive("String");
                    }
                }

                SourceColumnEntries.Add(entry);
            }
        }
 public StepDefinitionMock(PathMatch result)
 {
     Result = result;
 }
Esempio n. 19
0
        private void DirectMatch(SimpleCommit commit, TreeEntry entry, bool keepOnIgnore, ref PathMatch match)
        {
            // If callback return false, then we don't update entries to keep or delete
            SimpleEntry simpleEntry;
            var         pattern  = match.Pattern;
            var         callback = pattern.Callback;

            if (callback != null)
            {
                simpleEntry         = new SimpleEntry(repo, entry);
                simpleEntry.Discard = !keepOnIgnore;

                // Calls the script
                callback(repo, pattern.Path, commit, ref simpleEntry);

                // Skip if this commit is discarded by the tree filtering
                // Skip if this entry was discarded
                if (commit.Discard || (simpleEntry.Discard == keepOnIgnore))
                {
                    return;
                }
            }
            else
            {
                simpleEntry = default(SimpleEntry);
            }

            // We can update entries to keep
            lock (entriesToKeep)
            {
                if (keepOnIgnore)
                {
                    entriesToKeep.Add(entry, simpleEntry.NewEntryValue);
                }
                else
                {
                    entriesToKeep.Remove(entry);
                }
            }
        }
Esempio n. 20
0
        private void OkCommand_Executed(object state)
        {
            Mapping mapping;

            if (IsNew)
            {
                mapping = new Mapping(Column.Input, Column.Output);
            }
            else
            {
                mapping = Column.Definition.Mapping;
            }

            // For each entry decide what to do with the corresponding 1. match in the mapping 2. target column, depending on the comparision with the existing 1. match, target column
            foreach (var entry in Entries)
            {
                DcColumn sourceColumn = entry.Source;

                PathMatch match = mapping.GetMatchForSource(new DimPath(sourceColumn));

                DcColumn targetColumn;

                if (entry.IsMatched && match == null) // Newly added. Creation
                {
                    DcTable targetType       = entry.TargetType;
                    string  targetColumnName = sourceColumn.Name;

                    // Check if a column with this name already exists
                    targetColumn = Column.Output.GetColumn(targetColumnName);
                    if (targetColumn != null)
                    {
                        targetColumn.Output = targetType; // Alternatively, we can remove it and create a new column below
                    }

                    if (targetColumn == null) // Could not reuse an existing column
                    {
                        targetColumn = SelectedTargetSchema.CreateColumn(targetColumnName, Column.Output, targetType, entry.IsKey);
                        targetColumn.Add();
                    }

                    mapping.AddMatch(new PathMatch(new DimPath(sourceColumn), new DimPath(targetColumn)));
                }
                else if (!entry.IsMatched && match != null) // Newly removed. Deletion.
                {
                    targetColumn = match.TargetPath.FirstSegment;
                    targetColumn.Remove();

                    mapping.RemoveMatch(match.SourcePath, match.TargetPath);
                }
                else if (entry.IsMatched) // Remains included. Update properties (name, key, type etc.)
                {
                    targetColumn = match.TargetPath.FirstSegment;
                    if (targetColumn.Output != entry.TargetType) // Type has been changed
                    {
                        targetColumn.Remove();
                        targetColumn.Output = entry.TargetType;
                        targetColumn.Add();
                    }
                }
                else // Remains excluded
                {
                }
            }

            Column.Name = ColumnName;
            //Column.Output.Name = SelectedTargetTable.Name;

            if (IsNew)
            {
                // Target table could contain original columns from previous uses (loaded from csv file or added manually). Now they are not needed.
                foreach (DcColumn targetColumn in Column.Output.Columns)
                {
                    PathMatch match = mapping.GetMatchForTarget(new DimPath(targetColumn));
                    if (match != null)
                    {
                        continue;
                    }
                    if (targetColumn.Definition.DefinitionType != DcColumnDefinitionType.FREE)
                    {
                        continue;
                    }
                    if (targetColumn.Definition.DefinitionType != DcColumnDefinitionType.ANY)
                    {
                        continue;
                    }

                    targetColumn.Remove();
                }

                // Set parameters of the new column
                Column.Definition.DefinitionType = DcColumnDefinitionType.LINK;
                Column.Definition.Mapping        = mapping;
                Column.Definition.IsAppendData   = true;

                Column.Output.Definition.DefinitionType = DcTableDefinitionType.PROJECTION;
            }

            this.DialogResult = true;
        }
 public static void AssertPath(this PathMatch match, string path)
 {
     Assert.IsTrue(match.Success, match.FailReason);
     Assert.AreEqual(path, match.Path);
 }
        public void NavigatingToUnrecognizedRouteThrows()
        {
            Resolver.Setup(x => x.MatchRouteToPath(It.IsAny <RouteValueDictionary>())).Returns(PathMatch.Failure(null, "Boogedyboo"));

            var navigator = new Navigator(Factory.Object, null, "magellan", Resolver.Object, () => NavigationService.Object);

            Assert.Throws <UnroutableRequestException>(() => navigator.Navigate(new { Foo = "bar" }));
        }