Exemplo n.º 1
0
        public override void UpdateOrCreateSchema(SchemaStatus SchemaStatus)
        {
            if (XpoDefault.DataLayer == null)
            {
                using (var updateDataLayer =
                           new SimpleDataLayer(Dictionary, CreateUpdatingDataStore(true)))

                {
                    //HACK you can use any of the following versions to pass persistent types or assemblies
                    //updateDataLayer.UpdateSchema(false, dictionary.CollectClassInfos(GetPersistentTypes()));
                    if (Assemblies != null)
                    {
                        updateDataLayer.UpdateSchema(false, Dictionary.CollectClassInfos(Assemblies));

                        new UnitOfWork(updateDataLayer).CreateObjectTypeRecords();
                        return;
                    }

                    if (PersistentTypes != null)
                    {
                        updateDataLayer.UpdateSchema(false, Dictionary.CollectClassInfos(PersistentTypes));

                        new UnitOfWork(updateDataLayer).CreateObjectTypeRecords();
                        return;
                    }

                    throw new Exception(Message);
                }
            }
        }
        public void AutoScript()
        {
            // Создание скрипта
            const string path = "autoscript.txt";
            StreamWriter script = new StreamWriter(path);
            ReflectionDictionary dictionary = new ReflectionDictionary();
            XPDictionaryInformer.Register(dictionary);
            SimpleDataLayer dataLayer = new SimpleDataLayer(dictionary, new OracleConnectionProviderEx(
                ODPConnectionProvider.CreateConnection(Properties.Settings.Default.ConnectionAdmin), AutoCreateOption.SchemaOnly, script, UpdateSchemaOptions.Default));
            dataLayer.UpdateSchema(false, new Type[] {
                typeof(AutoIdClass), typeof(StringIdClass), typeof(ComplexIdClass), typeof(NoIdClass),
                typeof(NotNullClass), typeof(ReadOnlyClass),
                typeof(ConsistentPeriodClass), typeof(ConsistentPeriodClass2), typeof(ContinuousPeriodClass), typeof(HierarchyClass),
                typeof(SimpleConstraintClass), typeof(ConstraintClass), typeof(CategoryClass), typeof(SecurityClass),
                typeof(UniqueBaseClass), typeof(UniqueClass),
                typeof(DevExpress.Xpo.XPObjectType)
            }.Select(c => dictionary.GetClassInfo(c)).ToArray());
            script.Close();

            // Проверка непустого содержания файла
            FileStream file = new FileStream(path, FileMode.Open);
            Assert.IsFalse(file.Length == 0, "File of autoscript is empty.");
            file.Close();

            // Проверка валидности скрипта
            Connection.ExecuteFile(path);
            dataLayer.Dispose();
        }
        private static IDataLayer CreateDataLayer()
        {
            var dict     = new DevExpress.Xpo.Metadata.ReflectionDictionary();
            var classes  = dict.CollectClassInfos(typeof(SampleObject).Assembly);
            var provider = XpoDefault.GetConnectionProvider(DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("localhost", "XpoImportHelperTest"), Xpo.DB.AutoCreateOption.DatabaseAndSchema);
            var dal      = new SimpleDataLayer(dict, provider);

            ((IDataLayerForTests)dal).ClearDatabase();
            dal.UpdateSchema(false, classes);
            return(dal);
        }
Exemplo n.º 4
0
        public override void Init()
        {
            XpoDefault.DataLayer = null;
            XpoDefault.Session   = null;
            var Args = new SchemaMismatchEventArgs(this, SchemaStatus.None);

            PrepareDictionary();

            //Check if the schema requires update https://www.devexpress.com/Support/Center/Question/Details/Q245466/determining-if-schema-needs-to-be-updated
            if (XpoDefault.DataLayer == null)
            {
                try
                {
                    using (var CheckSchemaDataLayer = new SimpleDataLayer(Dictionary, CreateSchemaCheckingDataStore()))
                    {
                        //HACK new way to compare schema https://www.devexpress.com/Support/Center/Question/Details/T562023/xpo-how-to-detect-of-chnage-structure-of-database-by-new-change-in-db-model
                        var types  = Dictionary.Classes.Cast <XPClassInfo>().Where(ci => ci.IsPersistent).ToArray();
                        var Result = CheckSchemaDataLayer.UpdateSchema(true, types);
                        if (Result == UpdateSchemaResult.FirstTableNotExists)
                        {
                            OnSchemaMismatch(this, Args);
                        }
                        //HACK the old version of checking the schema https://www.devexpress.com/Support/Center/Question/Details/T189303/xpo-how-to-check-if-db-schema-needs-to-be-changed-without-changing-it
                        //using (var session = new Session(CheckSchemaDataLayer))
                        //{

                        //    session.UpdateSchema();
                        //    //session.CreateObjectTypeRecords();
                        //}
                    }

                    Args.Handled = true;
                }
                catch (SchemaCorrectionNeededException)
                {
                    OnSchemaMismatch(this, Args);
                }

                //catch (DevExpress.Xpo.DB.Exceptions.SchemaCorrectionNeededException)
                //{
                //    OnSchemaMismatch(this, Args);
                //}
                if (Args.Handled)
                {
                    workingStore =
                        XpoDefault.GetConnectionProvider(ConnectionString, AutoCreateOption.SchemaAlreadyExists);
                    DataLayer = new ThreadSafeDataLayer(Dictionary, workingStore);
                }
            }
        }
Exemplo n.º 5
0
        public static void InitXpo(IDataStore DataStore)
        {
            var dictionary = PrepareDictionary();



            if (XpoDefault.DataLayer == null)
            {
                using (var updateDataLayer = new SimpleDataLayer(dictionary, DataStore))
                {
                    updateDataLayer.UpdateSchema(false, dictionary.CollectClassInfos(entityTypes));
                }
            }

            var dataStore = DataStore;//XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.SchemaAlreadyExists);

            XpoDefault.DataLayer = new ThreadSafeDataLayer(dictionary, dataStore);
            XpoDefault.Session   = null;
        }