public static Dictionary<string, string> queryParameters_Indexed_ByName(this Uri uri)
 {
     var queryParameters = new Dictionary<string,string>();
     if (uri.notNull())
     {
         var query = uri.Query;
         if (query.starts("?"))
             query = query.removeFirstChar();
         foreach(var parameter in query.split("&"))
             if (parameter.valid())
             {
                 var splitParameter = parameter.split("=");
                 if (splitParameter.size()==2)
                     if (queryParameters.hasKey(splitParameter[0]))
                     {
                         "duplicate parameter key in property '{0}', adding extra parameter in a new line".info(splitParameter[0]);
                         queryParameters.add(splitParameter[0], queryParameters[splitParameter[0]].line() + splitParameter[1]);
                     }
                     else
                         queryParameters.add(splitParameter[0], splitParameter[1]);
                 else
                     "Something's wrong with the parameter value, there should only be one = in there: '{0}' ".info(parameter);
             }
     }
     return queryParameters;
 }
        public void Test_getFolders()
        {
            //var guidanceExplorers = TM_Xml_Database.loadGuidanceExplorerObjects();
            var libraryId = TM_Xml_Database.GuidanceExplorers_XmlFormat.Keys.first();
            var guidanceExplorerFolders = TM_Xml_Database.GuidanceExplorers_XmlFormat[libraryId].library.libraryStructure.folder;
            Assert.That(guidanceExplorerFolders.size() > 0,"guidanceExplorerFolders was empty");

            var tmFolders = tmXmlDatabase.tmFolders(libraryId);
            Assert.IsNotNull(tmFolders,"folders");
            Assert.That(tmFolders.size() > 0,"folders was empty");
            //show.info(guidanceExplorerFolders);
            //show.info(tmFolders);
            var mappedById = new Dictionary<Guid,Folder_V3>();

            foreach(var tmFolder in tmFolders)
                mappedById.Add(tmFolder.folderId, tmFolder);

            //Add checks for sub folders
            foreach(var folder in guidanceExplorerFolders)
            {
                Assert.That(mappedById.hasKey(folder.folderId.guid()), "mappedById didn't have key: {0}".format(folder.folderId));
                var tmFolder = mappedById[folder.folderId.guid()];
                Assert.That(tmFolder.name == folder.caption);
                Assert.That(tmFolder.libraryId == libraryId, "libraryId");
            }
        }
        public static Dictionary<Guid, guidanceExplorer> addGuidanceExplorerObject(this TM_FileStorage tmFileStorage, Dictionary<Guid, guidanceExplorer> guidanceExplorers, guidanceExplorer newGuidanceExplorer, string xmlFile)
        {
            if (newGuidanceExplorer.notNull())
            {
                try
                {
                    var libraryGuid = newGuidanceExplorer.library.name.guid();

                    //check if the name is already there
                    foreach(guidanceExplorer guidanceExplorer in guidanceExplorers.Values)
                    {
                        if (guidanceExplorer.library.caption == newGuidanceExplorer.library.caption)
                        {
                            "[addGuidanceExplorerObject]: Skipping load due to duplicate Library name '{0}' was in both library {1} and {2}".error(guidanceExplorer.library.caption, guidanceExplorer.library.name,  newGuidanceExplorer.library.name);
                            return guidanceExplorers;
                        }
                    }
                    //check if the guid is already there
                    if (guidanceExplorers.hasKey(libraryGuid))
                    {
                        "[addGuidanceExplorerObject]: for {0} , duplicate LibraryID detected, assiging a new Library Id: {0}".error(newGuidanceExplorer.library.caption, libraryGuid);
                        libraryGuid = Guid.NewGuid();
                        newGuidanceExplorer.library.name = libraryGuid.str();
                        "[addGuidanceExplorerObject]: new ID for library {0} is now {1}".error(newGuidanceExplorer.library.caption, libraryGuid);
                        newGuidanceExplorer.xmlDB_Save_GuidanceExplorer(TM_Xml_Database.Current);//, false);
                    }
                    tmFileStorage.GuidanceExplorers_Paths.add(newGuidanceExplorer, xmlFile); // add this mapping so that we can find it base on name
                    guidanceExplorers.Add(libraryGuid, newGuidanceExplorer);

                }
                catch//(Exception ex)
                {
                    "[addGuidanceExplorerObject] error importing guidanceExplorer: {0}".error(newGuidanceExplorer);
                }
            }
            return guidanceExplorers;
        }
        public static GitData_Repository map_File_Commits(this GitData_Repository gitDataRepository)
        {
            var mappedSha1s = new List<string>();
            var nGit = gitDataRepository.nGit;
            var results = new List<string>();
            var mappedFiles = new Dictionary<string, GitData_File>();
            foreach(var file in gitDataRepository.files())
                mappedFiles.Add(file.FilePath, file);

            foreach(var commit in nGit.commits())
            {
                Action<TreeWalk> onTreeWalk =
                    (treeWalk)=>
                        {
                            if (mappedFiles.hasKey(treeWalk.PathString))
                            {
                                var mappedSha1 = "{0}:{1}".format(treeWalk.GetObjectId(0).sha1(),mappedFiles[treeWalk.PathString].Sha1);
                                if (mappedSha1s.contains(mappedSha1))
                                    return;
                                var fileCommit = new GitData_File_Commit
                                    {
                                        File_Sha1    = treeWalk.GetObjectId(0).sha1(),
                                        Commit_Sha1  = commit.sha1(),
                                        Author       = commit.author_Name(),
                                        When         = commit.when().toFileTimeUtc()
                                    };
                                mappedFiles[treeWalk.PathString].Commits.add(fileCommit);
                                mappedSha1s.add(mappedSha1);
                                //mappedSha1.add(file.Sha1);
                            }
                        };
                nGit.files(commit.sha1(), onTreeWalk);
            }
            return gitDataRepository;
        }
        public static Library_V3 getFolderStructure_Library(this TM_WebServices tmWebServices, Guid libraryId, TM_GUI_Objects guiObjects)
        {
            // ReSharper disable AccessToModifiedClosure
            //pre-create this mapping since the view retrieval was a massive performance bottle neck
            var allViews = new Dictionary<Guid, View_V3>();
            foreach(var view in tmWebServices.GetViews())
                if (allViews.hasKey(view.viewId))
                    "[getFolderStructure_Library] duplicate viewID: {0} from Library {0}".format(view.viewId, view.libraryId);  // this should be moved into a TM Library health check
                else
                    allViews.Add(view.viewId, view);

            Action<Folder_V3> mapFolderViews =  null;

            Func<List<Guid>, List<View_V3>> mapViews =
                (viewGuids) =>
                            {
                                var views = new List<View_V3>();

                                foreach(var viewGuid in viewGuids)
                                {
                                    var view = 	allViews[viewGuid];

                                    /*// compress view.guidanceItems using guiObjects
                                    view.guidanceItems_Indexes = (from guid in view.guidanceItems
                                                                  select guiObjects.get_Index(guid.str()).str()).toList()
                                                                  .join(",").remove(" ");
                                    view.guidanceItems.Clear();*/
                                    views.add(view);
                                }
                                return views;
                            };
            // ReSharper disable PossibleNullReferenceException
            // ReSharper disable ImplicitlyCapturedClosure
            mapFolderViews =
                (folder) => {
                                 var mappedViews = mapViews(folder.views.guids());
                                 folder.views.Clear();
                                 folder.views.add(mappedViews);
                                 foreach(var subFolder in folder.subFolders)
                                    mapFolderViews(subFolder);
                            };
            Action<List<Folder_V3>, List<Folder_V3>> mapFolders = (folders, parentFolder) =>
                {
                    foreach(var folder in folders)
                    {
                        parentFolder.add(folder);
                        mapFolderViews(folder);
                    }
                };
            Func<Guid,string, Library_V3> mapLibrary =
                (library_Id, libraryName)=> {
                                        var libraryV3 = new Library_V3
                                            {
                                                        libraryId = library_Id,
                                                        name = libraryName
                                                    };
                                        mapFolders(tmWebServices.GetFolders(library_Id), libraryV3.subFolders);
                                        libraryV3.views.add(mapViews(tmWebServices.GetViewsInLibraryRoot(libraryId).guids()));
                                        libraryV3.guidanceItems = tmWebServices.getGuidanceItemsIds_NotInViews(library_Id);
                                        return libraryV3;
                                    };

            Func<Guid,Library_V3> getLibrary_TreeStructure =
                (id)=>{
                                var tmLibrary = tmWebServices.GetLibraryById(id);
                                if (tmLibrary.isNull())
                                {
                                    "[in getLibraryFolderStructure] could not find library with id: {0}".error(id);
                                    return null;
                                }
                                return mapLibrary(id, tmLibrary.caption);
                            };
            return getLibrary_TreeStructure(libraryId);
            // ReSharper restore PossibleNullReferenceException
            // ReSharper restore ImplicitlyCapturedClosure
            // ReSharper restore AccessToModifiedClosure
        }
