public void WriteToDisk(SchemaProvider provider, string FileName)
        {
            var Serializer = new ServiceStack.Text.Jsv.JsvSerializer<SchemaProvider>();

            StreamWriter writer = new StreamWriter(new FileStream(FileName, FileMode.Create));

            Serializer.SerializeToWriter(provider, writer);
            writer.Flush();
            writer.Close();
        }
예제 #2
0
        private static void SchemaTest()
        {
            SchemaProvider NewSchema = new SchemaProvider(new SAConnection("dsn=" + SchemaSourceDSN));

            SAConnection ConnectionToOldDatabase = new SAConnection("dsn=" + SchemaDestDSN);

            SchemaProvider OldSchema = new SchemaProvider(ConnectionToOldDatabase);

            new SchemaChanger(OldSchema, NewSchema, ConnectionToOldDatabase).Upgrade();
        }
        public Stream Serialize(SchemaProvider provider)
        {
            var Serializer = new ServiceStack.Text.TypeSerializer<SchemaProvider>();

            StreamWriter writer = new StreamWriter(new MemoryStream());

            Serializer.SerializeToWriter(provider, writer);

            writer.Flush();
            writer.BaseStream.Position = 0;

            return writer.BaseStream;
        }
        public SchemaDiff CompareSchematas(SchemaProvider newSchema, SchemaProvider oldSchema, SchemaComparerOptions options = null)
        {
            NewSchema = newSchema;
            OldSchema = oldSchema;

            Options = options;
            if (Options == null)
                Options = new SchemaComparerOptions();

            SchemaDiff diff = new SchemaDiff();

            diff.TablesToDrop = SearchForTablesToDrop();

            diff.TablesToCreate = SearchForMissingTables();

            return diff;
        }
예제 #5
0
        private static void DiffBetweenDataBaseAnProgramm()
        {
            ApplicationReader reader = new ApplicationReader();

            var ApplicationSchema = reader.ReadApplication("paraOffice", @"C:\HG\ParaXtrem 1.7\Output\", "paraOffice.exe", "XpoProvider=Asa;DataSourceName='paradat'", "dsn=" + SchemaSourceDSN);
            SchemaProvider NewSchema = new SchemaProvider(new SAConnection("dsn=" + SchemaSourceDSN));

            SchemaComparer comparer = new SchemaComparer();
            var diff = comparer.CompareSchematas(NewSchema, ApplicationSchema, new SchemaComparerOptions() { OldSchemaTreatsViewsAsTable = true, OldSchemaTableAsViewPrefix = "V_" });

            Console.WriteLine("tables missin in database");
            foreach (var table in diff.TablesToDrop)
                Console.WriteLine(table.ActualName);

            Console.WriteLine("tables missin in application");
            foreach (var table in diff.TablesToCreate)
                Console.WriteLine(table.ActualName);
        }
        public SchemaProvider ReadApplication(string ApplicationName, string ApplicationFolder, string exeName, string XPOConnectionString, string DBConnectionString)
        {
            IList<string> moduleList = new List<string>(){
               "Para.Core.Modules.SystemModule.Win.dll",
               "Para.Model.Definition.dll",
               "Para.Modules.WorkflowLight.dll",
               "Para.Core.Modules.SpellCheckerModule.dll",
               "Para.Modules.App.dll",
               "Para.Modules.App.Win.dll",
               "Para.Modules.ABF.dll",
               "Para.Modules.BH.dll",
               "Para.Modules.RA.dll",
               "Para.Modules.FV.dll",
               "Para.Modules.Workflow.dll",
               "Para.Modules.Document.Activities.dll",
               "Para.Modules.Intern.Win.dll",
               "Para.Modules.MV.dll"
            };

            IList<Assembly> assemblies = new List<Assembly>();
            foreach (var file in moduleList)
                assemblies.Add(Assembly.LoadFile(ApplicationFolder + file));

            ControllersManager controllerManager = new ControllersManager();

            ApplicationModulesManager man = new ApplicationModulesManager(controllerManager, ApplicationFolder);
            man.AddModuleFromAssemblies(assemblies.Select(ass => ass.FullName).ToArray());

            var sec = new SecurityDummy();

            SAConnection conn = new SAConnection(DBConnectionString);
            conn.Open();

            XpoDefault.DataLayer = XpoDefault.GetDataLayer("XpoProvider=Asa;DataSourceName='paradat'", new ReflectionDictionary(), AutoCreateOption.None);

            XPObjectSpaceProvider provider = new XPObjectSpaceProvider(new ConnectionStringDataStoreProvider(XPOConnectionString));

            DesignerModelFactory dmf = new DesignerModelFactory();

            string ApplicationFileName = ApplicationFolder + exeName;
            string ApplicationConfigFileName = String.Format("{0}{1}.config", ApplicationFolder, exeName);

            var app = dmf.CreateApplicationByConfigFile(ApplicationConfigFileName, ApplicationFileName, ref ApplicationFolder);
            app.DatabaseVersionMismatch += app_DatabaseVersionMismatch;
            app.Setup("paraOffice", provider, man, sec);

            var dict = (app.CreateObjectSpace() as XPObjectSpace).Session.Dictionary;

            SchemaProvider schemaProvider = new SchemaProvider();
            foreach (var classinfo in dict.Classes.Cast<XPClassInfo>().Where(c => c.IsPersistent))
            {
                if (classinfo.Table.IsView)
                {
                    schemaProvider.Views.Add(new FastSchemaProvider.View() { Name = classinfo.Table.Name });
                    continue;
                }

                var table = new Table();
                table.ActualName = classinfo.Table.Name;

                foreach (var column in classinfo.Table.Columns)
                    table.Columns.Add(new Column() { ActualName = column.Name, DataType = column.ColumnType.ToSchemaDbType(), MaxLength = column.Size, IsPrimaryKeyColumn = column.IsKey, IsIdentity = column.IsIdentity });

                table.BuildPrimaryKey();

                foreach (var index in classinfo.Table.Indexes)
                {
                    var schemaIndex = new Index() { IndexName = index.Name, IndexType = index.IsUnique ? IndexTypes.Unqiue : IndexTypes.NonUnqiue };
                    int i = 1;
                    foreach (var col in index.Columns)
                    {
                        var indexCol = new IndexColumn();
                        indexCol.ColumnName = col;
                        indexCol.Sequence = i;
                        indexCol.Order = Ordering.Ascending;
                        i++;

                        schemaIndex.Columns.Add(indexCol);
                    }
                    table.Indizes.Add(schemaIndex);
                }

                foreach (var fk in classinfo.Table.ForeignKeys)
                {
                    var foreignKey = new ForeignKey();
                    foreignKey.Name = fk.Name;
                    foreignKey.Columns.AddRange(fk.Columns.Cast<string>());
                    foreignKey.DetailTable = classinfo.TableName;
                    foreignKey.MasterTable = fk.PrimaryKeyTable;
                    foreignKey.UniqueColumns.AddRange(fk.PrimaryKeyTableKeyColumns.Cast<string>());

                    table.ForeignKeys.Add(foreignKey);
                }

                schemaProvider.Tables.Add(table);
            }

            return schemaProvider;
        }
예제 #7
0
 public SchemaChanger(SchemaProvider oldSchema, SchemaProvider newSchema, IDbConnection connectionToOldDatabase)
 {
     OldSchema = oldSchema;
     NewSchema = newSchema;
     ConnectionToOldDatabase = connectionToOldDatabase;
 }