private void SaveEntry(sdk_map2 map)
        {
            var id    = SDKSQLConnector.GetInstance().GetByName(sdkNameId).id;
            var ns    = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, map.namespace_map.old_namespace);
            var assem = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, map.assembly_map.old_path);

            SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id,
                                                                   map.model_identifier, map.old_classname, ns, assem);
            var entry = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, map.model_identifier);

            NSMappingSQLConnector.GetInstance().UpdateOrCreateNSMapping(ns, entry, map.namespace_map.new_namespace);
            AssemblyMappingSQLConnector.GetInstance().UpdateAssemblyMapping(assem, entry,
                                                                            map.assembly_map.new_path, map.assembly_map.name);
            SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(entry, map.new_classname);
        }
        private void ReplaceIdentifierNames()
        {
            // https://duckduckgo.com/?q=nested+selection+linq&ia=qa
            IEnumerable <IdentifierNameSyntax> identifierNames = tree.GetRoot().DescendantNodes().OfType <IdentifierNameSyntax>();

            foreach (IdentifierNameSyntax oldNameNode in identifierNames) // iterate over all identifier names in the file
            {
                if (!(oldNameNode.Parent is QualifiedNameSyntax))
                {
                    var semanticObjCreation = semanticModel.GetSymbolInfo(oldNameNode);
                    var nodeTypeInfo        = semanticModel.GetTypeInfo(oldNameNode);
                    if ((nodeTypeInfo.Type != null || oldNameNode.Parent is ObjectCreationExpressionSyntax) && semanticObjCreation.Symbol != null)
                    {
                        var oldNamespace = "";
                        for (var curNamespaceSymbol = semanticObjCreation.Symbol.ContainingNamespace; curNamespaceSymbol != null && curNamespaceSymbol.Name != "";
                             curNamespaceSymbol = curNamespaceSymbol.ContainingNamespace)
                        {
                            oldNamespace = "." + curNamespaceSymbol.Name + oldNamespace;
                        }
                        if (oldNamespace != "")
                        {
                            oldNamespace = oldNamespace.Substring(1);
                        }
                        String   oldClassname = semanticObjCreation.Symbol.Name.ToString();
                        sdk_map2 sdkMap       = SDKMappingSQLConnector.GetInstance().GetSDKMapFromClassAndNamespace(TransformProject.sdkId, oldNamespace, oldClassname);
                        if (sdkMap != null)
                        {
                            String newClassname = sdkMap.new_classname;
                            if (newClassname != null)
                            {
                                SyntaxToken          oldNameToken = oldNameNode.DescendantTokens().First();
                                SyntaxToken          name         = Identifier(newClassname).WithTriviaFrom(oldNameToken);
                                IdentifierNameSyntax newNameNode  = oldNameNode.WithIdentifier(name);
                                documentEditor.ReplaceNode(oldNameNode, newNameNode);
                            }
                            else
                            {
                                Console.WriteLine("Missing new class name for old class " + oldNamespace + "." + oldClassname);
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public void TestNSMappingSQLConnectorUpdateOrCreateNSMapping()
        {
            var mapA = instance.GetOrCreateOldNSMap(id, "space");
            var mapB = instance.GetOrCreateOldNSMap(id, "space");

            var asMap = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(id, "path");

            SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "A", "A", mapA, asMap);
            var targetA = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "A");

            SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "B", "B", mapB, asMap);
            var targetB = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "B");

            instance.UpdateOrCreateNSMapping(mapA, targetA, "spaceNew");
            SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetA, "A");
            var newA       = instance.GetNamespaceMapsFromOldNamespace(id, "space").First(x => x.id == targetA.namespace_map_id);
            var expectNewA = new namespace_map
            {
                old_namespace = "space",
                sdk_id        = id,
                new_namespace = "spaceNew"
            };

            AssertAditional.NamespaceMapEquals(expectNewA, newA, "issue on update");

            instance.UpdateOrCreateNSMapping(mapB, targetB, "spaceNew2");
            SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetB, "B");
            var newB       = instance.GetNamespaceMapsFromOldNamespace(id, "space").First(x => x.new_namespace == "spaceNew2");
            var expectNewB = new namespace_map
            {
                old_namespace = "space",
                sdk_id        = id,
                new_namespace = "spaceNew2"
            };

            AssertAditional.NamespaceMapEquals(expectNewB, newB, "issue on splitting");
            AssertAditional.NamespaceMapEquals(expectNewA, newA, "impropper modification of A");
        }
Example #4
0
        public void DoStuff(string dllPath, bool isOld, int sdkId)
        {
            var    assem         = Assembly.LoadFrom(dllPath);
            string assemFullName = assem.FullName;

            Console.WriteLine("Read from   " + dllPath);

            var types = assem.GetTypes(); // the types will tell you if there are custom data attributes

            foreach (var type in types)   // itereate over old dll to find custom attributes
            {
                foreach (var attr in type.CustomAttributes)
                {
                    if (attr.AttributeType.Name.Equals(ReadProject.CustomAttributeName))
                    {
                        string modelIdentifier = (string)attr.ConstructorArguments.First().Value;
                        if (isOld)
                        {
                            namespace_map nsMap = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(sdkId, type.Namespace);
                            assembly_map  asMap = AssemblyMappingSQLConnector.GetInstance().GetOrCreateOldAssemblyMap(sdkId, dllPath);
                            SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(sdkId, modelIdentifier, type.Name, nsMap, asMap);
                        }
                        else
                        {
                            sdk_map2 sdkMap = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(sdkId, modelIdentifier);
                            if (sdkMap != null)
                            {
                                NSMappingSQLConnector.GetInstance().UpdateOrCreateNSMapping(sdkMap.namespace_map, sdkMap, type.Namespace);
                                AssemblyMappingSQLConnector.GetInstance().UpdateAssemblyMapping(sdkMap.assembly_map, sdkMap, dllPath, assemFullName);
                                SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(sdkMap, type.Name);
                            }
                        }
                    }
                }
            }
        }