// WS-POS version 1.3 参照実装
// 
// 実装 version 0.6 

using System;
using System.Reflection;
using System.Configuration;
using System.Collections.Generic;

namespace WSPOSInitiative.Common
{
    /// <summary>
    /// セッションマネージャのインスタンスを生成するファクトリ
    /// The factory which generates the instance of a session manager. 
    /// </summary>
    class SessionManagerFactory
    {
        /// <summary>
        /// セッションマネージャのインスタンスを生成
        /// Generates the instance of a session manager. 
        /// </summary>
        /// <param name="log">ログ用インスタンス | log instance</param>
        /// <returns>セッションマネージャ | session manager</returns>
        internal static ISessionManager CreateSessionManagerInstance(ILog log)
        {
            if (StringArrayContainsHelper.Contains(ConfigurationManager.AppSettings.AllKeys, "CommonBehavior_SessionManagerImpl") == false)
            {
                return new SessionManagerDefaultImpl(log);
            }

            string[] managerLoadString = ConfigurationManager.AppSettings["CommonBehavior_SessionManagerImpl"].Split(',');

            Assembly sessionManagerAssembly = Assembly.LoadFrom(managerLoadString[0]);

            Type sessionManagerType = sessionManagerAssembly.GetType(managerLoadString[1]);

            object[] constructorArgs = new object[1];
            constructorArgs[0] = log;

            ISessionManager sessionManager = (ISessionManager)Activator.CreateInstance(sessionManagerType, constructorArgs);

            return sessionManager;
        }
    }
}
