Exemplo n.º 1
0
        public void TestParse__Match__ToString(string matchString, string testSting, bool result)
        {
            IStringMatcher matcher = StringMatcher.Parse(matchString);

            Assert.Equal(result, matcher.Match(testSting));

            Assert.Throws <ArgumentNullException>(delegate
            {
                matcher.Match(null);
            });

            string         otherString = matcher.ToString();
            IStringMatcher matcher2    = StringMatcher.Parse(otherString);

            Assert.Equal(result, matcher2.Match(testSting));
        }
Exemplo n.º 2
0
        private bool IsMatch(PartModule module)
        {
            if (!moduleName.Match(module.GetType().Name))
            {
                return(false);
            }

            foreach (ConfigNode.Value value in identifierNode.values)
            {
                if (value.name == "name")
                {
                    continue;
                }

                if (module.Fields[value.name] is BaseField baseField)
                {
                    IValueParser parser;
                    object       parsedValue;

                    try
                    {
                        parser = DefaultValueParseMap.Instance.GetParser(baseField.FieldInfo.FieldType);
                    }
                    catch (ParseTypeNotRegisteredException)
                    {
                        throw CannotParseFieldException.CannotFindParser(baseField.name, baseField.FieldInfo.FieldType);
                    }

                    try
                    {
                        parsedValue = parser.Parse(value.value);
                    }
                    catch (Exception ex)
                    {
                        throw CannotParseFieldException.ExceptionWhileParsing(baseField.name, baseField.FieldInfo.FieldType, ex);
                    }

                    if (!Equals(parsedValue, baseField.GetValue(module)))
                    {
                        return(false);
                    }
                }
                else if (module is CustomPartModule cpm && value.name == "moduleID")
                {
                    if (cpm.moduleID != value.value)
                    {
                        return(false);
                    }
                }
Exemplo n.º 3
0
        public Line Read()
        {
            string value;

            do
            {
                value = stringReader.Read();
                if (value == null)
                {
                    return(null);
                }
                index++;
            } while (discardMatcher.Match(value));

            return(new Line()
            {
                Value = value, Index = index - 1
            });
        }
Exemplo n.º 4
0
        public Log Read()
        {
            Log log;

            if (previousLine == null)
            {
                previousLine = lineReader.Read();
            }
            if (previousLine == null)
            {
                return(null);
            }

            do
            {
                log = new Log();
                log.Lines.Add(previousLine);

                while (true)
                {
                    previousLine = lineReader.Read();
                    if (previousLine == null)
                    {
                        break;
                    }
                    if (logPrefixMatcher.Match(previousLine.Value))
                    {
                        break;
                    }
                    log.Lines.Add(previousLine);
                }

                if (discardLogMatcher.Match(log.ToSingleLine()))
                {
                    log = null;                         // me must restart loading of a new log
                }
            } while ((previousLine != null) && (log == null));

            return(log);
        }
Exemplo n.º 5
0
        private void Parse(FileInfo fileInfo)
        {
            string line;

            using (var streamReader = new StreamReader(fileInfo.FullName))
            {
                while ((line = streamReader.ReadLine()) != null)
                {
                    if (_matcher.Match(line))
                    {
                        var result = new CrawlerResult()
                        {
                            FileName     = fileInfo.Name,
                            Extension    = fileInfo.Extension,
                            MatchContent = line,
                            Path         = fileInfo.FullName
                        };

                        _parser.parse(result);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public IEnumerable <IPartModifier> CreatePartModifiers(Part part, ILinearScaleProvider linearScaleProvider, Action <string> onError)
        {
            AttachNode node = part.attachNodes.FirstOrDefault(n => (n.nodeType == AttachNode.NodeType.Stack || n.nodeType == AttachNode.NodeType.Dock) && nodeID.Match(n.id));

            if (node == null)
            {
                onError($"Attach node with id matching '{nodeID}' not found for attach node modifier");
                yield break;
            }

            // Explanation
            // Config has scale and rescaleFactor which both multiply node positions, but doesn't store scale directly
            // Instead it stores scaleFactor which is scale / rescaleFactor
            // So we have to multiply by rescaleFactor again to get it back
            // Use the prefab since TweakScale modifies rescaleFactor
            Part  maybePrefab = part.partInfo?.partPrefab ?? part;
            float fixedScale  = maybePrefab.scaleFactor * maybePrefab.rescaleFactor * maybePrefab.rescaleFactor;

            if (position != null)
            {
                yield return(new AttachNodeMover(node, position.Value * fixedScale, linearScaleProvider));
            }
            if (size != null)
            {
                yield return(new AttachNodeSizeModifier(node, size.Value, linearScaleProvider));
            }
        }
Exemplo n.º 7
0
        public IEnumerable <IPartModifier> CreatePartModifiers(Part part, Action <string> onError)
        {
            part.ThrowIfNullArgument(nameof(part));
            onError.ThrowIfNullArgument(nameof(onError));

            if (transformName == null)
            {
                onError("transform name is null");
                yield break;
            }

            bool foundTransform = false;

            foreach (Transform transform in part.GetModelRoot().TraverseHierarchy().Where(t => transformName.Match(t.name)))
            {
                foundTransform = true;

                if (positionOffset.HasValue)
                {
                    yield return(new TransformMover(transform, positionOffset.Value));
                }
                if (rotationOffset.HasValue)
                {
                    yield return(new TransformRotator(transform, Quaternion.Euler(rotationOffset.Value)));
                }
                if (scaleOffset.HasValue)
                {
                    yield return(new TransformScaleModifier(transform, scaleOffset.Value));
                }
            }

            if (!foundTransform)
            {
                onError($"Could not find any transform named '{transformName}'");
            }
        }