LanguageDriverClassManager.cs :  » Testing » SystiN » Systin.Library » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Testing » SystiN 
SystiN » Systin.Library » LanguageDriverClassManager.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Threading;

namespace Systin.Library{
    /// <summary>
    /// This class manages all of the different Language Driver Classes for language assemblies.
    /// </summary>
    public sealed class LanguageDriverClassManager
    {
        #region Properties and Fields
        private Dictionary<string, LanguageDriverClass> mLanguageDriverClassHash;
        private Stack<MethodInfo> mInstructionStack;

        /// <summary>
        /// Gets the language driver class hash.
        /// </summary>
        /// <value>The language driver class hash.</value>
        public Dictionary<string, LanguageDriverClass> LanguageDriverClassHash
        {
            get { return mLanguageDriverClassHash; }
        }
        
        /// <summary>
        /// Gets the instruction stack.
        /// </summary>
        /// <value>The instruction stack.</value>
        public Stack<MethodInfo> InstructionStack
        {
            get { return mInstructionStack; }
        }       
  
  
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="LanguageDriverClassManager"/> class.
        /// </summary>
        private LanguageDriverClassManager() {
            this.mLanguageDriverClassHash = new Dictionary<string, LanguageDriverClass>();
            this.mInstructionStack = new Stack<MethodInfo>();
        }

        #endregion

        #region Public Methods
        /// <summary>
        /// Factories the specified language driver assembly.
        /// </summary>
        /// <param name="languageDriverAssembly">The language driver assembly.</param>
        /// <returns> <see cref="LanguageDriverClassManager"/> </returns>
        public static LanguageDriverClassManager Factory(Assembly languageDriverAssembly)
        {
            if (languageDriverAssembly == null)
            {
                throw new ArgumentNullException("languageDriverAssembly 1");
            }

            //Create a new LanguageDriverClass Manager
            LanguageDriverClassManager ldcm = new LanguageDriverClassManager();

            //Look through the list of classes in the assembly and find the Systin ones
            foreach (Type classType in languageDriverAssembly.GetTypes())
            {

                if (Attribute.GetCustomAttribute(classType, typeof(LanguageDriverAttribute)) != null)
                {
                    LanguageDriverClass ldc = LanguageDriverClass.Factory(classType);
                    ldcm.mLanguageDriverClassHash.Add(classType.Name, ldc);
                }
            }

            return ldcm;
        }

        /// <summary>
        /// Calls the method.
        /// </summary>
        /// <param name="methodToInvoke">The method to invoke.</param>
        /// <param name="langDriveMan">The language driver manager.</param>
        /// <returns>LanguageDriverClassManager </returns>
        public static LanguageDriverClassManager CallMethod(String methodToInvoke, LanguageDriverClassManager langDriveMan)
        {
            #region Validate Parms
            if (methodToInvoke == null)
            {
                throw new ArgumentNullException("methodToInvoke");
            }
            if (langDriveMan == null)
            {
                throw new ArgumentNullException("langDriveMan");
            }

            #endregion

            foreach (LanguageDriverClass ldc in langDriveMan.mLanguageDriverClassHash.Values)
            {


                if (LanguageDriverClass.MethodExists(methodToInvoke, ldc))
                {
                    //Thread newThread = new Thread(new ParameterizedThreadStart(ldc.CallMethod));

                    MethodInfo method = null;
                    ldc.CallMethod(methodToInvoke, ref method);
                    langDriveMan.mInstructionStack.Push(method);
                }
                else
                {
                    throw new TargetException("Method not found in Language Driver");
                }
            }

            LanguageDriverClassManager ldcm = null;
            ldcm = ((LanguageDriverClassManager)langDriveMan.MemberwiseClone());
            return ldcm;
        }

        /// <summary>
        /// Executes all instructions against the language driver.
        /// </summary>
        /// <param name="data">The data.</param>
        public static void CallMethodThreadedWrapper(object data)
        {
            //If the data input parm is null throw an ArgumentNullException
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            //If the type of data object is not a ThreadWorkermethodCall object throw an ArgumentException
            if (!data.GetType().Equals(typeof(ThreadWorkerMethodCall)))
            {
                throw new ArgumentException("data");
            }
            
            //Cast the data input to a string type
            ThreadWorkerMethodCall tworker = ((ThreadWorkerMethodCall)data);

            //Invoke all the methods in the queue
            foreach(Instruction instruction in tworker.Instructions){
                LanguageDriverClassManager.CallMethod(instruction.InstructionContent, tworker.LanguageDriverClassManager);
            }

            
        }
        #endregion


    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.