Exemple #1
0
        public static IRealTimePersister GetInstance(string name)
        {
            RealTimeSetting setting = RealTimeSection.GetSetting();

            if (name == null || name.Trim().Length <= 0)
            {
                name = setting.DefaultPersisteName;
            }
            if (name == null)
            {
                throw new ConfigurationErrorsException("The default persister name is not configured in config file.");
            }
            if (s_persisteProviders.ContainsKey(name))
            {
                return(s_persisteProviders[name]);
            }
            lock (s_SyncObj)
            {
                if (s_persisteProviders.ContainsKey(name))
                {
                    return(s_persisteProviders[name]);
                }
                if (!setting.ContainsKey(name))
                {
                    throw new ConfigurationErrorsException("The persister named '" + name + "' is not be found in config file.");
                }
                PersisteItemConfig item = setting[name];
                if (item.Type == null || item.Type.Trim().Length <= 0)
                {
                    throw new ConfigurationErrorsException("The type of persister '" + name + "' cannot be empty.");
                }
                Type p = Type.GetType(item.Type, true);
                if (!typeof(IRealTimePersister).IsAssignableFrom(p))
                {
                    throw new ConfigurationErrorsException("The type '" + p.AssemblyQualifiedName + "' of persister '" + name + "' dosen't implement the interface '" + typeof(IRealTimePersister).AssemblyQualifiedName + "'.");
                }
                IRealTimePersister rst = (IRealTimePersister)Activator.CreateInstance(p);
                s_persisteProviders.Add(name, rst);
                return(rst);
            }
        }
Exemple #2
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            RealTimeSetting setting = new RealTimeSetting();

            if (section != null)
            {
                string tmp = GetNodeAttribute(section, "default");
                setting.DefaultPersisteName = (tmp != null && tmp.Length > 0) ? tmp : null;
                XmlNode[] nodeList = GetChildrenNodes(section, "item");
                foreach (XmlNode node in nodeList)
                {
                    string name = GetNodeAttribute(node, "name");
                    if (name == null || name.Length <= 0)
                    {
                        throw new ConfigurationErrorsException("The attribute 'name' of the xml node 'persister/item' cannot be empty in config file.");
                    }
                    if (setting.ContainsKey(name))
                    {
                        throw new ConfigurationErrorsException("Duplicated name '" + name + "' of the xml node 'persister/item' in config file.");
                    }
                    string type = GetNodeAttribute(node, "type");
                    if (type == null || type.Length <= 0)
                    {
                        throw new ConfigurationErrorsException("The attribute 'type' of the xml node 'persister/item' cannot be empty in config file.");
                    }
                    NameValueCollection parms     = new NameValueCollection();
                    XmlNode[]           paramList = GetChildrenNodes(node.SelectSingleNode("parameters"), "add");
                    foreach (XmlNode pa in paramList)
                    {
                        parms.Add(GetNodeAttribute(pa, "key"), GetNodeAttribute(pa, "value"));
                    }
                    setting.Add(name, new PersisteItemConfig
                    {
                        Name       = name,
                        Type       = type,
                        Parameters = parms
                    });
                }
            }
            return(setting);
        }