public async Task <ActionResult <GetResult> > Default([FromBody] TemplateRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, MenuUtils.SitePermissions.Templates)) { return(Unauthorized()); } var site = await _siteRepository.GetAsync(request.SiteId); if (site == null) { return(NotFound()); } var templateInfo = await _templateRepository.GetAsync(request.TemplateId); if (templateInfo != null && !templateInfo.DefaultTemplate) { await _templateRepository.SetDefaultAsync(request.TemplateId); await _authManager.AddSiteLogAsync(site.Id, $"设置默认{templateInfo.TemplateType.GetDisplayName()}", $"模板名称:{templateInfo.TemplateName}"); } return(await GetResultAsync(site)); }
// SAMPLE: building-template-request private static TemplateRequest buildTemplateRequest() { var request = new TemplateRequest { RootDirectory = "root directory", SolutionName = "MySolution.sln" }; // Add a project named "MyProject" using a project template named "basic-new-project" request.AddProjectRequest("MyProject", "basic-new-project", project => { // Add some extra templates from the /alterations folder project.Alterations.Add("raven"); project.Alterations.Add("spark"); // Add some substitution values for the templating if desired // See the topic page for subsitutions and inputs project.Substitutions.Set("%SHORT_NAME%", "MyProj"); }); // Add a testing project related to our first project using the "unit-testing" project template // See the topic about testing projects request.AddTestingRequest(new ProjectRequest("MyProject.Testing", "unit-testing", "MyProject")); return(request); }
public async Task <TemplateResponse> GetTemplate(TemplateRequest templateRequest) { try { templateResponse = new TemplateResponse(); using (FacepinpointDBEntities db = new FacepinpointDBEntities()) { var objectContext = ((IObjectContextAdapter)db).ObjectContext; var command = db.Database.Connection.CreateCommand(); command.CommandType = System.Data.CommandType.Text; command.CommandText = "SELECT public.\"fn_getEmailTemplate\"('" + templateRequest.TName + "'," + templateRequest.UserId + " , '" + templateRequest.UserEmail + "')"; db.Database.Connection.Open(); using (var reader = await command.ExecuteReaderAsync()) { var result = ((IObjectContextAdapter)db).ObjectContext.Translate <string>(reader).ToList(); templateResponse.emailTemplate = result.FirstOrDefault(); } } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); templateResponse.Success = false; templateResponse.Message = CustomErrorMessages.INTERNAL_ERROR; } return(templateResponse); }
public async Task <ActionResult <GetResult> > Delete([FromBody] TemplateRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, MenuUtils.SitePermissions.Templates)) { return(Unauthorized()); } if (_settingsManager.IsSafeMode) { return(this.Error(Constants.ErrorSafeMode)); } var site = await _siteRepository.GetAsync(request.SiteId); if (site == null) { return(NotFound()); } var templateInfo = await _templateRepository.GetAsync(request.TemplateId); if (templateInfo != null && !templateInfo.DefaultTemplate) { await _templateRepository.DeleteAsync(_pathManager, site, request.TemplateId); await _authManager.AddSiteLogAsync(site.Id, $"删除{templateInfo.TemplateType.GetDisplayName()}", $"模板名称:{templateInfo.TemplateName}"); } return(await GetResultAsync(site)); }
public override bool Execute(NewStorytellerInput input) { // TODO -- duplication here string solutionFile = SolutionFinder.FindSolutionFile(); if (solutionFile == null) { return(false); } var projectRequest = new ProjectRequest(input.Name, "baseline"); projectRequest.AddAlteration("storyteller"); var request = new TemplateRequest { RootDirectory = Environment.CurrentDirectory, SolutionName = solutionFile }; request.AddProjectRequest(projectRequest); // TODO -- add an option to copy references from the parent project var plan = NewCommand.BuildTemplatePlan(request); NewCommand.ExecutePlan(plan); return(true); }
public static TemplateRequest BuildTemplateRequest(AddInput input, string solutionFile) { var request = new TemplateRequest { RootDirectory = Environment.CurrentDirectory, SolutionName = solutionFile }; var shortName = input.DetermineShortName(); request.Substitutions.Set(ProjectPlan.SHORT_NAME, shortName); var choices = input.ToChoices(); var project = Templating.Library.Graph.BuildProjectRequest(choices); if (input.DotNetFlag.IsNotEmpty()) { project.Version = input.DotNetFlag; } project.Version = project.Version ?? DotNetVersion.V40; request.AddProjectRequest(project); if (!input.NoTestsFlag) { request.AddMatchingTestingProject(project); } return(request); }
private void applyProjectTemplates(TemplateRequest request, TemplatePlan plan) { GenericEnumerableExtensions.Each <ProjectRequest>(request.Projects, delegate(ProjectRequest proj) { this.buildProjectPlan(plan, proj); }); }
public static TemplateRequest BuildTemplateRequest(NewCommandInput input) { var request = new TemplateRequest { RootDirectory = input.SolutionDirectory(), SolutionName = input.SolutionName }; request.AddTemplate(_rippleTemplates[input.RippleFlag]); if (input.AppFlag) { var projectRequest = addApplicationProject(input, request); if (input.TestsFlag) { var testing = new TestProjectRequest(projectRequest.Name + ".Testing", "baseline", projectRequest.Name); testing.AddAlteration("unit-testing"); request.AddTestingRequest(testing); } } request.AddTemplate("baseline"); return(request); }
private static ProjectRequest addApplicationProject(NewCommandInput input, TemplateRequest request) { var project = new ProjectRequest(input.SolutionName, "baseline"); project.AddAlteration("structuremap"); project.AddAlteration("fubumvc-empty"); if (input.OptionsFlag != null) { input.OptionsFlag.Each(x => project.AddAlteration(x)); } // TODO -- duplication! if (input.ShortNameFlag.IsNotEmpty()) { project.Substitutions.Set(ProjectPlan.SHORT_NAME, input.ShortNameFlag); } // TODO -- Will need to check for razor too! if (!project.Alterations.Contains("spark")) { project.AddAlteration("no-views"); } request.AddProjectRequest(project); return(project); }
public async Task <ActionResult <GetResult> > Default([FromQuery] TemplateRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.Templates)) { return(Unauthorized()); } var site = await _siteRepository.GetAsync(request.SiteId); if (site == null) { return(NotFound()); } Template template; if (request.TemplateId > 0) { template = await _templateRepository.GetAsync(request.TemplateId); } else { template = new Template { TemplateType = request.TemplateType }; } return(new GetResult { Template = await GetTemplateResultAsync(template, site) }); }
public TemplateRequest CreateRequestForSolution() { var request = new TemplateRequest { RootDirectory = SolutionDirectory(), SolutionName = SolutionName, Version = VersionFlag }; request.AddTemplate("baseline"); request.AddTemplate(_rippleTemplates[RippleFlag]); determineShortName(request); if (!Profile.EqualsIgnoreCase("empty")) { var choices = ToTemplateChoices(); var project = Templating.Library.Graph.BuildProjectRequest(choices); if (DotNetFlag.IsNotEmpty()) { project.Version = DotNetFlag; } project.Version = project.Version ?? DotNetVersion.V40; request.AddProjectRequest(project); if (!NoTestsFlag) { request.AddMatchingTestingProject(project); } } return(request); }
private void applySolutionTemplates(TemplateRequest request, TemplatePlan plan) { var planner = new SolutionPlanner(); _library.Find(TemplateType.Solution, request.Templates) .Each(template => planner.CreatePlan(template, plan)); }
private void applyTestingTemplates(TemplateRequest request, TemplatePlan plan) { request.TestingProjects.Each(proj => { buildProjectPlan(plan, proj); plan.Add(new CopyProjectReferences(proj.OriginalProject)); }); }
private void applyTestingTemplates(TemplateRequest request, TemplatePlan plan) { GenericEnumerableExtensions.Each <ProjectRequest>(request.TestingProjects, delegate(ProjectRequest proj) { this.buildProjectPlan(plan, proj); plan.Add(new CopyProjectReferences(proj.OriginalProject)); }); }
private void determineShortName(TemplateRequest request) { var shortName = ShortNameFlag.IsEmpty() ? SolutionName.Split('.').Skip(1).Join("") : ShortNameFlag; request.Substitutions.Set(ProjectPlan.SHORT_NAME, shortName); }
/// <summary> /// Save Template /// </summary> /// <param name="request">TemplateRequest parameters.</param> /// <seealso cref="http://docs.sailthru.com/api/template"/> /// <returns></returns> public SailthruResponse SaveTemplate(TemplateRequest request) { Hashtable hashForPost = new Hashtable(); hashForPost.Add("json", JsonConvert.SerializeObject(request, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); return(this.ApiPost("template", hashForPost)); }
private void applySolutionTemplates(TemplateRequest request, TemplatePlan plan) { SolutionPlanner planner = new SolutionPlanner(); GenericEnumerableExtensions.Each <Template>(this._library.Find(TemplateType.Solution, request.Templates), delegate(Template template) { planner.CreatePlan(template, plan); }); }
public async Task CreateTemplatesAsync_NullName_ShouldThrowArgumentException() { var templatePatchRequest = new TemplateRequest() { Name = null, }; Func <Task> create = () => _client.CreateTemplatesAsync(_workspaceId, templatePatchRequest); await create.Should().ThrowAsync <ArgumentException>() .WithMessage($"Value cannot be null. (Parameter '{nameof(TemplateRequest.Name)}')"); }
public IActionResult Template([FromQuery] TemplateRequest templateRequest) { // create a ReportingCloud object with stored API-Key ReportingCloud rc = new ReportingCloud(RCSettings.APIKey); // download document from ReportingCloud template storage byte[] document = rc.DownloadTemplate(templateRequest.TemplateName); // return Base64 string version return(new OkObjectResult(Convert.ToBase64String(document))); }
private static void prepareTargetDirectory(NewCommandInput input, TemplateRequest request) { if (input.CleanFlag) { new FileSystem().ForceClean(request.RootDirectory); } else if (!input.IgnoreFlag) { AssertEmpty(request.RootDirectory); } }
public void SetUp() { theInput = new BottleInput { Name = "MyBottle", OptionsFlag = new string[] { "raven", "spark" }, ShortNameFlag = "Mine" }; theRequest = BottleCommand.BuildTemplateRequest(theInput, "MySolution.sln"); }
public static void AddMatchingTestingProject(this TemplateRequest request, ProjectRequest project) { var testing = new ProjectRequest(project.Name + ".Testing", "baseline", project.Name); testing.Alterations.Add("unit-testing"); testing.OriginalProject = project.Name; testing.Version = project.Version ?? DotNetVersion.V40; request.AddTestingRequest(testing); }
public async Task<IEnumerable<Template>> GetAllAsync(TemplateRequest request) { using (var client = CreateMailClient("templates")) { var response = await client.GetAsync(request?.ToQueryString()); await response.EnsureSuccessMailChimpAsync(); var templateResponse = await response.Content.ReadAsAsync<TemplateResponse>(); return templateResponse.Templates; } }
public async Task <ActionResult <GetResult> > Copy([FromBody] TemplateRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, MenuUtils.SitePermissions.Templates)) { return(Unauthorized()); } var site = await _siteRepository.GetAsync(request.SiteId); if (site == null) { return(NotFound()); } var template = await _templateRepository.GetAsync(request.TemplateId); var templateName = template.TemplateName + "_复件"; var relatedFileName = PathUtils.RemoveExtension(template.RelatedFileName) + "_复件"; var createdFileFullName = PathUtils.RemoveExtension(template.CreatedFileFullName) + "_复件"; var templateNameList = await _templateRepository.GetTemplateNamesAsync(request.SiteId, template.TemplateType); if (templateNameList.Contains(templateName)) { return(this.Error("模板复制失败,模板名称已存在!")); } var fileNameList = await _templateRepository.GetRelatedFileNamesAsync(request.SiteId, template.TemplateType); if (ListUtils.ContainsIgnoreCase(fileNameList, relatedFileName)) { return(this.Error("模板复制失败,模板文件已存在!")); } var templateInfo = new Template { SiteId = request.SiteId, TemplateName = templateName, TemplateType = template.TemplateType, RelatedFileName = relatedFileName + template.CreatedFileExtName, CreatedFileExtName = template.CreatedFileExtName, CreatedFileFullName = createdFileFullName + template.CreatedFileExtName, DefaultTemplate = false }; var content = await _pathManager.GetTemplateContentAsync(site, template); var adminId = _authManager.AdminId; templateInfo.Id = await _templateRepository.InsertAsync(templateInfo); await _pathManager.WriteContentToTemplateFileAsync(site, template, content, adminId); return(await GetResultAsync(site)); }
public async Task CreateTemplatesAsync_NullProjectsAndTasks_ShouldThrowArgumentException() { var templatePatchRequest = new TemplateRequest() { Name = "Test name " + Guid.NewGuid(), ProjectsAndTasks = null }; Func <Task> create = () => _client.CreateTemplatesAsync(_workspaceId, templatePatchRequest); await create.Should().ThrowAsync <ArgumentException>() .WithMessage($"Value cannot be null. (Parameter '{nameof(TemplateRequest.ProjectsAndTasks)}')"); }
public void validate_missing_solution_template() { var request = new TemplateRequest(); request.AddTemplate("NonExistent"); var missing = request.Validate(theTemplates).Single(); missing.Name.ShouldEqual("NonExistent"); missing.TemplateType.ShouldEqual(TemplateType.Solution); missing.ValidChoices.ShouldHaveTheSameElementsAs("Complex", "Simple"); }
public void SetUp() { var input = new NewCommandInput { SolutionName = "NewThing", Profile = "web-app", }; TemplateRequest request = input.CreateRequestForSolution(); project = request.Projects.Single(); }
public async Task UpdateTemplateAsync_ShouldReturnTemplateDto() { // Create project for test var projectRequest = new ProjectRequest { Name = "Update Template test project " + Guid.NewGuid(), Color = "#FFFFFF" }; var projectResponse = await _client.CreateProjectAsync(_workspaceId, projectRequest); projectResponse.IsSuccessful.Should().BeTrue(); var projectId = projectResponse.Data.Id; // Create task var taskRequest = new TaskRequest { Name = "Template create task " + Guid.NewGuid() }; var taskResponse = await _client.CreateTaskAsync(_workspaceId, projectId, taskRequest); taskResponse.IsSuccessful.Should().BeTrue(); var taskId = taskResponse.Data.Id; var templatePatchRequest = new TemplateRequest() { Name = "Update Test template " + Guid.NewGuid(), ProjectsAndTasks = new List <ProjectsTaskTupleRequest>() { new ProjectsTaskTupleRequest { ProjectId = projectId, TaskId = taskId } } }; var createResult = await _client.CreateTemplatesAsync(_workspaceId, templatePatchRequest); createResult.IsSuccessful.Should().BeTrue(); createResult.Data.Should().NotBeNull(); var patchRequest = new TemplatePatchRequest { Name = "Updated " + Guid.NewGuid() }; var templateDto = createResult.Data.First(); templateDto.Name = patchRequest.Name; var getResponse = await _client.UpdateTemplateAsync(_workspaceId, templateDto.Id, patchRequest); getResponse.IsSuccessful.Should().BeTrue(); getResponse.Data.Should().BeEquivalentTo(templateDto); var deleteProject = await _client.ArchiveAndDeleteProject(_workspaceId, projectId); deleteProject.IsSuccessful.Should().BeTrue(); }
/// <summary> /// The get all async. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> /// <exception cref="ArgumentNullException"><paramref> /// <name>uriString</name> /// </paramref> /// is null. </exception> /// <exception cref="ArgumentOutOfRangeException">Enlarging the value of this instance would exceed <see cref="P:System.Text.StringBuilder.MaxCapacity" />. </exception> /// <exception cref="UriFormatException">In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, <see cref="T:System.FormatException" />, instead.<paramref name="uriString" /> is empty.-or- The scheme specified in <paramref name="uriString" /> is not correctly formed. See <see cref="M:System.Uri.CheckSchemeName(System.String)" />.-or- <paramref name="uriString" /> contains too many slashes.-or- The password specified in <paramref name="uriString" /> is not valid.-or- The host name specified in <paramref name="uriString" /> is not valid.-or- The file name specified in <paramref name="uriString" /> is not valid. -or- The user name specified in <paramref name="uriString" /> is not valid.-or- The host or authority name specified in <paramref name="uriString" /> cannot be terminated by backslashes.-or- The port number specified in <paramref name="uriString" /> is not valid or cannot be parsed.-or- The length of <paramref name="uriString" /> exceeds 65519 characters.-or- The length of the scheme specified in <paramref name="uriString" /> exceeds 1023 characters.-or- There is an invalid character sequence in <paramref name="uriString" />.-or- The MS-DOS path specified in <paramref name="uriString" /> must start with c:\\.</exception> /// <exception cref="NotSupportedException"><paramref name="element" /> is not a constructor, method, property, event, type, or field. </exception> /// <exception cref="MailChimpException"> /// Custom Mail Chimp Exception /// </exception> /// <exception cref="TypeLoadException">A custom attribute type cannot be loaded. </exception> public async Task <TemplateResponse> GetResponseAsync(TemplateRequest request = null) { using (var client = this.CreateMailClient("templates")) { var response = await client.GetAsync(request?.ToQueryString()).ConfigureAwait(false); await response.EnsureSuccessMailChimpAsync().ConfigureAwait(false); var templateResponse = await response.Content.ReadAsAsync <TemplateResponse>().ConfigureAwait(false); return(templateResponse); } }
public static TemplatePlan BuildPlan(TemplateRequest request) { var planner = new TemplatePlanBuilder(_templates.Value); var plan = planner.BuildPlan(request); if (plan.Steps.OfType <GemReference>().Any()) { plan.Add(new BundlerStep()); } return(plan); }
public void should_add_a_bundler_step_if_there_are_any_gem_references() { var request = new TemplateRequest { SolutionName = "Foo", RootDirectory = "Foo" }; request.AddTemplate("baseline"); NewCommand.BuildTemplatePlan(request) .Steps.OfType<BundlerStep>() .Count().ShouldEqual(1); }
public void SetUp() { theInput = new BottleInput { Name = "MyBottle", OptionsFlag = new string[]{"raven", "spark"}, ShortNameFlag = "Mine" }; theRequest = BottleCommand.BuildTemplateRequest(theInput, "MySolution.sln"); }