public void CheckThatObjectIsNotUsed_TMUser()
        {
            var methods = tmWebServices.type().methods();
            Assert.Less(100,methods.size());
            var returnTypeMappings = new Dictionary<string, List<MethodInfo>>();

            //Create a Mapping based on the return Type of all WebServices methods
            foreach (var method in methods)
            {
                var returnType = method.ReturnType;
                if (returnType.IsGenericType)
                    foreach(var genericParameter in returnType.GetGenericArguments())
                        returnTypeMappings.add(genericParameter.Name, method);
                returnTypeMappings.add(returnType.Name, method);
            }
            returnTypeMappings.Keys.toString().info();

            var typeNames = returnTypeMappings.Keys.toList();
            Assert.Less     (15, typeNames.size());

            Assert.IsTrue (typeNames.contains("TeamMentor_Article"));
            Assert.IsTrue (typeNames.contains("TM_Library"));
            Assert.IsTrue (typeNames.contains("Folder_V3"));
            Assert.IsTrue (typeNames.contains("View_V3"));
            Assert.IsTrue (typeNames.contains("Library"));
            Assert.IsTrue (typeNames.contains("Guid"));
            Assert.IsTrue (typeNames.contains("TM_User")  , "TM_User object should be used instead of TMUser");

            Assert.IsFalse(typeNames.contains("TMUser")   , "TMUser object must not be exposed on a WebService (since it contains all user info, including its passwordHash)");

            //returnTypeMappings["TMUser"].names().toString().info();
        }
 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;
 }
Exemple #3
0
        public static TreeView showIssues(this TreeView treeView, List <Issue> issues)
        {
            treeView.clear();
            if (issues.isNull())
            {
                return(treeView);
            }
            var byUser  = new Dictionary <string, List <Issue> >();
            var byLabel = new Dictionary <string, List <Issue> >();

            foreach (var issue in issues)
            {
                byUser.add(issue.User, issue);
                foreach (var label in issue.Labels)
                {
                    byLabel.add(label, issue);
                }
            }
            var allIssues = treeView.add_Node("All Issues")
                            .showIssues(issues)
                            .expand();

            treeView.add_Node("By User")
            .showIssues(byUser);
            treeView.add_Node("By Label")
            .showIssues(byLabel);
            return(treeView);
        }
        public static TreeNode jint_Show_Statements <T>(this TreeNode treeNode, Statement statement, bool addChildStatements)
            where T : Statement
        {
            treeNode.clear();
            var nodesAdded = new Dictionary <string, TreeNode>();

            foreach (var childStatement in statement.statements <T>(true))
            {
                var codeReference = childStatement.firstSourceCodeReference(true);
                var nodeText      = childStatement.str();
                if (nodeText.valid())
                {
                    if (codeReference.isNull())
                    {
                        nodeText += "   (no source code mapping)";
                    }

                    if (nodesAdded.hasKey(nodeText).isFalse())
                    {
                        nodesAdded.add(nodeText, treeNode.add_Node(nodeText, codeReference));
                    }

                    var newNode = nodesAdded[nodeText].add_Node(nodeText, codeReference);
                    if (addChildStatements)
                    {
                        newNode.jint_Show_AstTree(childStatement);
                    }
                }
            }
            return(treeNode);
        }
        public static Dictionary <string, List <MethodMapping> > indexedByKey(this MethodMappings methodMappings, string filter)
        {
            var result = new Dictionary <string, List <MethodMapping> >();

            if (methodMappings.MethodMappingItems.isNull())
            {
                "In IndexedByKey there were no methodMappingsItems (filer = '{0}'".error(filter ?? "");
            }
            else
            {
                foreach (var mappingItem in methodMappings.MethodMappingItems)
                {
                    var key = mappingItem.Key;
                    if (filter.valid().isFalse() || key.regEx(filter))
                    {
                        foreach (var methodMapping in mappingItem.MethodMappings)
                        {
                            methodMapping.Key = key;                                                                    //Hack(26-Aug-2010): fix until we create all methodMappings with this Key valu	e
                            result.add(key, methodMapping);
                        }
                    }
                }
            }
            return(result);
        }
        public static Dictionary <string, List <RunningInstance> > getEC2Instances(this API_AmazonEC2 amazonEC2, bool onlyShowDefaultRegion)
        {
            var instances = new Dictionary <string, List <RunningInstance> >();

            var reservations = new List <Reservation>();

            if (onlyShowDefaultRegion)
            {
                reservations.add(amazonEC2.getReservationsInRegion(amazonEC2.DefaultRegion));
            }
            else
            {
                foreach (var region in amazonEC2.getEC2Regions())
                {
                    reservations.add(amazonEC2.getReservationsInRegion(region));
                }
            }

            foreach (var reservation in reservations)
            {
                foreach (var runningInstance in reservation.RunningInstance)
                {
                    instances.add(reservation.GroupName.Aggregate((a, b) => a + ',' + b),
                                  runningInstance);
                }
            }
            return(instances);
        }
