Beispiel #1
0
        /// <summary>
        /// To get driver from session manager
        /// </summary>
        /// <param name="SessionName">Expected session</param>
        /// <returns>Object</returns>
        protected object GetInterface(string SessionName)
        {
            string strName = string.Format("{0}_{1}", SessionName, Position);

            try
            {
                object objSession = null;
                if (true == pISessionManagement.SessionExists(SessionName, Position))
                {
                    objSession = pISessionManagement.GetSessionByName(SessionName, Position);
                }
                else
                {
                    objSession = pISessionManagement.CreateSession(SessionName, Position);
                    //throw new Exception(string.Format("Can't find {0} in SessionManager.", strName));
                }
                ICommonComponent pICC = objSession as ICommonComponent;
                if (false == pICC.IsInitialized)
                {
                    pISessionManagement.InitializeSession(SessionName, Position);
                }

                return(objSession);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}->{1}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, ex.Message));
            }
        }
        public ArrayList Measurement(Dictionary <string, object> Input)
        {
            try
            {
                string strSessionName = string.Empty;
                GetInput(m_strSessionName_Lable, true, out strSessionName, string.Empty);

                pICC = GetInterface(m_strSessionName_Lable, 1) as ICommonComponent;

                if (pICC.IsInitialized == false)
                {
//                    pICC.Initialize();
                }
                else
                {
                    //Initialized
                }
                SaveValue(0);
            }
            catch
            {
                ///TODO:
                ///To implement error handling to report and do not interrupt test plan
            }
            return(Output);
        }
Beispiel #3
0
        /// <summary>
        /// To get session (driver instance) from manager by session name and position number
        /// </summary>
        /// <param name="SessionName">The name of session(interface name usually) without position number</param>
        /// <param name="Position">The position number</param>
        /// <returns>The instance of driver</returns>
        public object GetSessionByName(string SessionName, int Position)
        {
            try
            {
                if (true == this.SessionExists(SessionName, Position))
                {
                    string strName = string.Format("{0}_{1}", SessionName, Position);

                    ICommonComponent pICC = this[strName] as ICommonComponent;
                    if (pICC.IsInitialized == false)
                    {
                        this.InitializeSession(SessionName, Position);
                    }
                    return(this[strName]);
                }
                else
                {
                    return(CreateSession(SessionName, Position));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("GetSessionByName. -> {0}", ex.InnerException.Message));
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// To initialize an instance
        /// </summary>
        /// <param name="SessionName">The name (usually, interface name) of session without position number</param>
        /// <param name="Position">Position number</param>
        public void InitializeSession(string SessionName, int Position)
        {
            try
            {
                if (false == SessionExists(SessionName, Position))
                {
                    throw new Exception(string.Format("Can't get instance of the session {0}", string.Format("{0}_{1}", SessionName, Position)));
                }
                else
                {
                    //build name to search configs in session mapping
                    string strName = string.Format("{0}_{1}", SessionName, Position);
                    //get configuratoiin
                    Dictionary <string, object> dictSessionConfig = this.SessionMapping[strName].Configuration;

                    //get instance and call Initialize
                    ICommonComponent pICC = this[strName] as ICommonComponent;
                    pICC.Initialize(dictSessionConfig);
                    return;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}. -> {1}",
                                                  System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
                                                  ex.Message));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Create an instance.
        /// </summary>
        /// <param name="SessionName">The name of session(interface name usually) without position number</param>
        /// <param name="FileName">The library file contains the implementation of the interface</param>
        /// <param name="ClassName">The class name which implemented the interface</param>
        /// <param name="Position">The position number</param>
        /// <returns></returns>
        public object CreateSession(string SessionName, string FileName, string ClassName, int Position = 1)//, string MethodName, int input)
        {
            object objTest = null;

            try
            {
                //get instance
                objTest = NewInstance(SessionName, FileName, ClassName, Position);
                this.Add(string.Format("{0}_{1}", SessionName, Position), objTest);
                //set the session name to itself
                ICommonComponent pICC = objTest as ICommonComponent;
                pICC.SetSessionName(string.Format("{0}_{1}", SessionName, Position));
                //set logger to session
//                if (false == pICC.SessionName.ToLower().StartsWith("ilog"))
                {//if not ilog itself
                    string strLogSessionName = string.Format("ILog_{0}", Position);
                    foreach (DictionaryEntry de in this)
                    {
                        if (true == strLogSessionName.Equals(Convert.ToString(de.Key)))
                        {
                            pICC.ILogSession = de.Value as ILog;
                            break;
                        }
                    }
                }

                return(objTest);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("CreateSession(string, string, string, int)->{0}", ex.InnerException.Message));
            }
            return(null);
        }