Beispiel #1
0
        public ElementNodeTemplate LoadFromFile(string filePath)
        {
            IFileReader          fileReader      = FileReaderFactory.Instance.CreateFileReader();
            IObjectContentWriter contentWriter   = ObjectContentWriterFactory.Instance.CreateElementNodeTemplateContentWriter();
            IContentMigrator     contentMigrator = ContentMigratorFactory.Instance.CreateElementNodeTemplateContentMigrator();
            ElementNodeTemplate  obj             = MigratingObjectLoaderService.Instance.LoadFromFile <ElementNodeTemplate>(filePath, fileReader, contentWriter, contentMigrator, ObjectVersion.ElementNodeTemplate);

            return(obj);
        }
Beispiel #2
0
        public SystemContext LoadFromFile(string filePath)
        {
            IFileReader          fileReader      = FileReaderFactory.Instance.CreateFileReader();
            IObjectContentWriter contentWriter   = ObjectContentWriterFactory.Instance.CreateSystemContextContentWriter();
            IContentMigrator     contentMigrator = ContentMigratorFactory.Instance.CreateSystemContextContentMigrator();
            SystemContext        obj             = MigratingObjectLoaderService.Instance.LoadFromFile <SystemContext>(filePath, fileReader, contentWriter, contentMigrator, ObjectVersion.SystemContext);

            return(obj);
        }
Beispiel #3
0
        public ISequence LoadFromFile(string filePath)
        {
            if (filePath == null)
            {
                throw new InvalidOperationException("Cannot load from a null file path.");
            }
            if (!File.Exists(filePath))
            {
                throw new InvalidOperationException("File does not exist.");
            }

            IFileReader fileReader = FileReaderFactory.Instance.CreateFileReader();

            if (fileReader == null)
            {
                return(null);
            }

            IObjectContentWriter contentWriter = ObjectContentWriterFactory.Instance.CreateSequenceContentWriter(filePath);

            if (contentWriter == null)
            {
                return(null);
            }

            IContentMigrator contentMigrator = ContentMigratorFactory.Instance.CreateSequenceContentMigrator(filePath);

            if (contentMigrator == null)
            {
                return(null);
            }

            ISequenceTypeModuleInstance sequenceTypeModule = SequenceTypeService.Instance.CreateSequenceFactory(filePath);

            if (sequenceTypeModule == null)
            {
                return(null);
            }

            ISequence sequence = sequenceTypeModule.CreateSequence();

            if (sequence == null)
            {
                return(null);
            }

            sequence = MigratingObjectLoaderService.Instance.LoadFromFile(sequence, filePath, fileReader, contentWriter,
                                                                          contentMigrator, sequenceTypeModule.ObjectVersion);

            if (sequence != null)
            {
                sequence.FilePath = filePath;
            }

            return(sequence);
        }
Beispiel #4
0
        public ModuleStore LoadFromFile(string filePath)
        {
            IFileReader          fileReader      = FileReaderFactory.Instance.CreateFileReader();
            IObjectContentWriter contentWriter   = ObjectContentWriterFactory.Instance.CreateModuleStoreContentWriter();
            IContentMigrator     contentMigrator = ContentMigratorFactory.Instance.CreateModuleStoreContentMigrator();
            ModuleStore          obj             = MigratingObjectLoaderService.Instance.LoadFromFile <ModuleStore>(filePath, fileReader, contentWriter, contentMigrator, ObjectVersion.ModuleStore);

            if (obj != null)
            {
                obj.LoadedFilePath = filePath;
            }

            return(obj);
        }
Beispiel #5
0
        public Program LoadFromFile(string filePath)
        {
            IFileReader          fileReader      = FileReaderFactory.Instance.CreateFileReader();
            IObjectContentWriter contentWriter   = ObjectContentWriterFactory.Instance.CreateProgramContentWriter();
            IContentMigrator     contentMigrator = ContentMigratorFactory.Instance.CreateProgramContentMigrator();
            Program obj = MigratingObjectLoaderService.Instance.LoadFromFile <Program>(filePath, fileReader, contentWriter, contentMigrator, ObjectVersion.Program);

            if (obj != null)
            {
                obj.FilePath = filePath;
            }

            return(obj);
        }
Beispiel #6
0
        public SystemConfig LoadFromFile(string filePath)
        {
            IFileReader          fileReader      = FileReaderFactory.Instance.CreateFileReader();
            IObjectContentWriter contentWriter   = ObjectContentWriterFactory.Instance.CreateSystemConfigContentWriter();
            IContentMigrator     contentMigrator = ContentMigratorFactory.Instance.CreateSystemConfigContentMigrator();
            SystemConfig         obj             = MigratingObjectLoaderService.Instance.LoadFromFile <SystemConfig>(filePath, fileReader, contentWriter, contentMigrator, ObjectVersion.SystemConfig);

            if (obj != null)
            {
                obj.LoadedFilePath = filePath;
            }

            return(obj);
        }
        private MigrationPath _BuildMigrationPathUsingSequentialVersions(IContentMigrator migrator, int fromVersion,
            int toVersion)
        {
            MigrationPath migrationPath = new MigrationPath();

            while (fromVersion != toVersion) {
                IMigrationSegment segment = _FindExactMigration(migrator, fromVersion, fromVersion + 1);
                if (segment == null) return null;

                migrationPath.Add(segment);
                fromVersion++;
            }

            return migrationPath;
        }
        private object _MigrateContent(object content, int contentVersion, int targetVersion, IContentMigrator migrator)
        {
            MigrationPath migrationPath = _BuildMigrationPath(migrator, contentVersion, targetVersion);

            foreach (IMigrationSegment migrationSegment in migrationPath) {
                try {
                    content = migrator.MigrateContent(content, migrationSegment.FromVersion, migrationSegment.ToVersion);
                }
                catch (Exception ex) {
                    throw new Exception(
                        string.Format("Error when migrating from version {0} to version {1}", contentVersion, targetVersion), ex);
                }
            }

            return content;
        }
        public object MigrateObject(object content, IContentMigrator migrator, int contentVersion, int targetVersion,
            string filePath)
        {
            if (!_MigrationNeeded(contentVersion, targetVersion)) {
                return content;
            }

            if (!_MigrationPathAvailable(migrator, contentVersion, targetVersion)) {
                throw new Exception("The file requires a migration, but a proper migration path is not available.");
            }

            _BackupFile(filePath, contentVersion);

            content = _MigrateContent(content, contentVersion, targetVersion, migrator);

            return content;
        }
