예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <example>
        /// {
        ///     "name": "projects",
        ///     "projects": [
        ///         { "executionid": "", name="Core" }
        ///     ]
        /// }
        /// </example>
        public async Task ExecuteAsync(ProjectExecutionContext context)
        {
            if (!String.Equals(context.Name, "Projects", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var step = context.Step.ToObject <InternalStep>();
            var projectDictionary = new Dictionary <string, IDictionary <string, ProjectDescriptor> >();

            foreach (var pro in step.Values)
            {
                if (!projectDictionary.TryGetValue(pro.ExecutionId, out IDictionary <string, ProjectDescriptor> project))
                {
                    var projectCollections = await Task.WhenAll(_projectHarvesters.Select(x => x.HarvestProjectsAsync()));

                    project = projectCollections.SelectMany(x => x).ToDictionary(x => x.Name);
                    projectDictionary[pro.ExecutionId] = project;
                }

                if (!project.ContainsKey(pro.Name))
                {
                    throw new ArgumentException($"未在 '{pro.ExecutionId}' 中找到名称为 '{pro.Name}' 的项目.");
                }

                var executionId = Guid.NewGuid().ToString();
                await _executor.ExecuteAsync(executionId, project[pro.Name], context.Environment);
            }
        }
예제 #2
0
        public async Task ExecuteAsync(ProjectExecutionContext context)
        {
            if (!String.Equals(context.Name, "Roles", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var model = context.Step.ToObject <RolesStepModel>();

            foreach (var roleModel in model.Roles)
            {
                if (string.IsNullOrWhiteSpace(roleModel.Name))
                {
                    continue;
                }

                var role = (Role)await _roleManager.FindByNameAsync(roleModel.Name);

                bool isNewRole = role == null;

                if (isNewRole)
                {
                    role = new Role {
                        Rolename = roleModel.Name
                    };
                }
                role.RoleClaims.RemoveAll(e => e.ClaimType == PermissionInfo.ClaimType);
                role.RoleClaims.AddRange(roleModel.Permissions.Select(e => new RoleClaim {
                    ClaimType = PermissionInfo.ClaimType, ClaimValue = e
                }));

                if (isNewRole)
                {
                    await _roleManager.CreateAsync(role);
                }
                else
                {
                    await _roleManager.UpdateAsync(role);
                }
            }
        }
예제 #3
0
        public async Task ExecuteAsync(ProjectExecutionContext context)
        {
            if (!String.Equals(context.Name, "Feature", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var step = context.Step.ToObject <FeatureStepModel>();

            var features = _pluginManager.GetFeatures();

            foreach (var featureId in step.Disable)
            {
                if (features.Any(x => x.Id == featureId))
                {
                    throw new InvalidOperationException(string.Format("无法启用功能 {0}, 不存在.", featureId));
                }
            }

            foreach (var featureId in step.Enable)
            {
                if (!features.Any(x => x.Id == featureId))
                {
                    throw new InvalidOperationException(string.Format("无法启用功能 {0}, 不存在.", featureId));
                }
            }

            if (step.Disable.Any())
            {
                await _engineFeatureManager.DisableFeaturesAsync(features.Where(x => step.Disable.Contains(x.Id)).ToList(), true);
            }

            if (step.Enable.Any())
            {
                await _engineFeatureManager.EnableFeaturesAsync(features.Where(x => step.Enable.Contains(x.Id)).ToList(), true);
            }
        }
예제 #4
0
        public async Task ExecuteAsync(ProjectExecutionContext context)
        {
            if (!string.Equals(context.Name, "OpenIdApplication", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var model       = context.Step.ToObject <OpenIdApplicationStepModel>();
            var application = new OpenIddictApplication();

            if (model.Id != 0)
            {
                application = await _applicationManager.FindByIdAsync(model.Id.ToString(), CancellationToken.None);
            }
            application.ClientId    = model.ClientId;
            application.DisplayName = model.DisplayName;
            // application.AllowAuthorizationCodeFlow = model.AllowAuthorizationCodeFlow;
            // application.AllowClientCredentialsFlow = model.AllowClientCredentialsFlow;
            // application.AllowHybridFlow = model.AllowHybridFlow;
            // application.AllowImplicitFlow = model.AllowImplicitFlow;
            // application.AllowPasswordFlow = model.AllowPasswordFlow;
            // application.AllowRefreshTokenFlow = model.AllowRefreshTokenFlow;
            // application.LogoutRedirectUri = model.LogoutRedirectUri;
            // application.RedirectUri = model.RedirectUri;
            // application.SkipConsent = model.SkipConsent;
            // application.RoleNames = model.RoleNames;
            application.Type = model.Type.ToString();

            if (model.Type == ClientType.Private)
            {
                await _applicationManager.CreateAsync(application, model.ClientSecret, CancellationToken.None);
            }
            else
            {
                await _applicationManager.CreateAsync(application, CancellationToken.None);
            }
        }
예제 #5
0
        public async Task ExecuteAsync(ProjectExecutionContext context)
        {
            if (!String.Equals(context.Name, "Settings", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var model = context.Step;
            var site  = await _siteService.GetSiteInfoAsync();

            foreach (JProperty property in model.Properties())
            {
                switch (property.Name)
                {
                case "BaseUrl":
                    site.BaseUrl = property.Value.ToString();
                    break;

                //case "Calendar":
                //    site.Calendar = property.Value.ToString();
                //    break;

                //case "Culture":
                //    site.Culture = property.Value.ToString();
                //    break;

                // case "MaxPagedCount":
                //     site.MaxPagedCount = property.Value<int>();
                //     break;

                // case "MaxPageSize":
                //     site.MaxPageSize = property.Value<int>();
                //     break;

                case "PageCounts":
                    site.PageCounts = property.ToString();
                    break;

                case "PageSize":
                    site.PageSize = property.Value <int>();
                    break;

                //case "ResourceDebugMode":
                //    site.ResourceDebugMode = property.Value<ResourceDebugMode>();
                //    break;

                case "SiteName":
                    site.SiteName = property.ToString();
                    break;

                //case "SiteSalt":
                //    site.SiteSalt = property.ToString();
                //    break;

                case "SuperUser":
                    site.SuperUser = property.ToString();
                    break;

                //case "TimeZone":
                //    site.TimeZone = property.ToString();
                //    break;

                //case "UseCdn":
                //    site.UseCdn = property.Value<bool>();
                //    break;

                case "HomeRoute":
                    site.HomeRoute = property.Value.ToObject <RouteValueDictionary>();
                    break;

                default:
                    site.Properties.Add(property);
                    break;
                }
            }

            await _siteService.UpdateSiteInfoAsync(site);
        }
예제 #6
0
        public async Task <string> ExecuteAsync(string executionId, ProjectDescriptor projectDescriptor, object environment)
        {
            await _projectEventHandlers.InvokeAsync(e => e.ExecutingAsync(executionId, projectDescriptor), _logger);

            try
            {
                //_environmentMethodProvider = new ParametersMethodProvider(environment);

                var result = await _projectStore.CreateAsync(new ProjectResult
                {
                    ExecutionId = executionId,
                    ProjectName = projectDescriptor.Name,
                    DisplayName = projectDescriptor.DisplayName,
                    Description = projectDescriptor.Description,
                    Version     = projectDescriptor.Version
                });

                using (var stream = projectDescriptor.ProjectFileInfo.CreateReadStream())
                {
                    using (var file = new StreamReader(stream))
                    {
                        using (var reader = new JsonTextReader(file))
                        {
                            while (reader.Read())
                            {
                                //if (reader.Path == "variables")
                                //{
                                //    reader.Read();

                                //    var variables = JObject.Load(reader);
                                //    _variablesMethodProvider = new VariablesMethodProvider(variables);
                                //}

                                if (reader.Path == "steps" && reader.TokenType == JsonToken.StartArray)
                                {
                                    while (reader.Read() && reader.Depth > 1)
                                    {
                                        if (reader.Depth == 2)
                                        {
                                            var child = JObject.Load(reader);

                                            var projectStep = new ProjectExecutionContext
                                            {
                                                Name        = child.Value <string>("name"),
                                                Step        = child,
                                                ExecutionId = executionId,
                                                Environment = environment
                                            };

                                            var stepResult = new ProjectStepResult {
                                                StepName = projectStep.Name
                                            };
                                            result.Steps.Add(stepResult);
                                            await _projectStore.UpdateAsync(result);

                                            ExceptionDispatchInfo capturedException = null;
                                            try
                                            {
                                                await ExecuteStepAsync(projectStep);

                                                stepResult.IsSuccessful = true;
                                            }
                                            catch (Exception e)
                                            {
                                                stepResult.IsSuccessful = false;
                                                stepResult.ErrorMessage = e.ToString();

                                                capturedException = ExceptionDispatchInfo.Capture(e);
                                            }

                                            stepResult.IsCompleted = true;
                                            await _projectStore.UpdateAsync(result);

                                            if (stepResult.IsSuccessful == false)
                                            {
                                                capturedException.Throw();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                await _projectEventHandlers.InvokeAsync(x => x.ExecutedAsync(executionId, projectDescriptor), _logger);

                await _projectStore.UpdateAsync(result);

                return(executionId);
            }
            catch (Exception ex)
            {
                await _projectEventHandlers.InvokeAsync(e => e.ExecutionFailedAsync(executionId, projectDescriptor), _logger);

                throw ex;
            }
        }
예제 #7
0
        private async Task ExecuteStepAsync(ProjectExecutionContext projectStep)
        {
            var engineContext = _host.GetOrCreateEngineContext(_engineSettings);

            using (var scope = engineContext.EnterServiceScope())
            {
                if (!engineContext.IsActivated)
                {
                    var tenantEvents = scope.ServiceProvider.GetServices <IModuleTenantEvents>();

                    foreach (var tenantEvent in tenantEvents)
                    {
                        tenantEvent.ActivatingAsync().Wait();
                    }

                    engineContext.IsActivated = true;

                    foreach (var tenantEvent in tenantEvents)
                    {
                        tenantEvent.ActivatedAsync().Wait();
                    }
                }

                var projectStepHandlers = scope.ServiceProvider.GetServices <IProjectStepHandler>();
                //var scriptingManager = scope.ServiceProvider.GetRequiredService<IScriptingManager>();
                //scriptingManager.GlobalMethodProviders.Add(_environmentMethodProvider);

                //// Substitutes the script elements by their actual values
                //EvaluateScriptNodes(recipeStep, scriptingManager);

                foreach (var projectStepHandler in projectStepHandlers)
                {
                    if (_logger.IsEnabled(LogLevel.Information))
                    {
                        _logger.LogInformation("Executing project step '{0}'.", projectStep.Name);
                    }

                    await _projectEventHandlers.InvokeAsync(e => e.StepExecutingAsync(projectStep), _logger);

                    await projectStepHandler.ExecuteAsync(projectStep);

                    await _projectEventHandlers.InvokeAsync(e => e.StepExecutedAsync(projectStep), _logger);

                    if (_logger.IsEnabled(LogLevel.Information))
                    {
                        _logger.LogInformation("Finished executing project step '{0}'.", projectStep.Name);
                    }
                }
            }

            engineContext = _host.GetOrCreateEngineContext(_engineSettings);
            using (var scope = engineContext.EnterServiceScope())
            {
                var deferredTaskEngine = scope.ServiceProvider.GetService <IDeferredTaskEngine>();

                if (deferredTaskEngine != null && deferredTaskEngine.HasPendingTasks)
                {
                    await deferredTaskEngine.ExecuteTasksAsync(new DeferredTaskContext(scope.ServiceProvider));
                }
            }
        }