Exemplo n.º 1
0
        public static TenantContext Deserialize(string content)
        {
            var s  = new YAXLib.YAXSerializer(typeof(TenantContext));
            var tc = (TenantContext)s.Deserialize(content);

            tc.SiteContext.Tenant = tc.OrganizationContext.Tenant = tc.DbContext.Tenant = tc.TournamentContext.Tenant = tc;
            return(tc);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 格式化xml成对象
        /// </summary>
        /// <param name="text"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T ParseXml <T>(string text) where T : class
        {
            text = text.Replace(VERSION_INFO, "");
            YAXLib.YAXSerializer serializer = new YAXLib.YAXSerializer(typeof(T));
            var rst = serializer.Deserialize(text) as T;

            return(rst);
            //var xmlSeralizer = new XmlSerializer(typeof(ChinaBank));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     versucht die Config-Datei zu laden und erstellt sie ggf. neu
        /// </summary>

        private void loadConfigs()
        {
            YAXLib.YAXSerializer xml = new YAXLib.YAXSerializer(typeof(Config));
            try
            {
                string xmlString = File.ReadAllText(Path.Combine(pathBase, "config.xml"));
                configFile = (Config)xml.Deserialize(xmlString);
                DummyProvider.LOADED_CONFIG = configFile;
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                configFile = DummyProvider.DUMMY_CONFIG;
                string xmlString = xml.Serialize(configFile);
                File.WriteAllText(Path.Combine(pathBase, "config.xml"), xmlString);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Clears any existing <see cref="T"/> instances from the <see cref="ITenantStore{T}"/> and loads tenant configurations from the file system using the <see cref="GetTenantConfigurationFiles"/> delegate.
        /// <see cref="IDbContext.ConnectionString"/>s are added to the <see cref="DbContext"/> using the <see cref="DbContext.ConnectionKey"/>.
        /// </summary>
        /// <returns>Returns the current implementation of a <see cref="AbstractTenantStore{T}"/>.</returns>
        public virtual ITenantStore <T> LoadTenants()
        {
            Tenants.Clear();
            foreach (var configFile in GetTenantConfigurationFiles.Invoke())
            {
                var tc = (ITenantContext)TenantContextSerializer.Deserialize(ReadTenantConfigFile(configFile));
                tc.Filename = configFile;
                tc.DbContext.ConnectionString =
                    Configuration.GetConnectionString(tc.DbContext.ConnectionKey) ?? string.Empty;
                SetTenantForChildContexts((T)tc);
                if (!Tenants.TryAdd(tc.Identifier, (T)tc))
                {
                    throw new Exception($"Identifier '{tc.Identifier}' is already taken for another tenant");
                }
            }

            return(this);
        }