示例#1
0
        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);

                    }
                }
            }
        }
示例#2
0
 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);
             }
         }
     }
 }
示例#3
0
        public SimpleDataLayer GetDataLayer(XPDictionary xpDictionary, MultiDataStore multiDataStore,Type type) {
            string connectionString = multiDataStore.DataStoreManager.GetConnectionString(type);
            var xpoDataStoreProxy = new SqlDataStoreProxy(connectionString);
            xpoDataStoreProxy.DataStoreModifyData+=(o, eventArgs) => multiDataStore.ModifyData(eventArgs);            
            xpoDataStoreProxy.DataStoreSelectData+=(sender1, dataEventArgs) => {
                if (multiDataStore.DataStoreManager.SimpleDataLayers.Count>1&&IsQueryingXPObjectType(dataEventArgs)) {
                    createExcludeXPObjectTypeArgs(dataEventArgs.SelectStatements,xpDictionary);
                }
                multiDataStore.SelectData(dataEventArgs);
            };
            xpoDataStoreProxy.DataStoreUpdateSchema +=(o1, schemaEventArgs) => multiDataStore.UpdateSchema(schemaEventArgs);
            return new SimpleDataLayer(xpDictionary, xpoDataStoreProxy);

        }
示例#4
0
 public DataStoreProvider(string connectionString) {
     connectionStringCore = connectionString;
     proxyCore = new SqlDataStoreProxy(connectionString);
 }