Beispiel #10
0
        public object MigrateObject(object content, IContentMigrator migrator, int contentVersion, int targetVersion, string filePath)
        {
            if (!_MigrationNeeded(contentVersion, targetVersion))
            {
                return(content);
            }

            if (!_MigrationPathAvailable(migrator, contentVersion, targetVersion))
            {
                throw new Exception("The file requires a migration, but a proper migration path is not available.");
            }

            _BackupFile(filePath, contentVersion);

            content = _MigrateContent(content, contentVersion, targetVersion, migrator);

            return(content);
        }
Beispiel #11
0
        private MigrationPath _BuildMigrationPathUsingSequentialVersions(IContentMigrator migrator, int fromVersion, int toVersion)
        {
            MigrationPath migrationPath = new MigrationPath();

            while (fromVersion != toVersion)
            {
                IMigrationSegment segment = _FindExactMigration(migrator, fromVersion, fromVersion + 1);
                if (segment == null)
                {
                    return(null);
                }

                migrationPath.Add(segment);
                fromVersion++;
            }

            return(migrationPath);
        }
        public T LoadFromFile <T>(T objectToPopulate, string filePath, IFileReader fileReader,
                                  IObjectContentWriter contentWriter, IContentMigrator contentMigrator,
                                  int currentObjectVersion)
            where T : class
        {
            object content = fileReader.ReadFile(filePath);

            if (content == null)
            {
                return(null);
            }

            try {
                content = ObjectMigratorService.Instance.MigrateObject(content, contentMigrator,
                                                                       contentWriter.GetContentVersion(content),
                                                                       currentObjectVersion, filePath);
                contentWriter.WriteContentToObject(content, objectToPopulate);
            }
            catch (Exception ex) {
                Logging.Error(string.Format("Error when migrating file {0} to the current version.", filePath), ex);
            }

            return(objectToPopulate);
        }
Beispiel #13
0
 private IMigrationSegment _FindExactMigration(IContentMigrator migrator, int fromVersion, int toVersion)
 {
     return migrator.ValidMigrations.FirstOrDefault(x => x.FromVersion == fromVersion && x.ToVersion == toVersion);
 }
Beispiel #14
0
 private MigrationPath _BuildMigrationPath(IContentMigrator migrator, int contentVersion, int targetVersion)
 {
     return _BuildMigrationPathUsingSequentialVersions(migrator, contentVersion, targetVersion);
 }
Beispiel #15
0
 private bool _MigrationPathAvailable(IContentMigrator migrator, int contentVersion, int targetVersion)
 {
     return _BuildMigrationPath(migrator, contentVersion, targetVersion) != null;
 }
 public T LoadFromFile <T>(string filePath, IFileReader fileReader, IObjectContentWriter contentWriter,
                           IContentMigrator contentMigrator, int currentObjectVersion)
     where T : class, new()
 {
     return(LoadFromFile(new T(), filePath, fileReader, contentWriter, contentMigrator, currentObjectVersion));
 }
Beispiel #17
0
 private bool _MigrationPathAvailable(IContentMigrator migrator, int contentVersion, int targetVersion)
 {
     return(_BuildMigrationPath(migrator, contentVersion, targetVersion) != null);
 }
Beispiel #18
0
 private IMigrationSegment _FindExactMigration(IContentMigrator migrator, int fromVersion, int toVersion)
 {
     return(migrator.ValidMigrations.FirstOrDefault(x => x.FromVersion == fromVersion && x.ToVersion == toVersion));
 }
Beispiel #19
0
        private object _MigrateContent(object content, int contentVersion, int targetVersion, IContentMigrator migrator)
        {
            MigrationPath migrationPath = _BuildMigrationPath(migrator, contentVersion, targetVersion);

            foreach (IMigrationSegment migrationSegment in migrationPath)
            {
                try {
                    content = migrator.MigrateContent(content, migrationSegment.FromVersion, migrationSegment.ToVersion);
                }
                catch (Exception ex) {
                    throw new Exception(
                              string.Format("Error when migrating from version {0} to version {1}", contentVersion, targetVersion), ex);
                }
            }

            return(content);
        }
Beispiel #20
0
 private MigrationPath _BuildMigrationPath(IContentMigrator migrator, int contentVersion, int targetVersion)
 {
     return(_BuildMigrationPathUsingSequentialVersions(migrator, contentVersion, targetVersion));
 }