예제 #1
0
        public static string GetViewPath(this ViewComponent viewComponent, string viewName = "Default")
        {
            var theme = "";

            viewComponent.HttpContext.Request.Cookies.TryGetValue("theme", out string previewingTheme);
            if (!string.IsNullOrWhiteSpace(previewingTheme))
            {
                theme = previewingTheme;
            }
            else
            {
                var config = viewComponent.HttpContext.RequestServices.GetService <IConfiguration>();
                theme = config["Theme"];
            }

            var viewPath = $"/Modules/{viewComponent.GetType().Assembly.GetName().Name}/Views/Shared/Components/{viewComponent.ViewComponentContext.ViewComponentDescriptor.ShortName}/{viewName}.cshtml";

            if (!string.IsNullOrWhiteSpace(theme) && !string.Equals(theme, "Generic", System.StringComparison.InvariantCultureIgnoreCase))
            {
                var themeViewPath = $"/Themes/{theme}{viewPath}";
                var viewEngine    = viewComponent.ViewContext.HttpContext.RequestServices.GetRequiredService <ICompositeViewEngine>();
                //var result = viewEngine.FindView(viewComponent.ViewContext, themeViewPath, isMainPage: false);
                var result = viewEngine.GetView("", themeViewPath, isMainPage: false);
                if (result.Success)
                {
                    viewPath = themeViewPath;
                }
            }

            return(viewPath);
        }
		public override void Release(ViewComponent instance)
		{
			if (kernel.HasComponent(instance.GetType()))
			{
				kernel.ReleaseComponent(instance);
			}
			else
			{
				base.Release(instance);
			}
		}
 public override void Release(ViewComponent instance)
 {
     if (kernel.HasComponent(instance.GetType()))
     {
         kernel.ReleaseComponent(instance);
     }
     else
     {
         base.Release(instance);
     }
 }
예제 #4
0
        /// <summary>
        /// Initialize the view component with mock services it needs to
        /// be functional.
        /// </summary>
        /// <param name="component">The component instance.</param>
        protected void PrepareViewComponent(ViewComponent component)
        {
            if (Context == null)
            {
                BuildEngineContext("", "Controller", "Action");
            }

            viewEngine = BuildViewEngine();

            componentContext = BuildViewComponentContext(component.GetType().Name);

            component.Init(Context, componentContext);
        }
    public void Initialize()
    {
        List <ViewableEntityInitializer> initializableEntities = Object.FindObjectsOfType <ViewableEntityInitializer>().ToList();

        foreach (ViewableEntityInitializer initializableEntity in initializableEntities)
        {
            List <BaseComponentMonoBehaviour> monoComponents = initializableEntity.GetComponents <BaseComponentMonoBehaviour>().ToList();

            IContext currentContext = _contexts.game;

            Entity entity = (Entity)currentContext.GetType().InvokeMember("CreateEntity", BindingFlags.InvokeMethod, null, currentContext, null);

            string componentLookupClassName = currentContext.contextInfo.name + "ComponentsLookup";
            Type[] componentTypes           = (Type[])Type.GetType(componentLookupClassName).GetField("componentTypes", BindingFlags.Public | BindingFlags.Static).GetValue(null);

            IComponent viewComponent = new ViewComponent {
                gameObject = initializableEntity.gameObject
            };
            int viewComponentIndex = Array.IndexOf(componentTypes, viewComponent.GetType());
            entity.AddComponent(viewComponentIndex, viewComponent);

            foreach (BaseComponentMonoBehaviour monoComponent in monoComponents)
            {
                var component      = monoComponent.Component;
                int componentIndex = Array.IndexOf(componentTypes, component.GetType());

                //@todo Implement univeral 'special case' initializers
                if (component.GetType() == typeof(NavAgentComponent))
                {
                    ((NavAgentComponent)component).value = initializableEntity.GetComponent <NavAgentBehaviour>();
                }

                entity.AddComponent(componentIndex, component);

                Object.Destroy(monoComponent);
            }

            initializableEntity.gameObject.Link(entity, currentContext);
            Object.Destroy(initializableEntity);
        }
    }
예제 #6
0
 public ViewComponentInfo(ViewComponent component)
 {
     Type     = component.GetType();
     Details  = Type.GetCustomAttributes(typeof(ViewComponentDetailsAttribute), false).OfType <ViewComponentDetailsAttribute>().FirstOrDefault();
     Instance = component;
 }