Esempio n. 1
0
        /// <summary>
        /// Adds the extends.
        /// </summary>
        /// <returns></returns>
        private AbstractExtend[] LoadFrameworkExtends()
        {
            List <AbstractExtend> list          = new List <AbstractExtend>();
            string extPath                      = "System/Extends";
            IConfigurationService configService = this[typeof(IConfigurationService)] as IConfigurationService;

            if (configService.Exists(extPath))
            {
                IConfiguration extends = new XMLConfiguration(configService.GetItem(extPath));

                // 加载所有的扩展项
                foreach (IConfiguration extend in extends.Children)
                {
                    if (extend.Attributes["class"] == null)
                    {
                        throw new ArgumentException("系统扩展项配置不正确,没有配置[class]属性。");
                    }

                    string         extendDef = extend.Attributes["class"];
                    Type           type      = Type.GetType(extendDef);
                    AbstractExtend ext       = Activator.CreateInstance(type) as AbstractExtend;
                    ext.ConfigPath = extPath + extend.Name;
                    AddFacility(type.FullName, ext);
                    list.Add(ext);
                }
            }
            return(list.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// ��ȡ�ͻ������е�ģ��
        /// </summary>
        /// <returns>���ص�ǰ�û����Լ��ص�ģ����ϸ����</returns>
        public ClientModuleInfo[] GetClientModules()
        {
            string user = sessionService.CurrentSession[SessionVariables.SESSION_CURRENT_USER].ToString();
            List<ClientModuleInfo> list = new List<ClientModuleInfo>();

            IConfigurationService configService = kernal[typeof(IConfigurationService)] as IConfigurationService;
            IConfiguration workstations = new XMLConfiguration(configService.GetItem(WORKSTATION_PATH));
            foreach (IConfiguration workstation in workstations.Children) {
                // ���ӵ��ÿ����ϵͳ�Ľ�ɫ
                bool hasPower = false;
                if (workstation.Attributes["allowroles"] != null) {
                    string[] allowRoles = workstation.Attributes["allowroles"].Split(new char[]{' ', ',', ';'});
                    if (allowRoles.Length == 1 && allowRoles[0].ToLower() == "all")
                        hasPower = true;
                    else {
                        foreach (string role in allowRoles) {
                            if (Roles.IsUserInRole(user, role))
                                hasPower = true;
                        }
                    }
                    if (!hasPower) continue; // �����ǰ�û�û�����Ȩ��������һ����ϵͳ

                    // ���������ϵͳ�е�ÿ��ģ��
                    foreach (IConfiguration module in workstation.Children) {
                        if (module.Attributes["assemblyfile"] == null)
                            throw new ArgumentException("û�ж���ģ��ij�������[assemblyfile]��");
                        string assemblyFile = module.Attributes["assemblyfile"];
                        ClientModuleInfo client = new ClientModuleInfo(assemblyFile, module.Value == "MainModule");
                        list.Add(client);
                    }
                }
            }

            return list.ToArray();
        }
        public void XMLConfiguration_ctorTest()
        {
            Assert.AreEqual(true, configService.Exists("System/Services/SessionService"));

            XMLConfiguration config = new XMLConfiguration(configService.GetItem("System/Services/SessionService"));
            Console.WriteLine(config.ToString());

            Assert.IsNotNull(config);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取客户端所有的模块
        /// </summary>
        /// <returns>返回当前用户可以加载的模块明细数组</returns>
        public ClientModuleInfo[] GetClientModules()
        {
            string user = sessionService.CurrentSession[SessionVariables.SESSION_CURRENT_USER].ToString();
            List <ClientModuleInfo> list = new List <ClientModuleInfo>();

            IConfigurationService configService = kernal[typeof(IConfigurationService)] as IConfigurationService;
            IConfiguration        workstations  = new XMLConfiguration(configService.GetItem(WORKSTATION_PATH));

            foreach (IConfiguration workstation in workstations.Children)
            {
                // 检查拥有每个子系统的角色
                bool hasPower = false;
                if (workstation.Attributes["allowroles"] != null)
                {
                    string[] allowRoles = workstation.Attributes["allowroles"].Split(new char[] { ' ', ',', ';' });
                    if (allowRoles.Length == 1 && allowRoles[0].ToLower() == "all")
                    {
                        hasPower = true;
                    }
                    else
                    {
                        foreach (string role in allowRoles)
                        {
                            if (Roles.IsUserInRole(user, role))
                            {
                                hasPower = true;
                            }
                        }
                    }
                    if (!hasPower)
                    {
                        continue;            // 如果当前用户没有相关权限则处理下一个子系统
                    }
                    // 逐个处理子系统中的每个模块
                    foreach (IConfiguration module in workstation.Children)
                    {
                        if (module.Attributes["assemblyfile"] == null)
                        {
                            throw new ArgumentException("没有定义模块的程序集属性[assemblyfile]。");
                        }
                        string           assemblyFile = module.Attributes["assemblyfile"];
                        ClientModuleInfo client       = new ClientModuleInfo(assemblyFile, module.Value == "MainModule");
                        list.Add(client);
                    }
                }
            }

            return(list.ToArray());
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MySessionService"/> class.
        /// </summary>
        /// <param name="dbService">The db service.</param>
        /// <param name="configService">The config service.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="dispatcher">The dispatcher.</param>
        public SessionService(IDb4oDatabaseService dbService, IConfigurationService configService, ILoggerFactory loggerFactory, IEventDispatcher dispatcher)
        {
            this.dispatcher = dispatcher;
            logger = loggerFactory.CreateLogger<SessionService>("Framework");
            db = dbService.Open(SESSION_DB);

            // 加载会话数据库中的会话信息
            foreach (SessionState session in db.Load<SessionState>()) {
                sessions.Add(session.SessionId, session);
            }

            try {
                IConfiguration conf = new XMLConfiguration(configService.GetItem(SESSION_PAPH));
                timeOut = conf.Attributes["timeout"] != null ? Int32.Parse(conf.Attributes["timeout"]) : SESSION_DEFAULT_TIMEOUT;
                checkSpan = conf.Attributes["checkspan"] != null ? Int32.Parse(conf.Attributes["checkspan"]) : SESSION_DEFAULT_CHECKSPAN;
            }
            catch {
                timeOut = SESSION_DEFAULT_TIMEOUT;
                checkSpan = SESSION_DEFAULT_CHECKSPAN;
            }
            Start(); // 启动会话管理
        }
        /// <summary>
        /// Ĭ����������캯��
        /// </summary>
        /// <param name="workItem">ϵͳ�������</param>
        public DefaultVirtualCTI(WorkItem workItem)
        {
            this.workItem = workItem;
            this.workItem.Services.Add<IVirtualCTI>(this);
            logger = workItem.Services.Get<ILog>();

            IConfigurationService configService = workItem.Services.Get<IConfigurationService>();
            if (!configService.Exists(sectionPath))
            {
                String errStr = "��ϵͳ�����ļ����ļ�δ�ҵ� \"LightweightCTI\" ���ýڡ�";
                logger.Fatal(errStr);
                throw new Exception(errStr);
            }

            // ��������ļ���
            if (!Directory.Exists(resourceDir))
                Directory.CreateDirectory(resourceDir);
            if (!Directory.Exists(projectsDir))
                Directory.CreateDirectory(projectsDir);

            IConfiguration config = new XMLConfiguration(configService.GetItem(sectionPath));
            ConfigurationInterpreter confInterpreter = new ConfigurationInterpreter(workItem, config);
            confInterpreter.Parse(); // ����������Ϣ�������л�������
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MySessionService"/> class.
        /// </summary>
        /// <param name="dbService">The db service.</param>
        /// <param name="configService">The config service.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="dispatcher">The dispatcher.</param>
        public SessionService(IDb4oDatabaseService dbService, IConfigurationService configService, ILoggerFactory loggerFactory, IEventDispatcher dispatcher)
        {
            this.dispatcher = dispatcher;
            logger          = loggerFactory.CreateLogger <SessionService>("Framework");
            db = dbService.Open(SESSION_DB);

            // 加载会话数据库中的会话信息
            foreach (SessionState session in db.Load <SessionState>())
            {
                sessions.Add(session.SessionId, session);
            }

            try {
                IConfiguration conf = new XMLConfiguration(configService.GetItem(SESSION_PAPH));
                timeOut = conf.Attributes["timeout"] != null?Int32.Parse(conf.Attributes["timeout"]) : SESSION_DEFAULT_TIMEOUT;

                checkSpan = conf.Attributes["checkspan"] != null?Int32.Parse(conf.Attributes["checkspan"]) : SESSION_DEFAULT_CHECKSPAN;
            }
            catch {
                timeOut   = SESSION_DEFAULT_TIMEOUT;
                checkSpan = SESSION_DEFAULT_CHECKSPAN;
            }
            Start(); // 启动会话管理
        }
Esempio n. 8
0
        /// <summary>
        /// Adds the component from configuration.
        /// </summary>
        /// <returns></returns>
        private string[] LoadFrameworkComponents()
        {
            List<string> serviceList = new List<string>();

            string servicesPath = "/System/Services/";
            IConfigurationService configService = this[typeof(IConfigurationService)] as IConfigurationService;
            IConfiguration services = new XMLConfiguration(configService.GetItem(servicesPath));

            foreach (IConfiguration service in services.Children)
            {
                try {
                    string inteDef = String.Empty;
                    string commDef = String.Empty;
                    Type inteType = null;
                    Type commType = null;

                    try {
                        inteDef = service.Attributes["interface"];
                        commDef = service.Attributes["commponent"];
                    }
                    catch {
                        throw new ArgumentException(String.Format("服务 \"{0} \" 配置错误,请为其配置对应的[interface]及[commponent]属性。", service.Name));
                    }

                    if (!String.IsNullOrEmpty(inteDef)) {
                        inteType = Type.GetType(inteDef);
                        if (inteDef == null) throw new ArgumentException("无法获取接口 [" + inteDef + "] 的类型");
                    }
                    if (!String.IsNullOrEmpty(commDef)) {
                        commType = Type.GetType(commDef);
                        if (commType == null) throw new ArgumentException("无法获取组件 [" + commDef + "] 的类型");
                    }

                    // 向系统容器中注册服务
                    if (inteType != null) {
                        if (commType == null)
                            throw new ArgumentException("无法获取接口 [" + inteDef + "] 的实现类定义");
                        AddComponent(inteDef, inteType, commType);
                        serviceList.Add(inteDef);
                    }
                    else if (commType != null) {
                        AddComponent(commDef, commType);
                        serviceList.Add(commDef);
                    }
                }
                catch (Exception ex) {
                    logger.Error("在注册组件 [" + service.Name + "] 时发生错误", ex);
                }
            }

            return serviceList.ToArray();
        }
Esempio n. 9
0
        /// <summary>
        /// Adds the extends.
        /// </summary>
        /// <returns></returns>
        private AbstractExtend[] LoadFrameworkExtends()
        {
            List<AbstractExtend> list = new List<AbstractExtend>();
            string extPath = "System/Extends";
            IConfigurationService configService = this[typeof(IConfigurationService)] as IConfigurationService;
            if (configService.Exists(extPath)) {
                IConfiguration extends = new XMLConfiguration(configService.GetItem(extPath));

                // 加载所有的扩展项
                foreach (IConfiguration extend in extends.Children) {
                    if (extend.Attributes["class"] == null)
                        throw new ArgumentException("系统扩展项配置不正确,没有配置[class]属性。");

                    string extendDef = extend.Attributes["class"];
                    Type type = Type.GetType(extendDef);
                    AbstractExtend ext = Activator.CreateInstance(type) as AbstractExtend;
                    ext.ConfigPath = extPath + extend.Name;
                    AddFacility(type.FullName, ext);
                    list.Add(ext);
                }
            }
            return list.ToArray();
        }
 public void XmlConfigurationTest()
 {
     IConfiguration config = new XMLConfiguration(configService.GetItem("System/Services/ObjectDatabaseService/"));
     Assert.AreEqual("~/App_Data/", config.Attributes["dbpath"]);
 }
Esempio n. 11
0
        /// <summary>
        /// 从插件描述文件加载插件
        /// </summary>
        /// <param name="filename"></param>
        private void Load(string filename)
        {
            string addInfile = filename;
            if (!File.Exists(addInfile))
            {
                List<string> files = FileUtility.SearchDirectory(Directory.GetParent(Environment.CurrentDirectory) + AddinsPath, addInfile);
                if (files.Count > 0)
                {
                    addInfile = files[0];
                    addInFileName = addInfile;
                }
                else
                    return;
            }

            XMLConfigurationService configService = new XMLConfigurationService(addInfile);
            logger.Info(String.Format("开始解析插件描述文件 \"{0}\":", Path.GetFileName(addInfile)));
            IConfiguration configuration = null;

            // 解析插件描述文件信息
            configuration = new XMLConfiguration(configService.GetItem(""));
            if (configuration != null)
            {
                if (configuration.Attributes["name"] != null)
                    name = configuration.Attributes["name"];
                if (configuration.Attributes["author"] != null)
                    author = configuration.Attributes["author"];
                if (configuration.Attributes["copyright"] != null)
                    copyright = configuration.Attributes["copyright"];
                if (configuration.Attributes["description"] != null)
                    description = configuration.Attributes["description"];
                if (configuration.Attributes["url"] != null)
                    url = configuration.Attributes["url"];
                if (configuration.Attributes["hideninmanager"] != null)
                    hidenInManager = bool.Parse(configuration.Attributes["hideninmanager"]);
                else
                    hidenInManager = false;
            }

            // 解析图象、字符串资源
            if (configService.Exists(ResourcesPath))
            {
                configuration = new XMLConfiguration(configService.GetItem(ResourcesPath));
                ParseResource(configuration);
            }

            // 解析构建器
            if (configService.Exists(BuildersPath))
            {
                configuration = new XMLConfiguration(configService.GetItem(BuildersPath));
                ParseBuilders(configuration);
            }

            // 解析插件
            if (configService.Exists(AddInPath))
            {
                configuration = new XMLConfiguration(configService.GetItem(AddInPath));
                ParseAddIn(configuration);
            }
            logger.Info(String.Format("完成解析插件描述文件 \"{0}\"", Path.GetFileName(addInfile)));
        }
Esempio n. 12
0
        /// <summary>
        /// Adds the component from configuration.
        /// </summary>
        /// <returns></returns>
        private string[] LoadFrameworkComponents()
        {
            List <string> serviceList = new List <string>();

            string servicesPath = "/System/Services/";
            IConfigurationService configService = this[typeof(IConfigurationService)] as IConfigurationService;
            IConfiguration        services      = new XMLConfiguration(configService.GetItem(servicesPath));

            foreach (IConfiguration service in services.Children)
            {
                try {
                    string inteDef  = String.Empty;
                    string commDef  = String.Empty;
                    Type   inteType = null;
                    Type   commType = null;

                    try {
                        inteDef = service.Attributes["interface"];
                        commDef = service.Attributes["commponent"];
                    }
                    catch {
                        throw new ArgumentException(String.Format("服务 \"{0} \" 配置错误,请为其配置对应的[interface]及[commponent]属性。", service.Name));
                    }

                    if (!String.IsNullOrEmpty(inteDef))
                    {
                        inteType = Type.GetType(inteDef);
                        if (inteDef == null)
                        {
                            throw new ArgumentException("无法获取接口 [" + inteDef + "] 的类型");
                        }
                    }
                    if (!String.IsNullOrEmpty(commDef))
                    {
                        commType = Type.GetType(commDef);
                        if (commType == null)
                        {
                            throw new ArgumentException("无法获取组件 [" + commDef + "] 的类型");
                        }
                    }

                    // 向系统容器中注册服务
                    if (inteType != null)
                    {
                        if (commType == null)
                        {
                            throw new ArgumentException("无法获取接口 [" + inteDef + "] 的实现类定义");
                        }
                        AddComponent(inteDef, inteType, commType);
                        serviceList.Add(inteDef);
                    }
                    else if (commType != null)
                    {
                        AddComponent(commDef, commType);
                        serviceList.Add(commDef);
                    }
                }
                catch (Exception ex) {
                    logger.Error("在注册组件 [" + service.Name + "] 时发生错误", ex);
                }
            }

            return(serviceList.ToArray());
        }