public void TestLoadSingleLine() { Dictionary <string, string> props = new Dictionary <string, string>(); Stream sr = new MemoryStream("hello".getBytes()); props.Load(sr); assertEquals(1, props.size()); }
public static string findFileOnLocalScriptFolder(string file) { if (LocalScriptFileMappings.size() == 0) // if there are no mappings create the cached list { resetLocalScriptsFileMappings(); } var key = file.ToLower(); if (CompileEngine.LocalScriptFileMappings.hasKey(key)) { return(CompileEngine.LocalScriptFileMappings[key]); } PublicDI.log.debug("in CompileEngine, could NOT map file reference '{0}'", file); return(""); }
public bool resolveBooleanExpression(Dictionary <string, object> vars, string elExpression) { List <Variable> variables = new List <Variable>(); String[] keys = vars.keySet().toArray(new String[vars.size()]); for (int i = 0; keys != null && i < keys.length; i++) { String key = keys[i]; variables.add(Variable.createVariable(key, vars.get(key))); } Object result = ExpressionEvaluator.evaluate(elExpression, variables); Boolean b = (Boolean)result; return(b.booleanValue()); }
public static Dictionary <string, string> properties(this PropertyGrid propertyGrid) { var properties = new Dictionary <string, string>(); try { // I have to do this because the code from PropertyGridCategoty and PropertyGridProperties has a couple bugs var finder = propertyGrid.field("finder"); var rows = (List <AutomationElement>)finder.invoke("FindRows"); foreach (var element in rows) { AutomationPatterns automationPatterns = new AutomationPatterns(element); var propertyGridProperty = (PropertyGridProperty)typeof(PropertyGridProperty).ctor(element, finder, propertyGrid.ActionListener); properties.add(propertyGridProperty.Text, propertyGridProperty.Value); } } catch (Exception ex) { ex.log("in PropertyGrid properties"); } "Found {0} propeties in PropertyGridView".info(properties.size()); return(properties); }
public static List <ConstantPool> getConstantPoolEntries(this object classFile) { var constantsPool = new List <ConstantPool>(); var constantPoolRaw = new Dictionary <int, object>(); var constantPool = (IEnumerable)classFile.field("constantpool"); if (constantPool.isNull()) { "in getConstantPoolEntries , classFile.field(\"constantpool\") was null".error(); } else { ; var index = 0; foreach (var constant in constantPool) { constantPoolRaw.add(index++, constant); } //var constantPoolValues = new Dictionary<int,string>(); // var stillToMap = new List<object>(); for (int i = 0; i < constantPoolRaw.size(); i++) { var currentItem = constantPoolRaw[i]; var currentItemType = currentItem.str(); switch (currentItemType) { case "IKVM.Internal.ClassFile+ConstantPoolItemClass": constantsPool.add_Entry(i, currentItemType.remove("IKVM.Internal.ClassFile+ConstantPoolItem"), currentItem.prop("Name").str()); break; case "IKVM.Internal.ClassFile+ConstantPoolItemMethodref": constantsPool.add_Entry(i, currentItemType.remove("IKVM.Internal.ClassFile+ConstantPoolItem"), "{0}.{1}{2}".format(currentItem.prop("Class"), currentItem.prop("Name"), currentItem.prop("Signature"))); break; case "IKVM.Internal.ClassFile+ConstantPoolItemInterfaceMethodref": constantsPool.add_Entry(i, currentItemType.remove("IKVM.Internal.ClassFile+ConstantPoolItem"), "{0}.{1}{2}".format(currentItem.prop("Class"), currentItem.prop("Name"), currentItem.prop("Signature"))); break; case "IKVM.Internal.ClassFile+ConstantPoolItemFieldref": constantsPool.add_Entry(i, currentItemType.remove("IKVM.Internal.ClassFile+ConstantPoolItem"), "{0}.{1} : {2}".format(currentItem.prop("Class"), currentItem.prop("Name"), currentItem.prop("Signature"))); break; case "IKVM.Internal.ClassFile+ConstantPoolItemNameAndType": // skip this one since don;t know what they point to //constantPoolValues.Add(i,"IKVM.Internal.ClassFile+ConstantPoolItemNameAndType"); break; case "IKVM.Internal.ClassFile+ConstantPoolItemString": case "IKVM.Internal.ClassFile+ConstantPoolItemInteger": case "IKVM.Internal.ClassFile+ConstantPoolItemFloat": case "IKVM.Internal.ClassFile+ConstantPoolItemDouble": case "IKVM.Internal.ClassFile+ConstantPoolItemLong": var value = currentItem.prop("Value").str(); value = value.base64Encode(); //HACK to deal with BUG in .NET Serialization and Deserialization (to reseatch further) constantsPool.add_Entry(i, currentItemType.remove("IKVM.Internal.ClassFile+ConstantPoolItem"), value, true); break; case "[null value]": //constantsPool.add_Entry(i,"[null value]", null); break; default: "Unsupported constantPoll type: {0}".error(currentItem.str()); break; } } } return(constantsPool); }
public static Dictionary <IMethod, Dictionary <string, List <KeyValuePair <INode, IMethodOrProperty> > > > externalMethodsAndProperties(this O2MappedAstData astData, string filter, string targetFolder, int numberOfItemsToProcess) { var MimimumAvailableMemoryRequired = "".availableMemory() / 4; //50; "Starting externalMethodsAndProperties calculations (with min memory required set to: {0}".info(MimimumAvailableMemoryRequired); if (targetFolder.valid().isFalse()) { targetFolder = PublicDI.config.getTempFolderInTempDirectory("_AstEngine_ExternalMappings"); } var methodMappingHashesFile = targetFolder.pathCombine("_methodMappingHashes.txt"); var o2Timer = new O2Timer("Calculated externalMethodsAndProperties").start(); var iMethodMappings = new Dictionary <IMethod, Dictionary <string, List <KeyValuePair <INode, IMethodOrProperty> > > >(); var iMethods = astData.iMethods(); var itemsToMap = iMethods.size();// - targetFolder.files().size(); var itemsMapped = 0; foreach (var iMethod in iMethods) { // check avaialble memory var availableMemory = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes").NextValue(); if (availableMemory < MimimumAvailableMemoryRequired) { "In externalMethodsAndProperties, There is not enough free memory to continue (MimimumAvailableMemoryRequired = {0}, availableMemory = {1}. Stopping mappings".error(MimimumAvailableMemoryRequired, availableMemory); "There are {0} iMethodMappings".debug(iMethodMappings.size()); break; } //"Available Memory: {0}".debug(availableMemory); //convert method var fullName = iMethod.fullName(); var md5Hash = fullName.safeFileName().md5Hash(); var savedMethodMappingsFile = targetFolder.pathCombine(md5Hash) + ".xml"; //var savedMethodMappingsFile = targetFolder.pathCombine(iMethod.fullName().safeFileName(100))+ ".xml"; itemsMapped++; if (savedMethodMappingsFile.fileExists().isFalse()) // Skip if method mappings have already been calculated { //"Mapping :{0}".debug(iMethod.DotNetName); if (iMethod.Name.regEx(filter)) { var mappings = astData.externalMethodsAndProperties(iMethod); iMethodMappings.Add(iMethod, mappings); var savedMethodMappings = astData.saveMappings(mappings); if (savedMethodMappings.fileExists()) { Files.MoveFile(savedMethodMappings, savedMethodMappingsFile); methodMappingHashesFile.fileInsertAt(0, "{0}\t{1}".format(md5Hash, fullName).line()); } } //savedMethodMappingsFile if (itemsMapped % 10 == 0) // every 10 methods show a log message { "In externalMethodsAndProperties, mapped [{0}/{1}] to folder: {2}".info(itemsMapped, itemsToMap, targetFolder); if (itemsMapped % 100 == 0) { PublicDI.config.gcCollect(); // every 100 methods release some memory } } if (numberOfItemsToProcess > 0 && numberOfItemsToProcess < iMethodMappings.size()) { "In externalMethodsAndProperties, max number of Items To Process reached ({0}), so stopping mappings]".info(numberOfItemsToProcess); "There are {0} iMethodMappings".debug(iMethodMappings.size()); break; } } } o2Timer.stop(); return(iMethodMappings); }
/// <summary> /// Builds an <seealso cref="SynonymMap"/> and returns it. /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public SynonymMap build() throws java.io.IOException public virtual SynonymMap build() { ByteSequenceOutputs outputs = ByteSequenceOutputs.Singleton; // TODO: are we using the best sharing options? org.apache.lucene.util.fst.Builder <BytesRef> builder = new org.apache.lucene.util.fst.Builder <BytesRef>(FST.INPUT_TYPE.BYTE4, outputs); BytesRef scratch = new BytesRef(64); ByteArrayDataOutput scratchOutput = new ByteArrayDataOutput(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Set<Integer> dedupSet; HashSet <int?> dedupSet; if (dedup) { dedupSet = new HashSet <>(); } else { dedupSet = null; } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final byte[] spare = new byte[5]; sbyte[] spare = new sbyte[5]; Dictionary <CharsRef, MapEntry> .KeyCollection keys = workingSet.Keys; CharsRef[] sortedKeys = keys.toArray(new CharsRef[keys.size()]); Arrays.sort(sortedKeys, CharsRef.UTF16SortedAsUTF8Comparator); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.apache.lucene.util.IntsRef scratchIntsRef = new org.apache.lucene.util.IntsRef(); IntsRef scratchIntsRef = new IntsRef(); //System.out.println("fmap.build"); for (int keyIdx = 0; keyIdx < sortedKeys.Length; keyIdx++) { CharsRef input = sortedKeys[keyIdx]; MapEntry output = workingSet[input]; int numEntries = output.ords.Count; // output size, assume the worst case int estimatedSize = 5 + numEntries * 5; // numEntries + one ord for each entry scratch.grow(estimatedSize); scratchOutput.reset(scratch.bytes, scratch.offset, scratch.bytes.length); Debug.Assert(scratch.offset == 0); // now write our output data: int count = 0; for (int i = 0; i < numEntries; i++) { if (dedupSet != null) { // box once //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Integer ent = output.ords.get(i); int?ent = output.ords[i]; if (dedupSet.Contains(ent)) { continue; } dedupSet.Add(ent); } scratchOutput.writeVInt(output.ords[i]); count++; } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int pos = scratchOutput.getPosition(); int pos = scratchOutput.Position; scratchOutput.writeVInt(count << 1 | (output.includeOrig ? 0 : 1)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int pos2 = scratchOutput.getPosition(); int pos2 = scratchOutput.Position; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int vIntLen = pos2-pos; int vIntLen = pos2 - pos; // Move the count + includeOrig to the front of the byte[]: Array.Copy(scratch.bytes, pos, spare, 0, vIntLen); Array.Copy(scratch.bytes, 0, scratch.bytes, vIntLen, pos); Array.Copy(spare, 0, scratch.bytes, 0, vIntLen); if (dedupSet != null) { dedupSet.Clear(); } scratch.length = scratchOutput.Position - scratch.offset; //System.out.println(" add input=" + input + " output=" + scratch + " offset=" + scratch.offset + " length=" + scratch.length + " count=" + count); builder.add(Util.toUTF32(input, scratchIntsRef), BytesRef.deepCopyOf(scratch)); } FST <BytesRef> fst = builder.finish(); return(new SynonymMap(fst, words, maxHorizontalContext)); }
public static Dictionary<IMethod, Dictionary<string,List<KeyValuePair<INode,IMethodOrProperty>>>> externalMethodsAndProperties(this O2MappedAstData astData, string filter, string targetFolder, int numberOfItemsToProcess) { var MimimumAvailableMemoryRequired = "".availableMemory()/4; //50; "Starting externalMethodsAndProperties calculations (with min memory required set to: {0}".info(MimimumAvailableMemoryRequired); if (targetFolder.valid().isFalse()) targetFolder = PublicDI.config.getTempFolderInTempDirectory("_AstEngine_ExternalMappings"); var methodMappingHashesFile = targetFolder.pathCombine("_methodMappingHashes.txt"); var o2Timer = new O2Timer("Calculated externalMethodsAndProperties").start(); var iMethodMappings = new Dictionary<IMethod, Dictionary<string,List<KeyValuePair<INode,IMethodOrProperty>>>>(); var iMethods = astData.iMethods(); var itemsToMap = iMethods.size();// - targetFolder.files().size(); var itemsMapped = 0; foreach(var iMethod in iMethods) { // check avaialble memory var availableMemory = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes").NextValue(); if (availableMemory < MimimumAvailableMemoryRequired) { "In externalMethodsAndProperties, There is not enough free memory to continue (MimimumAvailableMemoryRequired = {0}, availableMemory = {1}. Stopping mappings".error(MimimumAvailableMemoryRequired,availableMemory); "There are {0} iMethodMappings".debug(iMethodMappings.size()); break; } //"Available Memory: {0}".debug(availableMemory); //convert method var fullName = iMethod.fullName(); var md5Hash = fullName.safeFileName().md5Hash(); var savedMethodMappingsFile = targetFolder.pathCombine(md5Hash) + ".xml"; //var savedMethodMappingsFile = targetFolder.pathCombine(iMethod.fullName().safeFileName(100))+ ".xml"; itemsMapped++; if (savedMethodMappingsFile.fileExists().isFalse()) // Skip if method mappings have already been calculated { //"Mapping :{0}".debug(iMethod.DotNetName); if (iMethod.Name.regEx(filter)) { var mappings = astData.externalMethodsAndProperties(iMethod); iMethodMappings.Add(iMethod, mappings); var savedMethodMappings = astData.saveMappings(mappings); if (savedMethodMappings.fileExists()) { Files.MoveFile(savedMethodMappings, savedMethodMappingsFile); methodMappingHashesFile.fileInsertAt(0,"{0}\t{1}".format(md5Hash, fullName).line()); } } //savedMethodMappingsFile if (itemsMapped % 10 ==0) // every 10 methods show a log message { "In externalMethodsAndProperties, mapped [{0}/{1}] to folder: {2}".info(itemsMapped, itemsToMap, targetFolder); if (itemsMapped % 100 ==0) PublicDI.config.gcCollect(); // every 100 methods release some memory } if (numberOfItemsToProcess > 0 && numberOfItemsToProcess < iMethodMappings.size()) { "In externalMethodsAndProperties, max number of Items To Process reached ({0}), so stopping mappings]".info(numberOfItemsToProcess); "There are {0} iMethodMappings".debug(iMethodMappings.size()); break; } } } o2Timer.stop(); return iMethodMappings; }
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); }
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; }