Exemplo n.º 1
0
        /// <summary>
        /// Creates <see cref="ResourceMigrationState"/>
        /// </summary>
        /// <param name="templateCode">The migrator template code</param>
        /// <param name="state">The migrator state</param>
        /// <param name="resource">The resource state</param>
        /// <param name="position">The migrator position</param>
        /// <returns>The <see cref="ResourceMigrationState"/></returns>
        public static ResourceMigrationState CreateFrom(
            string templateCode,
            MigratorConfigurationState state,
            ResourceConfigurationState resource,
            EnMigratorPosition position)
        {
            var sourcePoint      = position == EnMigratorPosition.New ? null : state.LastDefinedPoint;
            var destinationPoint = position == EnMigratorPosition.Obsolete ? null : state.LastDefinedPoint;

            var migrationToSourceExecutor = resource.CurrentPoint == state.LastDefinedPoint
                                                ? null
                                                : position == EnMigratorPosition.Obsolete &&
                                            state.MigrationPoints.Contains(resource.CurrentPoint) &&
                                            state.LastDefinedPoint != resource.CurrentPoint
                                                    ? EnMigrationSide.Source
                                                    : (EnMigrationSide?)null;

            var migrationToDestinationExecutor = resource.CurrentPoint == state.LastDefinedPoint
                                                     ? null
                                                     : position == EnMigratorPosition.New
                                                         ? EnMigrationSide.Destination
                                                         : (EnMigrationSide?)null;

            var resourceMigrationState = new ResourceMigrationState
            {
                Name                           = resource.Name,
                Code                           = resource.Code,
                CurrentPoint                   = resource.CurrentPoint,
                SourcePoint                    = sourcePoint,
                DestinationPoint               = destinationPoint,
                MigrationToSourceExecutor      = migrationToSourceExecutor,
                MigrationToDestinationExecutor = migrationToDestinationExecutor,
                MigratorTypeName               = state.TypeName,
                TemplateCode                   = templateCode
            };

            resourceMigrationState.SetPosition();
            return(resourceMigrationState);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates <see cref="MigratorTemplateMigrationState"/> from <see cref="MigratorTemplateConfigurationState"/>
        /// </summary>
        /// <param name="state">The state of template</param>
        /// <param name="position">The template position</param>
        /// <returns>The new <see cref="MigratorTemplateMigrationState"/></returns>
        public static MigratorTemplateMigrationState CreateFrom(
            MigratorTemplateConfigurationState state,
            EnMigratorPosition position)
        {
            if (position != EnMigratorPosition.New && position != EnMigratorPosition.Obsolete)
            {
                throw new ArgumentException(@"Can be called only for new or obsolete templates", nameof(position));
            }

            var sourceTemplate      = position == EnMigratorPosition.Obsolete ? state.Template : null;
            var destinationTemplate = position == EnMigratorPosition.New ? state.Template : null;
            var migrators           = state.MigratorsStates
                                      .Select(m => MigratorMigrationState.CreateFrom(state.Code, m, position)).ToList();

            return(new MigratorTemplateMigrationState
            {
                Code = state.Template.Code,
                SourceTemplate = sourceTemplate,
                DestinationTemplate = destinationTemplate,
                Position = position,
                Migrators = migrators
            });
        }
        /// <summary>
        /// Creates <see cref="MigratorMigrationState"/> from <see cref="MigratorConfigurationState"/>
        /// </summary>
        /// <param name="templateCode">The migrator template code</param>
        /// <param name="state">The state of template</param>
        /// <param name="position">The migration position</param>
        /// <returns>The new <see cref="MigratorTemplateMigrationState"/></returns>
        public static MigratorMigrationState CreateFrom(string templateCode, MigratorConfigurationState state, EnMigratorPosition position)
        {
            if (position != EnMigratorPosition.New && position != EnMigratorPosition.Obsolete)
            {
                throw new ArgumentException(@"Can be called only for new or obsolete templates", nameof(position));
            }

            var resources = state.Resources.Select(r => ResourceMigrationState.CreateFrom(templateCode, state, r, position)).ToList();

            return(new MigratorMigrationState
            {
                Name = state.Name,
                TypeName = state.TypeName,
                Position = position,
                Direction = EnMigrationDirection.Stay,
                DependencyType = state.DependencyType,
                Priority = state.Priority,
                Resources = resources
            });
        }