示例#1
0
        protected virtual void InitAppPlugins()
        {
            var types = ShReflectionUtils.GetTypesFromAssemblies <IPlugin>(AppPluginsAssemblies);

            foreach (var type in types.OrderByDescending(a => a.Name))
            {
                try
                {
                    if (!AppDataServices.Any(t => t.GetType() == type))
                    {
                        var instance = Activator.CreateInstance(type) as IPlugin;

                        instance.Init();

                        AppPlugins.Add(instance);
                    }
                }

                catch (System.Exception e)
                {
                    // TODO
                    throw;
                }
            }
        }
示例#2
0
        protected virtual void InitAppDataServices()
        {
            var types = ShReflectionUtils.GetTypesFromAssemblies <ShAppDataServiceBase>(AppDataServiceAssemblies)
                        .ToList();

            // special init for event hub
            var eventDataService = types.First(t => typeof(IAppEventService).IsAssignableFrom(t));

            AppDataServices.Add(Activator.CreateInstance(eventDataService) as ShAppDataServiceBase);
            types.Remove(eventDataService);

            // the rest
            foreach (var type in types.OrderByDescending(a => a.Name))
            {
                try
                {
                    if (!AppDataServices.Any(t => t.GetType() == type))
                    {
                        var instance = Activator.CreateInstance(type) as ShAppDataServiceBase;

                        instance.Init();

                        AppDataServices.Add(instance);
                    }
                }
                catch (Exception e)
                {
                    // TODO
                    throw;
                }
            }
        }
示例#3
0
        protected virtual void CreateAppUIServices()
        {
            var types = ShReflectionUtils.GetTypesFromAssemblies <ShAppUIServiceBase>(AppUIServiceAssemblies);

            foreach (var type in types.OrderByDescending(a => a.Name))
            {
                try
                {
                    if (!AppDataServices.Any(t => t.GetType() == type))
                    {
                        var instance = Activator.CreateInstance(type) as ShAppUIServiceBase;
                        AppUIServices.Add(instance);
                    }
                }
                catch (Exception e)
                {
                    // TODO
                    throw;
                }
            }
        }
示例#4
0
        public static Type GetUIComponentType(Type targetType, Type fallbackType)
        {
            if (!hasInitedAssemblies)
            {
                InitAssemblies();
                hasInitedAssemblies = true;
            }

            Type result = null;

            var allTypes = ShReflectionUtils.GetTypesFromAssemblies(targetType, uiAssemblies)
                           .Where(t => typeof(ShUserControlBase).IsAssignableFrom(t) &&
                                  !t.IsAbstract);

            if (allTypes.Count() == 0)
            {
                throw new ShAppException("Can't find implementation for type: " + targetType.Name);
            }


            if (allTypes.Count() == 1)
            {
                return(allTypes.First());
            }

            if (fallbackType != null)
            {
                var implType = allTypes.FirstOrDefault(t => t != fallbackType);

                if (implType != null)
                {
                    return(implType);
                }

                return(fallbackType);
            }

            throw new ShAppException("Can't find fallback type for type: " + targetType.Name);
        }
示例#5
0
        public ShBindService <TSrc> AutoBindProperty <TControl>(Expression <Func <TSrc, object> > srcExp,
                                                                TControl control, object dataSource)
            where TControl : Control
        {
            var type = typeof(TControl);

            if (typeof(TextBox).IsAssignableFrom(type))
            {
                var textBox = control as TextBox;
                BindProperty(srcExp, textBox, c => c.Text, dataSource);
            }
            else if (typeof(CheckBox).IsAssignableFrom(type))
            {
                var checkbox = control as CheckBox;
                BindProperty(srcExp, checkbox, c => c.Checked, dataSource);
            }
            else if (typeof(Label).IsAssignableFrom(type))
            {
                var label = control as Label;
                BindProperty(srcExp, label, c => c.Text, dataSource);
            }
            else if (typeof(Button).IsAssignableFrom(type))
            {
                var button = control as Button;
                BindProperty(srcExp, button, c => c.Text, dataSource);
            }
            else if (typeof(ComboBox).IsAssignableFrom(type))
            {
                var comboBox = control as ComboBox;

                if (dataSource != null)
                {
                    comboBox.DataSource = dataSource;
                }

                var srcProp = Src.GetExpressionValue <TSrc, object>(srcExp);

                comboBox.SelectedIndexChanged += (s, e) =>
                {
                    if (comboBox.SelectedIndex >= 0)
                    {
                        var value = comboBox.Items[comboBox.SelectedIndex];
                        var prop  = Src.GetType().GetProperty(srcProp.Name);

                        prop.SetValue(Src, value);
                    }
                };


                //BindProperty(srcExp, comboBox, c => c.SelectedItem, dataSource);
            }
            else if (ShReflectionUtils.HasProperty(control, "Text"))
            {
                BindProperty(srcExp, control, "Text", dataSource, true);
            }
            else
            {
                throw new Exception(
                          string.Format("Autobinding isn't supported for control type:[{0}]", type));
            }

            return(this);
        }