Exemplo n.º 1
0
        private List <string> RecursiveAddRegisterUseCase(IEnumerable <string> source, List <string> acc)
        {
            var(front, middle, rear) = TextSplitter.DivideIntoThree(
                source,
                line => line.TrimStart().StartsWith("#region"),
                line => line.TrimStart().StartsWith("#endregion")
                );

            IEnumerable <string> changedMiddle = middle;
            var middleHead = middle.FirstOrDefault();
            var isTarget   = middleHead != null && middleHead.Contains(controllerName);

            if (isTarget)
            {
                changedMiddle = InvokeAddRegisterUseCase(middle);
            }
            acc.AddRange(front.Concat(changedMiddle));
            if (rear.Any())
            {
                return(RecursiveAddRegisterUseCase(rear, acc));
            }
            else
            {
                return(acc);
            }
        }
Exemplo n.º 2
0
        public void Run()
        {
            var file = Path.Combine(
                param.WebProjectDirectoryFullPath,
                "ClArc",
                "DI",
                OnLauncherFileName()
                );
            var lines = File.ReadAllLines(file);

            var(front, middle, after) = TextSplitter.DivideIntoThree(
                lines,
                line => line.TrimStart().StartsWith("#region ClArc START"),
                line => line.TrimStart().StartsWith("#endregion ClArc END"),
                false
                );

            var adjustedFront = AddUsing(front);
            IEnumerable <string> newMiddle;

            if (middle.Any(x => x.TrimStart().StartsWith($"#region {param.ControllerName}")))
            {
                var usecaseLines = CreateAddedUsecaseLines(middle);
                newMiddle = usecaseLines;
            }
            else
            {
                var appendAfterMiddle = new List <string>
                {
                    "",
                    $"{Indent}#region {param.ControllerName}",
                    _registerUsecaseText(),
                    $"{Indent}#endregion"
                };
                newMiddle = middle.Concat(appendAfterMiddle);
            }
            var splitedMiddles = TextSplitter.Divide(newMiddle, x => x.Contains("#region"), false, true);
            var middles        = splitedMiddles.OrderBy(x => x.First()).Select(x => x.Where(text => !string.IsNullOrWhiteSpace(text)));
            var newMids        = TextJoiner.Join(middles, "");

            var result = adjustedFront.Concat(newMids).Concat(after);

            File.WriteAllLines(file, result, Encoding.UTF8);
        }
Exemplo n.º 3
0
        private IEnumerable <string> InvokeAddRegisterUseCase(IEnumerable <string> source)
        {
            var(front, middle, rear) = TextSplitter.DivideIntoThree(
                source,
                line => line.TrimStart().StartsWith("#region"),
                line => line.TrimStart().StartsWith("#endregion"),
                false
                );
            var prefix = controllerName + actionName;
            var reg    = new Regex(@"<(?<request>.*),(?<usecaseInterface>.*),(?<usecaseImplements>.*)>");
            var hit    = false;

            foreach (var m in middle)
            {
                var matched = reg.Match(m);
                if (matched.Success)
                {
                    var request = matched.Groups["request"].Value;
                    if (request.StartsWith(prefix))
                    {
                        hit = true;
                    }
                }
            }

            if (hit)
            {
                return(source);
            }
            else
            {
                var addedMiddle = new List <string>(middle)
                {
                    _registerUsecaseText()
                };
                addedMiddle.Sort();
                return(front
                       .Concat(addedMiddle)
                       .Concat(rear));
            }
        }