Esempio n. 1
0
        public void TestAssemblyMappingSQLConnectorGetAllNewDllPathsWithFullNameTest()
        {
            var nsMap = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "A");

            AssertAditional.DictionaryEquals(new Dictionary <string, string> {
            },
                                             instance.GetAllNewDllPathsWithFullName(id), "initial value");

            var mapA = instance.GetOrCreateOldAssemblyMap(id, "path");

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

            AssertAditional.DictionaryEquals(new Dictionary <string, string> {
            },
                                             instance.GetAllNewDllPathsWithFullName(id), "null entry");

            var mapB = instance.GetOrCreateOldAssemblyMap(id, "path2");

            SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "B", "B", nsMap, mapA);
            var targetB = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "B");

            instance.UpdateAssemblyMapping(mapB, targetB, "pathNew", "name");
            SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetB, "B");
            AssertAditional.DictionaryEquals(new Dictionary <string, string> {
                { "pathNew", "name" }
            },
                                             instance.GetAllNewDllPathsWithFullName(id), "first entry");

            var mapC = instance.GetOrCreateOldAssemblyMap(id, "path3");
            var mapD = instance.GetOrCreateOldAssemblyMap(id, "path3");

            SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "C", "C", nsMap, mapA);
            var targetC = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "C");

            SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "D", "D", nsMap, mapA);
            var targetD = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "D");

            instance.UpdateAssemblyMapping(mapC, targetC, "pathNew2", "name2");
            instance.UpdateAssemblyMapping(mapD, targetD, "pathNew3", "name3");
            SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetB, "C");
            SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetB, "D");
            AssertAditional.DictionaryEquals(new Dictionary <string, string> {
                { "pathNew", "name" }, { "pathNew2", "name2" },
                { "pathNew3", "name3" }
            }, instance.GetAllNewDllPathsWithFullName(id), "repeat old name");

            var mapE = instance.GetOrCreateOldAssemblyMap(id, "path4");

            SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "E", "E", nsMap, mapA);
            var targetE = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "E");

            instance.UpdateAssemblyMapping(mapE, targetE, "pathNew", "name");
            SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetB, "E");
            AssertAditional.DictionaryEquals(new Dictionary <string, string> {
                { "pathNew", "name" }, { "pathNew2", "name2" },
                { "pathNew3", "name3" }
            }, instance.GetAllNewDllPathsWithFullName(id), "dupplicate new entry");
        }
Esempio n. 2
0
        // add <Reference> tags to the new sdk
        private void AddNewDllReferences(string csprojFilePath, string hintPathRoot, string newRelativeOutputPath, string xmlElementHintPathName, string xmlElementReferenceName, XNamespace ns, XDocument xdoc)
        {
            asMappingConnector.GetAllNewDllPaths(sdkId);

            var elements = asMappingConnector.GetAllNewDllPathsWithFullName(sdkId);

            string originalCurrentWorkingDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(new FileInfo(csprojFilePath).DirectoryName);

            // find the common path
            string commonPath = GetLongestCommonPrefix(new string[] { Path.GetFullPath(hintPathRoot), elements.ElementAt(0).Key });

            // From stackoverflow: "Then you may need to cut the prefix on the right hand"
            string[] commonPathSplit = commonPath.Split('\\');
            commonPathSplit.SetValue("", commonPathSplit.Length - 1);
            commonPath = String.Join("\\", commonPathSplit);

            // find how many folders up the common path is from the hintpath root
            // number of relative paths
            string[] hintSplit = Path.GetFullPath(csprojFilePath).Split('\\');
            int      numberOfRelativePathsDifference = hintSplit.Length - commonPathSplit.Length;

            // create relative path
            string prependedRelativePath = "";

            for (int i = 0; i < numberOfRelativePathsDifference; i++)
            {
                prependedRelativePath += "..\\";
            }

            Directory.SetCurrentDirectory(originalCurrentWorkingDirectory);

            foreach (var element in elements)
            {
                // new hint path = number of relative paths + (new path - common path)
                string hintpathRightSide = element.Key.Substring(commonPath.Length);
                string hintpath          = prependedRelativePath + hintpathRightSide;

                // create new reference element
                XElement addedref = new XElement(ns + xmlElementReferenceName,
                                                 new XAttribute("Include", element.Value),
                                                 new XElement(ns + "SpecificVersion", "False"),
                                                 new XElement(ns + xmlElementHintPathName, hintpath),
                                                 new XElement(ns + "Private", "False")
                                                 );
                // add the element to the xml
                xdoc.Descendants(ns + "ItemGroup").First().AddFirst(addedref);
            }
        }