示例#1
0
        public void ExecuteJob(string jobName, JobTerminateOnErrorType jobTerminateOnErrorType, Type[] jobStepTypes)
        {
            var job = new Job(Guid.NewGuid(), jobName);

            job.TerminateOnErrorType = jobTerminateOnErrorType;

            job.AddDataSource(_sourceSideDataSource, SyncSide.Source);
            job.AddDataSource(_targetSideDataSource, SyncSide.Target);

            foreach (var jobStepType in jobStepTypes)
            {
                var jobStep = new JobStep(Guid.NewGuid(), jobStepType.Name, jobStepType.FullName);

                job.AddStep(jobStep);
            }

            JobQueueManager.QueueJob(_integration, _sourceSideDataSource, job, DateTime.Now, Path.GetFileName(Assembly.GetCallingAssembly().Location), JobInvocationSourceType.OnDemand);

            while (JobQueueManager.HasWaitingJobs || JobQueueManager.HasRunningJobs)
            {
                Thread.Sleep(500);
            }
        }
示例#2
0
        public IntegrationConfig LoadFromFile(string fileName)
        {
            var config = new IntegrationConfig();
            var doc    = XDocument.Load(fileName);
            var root   = doc.Element("integrationConfig");
            // connection strings
            var connectionStringQuery = from e in root.Elements("connectionStrings").Elements("connectionString")
                                        select new { Name = e.Attribute("name")?.Value, ConnectionString = e.Value };

            foreach (var cs in connectionStringQuery)
            {
                connectionStrings.Add(cs.Name, cs.ConnectionString);
            }
            // load assemblies
            LoadStepsFromAssembly(Assembly.GetExecutingAssembly());
            var assemblyQuery = from e in root.Elements("extensions").Elements("assembly")
                                select Assembly.Load(e.Attribute("name")?.Value);

            foreach (var a in assemblyQuery)
            {
                LoadStepsFromAssembly(a);
            }
            // jobs
            foreach (var jobElement in root.Elements("jobs").Elements("job"))
            {
                var jobId          = jobElement.Attribute("id")?.Value;
                var jobDescription = jobElement.Attribute("description")?.Value;
                if (string.IsNullOrEmpty(jobId))
                {
                    throw new InvalidConfigurationException("No Job Id specified.");
                }
                if (config.Jobs.ContainsKey(jobId))
                {
                    throw new InvalidConfigurationException($"Job '{jobId}' exists more than once in config.");
                }
                var job = new Job()
                {
                    Id          = jobId,
                    Description = jobDescription
                };
                foreach (var stepElement in jobElement.Elements("step"))
                {
                    var stepId = stepElement.Attribute("id")?.Value;
                    if (string.IsNullOrEmpty(stepId))
                    {
                        throw new InvalidConfigurationException("No step id specified.");
                    }
                    var stepType = stepElement.Attribute("type")?.Value;
                    if (string.IsNullOrEmpty(stepType))
                    {
                        throw new InvalidConfigurationException($"No step type specified for step {stepId}.");
                    }
                    if (!steps.ContainsKey(stepType))
                    {
                        throw new InvalidConfigurationException($"'{stepType}' is not a valid step type.");
                    }
                    var step = (JobStep)Activator.CreateInstance(steps[stepType]);
                    try
                    {
                        PopulateObjectProperties(stepElement, step);
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidConfigurationException(
                                  string.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid configuration for '{0}' step in job '{1}': {2}",
                                                string.IsNullOrEmpty(stepId) ? "anonymous" : stepId, jobId, ex.Message),
                                  ex);
                    }
                    var sourceId = stepElement.Attribute("source")?.Value;
                    if (sourceId != null)
                    {
                        job.AddStep(step, sourceId);
                    }
                    else
                    {
                        job.AddStep(step);
                    }
                }
                config.Jobs.Add(job.Id, job);
            }
            return(config);
        }