Exemple #7
0
        public static string findScriptOnLocalScriptFolder(string file)
        {
            if (file.contains("/", @"\"))       // currenlty relative paths are not supported
            {
                return("");
            }

            //string defaultLocalScriptsFolder = @"C:\O2\O2Scripts_Database\_Scripts";

            if (LocalScriptFileMappings.hasKey(file))
            {
                return(LocalScriptFileMappings[file]);
            }
            var mappedFilePath = "";

            var filesToSearch = PublicDI.config.LocalScriptsFolder.files(true, "*.cs");

            filesToSearch.add(PublicDI.config.LocalScriptsFolder.files(true, "*.o2"));
            foreach (var localScriptFile in filesToSearch)
            {
                if (localScriptFile.fileName().ToLower().StartsWith(file.ToLower()))
                //if (fileToResolve.lower() == localScriptFile.fileName().lower())
                {
                    PublicDI.log.debug("in CompileEngine, file reference '{0}' was mapped to local O2 Script file '{1}'", file, localScriptFile);
                    mappedFilePath = localScriptFile;
                    break;
                }
            }
            if (mappedFilePath.valid())
            {
                LocalScriptFileMappings.add(file, mappedFilePath);
            }
            return(mappedFilePath);
        }
Exemple #8
0
    private void CreateListBoxWithName(string name)
    {
        var lb = new ListBox();

        _listboxes.add(name, lb);
        // do other stuff ...
    }
Exemple #9
0
 public void JoinAttendence(Client client, List dates)
 {
     if (!participants.ContaintsKey(client))
     {
         participants.add(client, dates);
     }
 }
        public static MethodMappings loadAndMergeMethodMappings(this List <string> targetFiles)
        {
            "Creating MethodMappings from {0} files".info(targetFiles.size());
            var mergedMethodMappings = new Dictionary <string, List <MethodMapping> >();

            foreach (var targetFile in targetFiles)
            {
                var tempMethodMappings = loadMethodMappings(targetFile);
                var indexedMappings    = tempMethodMappings.indexedByKey("");
                foreach (var item in indexedMappings)
                {
                    foreach (var methodMapping in item.Value)
                    {
                        mergedMethodMappings.add(item.Key, methodMapping);
                    }
                }
            }
            var methodMappings = new MethodMappings();

            foreach (var item in mergedMethodMappings)
            {
                var methodMappingItem = new MethodMappingItem()
                {
                    Key = item.Key
                };
                methodMappingItem.MethodMappings = item.Value;
                methodMappings.MethodMappingItems.Add(methodMappingItem);
            }
            return(methodMappings);
        }
        static void Main(string[] args)
        {
            // Display the number of command line arguments:
            //Source for how to read files in this way: https://stackoverflow.com/questions/5840443/how-to-read-all-files-inside-particular-folder
            foreach (string file in Directory.EnumerateFiles(folderPath, "*.txt"))
            {
                string contents = File.ReadAllText(file);
                string line;
                string ListTag;   //figure out how to assign ListTag to list
                string ListTitle; //figure out how to get the filename
                while ((line = Console.ReadLine()) != null)
                {
                    //Read each variable and put it in an array based on how lines formatted
                    string[] attributes       = line.Split(';');
                    string   BaseGame         = attributes[0];
                    int      Rank             = attributes[1];
                    string   Title            = attributes[2];
                    string   CompletionStatus = attributes[3];
                    string   Franchise        = attributes[4];
                    string   Subfranchise     = attributes[5];
                    string   ReleaseDate      = attributes[6];
                    string   SpecialNotes     = attributes[7];
                    bool     Discontinued     = attributes[8];
                    Game     temp             = searchDatabase(BaseGame);
                    if (ListTag != "standardRed" && ListTag != "standardBlue")
                    {
                        SpecialCases();
                    }

                    Game Entry = Game(BaseGame, Rank, Title, CompletionStatus, Franchise, Subfranchise, ReleaseDate,
                                      SpecialNotes, Discontinued); //instantiate with new values
                    Entry.RankedScore += Rank;
                    if (temp.BaseGame == null)
                    {
                        GameIndex.add(BaseGame, Entry); //do an if/else check to see if already in dictionary first
                    }
                    else
                    {
                        //found a match, replace entry in database when updated (if list logged == false, inclusionscore++, logged = true?)
                        //add to lists on
                        if (ListIndex[ListTitle] == false) //fix how it checks?
                        {
                            //inclusionscore goes up
                        }

                        GameIndex[BaseGame] = Entry; //should update Entry value, with the now increased rank score
                    }
                }
            }
            //while reading all the entries in the database
            //compare ranked score to sort, then use alphabetical and release date for franchise
            //use the cases of completion status to inform formatting
            //print to row, move to the next entry (print score, titles in base game)

            //while reading all the entries in the database
            //compare inclusion score to sort, then use alphabetical and release date for franchise
            //use the cases of completion status to inform formatting
            //print to row, move to the next entry (print score, titles in base game)
        }
        public static void showInTreeView(this MethodMappings methodMappings, TreeView treeView, string filter, bool showSourceCodeSnippets, bool onlyShowSourceCodeLine)
        {
            treeView.parent().backColor("LightPink");
            treeView.visible(false);
            treeView.clear();
            var indexedMappings = methodMappings.indexedByKey(filter);

            if (onlyShowSourceCodeLine)
            {
                //do this so that we don't add more than one item per line
                var indexedByFileAndLine = new Dictionary <string, MethodMapping>();

                foreach (var item in indexedMappings)
                {
                    foreach (var methodMapping in item.Value)
                    {
                        if (methodMapping.File.valid())
                        {
                            var key = "{0}_{1}".format(methodMapping.File, methodMapping.Start_Line);
                            indexedByFileAndLine.add(key, methodMapping);
                        }
                    }
                }
                // now group then by the same text in the SourceCodeLine
                var indexedBySourceCodeLine = new Dictionary <string, List <MethodMapping> >();
                foreach (var methodMapping in indexedByFileAndLine.Values)
                {
                    indexedBySourceCodeLine.add(methodMapping.sourceCodeLine(), methodMapping);
                }

                //Finally show then
                foreach (var item  in indexedBySourceCodeLine)
                {
                    var uniqueTextNode = treeView.add_Node(item.Key, item.Value, true);
                }
            }
            else
            {
                foreach (var item in indexedMappings)
                {
                    var keyNodeText = "{0}                       ({1})".format(item.Key, item.Value.size());
                    var keyNode     = treeView.add_Node(keyNodeText, item.Value, true);
                }
                treeView.afterSelect <List <MethodMapping> >(
                    (mappings) => {
                    var keyNode = treeView.selected();
                    keyNode.clear();
                    foreach (var methodMapping in mappings)
                    {
                        var nodeText = (showSourceCodeSnippets)
                                                                                                                        ? methodMapping.sourceCodeLine()
                                                                                                                        : "{0} - {1}".format(methodMapping.INodeType, methodMapping.SourceCode);
                        keyNode.add_Node(nodeText, methodMapping);
                    }
                });
            }
            treeView.parent().backColor("Control");
            treeView.visible(true);
        }
 public static Dictionary<string, List<string>> indexed_By_MemberName(this List<ValidationResult> validationResults)
 {
     var mappedData = new Dictionary<string, List<string>>();
     foreach(var validationResult in validationResults)
         foreach (var memberName in validationResult.MemberNames)
             mappedData.add(memberName, validationResult.ErrorMessage);
     return mappedData;
 }
 public static Dictionary <string, string> add_Files_Indexed_by_FileName(this Dictionary <string, string> mappedFiles, string path)
 {
     foreach (var item in path.files_Indexed_by_FileName())
     {
         mappedFiles.add(item.Key, item.Value);
     }
     return(mappedFiles);
 }
        public static Dictionary <string, string> values(this List <FieldDeclaration> fieldDeclarations)
        {
            var values = new Dictionary <string, string>();

            foreach (var variable in fieldDeclarations.variables())
            {
                if (variable.Initializer is PrimitiveExpression)
                {
                    values.add(variable.Name, (variable.Initializer as PrimitiveExpression).StringValue);
                }
                else
                {
                    values.add(variable.Name, variable.Initializer.str());
                }
            }
            return(values);
        }
    private static void AddPropertyToDictionary <T>(PropertyDescriptor property, object source, Dictionary <string, T> dictionary)
    {
        object value = property.GetValue(source);

        if (IsOfType <T>(value))
        {
            dictionary.add(property.Name, (T)value);
        }
    }
 public static Dictionary <string, string> addCompilationPathMappings(string key, string value)
 {
     if (key.valid() && value.valid())
     {
         "Adding CompilationPathMappings: {0} = {1}".info(key, value);
         CompilationPathMappings.add(key, value);
     }
     return(CompilationPathMappings);
 }
        public static Dictionary <string, List <ConstantPool> > getDictionary_byType(this  List <ConstantPool> constantsPool)
        {
            var dictionary = new Dictionary <string, List <ConstantPool> >();

            foreach (var item in constantsPool)
            {
                dictionary.add(item.Type, item);
            }
            return(dictionary);
        }
        public static Dictionary <string, ProcessModule> modules_Indexed_by_FileName(this Process process)
        {
            var modulesIndexed = new Dictionary <string, ProcessModule>();

            foreach (var module in process.modules())
            {
                modulesIndexed.add(module.FileName.lower(), module);
            }
            return(modulesIndexed);
        }
        public static Dictionary <int, List <Java_Variable> > variables_byIndex(this Java_Method method)
        {
            var variables_byIndex = new Dictionary <int, List <Java_Variable> >();

            foreach (var variable in method.Variables)
            {
                variables_byIndex.add(variable.Index, variable);
            }
            return(variables_byIndex);
        }
        public static Dictionary <string, string> attributes(this Element element)
        {
            var attributeValues = new Dictionary <string, string>();

            foreach (IHTMLDOMAttribute attribute in attributesRaw(element))
            {
                attributeValues.add(attribute.nodeName.str(), attribute.nodeValue.str());
            }
            return(attributeValues);
        }
Exemple #22
0
        public static Dictionary <string, List <IO2Finding> > indexBy(this List <IO2Finding> o2Findings, Func <O2Finding, string> calculateIndex)
        {
            var indexedData = new Dictionary <string, List <IO2Finding> >();

            foreach (var o2Finding in o2Findings)
            {
                indexedData.add(calculateIndex((O2Finding)o2Finding), o2Finding);
            }
            return(indexedData);
        }
Exemple #23
0
 public static Dictionary<string, string> GetAvailableScripts()
 {
     var files = HttpContextFactory.Server.MapPath(TBOT_SCRIPTS_FOLDER)
                                   .files(true, "*.cshtml");
     var mappings = new Dictionary<string, string>();
     foreach (var file in files)
         mappings.add(file.fileName_WithoutExtension(), file);
     return mappings;
     //return files.toDictionary((file) => file.fileName_WithoutExtension()); //this doesn't handle duplicate files names
 }
Exemple #24
0
        public static Dictionary <string, List <IO2Finding> > indexBy(this List <IO2Finding> o2Findings, string propertyToIndexBy)
        {
            var indexedData = new Dictionary <string, List <IO2Finding> >();

            foreach (var o2Finding in o2Findings)
            {
                indexedData.add(o2Finding.prop(propertyToIndexBy).str(), o2Finding);
            }
            return(indexedData);
        }
Exemple #25
0
        public static Dictionary <string, List <IntPtr> > classNames_Indexed(this List <IntPtr> handles)
        {
            var indexedClassNames = new Dictionary <string, List <IntPtr> >();

            foreach (var handle in handles)
            {
                indexedClassNames.add(handle.className(), handle);
            }
            return(indexedClassNames);
        }
Exemple #26
0
        public static Dictionary <string, SpringMvcController> controllers_by_JavaClass(this SpringMvcMappings mvcMappings)
        {
            var controllers_by_JavaClass = new Dictionary <string, SpringMvcController>();

            foreach (var controller in mvcMappings.Controllers)
            {
                controllers_by_JavaClass.add(controller.JavaClass, controller);
            }
            return(controllers_by_JavaClass);
        }
        public static Dictionary <string, string> files_Indexed_by_FileName(this List <string> files)
        {
            var files_Indexed_By_FileName = new Dictionary <string, string>();

            foreach (var file in files)
            {
                files_Indexed_By_FileName.add(file.fileName(), file);
            }
            return(files_Indexed_By_FileName);
        }
        public static Dictionary <string, List <string> > files_Mapped_by_Extension(this List <string> files)
        {
            var files_Indexed_By_FileName = new Dictionary <string, List <string> >();

            foreach (var file in files)
            {
                files_Indexed_By_FileName.add(file.extension(), file);
            }
            return(files_Indexed_By_FileName);
        }
Exemple #29
0
        public static Dictionary <string, List <Statement> > statements_by_Type(this Statement statement)
        {
            Dictionary <string, List <Statement> > dictionary = new Dictionary <string, List <Statement> >();

            foreach (var childStatement in statement.statements(true))
            {
                string key = childStatement.typeName();
                dictionary.add <string, Statement>(key, childStatement);
            }
            return(dictionary);
        }
Exemple #30
0
 public ColorPrototype this[string key]
 {
     get
     {
         return(_dic[key]);
     }
     set
     {
         _dic.add(key, value);
     }
 }
        public static Dictionary <string, T> propertyValues_MappedBy_Name <T>(this object _object)
        {
            var propertyValues = new Dictionary <string, T>();
            var properties     = _object.type().properties <T>();

            foreach (var property in properties)
            {
                propertyValues.add(property.Name, (T)_object.prop(property.Name));
            }
            return(propertyValues);
        }
        public static Dictionary <string, ProcessModule> modules_Indexed_by_ModuleName(this Process process)
        {
            //return process.modules().ToDictionary((module)=> module.ModuleName.lower());;		 //doesn't handle duplicate names
            var modulesIndexed = new Dictionary <string, ProcessModule>();

            foreach (var module in process.modules())
            {
                modulesIndexed.add(module.ModuleName.lower(), module);
            }
            return(modulesIndexed);
        }
Exemple #33
0
        public static List <Image> show_ImagesList_In_TreeView(this API_AmazonEC2 amazonEC2, AmazonEC2Client ec2Client, Control control)
        {
            var treeView = control.clear().add_TreeView_with_PropertyGrid(false).sort();

            treeView.parent().backColor(System.Drawing.Color.Azure);
            treeView.visible(false);
            Application.DoEvents();
            var imagesList = amazonEC2.getImagesList(ec2Client);

            Func <Amazon.EC2.Model.Image, string> imageName =
                (image) => (image.Description.valid())
                                                                        ? "{0} - {1}".format(image.Description, image.Name)
                                                                        : "{0}".format(image.Name).trim();

            Action <string> mapByProperty =
                (propertyName) => {
                var byPropertyNode = treeView.add_Node("by {0}".format(propertyName), "");
                foreach (var distinctPropertyValue in imagesList.Select((image) => image.property(propertyName).str()).Distinct())
                {
                    var byDistinctPropertyValue = byPropertyNode.add_Node(distinctPropertyValue, "");

                    var mappedByImageName = new Dictionary <string, List <Image> >();
                    foreach (var imageInProperty in imagesList.Where((image) => image.property(propertyName).str() == distinctPropertyValue))
                    {
                        mappedByImageName.add(imageName(imageInProperty), imageInProperty);
                    }

                    foreach (var mappedData in mappedByImageName)
                    {
                        if (mappedData.Value.size() > 1)
                        {
                            byDistinctPropertyValue.add_Node("{0}".format(mappedData.Key, mappedData.Value.size()))
                            .add_Nodes(mappedData.Value, imageName);
                        }
                        else
                        {
                            byDistinctPropertyValue.add_Node(imageName(mappedData.Value.first()), mappedData.Value.first());
                        }
                    }
                }
            };

            mapByProperty("Visibility");
            mapByProperty("ImageOwnerAlias");
            mapByProperty("Platform");
            mapByProperty("Architecture");
            "Completed processing show_ImagesList_In_TreeView".info();
            if (treeView.nodes().size() > 0)
            {
                treeView.backColor(System.Drawing.Color.White);
            }
            treeView.visible(true);
            return(imagesList);
        }
        public static Dictionary <string, string> GetAvailableScripts()
        {
            var files    = TBotScriptsFiles();
            var mappings = new Dictionary <string, string>();

            foreach (var file in files)
            {
                mappings.add(file.fileName_WithoutExtension(), file);
            }
            return(mappings);
            //return files.toDictionary((file) => file.fileName_WithoutExtension()); //this doesn't handle duplicate files names
        }
        public static void showInTreeView(this MethodMappings methodMappings, TreeView treeView, string filter, bool showSourceCodeSnippets, bool onlyShowSourceCodeLine)
        {
            treeView.parent().backColor("LightPink");
            treeView.visible(false);
            treeView.clear();
            var indexedMappings = methodMappings.indexedByKey(filter);
            if (onlyShowSourceCodeLine)
            {
                //do this so that we don't add more than one item per line
                var indexedByFileAndLine = new Dictionary<string, MethodMapping>();

                foreach(var item in indexedMappings)
                    foreach(var methodMapping in item.Value)
                        if (methodMapping.File.valid())
                        {
                            var key = "{0}_{1}".format(methodMapping.File, methodMapping.Start_Line);
                            indexedByFileAndLine.add(key, methodMapping);
                        }
                // now group then by the same text in the SourceCodeLine
                var indexedBySourceCodeLine =  new Dictionary<string, List<MethodMapping>>();
                foreach(var methodMapping in indexedByFileAndLine.Values)
                    indexedBySourceCodeLine.add(methodMapping.sourceCodeLine(), methodMapping);

                //Finally show then
                foreach(var item  in indexedBySourceCodeLine)
                {
                    var uniqueTextNode = treeView.add_Node(item.Key, item.Value,true);
                }
            }
            else
            {
                foreach(var item in indexedMappings)
                {
                    var keyNodeText = "{0}                       ({1})".format(item.Key, item.Value.size());
                    var keyNode= treeView.add_Node(keyNodeText, item.Value,true);
                }
                treeView.afterSelect<List<MethodMapping>>(
                    (mappings)=>{
                                    var keyNode = treeView.selected();
                                    keyNode.clear();
                                    foreach(var methodMapping in mappings)
                                    {
                                        var nodeText = (showSourceCodeSnippets)
                                            ? methodMapping.sourceCodeLine()
                                            : "{0} - {1}".format(methodMapping.INodeType,methodMapping.SourceCode);
                                        keyNode.add_Node(nodeText, methodMapping);
                                    }
                    });
            }
            treeView.parent().backColor("Control");
            treeView.visible(true);
        }
     	public static Dictionary<string,string> executeScript_ConvertTo_DicionaryStringString(this API_Azure_via_WebREPL apiAzure, string script, string nameKey, string valueKey)
     	{
     		var data = new Dictionary<string,string>();
     		var response = apiAzure.executeScript(script);
     		if (response.valid())
     		{
     			var items = (Object[])response.json_Deserialize();			
				if (items.notNull())						
					foreach(Dictionary<string,object> item in items)				
						data.add(item[nameKey].str(),item[valueKey].str());						
     		}
     		return data;
     	}	
        public static Dictionary<string,List<KeyValuePair<INode,IMethodOrProperty>>> indexedBy_ResolvedSignature( this Dictionary<IMethod, Dictionary<string,List<KeyValuePair<INode,IMethodOrProperty>>>> iMethodMappings)
        {
        	var o2Timer = new O2Timer("Calculated indexedBy_ResolvedSignature").start();
        	var results = new Dictionary<string,List<KeyValuePair<INode,IMethodOrProperty>>>();
        	foreach(var iMethodMapping in iMethodMappings) 
        		foreach(var mapping in iMethodMapping.Value)
        			foreach(var keyValuePair in mapping.Value)	        			        			
	        			results.add(mapping.Key, keyValuePair);	        		
			o2Timer.stop();
        	return results;        	
        }
    	public static API_Veracode_DetailedXmlFindings show_Flaws_In_SourceCodeViewer(this API_Veracode_DetailedXmlFindings apiVeracode, Control control)
    	{
    		var topPanel = control.clear();
    		var codeViewer = topPanel.add_GroupBox("Flaw SourceCode reference").add_SourceCodeViewer();
			var treeView = codeViewer.parent().insert_Left("Flaws").add_TreeView(); 
			var propertyGrid = treeView.insert_Below(150,"Flaw properties")
									   .add_PropertyGrid().helpVisible(false);
			var description = codeViewer.insert_Below(150,"Flaw description")
									    .add_TextArea();
									    
			treeView.afterSelect<FlawType>(
				(flaw)=>{				
							propertyGrid.show(flaw);				
							if (apiVeracode.hasLocalSourceCodeFile(flaw))
							{
								codeViewer.open(apiVeracode.sourceCodeFile(flaw));
								codeViewer.editor().gotoLine((int)flaw.line); 
							}
							else
								codeViewer.set_Text(".. no source code available...");
							description.set_Text(flaw.description.fix_CRLF());
							treeView.focus();
						});
			 												
			treeView.beforeExpand<List<FlawType>>(
				(flaws)=>{
							var selectedNode = treeView.selected();
							if (selectedNode.nodes().size()== 1)
							{
								selectedNode.clear();
								selectedNode.add_Nodes(flaws, 
													   (flaw)=> flaw.type, 
													   (flaw) => apiVeracode.hasLocalSourceCodeFile(flaw)
																		? Color.DarkGreen
																		: Color.DarkRed
													   );
							}
						 });
										
			Action<TreeNode, Dictionary<string, List<FlawType>>> addFlawsToTreeNode =
				(treeNode, mappedFlaws) 
				   =>{
						foreach(var item in mappedFlaws)			
							treeNode.add_Node(item.Key,item.Value,item.Value.size()>0);
									/*.*/
					  };
					  
			Action showData = 		  
				()=>{
						treeView.clear();
						var o2Timer = new O2Timer("Building XRefs for flaws").start();
						var mappedFlawsByType = new Dictionary<string, List<FlawType>>();
						var mappedFlawsByCategoryName = new Dictionary<string, List<FlawType>>();
						var mappedFlawsByFile = new Dictionary<string, List<FlawType>>();
						var mappedFlawsBySeverity = new Dictionary<string, List<FlawType>>();
						
						foreach(var flaw in apiVeracode.flaws()) 
						{
							mappedFlawsByCategoryName.add(flaw.categoryname, flaw);
							mappedFlawsByType.add(flaw.type, flaw);
							mappedFlawsByFile.add(flaw.sourceCodeFile(), flaw);
							mappedFlawsBySeverity.add(flaw.severity.str(), flaw);	
						}
						o2Timer.stop();
						o2Timer = new O2Timer("Populating treeview").start();			
						addFlawsToTreeNode(treeView.add_Node("by Category Name"), mappedFlawsByCategoryName);
						addFlawsToTreeNode(treeView.add_Node("by Type"), mappedFlawsByType);
						addFlawsToTreeNode(treeView.add_Node("by File"), mappedFlawsByFile);
						addFlawsToTreeNode(treeView.add_Node("by Severity"),mappedFlawsBySeverity);
						o2Timer.stop();		
					};
			
			treeView.onDrop(
				(file)=>{
							apiVeracode.load(file);
							showData(); 			
						});
			if (apiVeracode.ReportXmlFile.valid())
				showData(); 
			else
				treeView.add_Node("drop a Veracode DetailedFindings Xml (or zip) file to view it"); 			
			
			
//			"There were {0} Files That Could Not Mapped Locally".error(apiVeracode.FilesThatCouldNotMappedLocally.size());			
			/*if (treeView.nodes()>0))
			{
				treeView.nodes()[0]
					 	.expand().nodes()[2].selected();
			}
			*/
			return apiVeracode;
    	}
		public static Dictionary<string,List<RunningInstance>> getEC2Instances(this API_AmazonEC2 amazonEC2,bool onlyShowDefaultRegion)
		{		
			var instances = new Dictionary<string,List<RunningInstance>>();		
			
			var reservations = new List<Reservation>();
			if (onlyShowDefaultRegion)
				reservations.add(amazonEC2.getReservationsInRegion(amazonEC2.DefaultRegion));
			else
				foreach(var region in amazonEC2.getEC2Regions()) 
					reservations.add(amazonEC2.getReservationsInRegion(region));				        
						
			foreach(var reservation in reservations)
					foreach(var runningInstance in reservation.RunningInstance)
						instances.add(reservation.GroupName.Aggregate((a, b) => a + ',' + b),
									  runningInstance); 			
			return instances;			
		}
		public static List<Image> show_ImagesList_In_TreeView(this API_AmazonEC2 amazonEC2, AmazonEC2Client ec2Client, Control control)
		{				
			var treeView = control.clear().add_TreeView_with_PropertyGrid(false).sort();  	 
			treeView.parent().backColor(System.Drawing.Color.Azure);
			treeView.visible(false);
			Application.DoEvents();
			var imagesList = amazonEC2.getImagesList(ec2Client); 
			
			Func<Amazon.EC2.Model.Image,string> imageName = 
				(image)=> (image.Description.valid())
									? "{0} - {1}".format(image.Description, image.Name)
									: "{0}".format(image.Name).trim();
									
			Action<string> mapByProperty  = 
				(propertyName)=>{				
									var byPropertyNode = treeView.add_Node("by {0}".format(propertyName),"");
									foreach(var distinctPropertyValue in imagesList.Select((image)=>image.property(propertyName).str()).Distinct())
									{										
										var byDistinctPropertyValue = byPropertyNode.add_Node(distinctPropertyValue,"");

										var mappedByImageName = new Dictionary<string, List<Image>>();
										foreach(var imageInProperty in imagesList.Where((image) => image.property(propertyName).str() == distinctPropertyValue))
											mappedByImageName.add(imageName(imageInProperty),imageInProperty);																				
											
										foreach(var mappedData in mappedByImageName)
										{
											if (mappedData.Value.size() > 1)
												byDistinctPropertyValue.add_Node("{0}".format(mappedData.Key,mappedData.Value.size()))
														      		   .add_Nodes(mappedData.Value, imageName);
											else
												byDistinctPropertyValue.add_Node(imageName(mappedData.Value.first()),mappedData.Value.first());
										}			     
									}													  			
								};
			mapByProperty("Visibility");
			mapByProperty("ImageOwnerAlias");
			mapByProperty("Platform"); 
			mapByProperty("Architecture"); 
			"Completed processing show_ImagesList_In_TreeView".info();
			if (treeView.nodes().size()>0)
				treeView.backColor(System.Drawing.Color.White); 
			treeView.visible(true);				
			return imagesList;
		}
 public static Dictionary<string, VariableDeclaration> filtered_ByName(this List<FieldDeclaration> fieldDeclarations)
 {
     var filtered_ByName = new Dictionary<string, VariableDeclaration>();
     foreach (var fieldDeclaration in fieldDeclarations)
         foreach (var variable in fieldDeclaration.Fields)
             filtered_ByName.add(variable.Name, variable);
     return filtered_ByName;
 }
 public static Dictionary<string, string> values(this List<FieldDeclaration> fieldDeclarations)
 {
     var values = new Dictionary<string, string>();
     foreach (var variable in fieldDeclarations.variables())
     {
         if (variable.Initializer is PrimitiveExpression)
             values.add(variable.Name, (variable.Initializer as PrimitiveExpression).StringValue);
         else
             values.add(variable.Name, variable.Initializer.str());
     }
     return values;
 }
 public static Dictionary<string, string> files_Indexed_by_FileName(this List<string> files)
 {
     var files_Indexed_By_FileName = new Dictionary<string,string>();
     foreach(var file in files)
         files_Indexed_By_FileName.add(file.fileName(), file);
     return files_Indexed_By_FileName;
 }
		public static Dictionary<string, List<MethodMapping>> indexedByKey(this MethodMappings methodMappings, string filter)
		{
			var result = new Dictionary<string, List<MethodMapping>>(); 
			if (methodMappings.MethodMappingItems.isNull())
				"In IndexedByKey there were no methodMappingsItems (filer = '{0}'".error(filter ?? "");
			else
				foreach(var mappingItem in methodMappings.MethodMappingItems)
				{
					var key = mappingItem.Key;   
					if (filter.valid().isFalse() || key.regEx(filter)) 
						foreach(var methodMapping in mappingItem.MethodMappings)
						{
							methodMapping.Key = key;					//Hack(26-Aug-2010): fix until we create all methodMappings with this Key valu	e
							result.add(key, methodMapping);
						}
				}
			return result;
		}
 public static Dictionary<string, List<string>> files_Mapped_by_Extension(this List<string> files)
 {
     var files_Indexed_By_FileName = new Dictionary<string,List<string>>();
     foreach(var file in files)
         files_Indexed_By_FileName.add(file.extension(), file);
     return files_Indexed_By_FileName;
 }
        public static string add_Properties(this O2MappedAstData astData, string targetFolder)
        {
        	//return methodMappingsIndexedBySignature;
        	//handle Properties
			var propertyMappings = new Dictionary<string,List<KeyValuePair<INode,IMethodOrProperty>>>();
//			show.info(methodMappingsIndexedBySignature);

            var fileName = "_MethodMapings_For_Properties";
            //var md5Hash = fullName.safeFileName().md5Hash();
            var savedPropertiesMappingsFile = targetFolder.pathCombine(fileName) + ".xml";
            if (savedPropertiesMappingsFile.fileExists())
                return savedPropertiesMappingsFile;

			var propertyRefs = new List<INode>();
			foreach(var propertyDeclaration in astData.MapAstToNRefactory.IPropertyToPropertyDeclaration.Values)
			{
				"Mapping property: {0}".info(propertyDeclaration.Name);
				
				propertyRefs.add(propertyDeclaration.iNodes<INode, MemberReferenceExpression>());
                propertyRefs.add(propertyDeclaration.iNodes<INode, InvocationExpression>());
                propertyRefs.add(propertyDeclaration.iNodes<INode, ObjectCreateExpression>());
                
			}
//			show.info(propertyRefs);
			try
			{
				foreach(Expression propertyRef in propertyRefs)
				{
					var methodOrProperty = astData.fromExpressionGetIMethodOrProperty(propertyRef);				
					var nodeText =	astData.getTextForINode(propertyRef);// propertyRef.str();
					propertyMappings.add(nodeText, new KeyValuePair<INode,IMethodOrProperty>(propertyRef,methodOrProperty)); 
				}			
			}
			catch(Exception ex)
			{
				ex.log("in add_Property");
			}
            var tempFile = astData.saveMappings(propertyMappings);
            if (tempFile.fileExists())
				Files.MoveFile(tempFile, savedPropertiesMappingsFile);            
            return savedPropertiesMappingsFile;
			/// PROPERTIES
        }
		public static Dictionary<string,List<IO2Finding>> indexBy(this List<IO2Finding> o2Findings, string propertyToIndexBy)
		{
			var indexedData = new Dictionary<string,List<IO2Finding>>();
			foreach(var o2Finding in o2Findings)
				indexedData.add(o2Finding.prop(propertyToIndexBy).str(),o2Finding);
			return indexedData;
		}
 public static Dictionary<string,List<KeyValuePair<IO2Finding, IO2Trace>>> filterBy_Traces_Property(this List<IO2Finding> iO2Findings, string propertyName)
 {
 	var filteredData = new Dictionary<string,List<KeyValuePair<IO2Finding, IO2Trace>>>();
 	foreach(var iO2Finding in iO2Findings)
 		foreach(var iO2Trace in iO2Finding.allTraces())
 		{
 			var propertyValue = (iO2Trace as O2Trace).prop(propertyName).str();
 			if (propertyValue.valid())
 			{
 				var keyValuePair = new KeyValuePair<IO2Finding, IO2Trace>(iO2Finding, iO2Trace);        			
 				filteredData.add(propertyValue.trim(), keyValuePair);        				
 			}        			
 		}        
 	return filteredData;
 }	
		public void loadFiles(string filesPath, List<string> filesToLoad)
		{						
			sourceCode.set_Text("Loading files from: {0}".format(filesPath));
			Path.set_Text(filesPath);
			var filesContent = new Dictionary<string,string>();
			var nonBinaryFiles = new List<string>();
			foreach(var file in filesToLoad) 
				if (file.isBinaryFormat().isFalse()) 
					nonBinaryFiles.add(file);
			
			foreach(var file in nonBinaryFiles) 
					filesContent.add(file.remove(filesPath),file.contents());	
					
			searchEngine = new SearchEngine();
			searchEngine.loadFiles(nonBinaryFiles); 			
			
			//searchEngine.fixH2FileLoadingIssue();
			
			leftPanel.clear();
			treeView = leftPanel.add_TreeViewWithFilter(filesContent); 
			treeView.afterSelect<string>(
				(fileContents)=>{					
									sourceCode.open(filesPath + treeView.selected().get_Text());
								});						
			sourceCode.colorCodeForExtension(treeView.selected().str());
			sourceCode.set_Text("");
			textSearch_TextBox = leftPanel.controls<TextBox>(true)[1];
			textSearch_TextBox.onEnter(
				(text)=>{
					var searchResults = searchEngine.searchFor(text);
					dataGridView.loadInDataGridView_textSearchResults(searchResults);  
				});
			
			
		}		
	public static MethodMappings loadAndMergeMethodMappings (this List<string> targetFiles)
	{
		"Creating MethodMappings from {0} files".info(targetFiles.size());
		var mergedMethodMappings = new Dictionary<string, List<MethodMapping>>();
		foreach(var targetFile in targetFiles)
		{
		
			var tempMethodMappings = loadMethodMappings(targetFile); 
			var indexedMappings = tempMethodMappings.indexedByKey(""); 
			foreach(var item in indexedMappings)
				foreach(var methodMapping in item.Value)									
					mergedMethodMappings.add(item.Key, methodMapping);																	
		}
		var methodMappings = new MethodMappings();							
		foreach(var item in mergedMethodMappings)
		{
			var methodMappingItem = new MethodMappingItem() { Key = item.Key};
			methodMappingItem.MethodMappings = item.Value;
			methodMappings.MethodMappingItems.Add(methodMappingItem); 
		}
		return methodMappings;
	}
		public static Dictionary<string, Java_Class> indexedBySignature(this List<Java_Class> classes)
		{
			var classesBySignature = new Dictionary<string, Java_Class>();
			if (classes.notNull())
				foreach(var _class in classes) 
					classesBySignature.add(_class.Signature, _class);
			return classesBySignature;
		}			
Exemple #52
0
		public static Dictionary<string, List<SpringMvcController>> controllers_by_CommandClass(this SpringMvcMappings mvcMappings)
		{
			var byCommandClass = new Dictionary<string, List<SpringMvcController>>();

			foreach(var controller in mvcMappings.Controllers)
			{
				if (controller.CommandClass.valid())
					byCommandClass.add(controller.CommandClass, controller);
				//var commandClass= controller.CommandClass ?? "[no commandName]";
				//byCommandClass.add(commandClass, controller);
			}
			return byCommandClass;
		}
 	public static Dictionary<string,string> environmentVariables(this API_Azure_via_WebREPL apiAzure)
 	{
 		var rawData = apiAzure.executeScript(@"return Environment.GetEnvironmentVariables();");
 		var rawDictionary = rawData.json_Deserialize() as Dictionary<string,object>;
 		var environmentVariables = new Dictionary<string,string>();
 		foreach(var item in rawDictionary)
 			environmentVariables.add(item.Key, item.Value.str());
 		return environmentVariables;     		
 	}
		public static Dictionary<string, List<Java_Class>> classes_MappedTo_Implementations(this API_IKVMC_Java_Metadata javaMetadata)
		{	
			//next map the Interfaces
			var implementations = new Dictionary<string, List<Java_Class>>();
			foreach(var _class in javaMetadata.Classes)			
				foreach(var _interface in _class.Interfaces)
					implementations.add(_interface, _class);
					
					
			//next map the SuperClasses
			var classes_bySignature = javaMetadata.classes_IndexedBySignature();
			foreach(var _class in javaMetadata.Classes)			
				if (_class.SuperClass.valid() && classes_bySignature.hasKey(_class.SuperClass))
					implementations.add(_class.SuperClass, _class);//.Signature, classes_bySignature[_class.SuperClass]);
					
			return implementations;
		}
		public static Dictionary<string, List<Java_Class>> classes_MappedTo_EnclosingMethod(this API_IKVMC_Java_Metadata javaMetadata)
		{
			var enclosingMethods = new Dictionary<string, List<Java_Class>>();
			foreach(var _class in javaMetadata.Classes)
				if (_class.EnclosingMethod.notNull())
					enclosingMethods.add(_class.EnclosingMethod, _class);
			return 	enclosingMethods;	
		}
		public static Dictionary<string, string> methods_MappedTo_EnclosingMethod(this API_IKVMC_Java_Metadata javaMetadata)
		{
			var enclosingMethods = new Dictionary<string, string>();
			foreach(var _class in javaMetadata.Classes)
				if (_class.EnclosingMethod.notNull())
					foreach(var method in _class.Methods)
						enclosingMethods.add(method.Signature, _class.EnclosingMethod);
			return 	enclosingMethods;			
		}		
		public static Dictionary<string,List<IO2Finding>> indexBy(this List<IO2Finding> o2Findings, Func<O2Finding,string> calculateIndex)
		{
			var indexedData = new Dictionary<string,List<IO2Finding>>();
			foreach(var o2Finding in o2Findings)
				indexedData.add(calculateIndex((O2Finding)o2Finding),o2Finding);
			return indexedData;
		}
		public static Dictionary<int, List<Java_Variable>> variables_byIndex(this Java_Method method)
		{
			var variables_byIndex = new Dictionary<int, List<Java_Variable>>();
			foreach(var variable in method.Variables)
				variables_byIndex.add(variable.Index, variable);
			return variables_byIndex;
		}
Exemple #59
0
		public static Dictionary<string, SpringMvcController> controllers_by_JavaClass(this SpringMvcMappings mvcMappings)
		{
			var controllers_by_JavaClass = new Dictionary<string, SpringMvcController>();
			foreach(var controller in mvcMappings.Controllers)
				controllers_by_JavaClass.add(controller.JavaClass, controller);
			return controllers_by_JavaClass;
		}
        public static Dictionary<string,List<KeyValuePair<INode,IMethodOrProperty>>> externalMethodsAndProperties(this O2MappedAstData astData, IMethod iMethod)
        {        	
        	var externalMethods = new Dictionary<string,List<KeyValuePair<INode,IMethodOrProperty>>>();
        	// add the current method
        	
        	externalMethods.add(iMethod.DotNetName,  new KeyValuePair<INode,IMethodOrProperty>(astData.methodDeclaration(iMethod) ,iMethod));
        	
        	var iNodesAdded = new List<INode>();
        	
        	foreach (var methodCalled in astData.calledINodesReferences(iMethod))
			 	if (methodCalled is MemberReferenceExpression)
                {                             	
                	var memberRef = (MemberReferenceExpression)methodCalled;                 	
                	{                	
                		var methodOrProperty = astData.fromMemberReferenceExpressionGetIMethodOrProperty(memberRef);
                		if(methodOrProperty.notNull())                     	
                		{
                			externalMethods.add(methodOrProperty.DotNetName, new KeyValuePair<INode,IMethodOrProperty>(memberRef,methodOrProperty)); 
                			iNodesAdded.Add(memberRef);
                		}
                		else
                			externalMethods.add(astData.getTextForINode(memberRef),new KeyValuePair<INode,IMethodOrProperty>(memberRef,null));
                	}
				}
			
			
        	foreach(var mapping in astData.calledIMethods_getMappings(iMethod))
        	{                
                var iMethodMapping = mapping.Key;
                var iNodeMapping = mapping.Value;
                if (iNodesAdded.Contains(iNodeMapping).isFalse())
                	if (iNodeMapping is ObjectCreateExpression ||
                	   ((iNodeMapping is InvocationExpression &&
                	    (iNodeMapping as InvocationExpression).TargetObject.notNull() && 
                	    iNodesAdded.Contains((iNodeMapping as InvocationExpression).TargetObject).isFalse())))
                	 {                	 	
						var nodeText = (iMethodMapping.notNull())
												? iMethodMapping.DotNetName
												: astData.getTextForINode(iNodeMapping);
						externalMethods.add(nodeText, new KeyValuePair<INode,IMethodOrProperty>(iNodeMapping,iMethodMapping)); 				
					 }	
            }
        	
        	return externalMethods;
        }