Ejemplo n.º 1
0
        /// <summary>
        /// Invoked by the framework.
        /// </summary>
        /// <param name="railsContext"></param>
        /// <param name="context"></param>
        public void Init(IRailsEngineContext railsContext, IViewComponentContext context)
        {
            this.railsContext = railsContext;
            this.context      = context;

            Initialize();
        }
        public IViewComponentResult Invoke(IViewComponentContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(this.View(context));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Invoked by the framework.
        /// </summary>
        /// <param name="context">Request context</param>
        /// <param name="componentContext">ViewComponent context</param>
        public void Init(IEngineContext context, IViewComponentContext componentContext)
        {
            engineContext = context;
            this.context  = componentContext;

            BindComponentParameters();

            Initialize();
        }
		internal void CreateViewComponent()
		{
			if ((viewComponentName == null) || (viewComponentName.Length < 1))
			{
				throw new RailsException("You must specify the component name with 'blockcomponent' and 'component'.");
			}
			viewComponent = ((ViewComponentStringTemplateGroup)group).ViewComponentFactory.Create(viewComponentName);
			viewComponentContext = new StringTemplateViewContextAdapter(viewComponentName, this);
		}
Ejemplo n.º 5
0
 internal void CreateViewComponent()
 {
     if ((viewComponentName == null) || (viewComponentName.Length < 1))
     {
         throw new RailsException("You must specify the component name with 'blockcomponent' and 'component'.");
     }
     viewComponent        = ((ViewComponentStringTemplateGroup)group).ViewComponentFactory.Create(viewComponentName);
     viewComponentContext = new StringTemplateViewContextAdapter(viewComponentName, this);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Invokes the view.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public IViewComponentResult Invoke(IViewComponentContext <SeparateWidgetPerTemplateEntity> context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(this.View(context.Entity.SfViewName));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Invokes the view.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public IViewComponentResult Invoke(IViewComponentContext <AllPropertiesEntity> context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var serializedProperties = JObject.FromObject(context.Entity).ToString();

            return(this.View("Default", serializedProperties));
        }
        public void OnBeforeViewComponent(IViewComponentContext viewComponentContext)
        {
            var startDateTime = DateTime.UtcNow;

            var message = new BeforeViewComponentMessage
            {
                ComponentId          = viewComponentContext.ViewComponentDescriptor.Id,
                ComponentDisplayName = viewComponentContext.ViewComponentDescriptor.FullName,
                ComponentName        = viewComponentContext.ViewComponentDescriptor.ShortName,
                ComponentStartTime   = startDateTime,
                Arguments            = viewComponentContext.Arguments?.Select(x => new ArgumentData {
                    Type = TypeNameHelper.GetTypeDisplayName(x, false), TypeFullName = TypeNameHelper.GetTypeDisplayName(x), Name = null, Value = SanitizeUserObjectsHelper.GetSafeObject(x)
                }).ToList()
            };

            _broker.BeginLogicalOperation(message, startDateTime);
            _broker.SendMessage(message);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Invokes the view.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public IViewComponentResult Invoke(IViewComponentContext <HelloWorldEntity> context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (this.renderContext.IsEdit)
            {
                context.Entity.Message = $"{context.Entity.Message} in edit";
            }
            else if (this.renderContext.IsPreview)
            {
                context.Entity.Message = $"{context.Entity.Message} in preview";
            }

            return(this.View(context.Entity));
        }
        public void OnAfterViewComponent(IViewComponentContext viewComponentContext)
        {
            var timing = _broker.EndLogicalOperation <BeforeViewComponentMessage>();

            if (timing != null)
            {
                var message = new AfterViewComponentMessage
                {
                    ComponentId       = viewComponentContext.ViewComponentDescriptor.Id,
                    ComponentName     = viewComponentContext.ViewComponentDescriptor.ShortName,
                    ComponentEndTime  = timing.End,
                    ComponentDuration = timing.Elapsed,
                    ComponentOffset   = timing.Offset
                };

                _broker.SendMessage(message);
            }
            else
            {
                _logger.LogCritical("OnAfterViewComponent: Couldn't publish `AfterViewComponentMessage` as `BeforeViewComponentMessage` wasn't found in stack");
            }
        }
        /// <summary>
        /// Invokes the view component.
        /// </summary>
        /// <param name="context">The view component context.</param>
        /// <returns>The view component result.</returns>
        public async Task <IViewComponentResult> InvokeAsync(IViewComponentContext <TestimonialEntity> context)
        {
            var viewModels = await this.model.GetViewModels(context.Entity);

            return(this.View(viewModels));
        }
Ejemplo n.º 12
0
		/// <summary>
		/// Invoked by the framework.
		/// </summary>
		/// <param name="engineContext">Request context</param>
		/// <param name="componentContext">ViewComponent context</param>
		public void Init(IRailsEngineContext engineContext, IViewComponentContext componentContext)
		{
			railsContext = engineContext;
			context = componentContext;

			BindComponentParameters();

			Initialize();
		}
Ejemplo n.º 13
0
		/// <summary>
		/// Invoked by the framework.
		/// </summary>
		/// <param name="context">Request context</param>
		/// <param name="componentContext">ViewComponent context</param>
		public void Init(IEngineContext context, IViewComponentContext componentContext)
		{
			engineContext = context;
			this.context = componentContext;

			BindComponentParameters();

			Initialize();
		}
        public void OnBeforeViewComponent(IViewComponentContext viewComponentContext)
        {
            var startDateTime = DateTime.UtcNow;

            var message = new BeforeViewComponentMessage
            {
                ComponentId = viewComponentContext.ViewComponentDescriptor.Id,
                ComponentDisplayName = viewComponentContext.ViewComponentDescriptor.FullName,
                ComponentName = viewComponentContext.ViewComponentDescriptor.ShortName,
                ComponentStartTime = startDateTime,
                Arguments = viewComponentContext.Arguments?.Select(x => new ArgumentData { Type = TypeNameHelper.GetTypeDisplayName(x, false), TypeFullName = TypeNameHelper.GetTypeDisplayName(x), Name = null, Value = SanitizeUserObjectsHelper.GetSafeObject(x) }).ToList()
            };
            
            _broker.BeginLogicalOperation(message, startDateTime);
            _broker.SendMessage(message);
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="JavascriptHelper"/> class.
		/// </summary>
		/// <param name="controller">The controller.</param>
		/// <param name="key">The key.</param>
		public JavascriptHelper(Controller controller, string key)
		{
			this.context = null;
			this.contextVars = controller.PropertyBag;
			this.id = key;
			this.browCaps = controller.Context.UnderlyingContext.Request.Browser;
            cacheProvider = controller.Context.Services.CacheProvider;
            GetJSSegments(controller.Context);
			Init();

		}
		/// <summary>
		/// Initializes a new instance of the JavascriptHelper class.
		/// </summary>
		/// <remarks>Different instances of JavascriptHelper created with the same key are render only once.
		/// </remarks>
		/// <example><code>
		/// JavascriptHelper helper = new JavascriptHelper(viewcomp.Context, viewcomp.EngineContext, "MyScript");
		/// </code></example>
		/// <param name="context">The context.</param>
		/// <param name="engine">The engine.</param>
		/// <param name="key">The key.</param>
		public JavascriptHelper(IViewComponentContext context, IEngineContext engine, string key)
		{
			this.context = context;
			this.contextVars = context.ContextVars;
			this.id = key;
			this.browCaps = engine.UnderlyingContext.Request.Browser;
            this.cacheProvider = engine.Services.CacheProvider;
            this.engine = engine;
            GetJSSegments(engine);
            Init();
		}
        public JavascriptHelper(IViewComponentContext context,HttpContext httpcontext, string key)
        {
            this.context = context;
			this.contextVars = context.ContextVars;
			this.id = key;
			this.browCaps = httpcontext.Request.Browser;
//            this.engine = engine;
            Init();
		}
        public void OnAfterViewComponent(IViewComponentContext viewComponentContext)
        {
            var timing = _broker.EndLogicalOperation<BeforeViewComponentMessage>();
            if (timing != null)
            {
                var message = new AfterViewComponentMessage
                {
                    ComponentId = viewComponentContext.ViewComponentDescriptor.Id,
                    ComponentName = viewComponentContext.ViewComponentDescriptor.ShortName,
                    ComponentEndTime = timing.End,
                    ComponentDuration = timing.Elapsed,
                    ComponentOffset = timing.Offset
                };

                _broker.SendMessage(message);
            }
            else
            {
                _logger.LogCritical("OnAfterViewComponent: Couldn't publish `AfterViewComponentMessage` as `BeforeViewComponentMessage` wasn't found in stack");
            }
        }