/// <summary> /// Configure object events and properties /// </summary> /// <param name="_view_name"></param> /// <param name="_control_guid"></param> /// <param name="ctrl"></param> public JToken Configure(TBaseObjects bObj, ref object obj) { JToken Config = bObj.Configuration; set_properties(ref obj, Config); Set_event_handler(bObj.Events, ref obj); return(Config); }
/// <summary> /// Generic new control from type /// </summary> /// <param name="control_guid"></param> /// <param name="type_control"></param> /// <returns></returns> private void CreateObjects(String main_view) { TBaseObjects bObj = new TBaseObjects(Globals, main_view); try { if (bObj.hasErrors()) { errors.add(bObj.jErrors); } else { JArray Obj_list = bObj.Object_list; foreach (JToken _bObj in Obj_list) { // Active object bObj.ActiveObject(_bObj); // create typed control String assembly_path = Globals.getAssembly(bObj.Assembly); Type type_control = null; if (System.IO.File.Exists(assembly_path)) { Assembly _dll = Assembly.Load(File.ReadAllBytes(assembly_path)); type_control = _dll.GetType(bObj.Object_name); } else { Assembly _dll = AppDomain.CurrentDomain.GetAssemblies().Where(ass => ass.GetName().Name == bObj.Assembly).FirstOrDefault(); type_control = _dll.GetType(bObj.Object_name); } if (type_control == null) { errors.add(String.Format("Error creating object instance '{0}' from type '{1}'.", bObj.GUID, bObj.Assembly)); } else { Object typed_control = (Object)Activator.CreateInstance(type_control); // Configure control JToken cfg = Configure(bObj, ref typed_control); // add control to list objects.Add(bObj.GUID, new ObjStruct(bObj.GUID, typed_control, cfg, bObj.Events, bObj.Methods)); } } } } catch (Exception exc) { errors.add(String.Format("Error loading assembly and type '{0}': {1}", bObj.Assembly, exc.Message)); } }
/// <summary> /// Generic new control from type /// </summary> /// <param name="control_guid"></param> /// <param name="type_control"></param> /// <returns></returns> private void CreateObjects(String main_view) { TBaseObjects bObj = new TBaseObjects(Globals, main_view); try { if (bObj.hasErrors()) { errors.add(bObj.jErrors); } else { JArray Obj_list = bObj.Object_list; foreach (JToken _bObj in Obj_list) { // Active object bObj.ActiveObject(_bObj); // display debug debug.add("New control: " + bObj.GUID); // create typed control Type type_control = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes().Where(type => type.FullName == bObj.Object_name)).FirstOrDefault(); if (type_control == null) { Assembly _dll = Assembly.LoadFrom(Globals.getAssembly(bObj.Assembly)); type_control = _dll.GetType(bObj.Object_name); } if (type_control == null) { errors.add(String.Format("Error creating object instance '{0}' from type '{1}'.", bObj.GUID, bObj.Assembly)); } else { Object typed_control = (Object)Activator.CreateInstance(type_control); // Configure control JToken cfg = Configure(bObj, ref typed_control); // add control to list objects.Add(bObj.GUID, new ObjStruct(bObj.GUID, typed_control, cfg, bObj.Events, bObj.Methods)); } } } } catch (Exception exc) { errors.add(String.Format("Error loading assembly and type '{0}': {1}", bObj.Assembly, exc.Message)); } }