Exemple #1
0
        public List <T> ImportFromFileToMemory <T>(string path, IErrorHandler errorHandler = null)
        {
            JobSettings settings = new JobSettings
            {
                Tables       = new List <Table>(),
                AuditColumns = new JobSettings.AuditSettings(),
                IgnoreAuditColumnsOnExport = true,
                UseAuditColumnsOnImport    = false,
                Path = Path.GetDirectoryName(path)
            };

            errorHandler = errorHandler ?? new DefaultErrorHandler();

            Table table = new Table();

            table.Name = typeof(T).Name;
            table.Initialize <T>(settings, errorHandler);

            var diffGenerator = new DiffGenerator();

            using (var target = new EmptyDataReader(table))
                using (var source = new XmlRecordDataReader(path, table))
                    using (var writer = new InMemoryDataWriter <T>(table))
                    {
                        diffGenerator.GenerateDifference(source, target, table, writer, settings);
                        return(writer.Data);
                    }
        }
Exemple #2
0
        public override void Run(JobSettings settings, string environment, IErrorHandler errorHandler)
        {
            using (var connection = new SqlConnection(settings.ConnectionString))
            {
                connection.Open();

                foreach (var table in settings.Tables)
                {
                    using (var cmd = connection.CreateCommand())
                    {
                        table.Initialize(connection, settings, errorHandler);
                        cmd.CommandText = $"SELECT * FROM {table.QualifiedName}";
                        var diffGenerator = new DiffGenerator();
                        var file          = Path.Combine(settings.Path, table.Name + ".xml");
                        try
                        {
                            File.Move(file, file + ".old");
                            using (var source = cmd.ExecuteReader())
                                using (var target = new XmlRecordDataReader(file + ".old", table))
                                    using (var writer = new XmlDataWriter(table, settings))
                                    {
                                        diffGenerator.GenerateDifference(source, target, table, writer, settings);
                                    }
                            File.Delete(file + ".old");
                        }
                        finally
                        {
                            if (File.Exists(file + ".old"))//If the old file still exists then something went wrong. Revert back to the original
                            {
                                if (File.Exists(file))
                                {
                                    File.Delete(file);
                                }
                                File.Move(file + ".old", file);
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        public override void Run(JobSettings settings, string environment, IErrorHandler errorHandler)
        {
            using (var connection = new SqlConnection(settings.ConnectionString))
            {
                connection.Open();

                foreach (var table in settings.Tables)
                {
                    using (var cmd = connection.CreateCommand())
                    {
                        table.Initialize(connection, settings, errorHandler);
                        cmd.CommandText = $"SELECT * FROM {table.QualifiedName}";
                        var diffGenerator = new DiffGenerator();
                        using (var target = cmd.ExecuteReader())
                            using (var source = new XmlRecordDataReader(Path.Combine(settings.Path, table.Name + ".xml"), table))
                                using (var writer = new SqlSimpleDataWriter(settings.ConnectionString, table, settings))
                                {
                                    diffGenerator.GenerateDifference(source, target, table, writer, settings);
                                }
                    }
                }
            }
        }