/// <summary> /// Creates a new new keyword map on a new app domain /// </summary> public static KeywordMap CreateDomain(KeywordMapConfig config) { try { log.Debug(String.Format("Creating appDomain for type {0}", config.Type)); //setup domain var kwdomainsetup = new AppDomainSetup(); kwdomainsetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; //create domain var kwdomain = AppDomain.CreateDomain(config.Type, null, kwdomainsetup); //get remote builder instance var remotebuilder = (KeywordMapBuilder)kwdomain.CreateInstanceAndUnwrap("NRobotRemote.Domain", typeof(KeywordMapBuilder).FullName); //call remote builder var map = remotebuilder.CreateMap(config); //log keyword names log.Debug(String.Format("Keyword names are, {0}", String.Join(",", map.GetKeywordNames().ToArray()))); return(map); } catch (Exception e) { log.Error(String.Format("Exception creating keyword domain, {0}", e.Message)); throw new KeywordDomainException(e.Message); } }
public KeywordMap CreateMap(KeywordMapConfig config) { try { //check _config = config; if (String.IsNullOrEmpty(config.Library)) { throw new ArgumentNullException("Unable to instanciate KeywordMap - no library specified"); } if (String.IsNullOrEmpty(config.Type)) { throw new ArgumentNullException("Unable to instanciate KeywordMap - no type specified"); } var result = new KeywordMap(); result._config = config; //load assembly AppDomain.CurrentDomain.AssemblyResolve += KeywordAssemblyResolveHandler; if (File.Exists(config.Library)) { //load from path result._library = Assembly.LoadFrom(result._config.Library); } else { //load from assembly name result._library = Assembly.Load(result._config.Library); } result._type = result._library.GetType(result._config.Type); if (result._type == null) { throw new Exception(String.Format("Type {0} was not found", result._config.Type)); } //create instance try { //if can create instance build map of instance and static methods result._instance = Activator.CreateInstance(result._type); result._executor = new KeywordExecutor(result, result._instance); result.BuildMap(BuildMapOptions.StaticAndInstance); } catch { //if can't create instance create map of only static methods result._instance = null; result._executor = new KeywordExecutor(result, null); result.BuildMap(BuildMapOptions.OnlyStatic); } //load xml doc XDocument xmldoc = null; if (!String.IsNullOrEmpty(result._config.DocFile)) { if (File.Exists(result._config.DocFile)) { xmldoc = XDocument.Load(result._config.DocFile); } else { throw new Exception(String.Format("Xml documentation file not found : {0}", result._config.DocFile)); } } //get doc from xml if (xmldoc != null) { //library result._doc = result._type.GetXmlDocumentation(xmldoc); //keywords foreach (Keyword key in result.GetKeywords()) { key._doc = key.Method.GetXmlDocumentation(xmldoc); } } return(result); } catch (Exception e) { throw new Exception(e.Message); } }