private void SetProjectItemsRefsAndNamespaces()
        {
            var namespaceRegex = new Regex(_nameSpacePattern);

            foreach (var mksProjectFile in MksProjectFiles)
            {
                var items = mksProjectFile.ProjectItems;
                foreach (var item in items)
                {
                    var walker = new CsharpFileWalker();
                    walker.ProcessFile(item.AbsoluteSourcePath);
                    if (walker.UsingsDictionary.ContainsKey(item.AbsoluteSourcePath))
                    {
                        item.References = walker.UsingsDictionary[item.AbsoluteSourcePath]
                                          .Select(c => c.ToString().Replace("using ", "").Replace(";", "")).ToArray();
                    }
                    else
                    {
                        item.References = new string[0];
                    }

                    if (walker.NameSpacesDictionary.ContainsKey(item.AbsoluteSourcePath))
                    {
                        item.NameSpaces = walker.NameSpacesDictionary[item.AbsoluteSourcePath]
                                          .Select(c => namespaceRegex.Match(c.ToString()).Groups[1].Value.Trim()).ToArray();
                        //.Select(c => c.ToString().Replace("namespace ", "").Replace(";", "")).ToArray();
                    }
                    else
                    {
                        item.NameSpaces = new string[0];
                    }
                }
            }
        }
        private void MoveFilesToCoreAndUtil(string rootTargetDirPath)
        {
            var           rootUri = new Uri(rootTargetDirPath);
            DirectoryInfo root    = new DirectoryInfo(rootTargetDirPath);
            var           subDirs = root.GetDirectories();

            foreach (var subDir in subDirs)
            {
                var rootFiles = subDir.GetFiles();

                foreach (var file in rootFiles)
                {
                    var fileUri      = new Uri(file.FullName);
                    var relativePath = rootUri.MakeRelativeUri(fileUri).ToString().Replace('/', '\\');
                    var depth        = (relativePath.SplitWithStrings("\\").Length);

                    var walker = new CsharpFileWalker();
                    walker.ProcessFile(file.FullName);
                    var refs = walker.UsingsDictionary.SelectMany(c => c.Value)
                               .Select(d => d.ToString().Replace("using ", "").Replace(";", "")).ToArray();

                    if (refs.Any(c => c.StartsWith("MKS")) == false && depth == 2)
                    {
                        var coreFileDir = subDir.CreateSubdirectory(".\\Core\\");
                        var filePath    = $"{file.DirectoryName}\\core\\{file.Name}";
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }

                        file.MoveTo(filePath);
                    }
                    else if (depth == 2)
                    {
                        var helperFileDir = subDir.CreateSubdirectory($".\\{subDir.Name}\\");
                        var filePath      = $"{file.DirectoryName}\\{subDir.Name}\\{file.Name}";
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }

                        file.MoveTo(filePath);
                    }
                }
            }
        }
Beispiel #3
0
        private void UpdateReferecesAndNameSpaces(List <MksProjectFile> mksProjectFiles)
        {
            var walker = new CsharpFileWalker();

            foreach (var mksProjectFile in mksProjectFiles)
            {
                var items = mksProjectFile.ProjectItems;
                foreach (var item in items)
                {
                    walker.ProcessFile(item.AbsoluteSourcePath);
                    if (walker.UsingsDictionary.ContainsKey(item.AbsoluteSourcePath))
                    {
                        item.References = walker.UsingsDictionary[item.AbsoluteSourcePath]?
                                          .Select(c => c.ToString().Replace("using ", "").Replace(";", "")).ToArray();
                    }
                }
            }
        }