Esempio n. 1
0
        /// <summary>
        ///   检查文件是否存在,系统首先会在全局资源文件夹中查找该文件,如果不存在
        /// 就查询项目文件夹或系统安装目录。当前版本只在资源文件夹中进行搜索,没有
        /// 采用智能搜索的功能。
        /// </summary>
        /// <param name="filename">待检查的文件名</param>
        /// <returns>文件的绝对路径名称</returns>
        protected string CheckFile(string filename)
        {
            IVirtualCTI virtualCTI = driver.WorkItem.Services.Get <IVirtualCTI>();
            string      dir        = virtualCTI.GlobalVars[SwitchVariableNames.ResourceDir] as String;
            string      file       = string.Empty;

            if (File.Exists(filename))
            {
                return(filename);
            }
            else
            {
                dir = (dir != null && dir != string.Empty) ? dir : AppDomain.CurrentDomain.BaseDirectory;
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                switch (voiceResource)
                {
                case VoiceResource.UNKNOWN:
                    file = dir + filename;
                    break;

                case VoiceResource.STANDARD:
                    file = Path.Combine(dir, VoiceResourcePath[0]) + Path.DirectorySeparatorChar + filename;
                    break;

                case VoiceResource.LOCALIZE:
                    file = Path.Combine(dir, VoiceResourcePath[1]) + Path.DirectorySeparatorChar + filename;
                    break;

                case VoiceResource.ENGLISH:
                    file = Path.Combine(dir, VoiceResourcePath[2]) + Path.DirectorySeparatorChar + filename;
                    break;
                }
                if (File.Exists(file))
                {
                    return(file);
                }
            }
            return(file);
        }
        /// <summary>
        /// 逐项分析系统配置项
        /// </summary>
        public void Parse()
        {
            logger.Info("开始从系统配置文件中加载LightweightCTi组件……");
            IVirtualCTI virtualCTI = workItem.Services.Get <IVirtualCTI>();

            // 读取系统配置的全局变量
            if (config.Children["Variables"] != null)
            {
                foreach (IConfiguration conf in config.Children["Variables"].Children)
                {
                    if (conf.Name.ToLower() == "clear")
                    {
                        virtualCTI.GlobalVars.Clear();
                    }
                    else
                    {
                        if (conf.Name.ToLower() == "add")
                        {
                            virtualCTI.GlobalVars.Add(conf.Attributes["key"], conf.Attributes["value"]);
                        }
                        else if (conf.Name.ToLower() == "remove")
                        {
                            virtualCTI.GlobalVars.Remove(conf.Attributes["key"]);
                        }
                    }
                }
            }

            #region 以下配置工作移入相关的接入层终端自行处理

            //// 注册事件侦听、分配器组件
            //IEventService eventService = workItem.Services.Get<IEventService>();
            //if (config.Children["EventDispatchers"] != null && eventService != null)
            //{
            //    foreach (IConfiguration conf in config.Children["EventDispatchers"].Children)
            //    {
            //        if (conf.Name.ToLower() == "clear")
            //            eventService.ClearEventDispatcher();
            //        else
            //        {
            //            if (conf.Name.ToLower() == "add")
            //            {
            //                string dispname = conf.Attributes["name"];
            //                Type dispType = Type.GetType(conf.Attributes["type"]);
            //                Type serviceType = Type.GetType(conf.Attributes["servicetype"]);
            //                Type baseType = Type.GetType(conf.Attributes["basetype"]);
            //                EventDispatcher dispatcher = null;
            //                if (serviceType != null && baseType != null)
            //                {
            //                    dispatcher = Activator.CreateInstance(dispType, new object[] { serviceType, baseType }) as EventDispatcher;
            //                }
            //                else
            //                    if (serviceType != null)
            //                    {

            //                        dispatcher = Activator.CreateInstance(dispType, new object[] { serviceType }) as EventDispatcher;
            //                    }

            //                logger.Info("向系统注册事件分配器 " + dispname);
            //                if (dispatcher is IConfigurable)
            //                    ((IConfigurable)dispatcher).Configuration(conf);
            //                eventService.RegisterEventDispatcher(dispname, dispatcher);
            //            }
            //            else if(conf.Name.ToLower() == "remove")
            //            {
            //                eventService.UnRegisterEventDispatcher(conf.Attributes["name"]);
            //            }
            //        }
            //    }
            //}

            //// 注册事件订阅者组件
            //if (config.Children["Subscripters"] != null && eventService != null)
            //{
            //    foreach (IConfiguration conf in config.Children["Subscripters"].Children)
            //    {
            //        if (conf.Name.ToLower() == "add")
            //        {
            //            string name = conf.Attributes["name"];
            //            Type subscripterType = Type.GetType(conf.Attributes["type"]);
            //            if ((conf.Attributes["EventDispatcher"] != null || conf.Attributes["EventDispatcher"] != string.Empty) && subscripterType != null)
            //            {
            //                object sub = Activator.CreateInstance(subscripterType); // 此处必须支持默认的构造函数
            //                if (sub is IConfigurable)
            //                    ((IConfigurable)sub).Configuration(conf);
            //                eventService.RegisterSubscripter(sub as ISubscripterRegister);
            //                logger.Debug("注册事件订阅器,注册于 " + conf.Attributes["EventDispatcher"]);
            //            }
            //        }
            //        else if(conf.Name.ToLower() == "remove")
            //        {
            //            eventService.UnRegisterSubscripter(conf.Attributes["name"]);
            //        }
            //    }
            //}

            #endregion

            // 逐个初始化接入层的设备

            if (config.Children["Endpoints"] == null)
            {
                return;
            }

            foreach (IConfiguration conf in config.Children["Endpoints"].Children)
            {
                if (conf.Name.ToLower() == "clear")
                {
                    workItem.Services.Remove <ICTIDriver>();
                }
                else
                {
                    if (conf.Name.ToLower() == "add")
                    {
                        string endpointName = conf.Attributes["name"];
                        bool   active       = bool.Parse(conf.Attributes["active"]);
                        Type   adapterType  = Type.GetType(conf.Attributes["type"]);
                        if (adapterType == null)
                        {
                            continue;
                        }

                        AbstractCTIDriver driver = Activator.CreateInstance(adapterType, new object[] { workItem }) as AbstractCTIDriver;
                        workItem.Services.Add(typeof(ICTIDriver), driver);
                        if (driver is IConfigurable)
                        {
                            ((IConfigurable)driver).Configuration(conf);
                        }
                    }
                }
            }
        }