Beispiel #1
0
        public void TestNSMappingSQLConnectorGetAllNamespaces()
        {
            AssertAditional.SetEquals(new HashSet <string> {
            }, instance.GetAllNamespaces(id), "initial value");

            var mapA = instance.GetOrCreateOldNSMap(id, "space");
            var mapB = instance.GetOrCreateOldNSMap(id, "space");

            AssertAditional.SetEquals(new HashSet <string> {
                "space"
            }, instance.GetAllNamespaces(id), "added entry");

            var mapC = instance.GetOrCreateOldNSMap(id, "space2");

            AssertAditional.SetEquals(new HashSet <string> {
                "space", "space2"
            },
                                      instance.GetAllNamespaces(id), "added second entry");

            var targetSdkMap = new sdk_map2();

            instance.UpdateOrCreateNSMapping(mapA, targetSdkMap, "spaceNew");
            instance.UpdateOrCreateNSMapping(mapA, targetSdkMap, "spaceNew2");
            AssertAditional.SetEquals(new HashSet <string> {
                "space", "space2"
            },
                                      instance.GetAllNamespaces(id), "split first entry");
        }
Beispiel #2
0
        public void ProcessProject(string[] args)
        {
            Helper.verifyFileExists(args[0]);
            var filePath = args[0];

            if (filePath.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase))
            {
                // put all changes in new project folder
                // create copies of the project so don't have to overwrite the original files
                string projectParentFolder = new FileInfo(filePath).DirectoryName;
                string transformed_folder  = projectParentFolder + "_transformed";
                Console.WriteLine("Copying project directory");
                Console.WriteLine("Removing the old transformed directory before copying contents");
                CopyDirectory(transformed_folder, projectParentFolder);
                Console.WriteLine("Begin transforming files");

                // Proccess the project here
                Project          proj         = MSBuildWorkspace.Create().OpenProjectAsync(filePath).Result;
                HashSet <String> namespaceSet = nsMappingConnector.GetAllNamespaces(sdkId);
                Dictionary <String, HashSet <String> > namespaceToClassnameSetMap = new Dictionary <string, HashSet <string> >();

                foreach (Document doc in proj.Documents)
                {
                    var semanticModel = doc.GetSemanticModelAsync().Result;
                    var syntaxTree    = doc.GetSyntaxTreeAsync().Result;

                    // do processing here
                    var documentEditor = DocumentEditor.CreateAsync(doc).Result;

                    if (IsDocCSharp(doc))
                    {
                        TransformFileCSharp ft = new TransformFileCSharp(documentEditor);
                        syntaxTree = ft.ReplaceSyntax();
                    }

                    if (IsDocVB(doc))
                    {
                        TransformFileVBasic ft = new TransformFileVBasic(documentEditor);
                        syntaxTree = ft.ReplaceSyntax();
                    }

                    File.WriteAllText(doc.FilePath.Replace(projectParentFolder, transformed_folder), syntaxTree.GetText().ToString());

                    Console.WriteLine("Transformed   " + doc.FilePath);
                }

                HashSet <String> olddllSet = asMappingConnector.GetAllOldDllPaths(sdkId);
                TransformXml(olddllSet, sdkId, proj.FilePath, projectParentFolder, transformed_folder, Path.GetExtension(proj.FilePath));

                Console.WriteLine("Transformed   " + proj.FilePath);
            }
            else
            {
                Console.WriteLine("first parameter must be .csproj or .vbproj");
            }
        }