void SynchronizeTypes(string connectionString, IEnumerable<XPObjectType> xpObjectTypes) { var sqlDataStoreProxy = new SqlDataStoreProxy(connectionString); using (var simpleDataLayer = new SimpleDataLayer(sqlDataStoreProxy)) { using (var session = new Session(simpleDataLayer)) { var xpoObjectHacker = new XpoObjectHacker(); bool sync = false; int[] oid = { 0 }; sqlDataStoreProxy.DataStoreUpdateSchema += (o, eventArgs) => xpoObjectHacker.EnsureIsNotIdentity(eventArgs.Tables); sqlDataStoreProxy.DataStoreModifyData += (sender, args) => { var insertStatement = args.ModificationStatements.OfType<InsertStatement>().Where(statement => statement.TableName == typeof(XPObjectType).Name).SingleOrDefault(); if (insertStatement != null && !sync) { sync = true; xpoObjectHacker.CreateObjectTypeIndetifier(insertStatement, simpleDataLayer, oid[0]); var modificationResult = sqlDataStoreProxy.ModifyData(insertStatement); sync = false; args.ModificationResult = modificationResult; args.ModificationResult.Identities = new[] { new ParameterValue { Value = oid[0] }, }; } }; foreach (var xpObjectType in xpObjectTypes) { oid[0] = xpObjectType.Oid; SynchronizeTypesCore(xpObjectType, session); } } } }
void SynchronizeTypes(UnitOfWork unitOfWork) { var xpObjectTypes = new XPCollection<XPObjectType>(unitOfWork); var dataStoreManager = new SqlMultiDataStoreProxy(ConnectionString); foreach (var xpObjectType in xpObjectTypes) { var type = ReflectionHelper.FindType(xpObjectType.TypeName); if (type != null) { var connectionString = dataStoreManager.DataStoreManager.GetConnectionString(type); var sqlDataStoreProxy = new SqlDataStoreProxy(connectionString); var xpoObjectHacker = new XpoObjectHacker(); XPObjectType type1 = xpObjectType; var simpleDataLayer = new SimpleDataLayer(sqlDataStoreProxy); var session = new Session(simpleDataLayer); bool sync = false; sqlDataStoreProxy.DataStoreModifyData += (sender, args) => { var insertStatement = args.ModificationStatements.OfType<InsertStatement>().Where(statement => statement.TableName == typeof(XPObjectType).Name).SingleOrDefault(); if (insertStatement != null && !sync) { sync = true; xpoObjectHacker.CreateObjectTypeIndetifier(insertStatement, simpleDataLayer, type1.Oid); ModificationResult modificationResult = sqlDataStoreProxy.ModifyData(insertStatement); args.ModificationResult = modificationResult; args.ModificationResult.Identities = new[] { new ParameterValue { Value = type1.Oid }, }; } }; if (session.FindObject<XPObjectType>(objectType => objectType.TypeName == type1.TypeName) == null) { var objectType = new XPObjectType(session, xpObjectType.AssemblyName, xpObjectType.TypeName); session.Save(objectType); } } } }