Example #1
0
 void SynchronizeTypes(string connectionString, IEnumerable<XPObjectType> xpObjectTypes) {
     var sqlDataStoreProxy = new DataStoreProxy(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 += EnsureIsNotIdentity(xpoObjectHacker);
             sqlDataStoreProxy.DataStoreModifyData += (sender, args) => {
                 var insertStatement = args.ModificationStatements.OfType<InsertStatement>().SingleOrDefault(statement => statement.TableName == typeof(XPObjectType).Name);
                 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);
             }
         }
     }
 }
Example #2
0
 static EventHandler<DataStoreUpdateSchemaEventArgs> EnsureIsNotIdentity(XpoObjectHacker xpoObjectHacker) {
     return (o, eventArgs) => xpoObjectHacker.EnsureIsNotIdentity(eventArgs.Tables);
 }