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); }
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); }
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); }
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); }
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); }
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; }
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); }
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); }
private IMigrationSegment _FindExactMigration(IContentMigrator migrator, int fromVersion, int toVersion) { return migrator.ValidMigrations.FirstOrDefault(x => x.FromVersion == fromVersion && x.ToVersion == toVersion); }
private MigrationPath _BuildMigrationPath(IContentMigrator migrator, int contentVersion, int targetVersion) { return _BuildMigrationPathUsingSequentialVersions(migrator, contentVersion, targetVersion); }
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)); }
private bool _MigrationPathAvailable(IContentMigrator migrator, int contentVersion, int targetVersion) { return(_BuildMigrationPath(migrator, contentVersion, targetVersion) != null); }
private IMigrationSegment _FindExactMigration(IContentMigrator migrator, int fromVersion, int toVersion) { return(migrator.ValidMigrations.FirstOrDefault(x => x.FromVersion == fromVersion && x.ToVersion == toVersion)); }
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); }
private MigrationPath _BuildMigrationPath(IContentMigrator migrator, int contentVersion, int targetVersion) { return(_BuildMigrationPathUsingSequentialVersions(migrator, contentVersion, targetVersion)); }