Ejemplo n.º 1
0
 /// <summary>
 /// Constructor from keyword map
 /// </summary>
 public KeywordExecutor(KeywordMap map, object instance)
 {
     if (map==null) throw new ArgumentNullException("Unable to instanciate keyword executor - null keyword map");
     _keywords = map;
     _instance = instance;
     _tracecontent = new MemoryStream();
     _tracelistener = new TextWriterTraceListener(_tracecontent);
     _timer = new Stopwatch();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor from keyword map
 /// </summary>
 public KeywordExecutor(KeywordMap map, object instance)
 {
     if (map == null)
     {
         throw new ArgumentNullException("Unable to instanciate keyword executor - null keyword map");
     }
     _keywords      = map;
     _instance      = instance;
     _tracecontent  = new MemoryStream();
     _tracelistener = new TextWriterTraceListener(_tracecontent);
     _timer         = new Stopwatch();
 }
Ejemplo n.º 3
0
        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);
            }
        }
        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);
            }
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Process xmlrpc request with a specific keyword map
		/// </summary>
		public void ProcessRequest(HttpListenerContext RequestContext, KeywordMap map)
		{
			if (map==null) throw new Exception("No keyword map for xmlrpc process");
			_map = map;
			base.ProcessRequest(RequestContext);
		}