private void ReplacePlaceholders(string html, TextWriter writer, Rendering rendering) { var index = html.IndexOf(placeholderStartSearch, StringComparison.Ordinal); if (index < 0) { writer.Write(html); return; } var endOfStartTag = html.IndexOf(" -->", index, StringComparison.Ordinal); var startOfKey = index + placeholderStartSearch.Length; var placeHolderKey = html.Substring(startOfKey, endOfStartTag - startOfKey); var endTag = string.Format(placeHolderEndSearch, placeHolderKey); var endOfPlaceHolder = html.IndexOf(endTag, endOfStartTag, StringComparison.Ordinal); if (endOfPlaceHolder < 0) { throw new Exception("Could not find end of placeholder " + placeHolderKey); } if (placeHolderKey.IndexOf("_cacheable", StringComparison.Ordinal) > placeHolderKey.LastIndexOf('/')) //another way to cache placeholders is to have the name contain _cacheable { writer.Write(html.Substring(0, endOfPlaceHolder + endTag.Length)); } else { writer.Write(html.Substring(0, index)); PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder", new RenderPlaceholderArgs(placeHolderKey, writer, rendering)); } ReplacePlaceholders(html.Substring(endOfPlaceHolder + endTag.Length), writer, rendering); }
public HttpResponseMessage GetHtml(string id) { var item = ID.Parse(id); var database = Sitecore.Context.Database; Sitecore.Context.Item = database.GetItem(item); var personalisedRenderingList = new List <PersonalisedRendering>(); using (new PersonalisationContext()) { var renderings = PageContext.Current.PageDefinition.Renderings.Where(IsPersonalisedRendering).ToList(); foreach (Rendering current in renderings) { using (StringWriter stringWriter = new StringWriter()) { PipelineService.Get() .RunPipeline <RenderRenderingArgs>("mvc.renderRendering", new RenderRenderingArgs(current, stringWriter)); var personalisedRendering = new PersonalisedRendering() { Id = current.UniqueId.ToString(), Html = stringWriter.ToString() }; personalisedRenderingList.Add(personalisedRendering); } } } return(Request.CreateResponse(HttpStatusCode.OK, personalisedRenderingList)); }
static async Task Main(string[] args) { if (args == null || args.Length < 1) { Console.WriteLine("Pipeline id is missing"); Environment.ExitCode = -1; return; } string pipelineId = args[0]; Console.WriteLine($"Executing pipeline with id: '{pipelineId}'"); var appConfig = GetConfig(); var pipelineSevice = new PipelineService(appConfig.DatabaseSettings); var pipelineExecutor = new PipelineExecutor(pipelineSevice); long runTime = await pipelineExecutor.ExecuteAsync(pipelineId); Console.WriteLine($"Run time was: {runTime} ms"); }
public ActionResult Get() { var userId = User.Identity.GetUserId(); var data = PipelineService.Query <ProjectsQueries>().With(q => q.GetByUserDto(userId)); return(Json(data, JsonRequestBehavior.AllowGet)); }
public ActionResult Check(CheckTaskCommand command) { var userId = User.Identity.GetUserId(); command.UserId = userId; PipelineService.HandleCommand(command); return(Json(true)); }
public ActionResult RemovePost(int id) { PipelineService.HandleCommand(new RemoveProjectCommand() { ProjectId = id, UpdatedByUserId = User.Identity.GetUserId(), }); return(RedirectToAction("Index")); }
public ActionResult Index(bool isUpdated = false) { ViewBag.StatusMessage = isUpdated ? "Profile updated" : string.Empty; var userId = User.Identity.GetUserId(); var model = new UpdateUserCommand(PipelineService.Query(userQueries).With(q => q.GetById(userId))); return(View(model)); }
public ActionResult Put(UpdateTaskCommand command) { var userId = User.Identity.GetUserId(); command.UserId = userId; PipelineService.HandleCommand(command); var data = PipelineService.Query <TasksQueries>().With(q => q.GetByIdDto(command.Id)); return(Json(data)); }
public ActionResult Create(CreateProjectCommand command) { if (!ModelState.IsValid) { return(View(command)); } command.CreatedByUserId = User.Identity.GetUserId(); PipelineService.HandleCommand(command); return(RedirectToAction("Index")); }
public ActionResult Remove(int id) { var project = PipelineService.Query <ProjectsQueries>().With(q => q.GetById(id)); if (project == null) { return(HttpNotFound()); } return(View(project)); }
public ActionResult Index(UpdateUserCommand command) { if (!ModelState.IsValid) { return(View(command)); } command.UserId = User.Identity.GetUserId(); PipelineService.HandleCommand(command); return(View(command)); }
protected virtual string Placeholder(string placeholderName, Rendering rendering) { Assert.ArgumentNotNull(placeholderName, "placeholderName"); var stringWriter = new StringWriter(); PipelineService.Get() .RunPipeline( "mvc.renderPlaceholder", new RenderPlaceholderArgs(placeholderName, stringWriter, rendering)); return(stringWriter.ToString()); }
public ActionResult Edit(int id, UpdateProjectCommand command) { command.ProjectId = id; command.UpdatedByUserId = User.Identity.GetUserId(); if (!ModelState.IsValid) { return(View(command)); } PipelineService.HandleCommand(command); return(RedirectToAction("Index")); }
protected virtual void Render(string placeholderName, TextWriter writer, RenderPlaceholderArgs args) { IEnumerable <Rendering> renderings = this.GetRenderings(placeholderName, args); if (renderings != null) { foreach (Rendering rendering in renderings) { PipelineService.Get().RunPipeline <RenderRenderingArgs>("mvc.renderRendering", new RenderRenderingArgs(rendering, writer)); } } }
public ActionResult Delete(int id) { var userId = User.Identity.GetUserId(); var command = new RemoveTaskCommand { UserId = userId, TaskId = id, }; PipelineService.HandleCommand(command); return(Json(true)); }
public ActionResult EditLayout() { var pageContext = PageContext.CurrentOrNull; Assert.IsNotNull(pageContext, "Page context is required"); var stringWriter = new StringWriter(); stringWriter.Write("<html><head></head><body>"); PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder", new RenderPlaceholderArgs(pageContext.Item["PlaceholderName"] ?? "compositecontent", (TextWriter)stringWriter, new ContentRendering())); stringWriter.Write("</body></html>"); return(Content(stringWriter.ToString())); }
public AdCenterApi(PipelineService service) { _service = service; // Get customer account IDs string originalIDs = _service.Instance.Configuration.Options["AdCenter.CustomerAccountID"]; string[] split = originalIDs.Split(','); _accountOriginalIDs = new long[split.Length]; for (int i = 0; i < _accountOriginalIDs.Length; i++) { _accountOriginalIDs[i] = long.Parse(split[i]); } }
public override IValueProvider GetValueProvider(ControllerContext controllerContext) { if (RenderingContext.CurrentOrNull?.Rendering?.Parameters == null) { return(null); } var args = new GetControllerRenderingValueParametersArgs(HttpContext.Current, RenderingContext.Current); var parameters = PipelineService.Get().RunPipeline("elision.getControllerRenderingValueParameters", args, x => x.Parameters); return(new PipelineValueProvider(parameters ?? new Dictionary <string, object>(), CultureInfo.CurrentCulture)); }
protected override IValueProvider GetValueProvider(HttpContextBase httpContext, RenderingContext renderingContext) { if (renderingContext.Rendering.Parameters == null) { return(null); } var args = new GetControllerRenderingValueParametersArgs(httpContext, renderingContext); var parameters = PipelineService.Get().RunPipeline("mvc.getControllerRenderingValueParameters", args, x => x.Parameters); return(new PipelineValueProvider(parameters ?? new Dictionary <string, object>(), CultureInfo.CurrentCulture)); }
public ActionResult Edit(int id) { var project = PipelineService.Query <ProjectsQueries>().With(q => q.GetById(id)); if (project == null) { return(HttpNotFound()); } return(View(new UpdateProjectCommand() { ProjectId = project.Id, Color = project.Color, Name = project.Name, })); }
public void Page_Load(object sender, EventArgs e) { // Workaround for Cassini issue with request to /, IIS 6 and IIS 7 Classic mode. // In IIS7 Integrated mode, Default.aspx can be deleted. var serviceLocator = Bootstrapper.ServiceLocator; var pipelineService = new PipelineService(new HttpContextWrapper(HttpContext.Current), serviceLocator); var route = new RootRoute(HostInfo.Instance.BlogAggregationEnabled, serviceLocator); IRouteHandler routeHandler = new PageRouteHandler( HostInfo.Instance.BlogAggregationEnabled ? "~/aspx/AggDefault.aspx" : "~/aspx/Dtp.aspx", serviceLocator.GetService <ISubtextPageBuilder>(), serviceLocator); pipelineService.ProcessRootRequest(route, routeHandler); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IPipelineRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Pipeline>(null)); var service = new PipelineService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPipelineMapperMock, mock.DALMapperMockFactory.DALPipelineMapperMock); ApiPipelineResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public void Process(HandlebarHelpersPipelineArgs pipelineArgs) { pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("placeholder", (writer, context, args) => { var passedInName = args[0].ToString(); var placeholderName = args[0].ToString(); var placeholderIndex = args.Length > 1 ? args[1].ToString() : "1"; placeholderIndex = string.IsNullOrEmpty(placeholderIndex) ? "1" : placeholderIndex; Guid currentRenderingId = RenderingContext.Current.Rendering.UniqueId; if (currentRenderingId != Guid.Empty) { placeholderName = String.Format("{0}-{1}-{2}", placeholderName, currentRenderingId.ToString("B"), placeholderIndex); } if (Sitecore.Context.PageMode.IsExperienceEditorEditing) { writer.Write(@"<div data-container-title=""{0}"">", placeholderName); } //save current context for later var oldContext = HttpContext.Current.Items["HandlebarDataSource"]; var oldRenderingItem = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item; //Helper set from Variant field class as it's passed as arg. HtmlHelper helper = HttpContext.Current.Items["htmlHelper"] as HtmlHelper; if (helper != null) { var placeholderStr = (new Sitecore.Mvc.Helpers.SitecoreHelper(helper)).DynamicPlaceholder(passedInName).ToHtmlString(); writer.Write(placeholderStr); } else { //The old manual way where we have no access to helper. PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder", new RenderPlaceholderArgs(placeholderName, writer, new ContentRendering())); } //put it back. HttpContext.Current.Items["HandlebarDataSource"] = oldContext; Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item = oldRenderingItem; if (Sitecore.Context.PageMode.IsExperienceEditorEditing) { writer.Write(@"</div>"); } })); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest httpRequest, ILogger logger) { logger.LogInformation("CancelPipeline Function triggered by HTTP request."); logger.LogInformation("Parsing body from request."); PipelineRunRequest request = await new BodyReader(httpRequest).GetRunRequestBodyAsync(); request.Validate(logger); using (var service = PipelineService.GetServiceForRequest(request, logger)) { PipelineRunStatus result = service.CancelPipeline(request); logger.LogInformation("CancelPipeline Function complete."); return(new OkObjectResult(JsonConvert.SerializeObject(result))); } }
public async void Create() { var mock = new ServiceMockFacade <IPipelineRepository>(); var model = new ApiPipelineRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pipeline>())).Returns(Task.FromResult(new Pipeline())); var service = new PipelineService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPipelineMapperMock, mock.DALMapperMockFactory.DALPipelineMapperMock); CreateResponse <ApiPipelineResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPipelineRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Pipeline>())); }
public async void All() { var mock = new ServiceMockFacade <IPipelineRepository>(); var records = new List <Pipeline>(); records.Add(new Pipeline()); mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); var service = new PipelineService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPipelineMapperMock, mock.DALMapperMockFactory.DALPipelineMapperMock); List <ApiPipelineResponseModel> response = await service.All(); response.Should().HaveCount(1); mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public async void Delete() { var mock = new ServiceMockFacade <IPipelineRepository>(); var model = new ApiPipelineRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new PipelineService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPipelineMapperMock, mock.DALMapperMockFactory.DALPipelineMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IPipelineService, IPipelineRepository>(); var model = new ApiPipelineServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new PipelineService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Object, mock.DALMapperMockFactory.DALPipelineMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PipelineDeletedNotification>(), It.IsAny <CancellationToken>())); }
protected override void DoRender(HtmlTextWriter output) { HttpContextWrapper httpCtxWrapper = _pageCtx.RequestContext.HttpContext as HttpContextWrapper; if (httpCtxWrapper != null) { using (ContextService.Get().Push <Sitecore.Mvc.Presentation.PageContext>(_pageCtx)) { ViewContext viewCtx = CreateViewContext(httpCtxWrapper, _pageCtx.RequestContext.RouteData, _rendering); using (ContextService.Get().Push <ViewContext>(viewCtx)) { PipelineService.Get().RunPipeline <RenderRenderingArgs>("mvc.renderRendering", new RenderRenderingArgs(_rendering, output)); } } } else { throw new Exception("Invalid HttpContextWrapper"); } }
public GenPhHtml CreateModel(string placeholderKey) { string returnHtml = null; Item currentItem = RenderingContext.Current.Rendering.Item; var renderings = new List <Sitecore.Mvc.Presentation.Rendering>(); var renderingCount = currentItem.Visualization.GetRenderings(Sitecore.Context.Device, false).ToList(); if (renderingCount.Count > 0) { renderings.AddRange(renderingCount.Select(r => new Sitecore.Mvc.Presentation.Rendering { RenderingItemPath = r.RenderingID.ToString(), Parameters = new RenderingParameters(r.Settings.Parameters), DataSource = r.Settings.DataSource, Placeholder = r.Placeholder, })); foreach (var r in renderings.Where(r => r.Placeholder.Contains(placeholderKey))) { using (var stringWriter = new StringWriter()) { PipelineService.Get() .RunPipeline("mvc.renderRendering", new RenderRenderingArgs(r, stringWriter)); returnHtml += stringWriter.ToString(); } } } //var imageRenderings = new List<string>(); //imageRenderings.Add(FieldRenderer.Render(currentItem, "Image", "mw=400")); return(new GenPhHtml { PlaceholderKey = placeholderKey, GenHtml = returnHtml, ItemID = RenderingContext.Current.Rendering.Item.ID.ToString() }); }