Example #6
0
		public static Color treeNodeColor(this string signature, Dictionary<string, Java_Method> methods_bySignature)
		{
			return methods_bySignature.hasKey(signature) 
		   				? methods_bySignature[signature].IsAbstract
		   						? Color.DarkBlue 
		   						: Color.DarkGreen
		   				: Color.DarkRed;
		}
Example #7
0
		public static TreeNode add_Implements(this TreeNode treeNode, Method_CallMapping callMapping, Dictionary<string, Method_CallMapping> callMappings , Dictionary<string, Java_Method> methods_bySignature , bool showStubTreeNode)		
		{			
			if (callMapping.Implements.size()==0)
				return treeNode;
			var implementsNode = (showStubTreeNode) 
										? treeNode.add_Node("Implements").color(Color.Gray)
										: treeNode;	
			
			implementsNode.add_Nodes(callMapping.Implements
											 	.OrderBy((implements)=>implements.Signature)
											 	.Where((implements)=>callMappings.hasKey(implements.Signature)),
									 (implements) => implements.Signature,
									 (implements) => callMappings[implements.Signature],
									 (implements) => true, //callMappings.hasMapping_ImplementedBy(implementedBy.Signature), 
									 (implements) => implements.Signature.treeNodeColor(methods_bySignature));
										   						
			return treeNode;
		}
