Ejemplo n.º 1
0
        /// <summary>
        /// Configures the workspace services.
        /// </summary>
        private void ConfigureServices()
        {
            if (null != ApplicationModelConfiguration.Configuration)
            {
                Configuration.Environment environment = ApplicationModelConfiguration.Configuration.Server.Environments.GetEnabledEnvironment();

                // Configure the AUTHENTICATIONSERVICE.
                if (!string.IsNullOrEmpty(environment.AuthenticationService.Type))
                {
                    Type authenticationServiceType = Type.GetType(environment.AuthenticationService.Type);
                    this.authenticationService = Activator.CreateInstance(authenticationServiceType) as IAuthenticationService;
                }

                // Configure the AUTHORIZATIONSERVICE.
                if (!string.IsNullOrEmpty(environment.AuthorizationService.Type))
                {
                    Type authorizatinServiceType = Type.GetType(environment.AuthorizationService.Type);
                    this.authorizationService = Activator.CreateInstance(authorizatinServiceType) as IAuthorizationService;
                }

                // Configure the AUDITSERVICE.
                if (!string.IsNullOrEmpty(environment.AuditService.Type))
                {
                    Type auditServiceType = Type.GetType(environment.AuditService.Type);
                    this.auditService = Activator.CreateInstance(auditServiceType) as IAuditService;
                }
            }
        }
Ejemplo n.º 2
0
        private void InitExecutionContext(Project project, Configuration.Environment sourceEnvir,
                                          Configuration.Environment destinationEnvir,
                                          string configFileHash, Metadatas metadatas = null)
        {
            ExecutionContextCacheHash = configFileHash;

            //Init connection strings
            ConnectionsContext.Initialize(project.ConnectionStrings, metadatas);

            //Init maps
            if (sourceEnvir == null || sourceEnvir.Schemas == null)
            {
                return;
            }

            foreach (var sourceSchema in sourceEnvir.Schemas)
            {
                var destinationSchema = destinationEnvir.Schemas.FirstOrDefault(s => s.Id == sourceSchema.Id);
                if (destinationSchema == null)
                {
                    throw new Exception($"The destination schema {sourceSchema.Id} is not found in the environment {destinationEnvir.Name}. Please declare it.");
                }

                var source = new SehemaIdentifier
                {
                    ServerId = sourceSchema.Server,
                    Database = sourceSchema.Database,
                    Schema   = sourceSchema.Schema
                };

                var destination = new SehemaIdentifier
                {
                    ServerId = destinationSchema.Server,
                    Database = destinationSchema.Database,
                    Schema   = destinationSchema.Schema
                };

                if (!Map.ContainsKey(source))
                {
                    Map.Add(source, destination);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Verify if the last build of the container's metadata still match with the current cloning context.
        /// </summary>
        private void LoadCache(Project project, CloningContext context = null)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }
            if (project.ConnectionStrings == null || !project.ConnectionStrings.Any())
            {
                throw new NullReferenceException(nameof(project.ConnectionStrings));
            }

            Behavior behavior = null;

            Configuration.Environment source      = null;
            Configuration.Environment destination = null;
            if (project.Name == null)
            {
                project.Name = Guid.NewGuid().ToString();
            }
            var containerFileName = project.Name;

            //Hash the selected map, connnectionStrings and the cloner
            //configuration to see if it match the lasted builded container
            var configData = new MemoryStream();

            SerializationHelper.Serialize(configData, project.ConnectionStrings);

            //Append context data
            if (context != null)
            {
                if (context.SourceEnvironment != null)
                {
                    //Map
                    source = project.Environments.FirstOrDefault(e => e.Name == context.SourceEnvironment);
                    if (source == null)
                    {
                        throw new Exception($"Source environment name '{context.SourceEnvironment}' not found in configuration file for application '{project.Name}'!");
                    }
                    destination = project.Environments.FirstOrDefault(e => e.Name == context.DestinationEnvironment);
                    if (destination == null)
                    {
                        throw new Exception($"Destination environment name '{context.DestinationEnvironment}' not found in configuration file for application '{project.Name}'!");
                    }

                    containerFileName += "_" + context.SourceEnvironment + "_" + context.DestinationEnvironment;
                    SerializationHelper.Serialize(configData, source);

                    //Behavior
                    if (!string.IsNullOrWhiteSpace(context.Behaviour))
                    {
                        behavior = project.BuildBehavior(context.Behaviour);

                        SerializationHelper.Serialize(configData, behavior);
                        SerializationHelper.Serialize(configData, project.ExtractionTemplates);

                        containerFileName += "_" + context.Behaviour;
                    }
                }
                else
                {
                    containerFileName += "_noMap";
                }
            }
            containerFileName += ".cache";

            //Hash user config
            configData.Position = 0;
            string currentHash;

            using (var md5Hash = MD5.Create())
                currentHash = Encoding.UTF8.GetString(md5Hash.ComputeHash(configData));

            //If in-memory container is good, we use it
            if (ExecutionContextCacheHash == currentHash)
            {
                return;
            }

            Metadatas metadatas = null;

            //If we can load cache from disk
            if ((context == null || !context.UseInMemoryCacheOnly))
            {
                //If container on disk is good, we use it
                if (TryLoadContainerFromFile(containerFileName, currentHash, ref metadatas))
                {
                    InitExecutionContext(project, source, destination, currentHash, metadatas);
                    return;
                }
            }

            //Else we rebuild the container
            HashSet <SchemaVar> schemas = null;

            if (source != null && source.Schemas != null)
            {
                schemas = new HashSet <SchemaVar>(source.Schemas);
            }

            metadatas = MetadataBuilder.BuildMetadata(project.ConnectionStrings, behavior, schemas);
            InitExecutionContext(project, source, destination, currentHash, metadatas);

            if ((context == null || !context.UseInMemoryCacheOnly))
            {
                Save(containerFileName);
            }
        }