Beispiel #1
0
        public void SetUp()
        {
            engine = new ReflectionEngine();

            param = new ReflectionEngineParameters();
            param.AssemblyFileNames = new string[] { "TopCoder.LoggingWrapper.dll" };
            param.ReferencePaths    = new string[] { "../../test_files/failuretests" };
        }
Beispiel #2
0
 public virtual void AddChannel(AnalogInputChannel channelInfo, params object[] parameter)
 {
     try
     {
         if (!_isSim)
         {
             MethodInfo      mi    = ReflectionEngine.GetMethods(this.AITask).ToList().Find(x => x.Name == "AddChannel");
             ParameterInfo[] pi    = mi.GetParameters();
             object[]        param = new object[pi.Length];
             for (int i = 0; i < pi.Length; i++)
             {
                 if (i == 0)
                 {
                     param[i] = channelInfo.ChannelID;
                 }
                 else if (i == 1)
                 {
                     param[i] = channelInfo.RangeLow;
                 }
                 else if (i == 2)
                 {
                     param[i] = channelInfo.RangeHigh;
                 }
                 else
                 {
                     if (parameter.Length == 0 || parameter[i - 3] == null)
                     {
                         if (pi[i].DefaultValue == null)
                         {
                             throw new Exception("参数未指定值");
                         }
                         else
                         {
                             param[i] = pi[i].DefaultValue;
                         }
                     }
                     else
                     {
                         Type t = pi[i].ParameterType;
                         param[i] = Utility.TypeCast(parameter[i - 3], t);
                     }
                 }
             }
             mi.Invoke(this.AITask, param);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #3
0
        /// <summary>
        /// <para>This method generates the CSharp API documentation to the given XmlDocument instance. The API
        /// documentation is merged into the XmlDocument instance so that any additional information in the XmlDocument
        /// is kept unchanged and the overlapped information is updated.</para>
        /// <para>The general processing sequence is as follows: The ProcessDocument method is called each time
        /// to explore the API metadata using reflection. In order to keep current AppDomain clean, a new AppDomain
        /// named 'ReflectionEngine' is created and finally unloaded by the time the ProcessDocument method exits.
        /// A ReflectionEngine instance is created with the
        /// referenced ReflectionEngineParameters instance in the new Domain. And all the assemblies to be analyzed are
        /// also loaded in the new AppDomain. A MarshalByRef logger is created when possible and passed to the new
        /// Domain so that the logging is acutally performed in the current domain. Finally when the process is
        /// finished, all the assemblies in the new domain are unloaded. And the current AppDomain keeps clean.</para>
        /// </summary>
        /// <param name="apiSpec">the given XmlDocument instance to which the CSharp API documentation is generated.
        /// This XmlDocument should follow the apiSpec.xsd file given by this component.</param>
        /// <exception cref="ArgumentNullException">if apiSpec is null.</exception>
        /// <exception cref="ArgumentException">if the root element of apiSpec is not 'apispec'</exception>
        /// <exception cref="XmlProcessorException">if anything else goes wrong.</exception>
        public void ProcessDocument(XmlDocument apiSpec)
        {
            Helper.ValidateNotNull(apiSpec, "apiSpec");
            //throw exception if root node is not apiSpec
            if (apiSpec.DocumentElement == null || apiSpec.DocumentElement.Name != "apispec")
            {
                throw new ArgumentException("apiSpec must have root node with name 'apispec'", "apiSpec");
            }

            AppDomain appDomain = null;

            try
            {
                MBRLogger mbrLogger = null;
                if (rep.LoggerNamespace != null)
                {
                    Logger logger = LogManager.CreateLogger(rep.LoggerNamespace);
                    mbrLogger = new MBRLogger(logger);
                }

                //Create new app domain
                appDomain = AppDomain.CreateDomain("ReflectionEngine", AppDomain.CurrentDomain.Evidence,
                                                   AppDomain.CurrentDomain.SetupInformation);

                //Create the ReflectionEngine instance in the new AppDomain
                object[]         createInstanceArgs = mbrLogger == null ? new object[0] : new object[] { mbrLogger };
                ReflectionEngine re = (ReflectionEngine)appDomain.CreateInstanceAndUnwrap(
                    typeof(ReflectionEngine).Assembly.FullName, typeof(ReflectionEngine).FullName, false,
                    BindingFlags.Public | BindingFlags.Instance, null, createInstanceArgs,
                    CultureInfo.InvariantCulture, new object[0], AppDomain.CurrentDomain.Evidence);

                //Process the APIs
                string newSpec = re.WriteAPISpec(rep, apiSpec.InnerXml);

                //Load the newly formed API specification in the xml document.
                apiSpec.LoadXml(newSpec);
            }
            catch (Exception e)
            {
                throw new XmlProcessorException("Unable to generate CSharp API documentation.", e);
            }
            finally
            {
                if (appDomain != null)
                {
                    AppDomain.Unload(appDomain);
                }
            }
        }
Beispiel #4
0
 public virtual void Stop()
 {
     try
     {
         if (!_isSim)
         {
             MethodInfo mi = ReflectionEngine.GetMethods(this.AITask).ToList().Find(x => x.Name == "Stop");
             mi.Invoke(this.AITask, null);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #5
0
 public virtual void RemoveChannel(int channelID)
 {
     try
     {
         if (!_isSim)
         {
             MethodInfo mi = ReflectionEngine.GetMethods(this.AITask).ToList().Find(x => x.Name == "RemoveChannel");
             mi.Invoke(this.AITask, new object[] { channelID });
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #6
0
        public void DemoTest_NonCommandLine1()
        {
            //Setup options
            ReflectionEngineParameters rep = new ReflectionEngineParameters();

            rep.AssemblyFileNames = new string[] { UnitTestHelper.MOCKLIBPATH };
            rep.ReferencePaths    = new string[] { UnitTestHelper.REFPATH };
            rep.SlashDocFileNames = new string[] { UnitTestHelper.MOCKXMLPATH };
            rep.DocumentPrivates  = true;

            ReflectionEngine re = new ReflectionEngine();

            //Write the API specification
            string      xml       = re.WriteAPISpec(rep, "<apispec></apispec>");
            XmlDocument xmlOutput = new XmlDocument();

            xmlOutput.LoadXml(xml);
        }
Beispiel #7
0
 public virtual void Initialize(params object[] parameter)
 {
     try
     {
         if (!_isSim)
         {
             ConstructorInfo ctor = ReflectionEngine.GetConstructors(this.DriverPath, this.DeviceName, this.DeviceName + "AITask")[0];
             this.AITask = ReflectionEngine.CreateObject(ctor, parameter);
         }
         else
         {
             Generation.SineWave(ref sineData, 1, 0, 10, 10000);
             Generation.SquareWave(ref squreData, 1, 50, 10, 10000);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #8
0
        /// <summary>
        /// Prepares the result fields.
        /// </summary>
        /// <param name="parameters">The parameters to use.</param>
        protected void DoResults(ReflectionEngineParameters parameters)
        {
            engine = new ReflectionEngine();

            // No existing spec, really, you can't have everything
            resultString = engine.WriteAPISpec(parameters, "<apispec><package name='IDONTEXIST'/></apispec>");

            resultDocument = new XmlDocument();
            resultDocument.LoadXml(resultString);
            resultString = resultDocument.InnerXml;

            Console.WriteLine("RESULTS FOR TEST {0}", GetType());

            Console.WriteLine();
            Console.WriteLine("You can comment out the code that creates a text version of the accuracy XML.");
            Console.WriteLine("Manual inspection might show additional, unexpected errors.");
            Console.WriteLine("Ideally, the results should be well-defined enough for one unique XML structure" +
                              "to be expected.");
            Console.WriteLine("When the component has gone through final fixes, a 'gold standard' with the output can");
            Console.WriteLine("be created for future regression testing.");

            // File.WriteAllText(@"../../test_files/accuracy/somelittlefile.xml", resultString);
        }