Example #8
0
		public static TreeNode add_IsCalledBy(this TreeNode treeNode, Method_CallMapping callMapping, Dictionary<string, Method_CallMapping> callMappings , Dictionary<string, Java_Method> methods_bySignature , bool showStubTreeNode)		
		{			
			if (callMapping.IsCalledBy.size()==0)
				return treeNode;

			//var isCalledByLocations = treeNode.add_Node("_IsCalledBy_Locations");																		
			var locations = new List<MethodCall_Location>();
			foreach(var isCalledBy in callMapping.IsCalledBy)
				foreach(var atLocation in isCalledBy.AtLocations)				
				{
					atLocation.Signature = isCalledBy.Signature;		// did this so that we don't have to store/serialize the Signature here
					locations.Add(atLocation);					
				}
			locations = locations.OrderBy((atLocation)=>atLocation.Pc)
								 .OrderBy((atLocation)=>atLocation.Signature).toList();	
			
			//isCalledByLocations.add_Nodes(locations);
		
			var isCalledByToNode = (showStubTreeNode) 
										? treeNode.add_Node("IsCalledBy").color(Color.Gray)
										: treeNode;
			
			isCalledByToNode.add_Node("_IsCalledBy_Locations").color(Color.Gray)
							.add_Nodes(locations);
			
			isCalledByToNode.add_Nodes(callMapping.IsCalledBy
												  .OrderBy((calledBy)=>calledBy.Signature)
												  .Where((calledBy)=>callMappings.hasKey(calledBy.Signature)),
									   (calledBy) => calledBy.Signature,
									   (calledBy) => callMappings[calledBy.Signature],
									   (calledBy) => true, //callMappings.hasMapping_IsCalledBy(calledBy.Signature), 
									   (calledBy) => methods_bySignature.hasKey(calledBy.Signature) 
										   				? Color.DarkGreen
										   				: Color.DarkRed);
			return treeNode;
		}
		public static List<Java_Method> implementations(this Java_Method method, Dictionary<string, List<Java_Class>> classesImplementations)
		{
			var implementations = new List<Java_Method>();
			if (classesImplementations.hasKey(method.ClassName))
			{
				foreach(var _class in classesImplementations[method.ClassName])
					foreach(var implementationMethod in _class.Methods)
						if (method.SimpleSignature == implementationMethod.SimpleSignature)
						{
							implementations.Add(implementationMethod);
							break;
						}
			}
			return implementations;						
		}
        public JsTree JsTreeWithFoldersAndGuidanceItems()
        {
            // ReSharper disable JoinDeclarationAndInitializer
            var jsTree = new JsTree();
            Func<Guid, List<Folder_V3>, JsTreeNode, List<Guid>> mapFolders = null;
            Func<Guid, Guid, List<Guid>, JsTreeNode, List<Guid>> mapViews;
            // ReSharper restore JoinDeclarationAndInitializer

            //precalculate for performance reasons
            var allViews = new Dictionary<Guid, View_V3>();
            foreach(var view in GetViews())
                if (allViews.hasKey(view.viewId))
                    "[getFolderStructure_Library] duplicate viewID: {0} from Library {0}".format(view.viewId, view.libraryId);  // this should be moved into a TM Library health check
                else
                    allViews.Add(view.viewId, view);

            mapViews = (libraryId, folderId, viewIds, targetNode) =>
                {
                    var viewsId = new List<Guid>();
                    foreach(var viewId in viewIds)
                    {
                        var view = allViews[viewId];//GetViewById(viewId.str());

                        var viewNodeText =  view.viewId.str();
                        var viewNode = targetNode.add_Node(view.caption, viewNodeText);
                        //viewNode.state = "closed";   // views don't need this
                        viewNode.data.icon = "/Images/ViewIcon.png";
                        viewsId.add(view.viewId);
                    }
                    return viewsId;
                };

            mapFolders = (libraryId, folders, targetNode)=>
                {
                    var folderViewsId = new List<Guid>();
                    foreach(var folder in folders)
                    {
                        var subFolderViewsId  = new List<Guid>();
                        var folderId = folder.folderId;
                        var folderNode = targetNode.add_Node(folder.name);
                        folderNode.state = "closed";
                        folderNode.data.icon = "/Images/FolderIcon.png";
                        // ReSharper disable AccessToModifiedClosure
                        // ReSharper disable PossibleNullReferenceException
                        subFolderViewsId.AddRange(mapFolders(libraryId, folder.subFolders, folderNode));
                        // ReSharper restore PossibleNullReferenceException
                        // ReSharper restore AccessToModifiedClosure
                        var viewIds = (from view in folder.views
                                       select view.viewId).toList();
                        subFolderViewsId.AddRange(mapViews(libraryId, folderId, viewIds, folderNode));

                        folderNode.attr.id = folderId.str();
                        folderViewsId.AddRange(subFolderViewsId);
                    }
                    return folderViewsId;

                };
            var sessionLibraryId = GetCurrentSessionLibrary();

            var libraries = (sessionLibraryId == Guid.Empty)
                                ? tmXmlDatabase.tmLibraries()
                                : tmXmlDatabase.tmLibrary(sessionLibraryId).wrapOnList();

            foreach(var library in libraries)
            {
                var libraryNode =jsTree.add_Node(library.Caption);
                //var mappedFolders = new Dictionary<string, List<Folder_V3>>();
                mapFolders(library.Id, GetFolders(library.Id), libraryNode);
                mapViews(library.Id, Guid.Empty, GetViewsInLibraryRoot(library.Id).guids(), libraryNode);
                //libraryNode.state = "open";
                libraryNode.state = "closed";
                libraryNode.data.icon = "/Images/SingleLibrary.png";

                var libraryNodeText = library.Id.str();

                libraryNode.attr.id = libraryNodeText;

            }
            return jsTree;
        }
        public static Assembly loadAssemblyAndAllItsDependencies(this string pathToAssemblyToLoad)
        {
            var referencesFolder = pathToAssemblyToLoad.directoryName();
            var referencesFiles = referencesFolder.files(true,"*.dll", "*.exe");

            Func<string,string> resolveAssemblyName =
                (name)=>{
                            if (name.starts("System"))
                                return name;
                            if (name.isAssemblyName())
                                name = name.assembly_Name();

                            var resolvedPath = referencesFiles.find_File_in_List(name, name+ ".dll", name+ ".exe");

                            if(resolvedPath.fileExists())
                            {
                                //"**** Found match:{0}".info(resolvedPath);
                                return resolvedPath;
                            }

                            //"**** Couldn't match:{0}".error(resolvedPath);
                            return null;
                };

            var loadedAssemblies = new Dictionary<string, Assembly>();
            // ReSharper disable ImplicitlyCapturedClosure
            // ReSharper disable AccessToModifiedClosure
            Action<Assembly> loadReferencedAssemblies = (assembly) => { };
            Func<string, Assembly> loadAssembly = null;
            loadAssembly =
                (assemblyPathOrName) => {
                                            if (loadedAssemblies.hasKey(assemblyPathOrName))
                                                return loadedAssemblies[assemblyPathOrName];
                                            var assembly = assemblyPathOrName.resolveAssembly(resolveAssemblyName);
                                            if(assembly.notNull())
                                            {
                                                loadedAssemblies.add(assemblyPathOrName, assembly);
                                                loadReferencedAssemblies(assembly);
                                                if (assembly.Location.valid().isFalse())
                                                {
                                                    loadAssembly(assembly.FullName.assembly_Name());
                                                    loadAssembly(assembly.ManifestModule.Name != "<Unknown>"
                                                                     ? assembly.ManifestModule.Name
                                                                     : assembly.ManifestModule.ScopeName);
                                                }
                                                //loadAssembly(assembly.ManifestModule.Name);

                                            }
                                            return assembly;
                };

            loadReferencedAssemblies =
                (assembly)=>{
                                var referencedAssemblies =  assembly.referencedAssemblies();
                                foreach(var referencedAssembly in referencedAssemblies)
                                {
                                    var assemblyName = referencedAssembly.str();
                                    if (loadAssembly(assemblyName).isNull())
                                        "COULD NOT LOAD Referenced Assembly: {0}".error(assemblyName);
                                }
                };
            // ReSharper restore ImplicitlyCapturedClosure
            // ReSharper restore AccessToModifiedClosure
            var mainAssembly = loadAssembly(pathToAssemblyToLoad);

            "[loadAssemblyAndAllItsDependencies] there were {0} references loaded/mapped from '{1}'".info(loadedAssemblies.size(), pathToAssemblyToLoad);
            //show.info(loadedAssemblies);

            return mainAssembly;
        }