static ArrayTypeMetadata() { s_szArrayLowerBounds = new [] { 0 }.ToImmutableArray(); s_szArrayShape = new ArrayShape(rank: 1, sizes: ImmutableArray <int> .Empty, lowerBounds: s_szArrayLowerBounds); s_arrayProbeTypeMetadata = (ClassMetadata)LoadedTypes.FromType(typeof(ArrayProbeType)); s_arrayTypeMetadata = (DefinedTypeMetadata)LoadedTypes.FromType(typeof(ArrayProbeType[])); }
private static Type GetClrType(EdmTypeStructure edmTypeStructure, IDictionary <EdmTypeStructure, Type> typesCache) { if (typesCache.TryGetValue(edmTypeStructure, out Type type)) { return(type); } type = LoadedTypes.SingleOrDefault ( item => edmTypeStructure.FullName == item.FullName ); if (type != null) { if (type.IsValueType && !type.IsNullableType() && edmTypeStructure.IsNullable) { type = type.ToNullable(); typesCache.Add(edmTypeStructure, type); } return(type); } throw new ArgumentException($"Cannot find CLT type for EDM type {edmTypeStructure.FullName}"); }
private void LoadAssembliesIntoDynamo(DynamoLoader loader, ILogger logger, LibraryServices libraryServices) { var assemblies = LoadAssembliesInBinDirectory(logger); // filter the assemblies var zeroTouchAssemblies = new List <Assembly>(); var nodeModelAssemblies = new List <Assembly>(); foreach (var assem in assemblies) { if (loader.ContainsNodeModelSubType(assem)) { nodeModelAssemblies.Add(assem); } else { zeroTouchAssemblies.Add(assem); } } // load the zero touch assemblies foreach (var zeroTouchAssem in zeroTouchAssemblies) { libraryServices.ImportLibrary(zeroTouchAssem.Location, logger); } // load the node model assemblies foreach (var nodeModelAssem in nodeModelAssemblies) { var nodes = loader.LoadNodesFromAssembly(nodeModelAssem); nodes.ForEach(x => LoadedTypes.Add(x)); } }
/// <summary> /// Loads all the classes with SosigScriptLibraryAttribute in the specified assembly /// </summary> /// <param name="asm">Assembly to get types from</param> private void LoadAssemblyTypes(Assembly asm) { var typeList = new SosigScriptTypeList() { Source = asm }; foreach (var type in asm.SafeGetTypes()) { if (!type.IsClass) { continue; } if (type.BaseType != typeof(SosigScriptTypeList)) { continue; } var types = new Type[] { typeof(SosigScriptTypeList) }; var ctor = type.GetConstructor ( BindingFlags.Instance | BindingFlags.Public, null, CallingConventions.HasThis, types, null ); ctor?.Invoke(new object[] { typeList }); } LoadedTypes.AddItem(typeList); }
public void Clear() { IsCleared = true; DelegateManager.Clear(); freeIntepreters.Clear(); intepreters.Clear(); crossAdaptors.Clear(); valueTypeBinders.Clear(); mapType.Clear(); clrTypeMapping.Clear(); mapTypeToken.Clear(); mapMethod.Clear(); mapString.Clear(); redirectMap.Clear(); fieldGetterMap.Clear(); fieldSetterMap.Clear(); memberwiseCloneMap.Clear(); createDefaultInstanceMap.Clear(); createArrayInstanceMap.Clear(); loadedAssemblies = null; references.Clear(); LoadedTypes.Clear(); RedirectMap.Clear(); FieldGetterMap.Clear(); FieldSetterMap.Clear(); MemberwiseCloneMap.Clear(); CreateDefaultInstanceMap.Clear(); CreateArrayInstanceMap.Clear(); CrossBindingAdaptors.Clear(); ValueTypeBinders.Clear(); Intepreters.Clear(); FreeIntepreters.Clear(); }
// TODO [GetCurrentMethod] Note that '(' will be valid, and "(" too... Plus, in comments too. IEnumerable <MethodInfo> GetCurrentMethod() { var str = Text.Substring(0, SelectionStart); // ( ) positions var opened = str.LastIndexOf('('); if (opened < 0) { return(null); } var closed = Text.IndexOf(')', opened); int endMethod = closed < 0 || (closed > opened && SelectionStart < closed) ? opened : -1; if (endMethod < 0) { return(null); } while (endMethod > -1) { if (IsAlpha(Text[endMethod])) { break; } endMethod--; } int startMethod = endMethod++; while (startMethod > -1) { if (!IsAlpha(Text[startMethod])) { break; } startMethod--; } startMethod++; // Getting type and method name string method = Text.Substring(startMethod, endMethod - startMethod); string type = GetLastWord(1, startMethod, true); if (method.Length == 0 || type.Length == 0) { return(null); // TODO [GetCurrentMethod] if (type.Length == 0) -> it is a made-by-user method } var typ = LoadedTypes.FirstOrDefault(t => t.Name == type); if (typ == null || Instructions.Contains(method)) { return(null); } return(typ.GetMethods().Where(m => m.Name == method)); }
public TypeMetadata GetTypeFromSerializedName(string name) { if (!LoadedTypes.TryFindByName(name, out TypeMetadata typeMetadata)) { throw new Exception($"Cannot find type: '{name}'"); } return(typeMetadata); }
public TypeMetadata GetSZArrayType(TypeMetadata elementType) { if (LoadedTypes.IsTypeLoaded(elementType.FullName)) { return(LoadedTypes.GetByName(elementType.FullName + "[]")); } throw new NotImplementedException(); }
public bool InUse() { // get all of the function ids from the custom nodes in this package var guids = LoadedCustomNodes.Select(x => x.Guid); // check if any of the custom nodes is in a workspace var customNodeInUse = dynSettings.Controller.DynamoModel.AllNodes.Where(x => x is dynFunction) .Cast <dynFunction>() .Any(x => guids.Contains(x.Definition.FunctionId)); return((LoadedTypes.Any() || customNodeInUse) && Loaded); }
private void LoadAssembliesIntoDynamo(LoadPackageParams loadPackageParams) { var loader = loadPackageParams.Loader; var assemblies = LoadAssembliesInBinDirectory(); // filter the assemblies var zeroTouchAssemblies = new List <Assembly>(); var nodeModelAssemblies = new List <Assembly>(); // categorize the assemblies to load, skipping the ones that are not identified as node libraries foreach (var assem in assemblies.Where(x => x.IsNodeLibrary).Select(x => x.Assembly)) { if (loader.ContainsNodeModelSubType(assem)) { nodeModelAssemblies.Add(assem); } else { zeroTouchAssemblies.Add(assem); } } // load the zero touch assemblies var libraryServices = loadPackageParams.LibraryServices; foreach (var zeroTouchAssem in zeroTouchAssemblies) { libraryServices.ImportLibrary(zeroTouchAssem.Location); } // load the node model assemblies var context = loadPackageParams.Context; var nodes = nodeModelAssemblies.SelectMany( assem => { var assemblyNodes = new List <TypeLoadData>(); loader.LoadNodesFromAssembly(assem, context, assemblyNodes, new List <TypeLoadData>()); return(assemblyNodes); }); foreach (var node in nodes) { LoadedTypes.Add(node.Type); } }
/// <summary> /// Loads the specified assemblies /// </summary> /// <param name="assemblyFiles">Assemblies</param> public void LoadAssemblies(params string[] assemblyFiles) { new TaskFactory().StartNew(() => { while (LoadingAssemblies) /* wait */ } { LoadingAssemblies = true; foreach (string asm in assemblyFiles) { foreach (var t in Assembly.LoadFile(asm.Contains("\\") ? asm : AssembliesLocation + asm) .GetTypes().Where(t => t.IsPublic)) { LoadedTypes.Add(t); LoadedNamespaces.Add(t.Namespace); } } LoadingAssemblies = false; });
public object GetByName(Type t, string Name, bool flag = true) { var TableName = (GetTablenameFromAttribute(t) == null) ? t.Name : GetTablenameFromAttribute(t); using (var connection = new SqlConnection(str)) { LoadedTypes.Add(TableName); connection.Open(); var TableInfo = GetTableInfo(TableName); var commandText = string.Format("SELECT * FROM {0} WHERE UserName = '******';", TableName, Name); var reader = new SqlCommand(commandText, connection).ExecuteReader(); while (reader.Read()) { var CtorParams = new List <object>(); foreach (var item in TableInfo) { if (item.Key == "Descriminator") { t = GetTypeByName(reader[item.Key].ToString()); } else { CtorParams.Add(reader[item.Key]); } if (GetForeighKeysList(TableName).Contains(item.Key)) { if (flag) { var type = GetTypeByName(item.Key.Replace("Id", "")); var o = GetById(type, CtorParams.LastOrDefault().ToString(), false); CtorParams.Add(o); } else { CtorParams.Add(null); } } } foreach (var TypeName in GetTypeOneToMany(t)) { if (flag) { var type = GetTypeByName(TypeName); var smt = (GetTablenameFromAttribute(type) == null) ? type.Name : GetTablenameFromAttribute(type); var searchRes = ""; foreach (var item in GetForeighKeysList(smt)) { if (item.Contains(TableName)) { searchRes = item; } } var listOfType = getList(CtorParams.FirstOrDefault().ToString(), searchRes, type, false); var listInstance = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { type })); foreach (var item in listOfType) { listInstance.Add(item); } CtorParams.Add(listInstance); } else { CtorParams.Add(null); } } return(Activator.CreateInstance(t, CtorParams.ToArray())); } return(null); } }
public static Type[] GetTypes(Assembly assembly) { if (LoadedTypes.TryGetValue(assembly, out Type[] types))
public TypeMetadata GetPrimitiveType(PrimitiveTypeCode typeCode) { switch (typeCode) { case PrimitiveTypeCode.Boolean: return(LoadedTypes.FromType(typeof(Boolean))); case PrimitiveTypeCode.Byte: return(LoadedTypes.FromType(typeof(Byte))); case PrimitiveTypeCode.Char: return(LoadedTypes.FromType(typeof(Char))); case PrimitiveTypeCode.Double: return(LoadedTypes.FromType(typeof(Double))); case PrimitiveTypeCode.Int16: return(LoadedTypes.FromType(typeof(Int16))); case PrimitiveTypeCode.Int32: return(LoadedTypes.FromType(typeof(Int32))); case PrimitiveTypeCode.Int64: return(LoadedTypes.FromType(typeof(Int64))); case PrimitiveTypeCode.IntPtr: return(LoadedTypes.FromType(typeof(IntPtr))); case PrimitiveTypeCode.Object: return(LoadedTypes.FromType(typeof(Object))); case PrimitiveTypeCode.SByte: return(LoadedTypes.FromType(typeof(SByte))); case PrimitiveTypeCode.Single: return(LoadedTypes.FromType(typeof(Single))); case PrimitiveTypeCode.String: return(LoadedTypes.FromType(typeof(String))); case PrimitiveTypeCode.TypedReference: return(LoadedTypes.FromType(typeof(TypedReference))); case PrimitiveTypeCode.UInt16: return(LoadedTypes.FromType(typeof(UInt16))); case PrimitiveTypeCode.UInt32: return(LoadedTypes.FromType(typeof(UInt32))); case PrimitiveTypeCode.UInt64: return(LoadedTypes.FromType(typeof(UInt64))); case PrimitiveTypeCode.UIntPtr: return(LoadedTypes.FromType(typeof(UIntPtr))); case PrimitiveTypeCode.Void: return(LoadedTypes.FromType(typeof(void))); default: throw new Exception(String.Format("Unknown typecode: '{0}'", typeCode)); } }
/// <summary> /// Finds a type by a variable name /// </summary> /// <param name="variableName">The variable whose type is going to be found</param> /// <returns>The found type</returns> public Type FindType(string variableName) { var idx = Text.IndexOf(variableName, StringComparison.InvariantCulture); // Seeking before it int lstEnd = idx - 1; while (lstEnd > 0) { if (IsAlphaOrNumeric(Text[lstEnd])) { break; } lstEnd--; } int lstStart = lstEnd++ - 1; while (lstStart > -1) { if (!IsAlphaOrNumeric(Text[lstStart])) { break; } lstStart--; } lstStart++; var type = TranslateGenericType(Text.Substring(lstStart, lstEnd - lstStart)); if (type == "var") // Seeking after = { lstStart = idx + variableName.Length; while (lstStart < Text.Length) { if (Text[lstStart] == '(') // explicit var { lstEnd = lstStart; while (lstEnd < Text.Length) { if (Text[lstEnd++] == ')') { lstStart++; lstEnd--; break; } } break; } else if (Text[lstStart] == 'n') { if (Text.Length < lstStart + 3) { return(null); // Nothing after "new" } if (Text.Substring(lstStart, 3) == "new") // Seek for it { lstStart += 3; while (lstStart < Text.Length) { if (IsAlpha(Text[lstStart])) { break; } lstStart++; } lstEnd = lstStart; while (lstEnd < Text.Length) { if (Text[lstEnd] == '(') { break; } lstEnd++; } break; } } // else, it's from a method lstStart++; } type = Text.Substring(lstStart, lstEnd - lstStart); } return(LoadedTypes.FirstOrDefault(t => t.Name == type)); }
public bool InUse() { return((LoadedTypes.Any() || WorkspaceOpen() || CustomNodeInWorkspace()) && Loaded); }
public void Load() { try { GetAssemblies().Select(DynamoLoader.LoadNodesFromAssembly).SelectMany(x => x).ToList().ForEach(x => LoadedTypes.Add(x)); DynamoLoader.LoadCustomNodes(CustomNodeDirectory).ForEach(x => LoadedCustomNodes.Add(x)); Loaded = true; } catch (Exception e) { dynSettings.DynamoLogger.Log("Exception when attempting to load package " + this.Name + " from " + this.RootDirectory); dynSettings.DynamoLogger.Log(e.GetType() + ": " + e.Message); } }
/// <summary> /// Refresh the suggestions in the autocomplete /// </summary> void RefreshSuggestions() { if (LoadingAssemblies) { return; } ShowAutocomplete(); Autocomplete.BeginUpdate(); var suggestions = new List <string>(); string lstType = GetLastWord(1, true); string curWord = GetLastWord(0); string lstWord = GetLastWord(); int added = 0; // using Namespace if (lstWord == "using") { foreach (var ns in LoadedNamespaces) { if (!ns.Contains(curWord, StringComparison.InvariantCultureIgnoreCase)) { continue; } if (added++ >= MaximumSuggestions) { break; } Autocomplete.AddSuggestion(new Suggestion(ns, "namespace", "")); } } // Type.Something else if (lstType.Length > 0) { var type = LoadedTypes.FirstOrDefault(t => t.Name == lstType); bool mustStatic = !FoundParenthesis; if (type == null) { type = FindType(lstType); mustStatic = false; } if (type != null) { if (type.IsEnum) { foreach (var f in type.GetFields()) { if (!f.Name.Contains(curWord, StringComparison.InvariantCultureIgnoreCase)) { continue; } if (added++ >= MaximumSuggestions) { break; } if (f.Name != "value__") { Autocomplete.AddSuggestion(new Suggestion(f.Name, "enumprop", "")); } } } else { foreach (var m in type.GetMethods()) { if (m.IsStatic != mustStatic || !m.IsPublic || !m.Name.Contains(curWord, StringComparison.InvariantCultureIgnoreCase)) { continue; } if (added++ >= MaximumSuggestions) { break; } if (m.Name.IndexOf("get_", StringComparison.InvariantCulture) == 0 || m.Name.IndexOf("set_", StringComparison.InvariantCulture) == 0) { Autocomplete.AddSuggestion(new Suggestion(m.Name.Substring(4), "property", "")); } else if (m.Name.IndexOf("add_", StringComparison.InvariantCulture) == 0) { Autocomplete.AddSuggestion(new Suggestion(m.Name.Substring(4), "event", "")); } else if (m.Name.IndexOf("remove_", StringComparison.InvariantCulture) == 0) { Autocomplete.AddSuggestion(new Suggestion(m.Name.Substring(7), "event", "")); } else { Autocomplete.AddSuggestion(new Suggestion(m.Name, "method", "")); } } } } } // No type has been declared else { foreach (var v in GetDeclaredVariablesAndMethods()) { if (!v.Contains(curWord, StringComparison.InvariantCultureIgnoreCase)) { continue; } if (added++ >= MaximumSuggestions) { break; } Autocomplete.AddSuggestion(new Suggestion(v, "custom", "")); } foreach (var k in Keywords) { if (!k.Contains(curWord, StringComparison.InvariantCultureIgnoreCase)) { continue; } if (added++ >= MaximumSuggestions) { break; } Autocomplete.AddSuggestion(new Suggestion(k, "keyword", "")); } foreach (var t in LoadedTypes) { if (!t.IsPublic || !t.Name.Contains(curWord, StringComparison.InvariantCultureIgnoreCase) || t.Name.Contains("`")) // Well, about this... Maybe the user wants. { continue; } if (added++ >= MaximumSuggestions) { break; } if (t.IsEnum) { Autocomplete.AddSuggestion(new Suggestion(t.Name, "enum", t.Namespace)); } else if (t.IsClass) { Autocomplete.AddSuggestion(new Suggestion(t.Name, "class", t.Namespace)); } else { Autocomplete.AddSuggestion(new Suggestion(t.Name, "method", t.Namespace)); } } } Autocomplete.EndUpdate(curWord); }
private bool LoadFigureFromAssembly(string path, int figureNum) { try { string asmName = GetAssemblyName(Path.GetFileName(path)); Assembly asm = Assembly.LoadFrom(path); Type[] types = asm.GetTypes(); Type figure = null; Type factory = null; foreach (Type t in types) { if (t.BaseType.Equals(typeof(CTwoDFigureFactory))) { factory = t; } if (t.BaseType.Equals(typeof(CTwoDFigure))) { figure = t; } } if ((factory == null) || (figure == null)) { return(false); } MethodInfo[] methods = factory.GetMethods(BindingFlags.Public | BindingFlags.Static); if (methods.Length == 0) { return(false); } List <MethodInfo> goodMethods = new List <MethodInfo>(); foreach (MethodInfo m in methods) { ParameterInfo[] parameters = m.GetParameters(); if (parameters.Length == 0) { if (m.ReturnType.BaseType.Equals(typeof(CTwoDFigureFactory))) { goodMethods.Add(m); } } } if (goodMethods.Count != 1) { return(false); } LoadedTypes.Add(figure); LoadedMethods.Add(goodMethods[0]); if (FiguresGroupType == null) { Type[] interfaces = figure.GetInterfaces(); foreach (Type t in interfaces) { if (t.Equals(typeof(IFiguresGroup))) { FiguresGroupType = figure; } } } bool isPictureLoaded; Image pic = null; try { pic = Image.FromFile(String.Format(PICTURE_FILE_TEMPLATE, asmName)); isPictureLoaded = true; } catch (Exception) { isPictureLoaded = false; } if (isPictureLoaded) { UI.CreateButton(String.Format(BUTTON_NAME_TEMPLATE, figureNum), pic); } else { UI.CreateButton(String.Format(BUTTON_NAME_TEMPLATE, figureNum), figure.Name); } string[] typeDeclar = figure.FullName.Split('.'); NamespacesNames.Add(typeDeclar[0]); TypesNames.Add(typeDeclar[1]); return(true); } catch (Exception) { return(false); } }