/// <summary> /// Creates configuration from cmd line options /// </summary> public RemoteServiceConfig(string[] args) { if (args.Length < 2) { throw new ConfigurationErrorsException("No enough config parameters"); } _mapconfigs = new Dictionary <String, KeywordMapConfig>(); port = CNoPortSpecified; int argcount = args.Length; //get indexes int portindex = -1; int keyindex = -1; for (int counter = 0; counter < argcount; counter++) { if (args[counter].Equals(CTokenPort, StringComparison.CurrentCultureIgnoreCase)) { portindex = counter; } if (args[counter].Equals(CTokenKeyword, StringComparison.CurrentCultureIgnoreCase)) { keyindex = counter; } } if ((portindex == -1) || (portindex == argcount)) { throw new ConfigurationErrorsException("No port specified"); } if ((keyindex == -1) || (keyindex == argcount)) { throw new ConfigurationErrorsException("No keyword libraries specified"); } //process port int temport; if (!int.TryParse(args[portindex + 1], out temport)) { throw new ConfigurationErrorsException("Invalid port specified"); } this.port = temport; //process key libraries int startindex; int endindex; if (portindex > keyindex) { endindex = portindex - 1; startindex = keyindex + 1; } else { endindex = argcount - 1; startindex = keyindex + 1; } for (int counter = startindex; counter <= endindex; counter++) { var config = new KeywordMapConfig(args[counter]); this._mapconfigs.Add(config.Type, config); } }
/// <summary> /// Add a new keyword assembly/type config /// </summary> public void AddKeywordConfig(KeywordMapConfig config) { if (config == null) { throw new ConfigurationErrorsException("Config specified is null"); } if (String.IsNullOrEmpty(config.Type)) { throw new ConfigurationErrorsException("Config has not Type defined"); } _mapconfigs.Add(config.Type, config); }
/// <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); } }
/// <summary> /// Creates configuration from cmd line options /// </summary> public RemoteServiceConfig(string[] args) { if (args.Length < 2) throw new ConfigurationErrorsException("No enough config parameters"); _mapconfigs = new Dictionary<String,KeywordMapConfig>(); port = CNoPortSpecified; int argcount = args.Length; //get indexes int portindex = -1; int keyindex = -1; for (int counter=0; counter < argcount; counter++) { if (args[counter].Equals(CTokenPort,StringComparison.CurrentCultureIgnoreCase)) { portindex = counter; } if (args[counter].Equals(CTokenKeyword,StringComparison.CurrentCultureIgnoreCase)) { keyindex = counter; } } if ((portindex==-1)||(portindex==argcount)) throw new ConfigurationErrorsException("No port specified"); if ((keyindex==-1)||(keyindex==argcount)) throw new ConfigurationErrorsException("No keyword libraries specified"); //process port int temport; if (!int.TryParse(args[portindex+1],out temport)) throw new ConfigurationErrorsException("Invalid port specified"); this.port = temport; //process key libraries int startindex; int endindex; if (portindex > keyindex) { endindex = portindex-1; startindex = keyindex + 1; } else { endindex = argcount-1; startindex = keyindex + 1; } for (int counter=startindex; counter<=endindex; counter++) { var config = new KeywordMapConfig(args[counter]); this._mapconfigs.Add(config.Type,config); } }
/// <summary> /// Add a new keyword assembly/type config /// </summary> public void AddKeywordConfig(KeywordMapConfig config) { if (config==null) throw new ConfigurationErrorsException("Config specified is null"); if (String.IsNullOrEmpty(config.Type)) throw new ConfigurationErrorsException("Config has not Type defined"); _mapconfigs.Add(config.Type,config); }