public void AddRegisteredComponent(Type componentType, IContainerComponent component)
        {
            if (null == componentType)
            {
                throw new ArgumentNullException(nameof(componentType));
            }

            if (null == component)
            {
                throw new ArgumentNullException(nameof(component));
            }

            if (this.HasRegisteredComponent(componentType))
            {
                throw new ArgumentException("This type is already registred.", nameof(componentType));
            }

            this.componentsLocker.EnterWriteLock();

            try
            {
                this.Components.Add(componentType, component);
            }
            finally
            {
                this.componentsLocker.ExitWriteLock();
            }

            if (this.PrepareCompositionOnRegister && component.IsCompositionPreparationSupported)
            {
                component.PrepareComposition(this.DefaultComposer, this.DefaultConstructorSelector);
            }
        }
示例#2
0
 static void EnsureComponentStatus(IContainerComponent container)
 {
     if (string.IsNullOrWhiteSpace(container.Container.Id))
     {
         throw new Exception("要置为 Loading 状态的组件尚未加载完成,IContainerComponent.Container 的 Id 为 null");
     }
 }
示例#3
0
 /// <summary>
 /// 显示 Loading 状态
 /// </summary>
 /// <param name="container"></param>
 /// <returns></returns>
 public static void Loading(this IContainerComponent container)
 {
     EnsureComponentStatus(container);
     container.LoadingService.Show(new LoadingOption()
     {
         Target = container.Container
     });
 }
示例#4
0
 public static void Loading(this IContainerComponent container, LoadingService loadingService, string text)
 {
     EnsureComponentStatus(container);
     loadingService.Show(new LoadingOption()
     {
         Text   = text,
         Target = container.Container
     });
 }
示例#5
0
        public static void Close(this IContainerComponent container)
        {
            EnsureComponentStatus(container);
            var option = container.LoadingService.LoadingOptions.FirstOrDefault(x => x.Target.Id == container.Container.Id);

            if (option == null)
            {
                return;
            }
            container.LoadingService.LoadingOptions.Remove(option);
        }
 protected void RegisterOrReplace(IContainerComponent component)
 {
     if (this.IsReplace)
     {
         this.Container.ReplaceRegisteredComponent <TComponentType>(component);
     }
     else
     {
         this.Container.AddRegisteredComponent <TComponentType>(component);
     }
 }
示例#7
0
 public static void Loading(this IContainerComponent container, LoadingService loadingService, string text, string iconClass, string background)
 {
     EnsureComponentStatus(container);
     loadingService.Show(new LoadingOption()
     {
         Text       = text,
         Target     = container.Container,
         IconClass  = iconClass,
         Background = background
     });
 }
示例#8
0
 /// <summary>
 /// 显示 Loading 状态
 /// </summary>
 /// <param name="container"></param>
 /// <param name="action">在 Loading 状态期间要做的事</param>
 /// <param name="text"></param>
 /// <returns></returns>
 public static async Task WithLoadingAsync(this IContainerComponent container, Func <Task> action, string text)
 {
     EnsureComponentStatus(container);
     container.LoadingService.Show(new LoadingOption()
     {
         Text   = text,
         Target = container.Container
     });
     try
     {
         await action();
     }
     finally
     {
         container.Close();
     }
 }
        public void ReplaceRegisteredComponent(Type componentType, IContainerComponent component)
        {
            if (this.disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            this.componentsLocker.EnterWriteLock();

            try
            {
                this.Components[componentType] = component;
            }
            finally
            {
                this.componentsLocker.ExitWriteLock();
            }
        }
示例#10
0
        public void SetParent(IContainerComponent parent, IReactComponent relativeTo = null, bool insertAfter = false)
        {
            if (Parent != null)
            {
                Parent.UnregisterChild(this);
            }

            Parent = parent;

            if (Parent == null)
            {
                return;
            }

            relativeTo = relativeTo ?? (insertAfter ? null : parent.AfterPseudo);

            if (relativeTo == null)
            {
                parent.RegisterChild(this);
            }
            else
            {
                var ind = parent.Children.IndexOf(relativeTo);
                if (insertAfter)
                {
                    ind++;
                }

                parent.RegisterChild(this, ind);
            }

            Style.Parent = parent.Style;
            ResolveStyle(true);

            Parent.ScheduleLayout();
        }
示例#11
0
 public void AddRegisteredComponent <T>(IContainerComponent component)
 {
     this.AddRegisteredComponent(typeof(T), component);
 }
示例#12
0
 /// <summary>
 /// Raises the expiration event.
 /// </summary>
 public virtual void OnExpiration(IContainerComponent container)
 {
 }