Represents an individual scaffolding file to copy and/or transform.
Exemplo n.º 1
0
        internal static Scaffold Parse(string path)
        {
            Debug.Assert(File.Exists(path));
            XDocument document = XDocument.Load(path);
            Scaffold  scaffold = new Scaffold();

            foreach (XElement fileElement in document.Root.Elements(XName.Get("ScaffoldFile")))
            {
                ScaffoldFile scaffoldFile = new ScaffoldFile();
                scaffoldFile.Path            = GetAttribute(fileElement, "Path");
                scaffoldFile.Copy            = bool.Parse(GetAttribute(fileElement, "Copy") ?? "true");
                scaffoldFile.TargetPath      = GetAttribute(fileElement, "TargetPath");
                scaffoldFile.PathExpression  = GetAttribute(fileElement, "PathExpression");
                scaffoldFile.SourceDirectory = GetAttribute(fileElement, "SourceDirectory");

                foreach (XElement ruleElement in fileElement.Elements())
                {
                    string[]     names      = ruleElement.Name.LocalName.Split('.');
                    string       className  = string.Format("{0}.{1}", typeof(Scaffold).Namespace, names[0]);
                    string       methodName = names[1];
                    Type         type       = typeof(Scaffold).Assembly.GetType(className);
                    MethodInfo   ruleInfo   = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public);
                    ScaffoldRule rule       = Delegate.CreateDelegate(typeof(ScaffoldRule), ruleInfo) as ScaffoldRule;
                    scaffoldFile.Rules.Add(rule);
                }

                scaffold.Files.Add(scaffoldFile);
            }

            return(scaffold);
        }
Exemplo n.º 2
0
        private static List <string> GetPaths(string sourcePath, ScaffoldFile file)
        {
            List <string> paths = new List <string>();

            if (!string.IsNullOrEmpty(file.PathExpression))
            {
                foreach (string fullPath in Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories))
                {
                    string relativePath = GetRelativePath(sourcePath, fullPath);
                    if (Regex.IsMatch(relativePath, file.PathExpression))
                    {
                        paths.Add(fullPath);
                    }
                }
            }
            else
            {
                paths.Add(Path.Combine(sourcePath, file.Path));
            }

            return(paths);
        }
Exemplo n.º 3
0
        internal static Scaffold Parse(string path)
        {
            Debug.Assert(File.Exists(path));
            XDocument document = XDocument.Load(path);
            Scaffold scaffold = new Scaffold();

            foreach (XElement fileElement in document.Root.Elements(XName.Get("ScaffoldFile")))
            {
                ScaffoldFile scaffoldFile = new ScaffoldFile();
                scaffoldFile.Path = GetAttribute(fileElement, "Path");
                scaffoldFile.Copy = bool.Parse(GetAttribute(fileElement, "Copy") ?? "true");
                scaffoldFile.TargetPath = GetAttribute(fileElement, "TargetPath");
                scaffoldFile.PathExpression = GetAttribute(fileElement, "PathExpression");
                scaffoldFile.SourceDirectory = GetAttribute(fileElement, "SourceDirectory");

                foreach (XElement ruleElement in fileElement.Elements())
                {
                    string[] names = ruleElement.Name.LocalName.Split('.');
                    string className = string.Format("{0}.{1}", typeof(Scaffold).Namespace, names[0]);
                    string methodName = names[1];
                    Type type = typeof(Scaffold).Assembly.GetType(className);
                    MethodInfo ruleInfo = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public);
                    ScaffoldRule rule = Delegate.CreateDelegate(typeof(ScaffoldRule), ruleInfo) as ScaffoldRule;
                    scaffoldFile.Rules.Add(rule);
                }

                scaffold.Files.Add(scaffoldFile);
            }

            return scaffold;
        }
Exemplo n.º 4
0
        private static List<string> GetPaths(string sourcePath, ScaffoldFile file)
        {
            List<string> paths = new List<string>();
            if (!string.IsNullOrEmpty(file.PathExpression))
            {
                foreach (string fullPath in Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories))
                {
                    string relativePath = GetRelativePath(sourcePath, fullPath);
                    if (Regex.IsMatch(relativePath, file.PathExpression))
                    {
                        paths.Add(fullPath);
                    }
                }
            }
            else
            {
                paths.Add(Path.Combine(sourcePath, file.Path));
            }

            return paths;
        }