public LoadedDatabaseConfig Load(string path, IDatabaseConfig databaseConfig, OutputActionDelegate _LogAction = null) { lock (olock) { LoadedDatabaseConfig __LoadedDatabaseConfig = null; if (_DbConfigCached.TryGetValue(path, out __LoadedDatabaseConfig)) { return(__LoadedDatabaseConfig); } else { //string fullConfigPath = ""; //lock (olock) //{ // if (_LogAction == null) // { // _LogAction = (str, ex, type) => // { // ConsoleHelper.Instance.OutputMessage(str, ex, type); // }; // } // LogAction = _LogAction; // if (PureDataConfiguration == null) // { // fullConfigPath = FileLoader.GetPath(path); // Log(string.Format("LocalDatabaseConfigLoader Load: {0} Starting", fullConfigPath)); // var configStream = LoadConfigStream(path); // try // { // using (configStream.Stream) // { // fullConfigPath = configStream.Path; // XmlSerializer xmlSerializer = new XmlSerializer(typeof(PureDataConfiguration)); // PureDataConfiguration config = xmlSerializer.Deserialize(configStream.Stream) as PureDataConfiguration; // config.Path = configStream.Path; // PureDataConfiguration = config; // } // } // catch (Exception ex) // { // Log(string.Format("LocalDatabaseConfigLoader Load fail: {0} ", ex.Message + "------" + ex)); // } // } //} //__LoadedDatabaseConfig = new LoadedDatabaseConfig(); //__LoadedDatabaseConfig.PureDataConfiguration = PureDataConfiguration; //__LoadedDatabaseConfig.Path = path; ////设定配置 //var metaInfo = MapToDatabseConfig(PureDataConfiguration, databaseConfig); //databaseConfig.OutputAction = _LogAction; //databaseConfig.InitByPureDataConfiguration = true; //__LoadedDatabaseConfig.DatabaseConfig = databaseConfig; //__LoadedDatabaseConfig.DbConnectionMetaInfo = metaInfo; //_DbConfigCached[path] = __LoadedDatabaseConfig; //Log(string.Format("Init DatabaseConfig Successfully : {0} ", fullConfigPath)); //return __LoadedDatabaseConfig; //#region Watch __LoadedDatabaseConfig = LoadDatabaseConfig(path, databaseConfig, _LogAction); ////watch pure config //var fullpath = FileLoader.GetPath(path); //string dir = System.IO.Path.GetDirectoryName(fullpath); //string filename = System.IO.Path.GetFileName(fullpath); //Log("Watch PureDataConfiguration changed on :" + fullpath); //FileWatcherLoader.Instance.Watch(dir, filename, () => //{ // __LoadedDatabaseConfig = LoadDatabaseConfig(path, databaseConfig, _LogAction); // Log(__LoadedDatabaseConfig.DatabaseConfig.ToString()); // Log(string.Format(" PureDataConfiguration has reloaded at : {0} ", path)); //}, 500); return(__LoadedDatabaseConfig); //#endregion } } }
private LoadedDatabaseConfig LoadDatabaseConfig(string path, IDatabaseConfig databaseConfig, OutputActionDelegate _LogAction = null) { string fullConfigPath = ""; LoadedDatabaseConfig __LoadedDatabaseConfig = null; if (_LogAction == null) { _LogAction = (str, ex, type) => { ConsoleHelper.Instance.OutputMessage(str, ex, type); }; } LogAction = _LogAction; //if (PureDataConfiguration == null) //{ fullConfigPath = FileLoader.GetPath(path); Log(string.Format("LocalDatabaseConfigLoader Load: {0} Starting", fullConfigPath)); try { var configStream = LoadConfigStream(path); using (configStream.Stream) { fullConfigPath = configStream.Path; XmlSerializer xmlSerializer = new XmlSerializer(typeof(PureDataConfiguration)); PureDataConfiguration config = xmlSerializer.Deserialize(configStream.Stream) as PureDataConfiguration; config.Path = configStream.Path; PureDataConfiguration = config; } } catch (Exception ex) { Log(string.Format("LocalDatabaseConfigLoader Load fail: {0} ", ex.Message + "------" + ex)); return(__LoadedDatabaseConfig); } // } __LoadedDatabaseConfig = new LoadedDatabaseConfig(); __LoadedDatabaseConfig.PureDataConfiguration = PureDataConfiguration; __LoadedDatabaseConfig.Path = path; //设定配置 var metaInfo = MapToDatabseConfig(PureDataConfiguration, databaseConfig); databaseConfig.OutputAction = _LogAction; databaseConfig.InitByPureDataConfiguration = true; __LoadedDatabaseConfig.DatabaseConfig = databaseConfig; __LoadedDatabaseConfig.DbConnectionMetaInfo = metaInfo; _DbConfigCached[path] = __LoadedDatabaseConfig; Log(string.Format("Load DatabaseConfig Successfully : {0} ", fullConfigPath)); return(__LoadedDatabaseConfig); }