| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using DevExpress.Xpo;
- using DevExpress.Xpo.DB;
- using DevExpress.Xpo.Metadata;
- using Ips.Spd.SysSettings;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ips.Sps
- {
- public static class ConnectionHelper
- {
- static readonly Type[] PersistentTypes = new Type[]{
- typeof(Adcs.AdCard),
- typeof(Adcs.AdChannel),
- typeof(Ants.Ant),
- typeof(Emts.Emt),
- typeof(Emts.EmtSample),
- typeof(Ephs.Eph),
- typeof(Ephs.EphHigh),
- typeof(Sats.Sat),
- typeof(Sigs.Signal),
- typeof(TskResults.Pases.Pas),
- typeof(TskResults.Peses.Pes),
- typeof(TskResults.Peses.PesXgf),
- typeof(TskResults.Peses.PesRef),
- typeof(TskResults.Poses.Pos),
- typeof(TskResults.Poses.PosRel),
- typeof(TskResults.Stses.Tst),
- typeof(Tsks.Tsk),
- typeof(Tsks.TskAdCard),
- typeof(Tsks.TskAdChannel),
- typeof(Tsks.TskSignal),
- typeof(TskStrategys.TskStrategy),
- typeof(SysSetting)
- };
- public static string connectionString;
- public static void Connect(string conString, bool threadSafe = true)
- {
- XPBaseObject.AutoSaveOnEndEdit = false;
- //XpoDefault.NullableBehavior = NullableBehavior.ByUnderlyingType;
- connectionString = conString;
- XpoDefault.DataLayer = CreateDataLayer(threadSafe);
- }
- static IDataLayer CreateDataLayer(bool threadSafe)
- {
- ReflectionDictionary dictionary = new ReflectionDictionary();
- dictionary.GetDataStoreSchema(PersistentTypes);
- AutoCreateOption autoCreateOption = AutoCreateOption.DatabaseAndSchema;
- IDataStore provider = XpoDefault.GetConnectionProvider(connectionString, autoCreateOption);
- return threadSafe ? new ThreadSafeDataLayer(dictionary, provider) : new SimpleDataLayer(dictionary, provider);
- }
- public static string GetMigrationSql()
- {
- IDataStore provider = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);
- var migrationProvider = (IDataStoreSchemaMigrationProvider)provider;
- var migrationScriptFormatter = (IUpdateSchemaSqlFormatter)provider;
- var dictionary = new ReflectionDictionary();
- DBTable[] targetSchema = dictionary.GetDataStoreSchema(PersistentTypes);
- var migrationOptions = new SchemaMigrationOptions();
- var updateSchemaStatements = migrationProvider.CompareSchema(targetSchema, migrationOptions);
- string sql = migrationScriptFormatter.FormatUpdateSchemaScript(updateSchemaStatements);
- return sql;
- }
- }
- }
|