Exemplo n.º 1
0
 public MooseImporter()
 {
     _repository  = FamixModel.Metamodel();
     ignoreFolder = "";
     this.InitializeForImport();
 }
Exemplo n.º 2
0
        private static void ExportToMSE(string input, string output)
        {
            try
            {
                string path = Assembly.GetAssembly(typeof(MainClass)).Location;
                Console.WriteLine("Current executable location " + path);
                path = path.Replace("RoslynMonoFamix.exe", "");

                var metamodel = FamixModel.Metamodel();

                var msWorkspace = MSBuildWorkspace.Create();

                var solution = msWorkspace.OpenSolutionAsync(input).Result;
                Uri uri      = null;
                try
                {
                    uri = new Uri(input);;
                }
                catch (UriFormatException e)
                {
                    var currentFolder = new Uri(Environment.CurrentDirectory + "\\");
                    uri = new Uri(currentFolder, input.Replace("\\", "/"));
                    Console.WriteLine(e.StackTrace);
                }

                var ignoreFolder = Path.GetDirectoryName(uri.AbsolutePath);
                var importer     = new InCSharp.InCSharpImporter(metamodel, ignoreFolder);
                var documents    = new List <Document>();
                Console.WriteLine("Solution with id " + solution.Id.Id + " opened and contains " + solution.Projects.Count <Project>() + " projects.");

                var diagnostics = msWorkspace.Diagnostics;
                foreach (var diagnostic in diagnostics)
                {
                    Console.WriteLine(diagnostic.Message);
                }

                for (int i = 0; i < solution.Projects.Count <Project>(); i++)
                {
                    var project = solution.Projects.ElementAt <Project>(i);

                    System.Console.WriteLine("(project " + (i + 1) + " / " + solution.Projects.Count <Project>() + ") contains " + project.Documents.Count <Document>() + " documents.");

                    var projectCompilation = project.GetCompilationAsync().Result;
                    for (int j = 0; j < project.Documents.Count <Document>(); j++)
                    {
                        var document = project.Documents.ElementAt <Document>(j);
                        if (document.SupportsSyntaxTree)
                        {
                            System.Console.Write("(project " + (i + 1) + " / " + solution.Projects.Count <Project>() + ")");
                            System.Console.WriteLine("(document " + (j + 1) + " / " + project.Documents.Count <Document>() + " " + document.FilePath + ")");
                            var syntaxTree = document.GetSyntaxTreeAsync().Result;

                            var compilationAsync = project.GetCompilationAsync().Result;
                            var semanticModel    = compilationAsync.GetSemanticModel(syntaxTree);

                            semanticModel.ToString();

                            if (semanticModel.Language == "C#")
                            {
                                var visitor = new ASTVisitor(semanticModel, importer);
                                visitor.Visit(syntaxTree.GetRoot());
                            }
                            else
                            {
                                var visitor = new VBASTVisitor(semanticModel, importer);
                                visitor.Visit(syntaxTree.GetRoot());
                            }
                        }
                    }
                }
                metamodel.ExportMSEFile(output);
            }
            catch (ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (System.Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                Console.WriteLine(errorMessage);
                //Display or log the error based on your application.
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                //The code that causes the error goes here.

                ValidateArgs(args);//validates arguments
                string path = Assembly.GetAssembly(typeof(MainClass)).Location;
                Console.WriteLine("Current executable location" + path);
                path = path.Replace("RoslynMonoFamix.exe", "");
                string solutionPath = args[0];

                var metamodel = FamixModel.Metamodel();

                var msWorkspace = MSBuildWorkspace.Create();

                var solution = msWorkspace.OpenSolutionAsync(solutionPath).Result;
                Uri uri      = null;
                try
                {
                    uri = new Uri(solutionPath);;
                }
                catch (UriFormatException e)
                {
                    var currentFolder = new Uri(Environment.CurrentDirectory + "\\");
                    uri = new Uri(currentFolder, solutionPath.Replace("\\", "/"));
                    Console.WriteLine(e.StackTrace);
                }

                var ignoreFolder = Path.GetDirectoryName(uri.AbsolutePath);

                var importer  = new InCSharp.InCSharpImporter(metamodel, ignoreFolder);
                var documents = new List <Document>();

                for (int i = 0; i < solution.Projects.Count <Project>(); i++)
                {
                    var project = solution.Projects.ElementAt <Project>(i);

                    for (int j = 0; j < project.Documents.Count <Document>(); j++)
                    {
                        var document = project.Documents.ElementAt <Document>(j);
                        if (document.SupportsSyntaxTree)
                        {
                            System.Console.Write("(project " + (i + 1) + " / " + solution.Projects.Count <Project>() + ")");
                            System.Console.WriteLine("(document " + (j + 1) + " / " + project.Documents.Count <Document>() + " " + document.FilePath + ")");
                            var syntaxTree = document.GetSyntaxTreeAsync().Result;


                            var compilationAsync = project.GetCompilationAsync().Result;
                            var semanticModel    = compilationAsync.GetSemanticModel(syntaxTree);
                            var visitor          = new ASTVisitor(semanticModel, importer);
                            visitor.Visit(syntaxTree.GetRoot());
                        }
                    }
                }

                metamodel.ExportMSEFile(args[1]);
            }
            catch (ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (System.Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                Console.WriteLine(errorMessage);
                //Display or log the error based on your application.
            }
        }