예제 #1
0
        public void Load(Type[] types)
        {
            if (types == null)
            {
                return;
            }

            foreach (Type type in types)
            {
                if (type == null)
                {
                    continue;
                }
                try
                {
                    IChoPlugIn <T> plugIn = ChoActivator.CreateInstance <IChoPlugIn <T> >();
                    if (plugIn != null)
                    {
                        _plugInsObjs.Add(plugIn);
                    }
                }
                catch (Exception ex)
                {
                    ChoTrace.Write(ex);
                }
            }
        }
예제 #2
0
        public virtual ChoPlugIn CreatePlugIn()
        {
            ChoPlugInAttribute plugInAttribute = ChoType.GetAttribute <ChoPlugInAttribute>(GetType());

            if (plugInAttribute == null)
            {
                throw new ChoPlugInException("Missing ChoPlugInAttribute decorated for '{0}' plugin builder.".FormatString(GetType().Name));
            }

            Type type = plugInAttribute.PlugInType;

            if (type == null)
            {
                throw new ChoPlugInException("Can't find plugin for '{0}' plugin builder.".FormatString(GetType().Name));
            }

            ChoPlugIn p = ChoActivator.CreateInstance(type) as ChoPlugIn;

            if (p == null)
            {
                throw new ChoPlugInException("Can't find plugin for '{0}' plugin builder.".FormatString(GetType().Name));
            }

            InitPlugIn(p);
            return(p);
        }
예제 #3
0
        protected override object Execute(object value, out bool isHandled)
        {
            isHandled = false;

            Type type = ChoType.GetType(TypeName);

            if (type == null)
            {
                return(value);
            }

            MethodInfo info = type.GetMethod(MethodName);

            if (info == null)
            {
                return(value);
            }

            object obj = null;

            if (!IsStaticMethod)
            {
                obj = ChoActivator.CreateInstance(type);
            }

            string arguments = !Arguments.IsNullOrWhiteSpace() ? "{0} {1}".FormatString(value.ToNString(), ResolveText(Arguments)) : value.ToNString();

            return(info.Invoke(obj, arguments.SplitNConvertToObjects(' ')));
        }
예제 #4
0
        public virtual object Clone()
        {
            object cloneObj = ChoActivator.CreateInstance(GetType());

            Clone(cloneObj as ChoPlugInBuilder);

            return(cloneObj);
        }
예제 #5
0
        private void btnAddNewPlugIn_Click(object sender, EventArgs e)
        {
            KeyValuePair <string, Type> keyValuePair = (KeyValuePair <string, Type>)cmbAvailPlugIns.SelectedItem;

            if (keyValuePair.Value == null)
            {
                return;
            }

            ChoPlugInBuilder builder = ChoActivator.CreateInstance(keyValuePair.Value) as ChoPlugInBuilder;

            if (builder == null)
            {
                return;
            }

            builder.Name = "{0}_{1}".FormatString(ChoPlugInBuilder.GetPlugInName(builder.GetType()), NextIndex());
            AddNewBuilder(builder);
        }
예제 #6
0
        public virtual ChoPlugInBuilder CreateBuilder()
        {
            Type type = ChoType.GetTypeFromXmlSectionName(GetType().Name);

            if (type == null)
            {
                throw new ChoPlugInException("Can't find builder for '{0}' plugin.".FormatString(GetType().Name));
            }

            ChoPlugInBuilder builder = ChoActivator.CreateInstance(type) as ChoPlugInBuilder;

            if (builder == null)
            {
                throw new ChoPlugInException("Can't find builder for '{0}' plugin.".FormatString(GetType().Name));
            }

            InitializeBuilder(builder);
            return(builder);
        }
예제 #7
0
        public void Load(string[] types)
        {
            if (types == null)
            {
                return;
            }

            foreach (string typeString in types)
            {
                if (typeString.IsNullOrWhiteSpace())
                {
                    continue;
                }

                foreach (string typeText in typeString.SplitNTrim())
                {
                    try
                    {
                        Type type = ChoType.GetType(typeText);
                        if (type == null)
                        {
                            continue;
                        }

                        IChoPlugIn <T> plugIn = ChoActivator.CreateInstance <IChoPlugIn <T> >();
                        if (plugIn != null)
                        {
                            _plugInsObjs.Add(plugIn);
                        }
                    }
                    catch (Exception ex)
                    {
                        ChoTrace.Write(ex);
                    }
                }
            }
        }
예제 #8
0
        public ChoPlugInBuilder()
        {
            _plugInBuilderProperty = new Lazy <ChoPlugInBuilderProperty>(() =>
            {
                ChoPlugInAttribute plugInAttribute = ChoType.GetAttribute <ChoPlugInAttribute>(GetType());
                if (plugInAttribute == null)
                {
                    throw new ChoPlugInException("Missing ChoPlugInAttribute decorated for '{0}' plugin builder.".FormatString(GetType().Name));
                }

                Type type = plugInAttribute.PlugInBuilderPropertyType;
                if (type == null)
                {
                    throw new ChoPlugInException("Can't find plugin property for '{0}' plugin builder.".FormatString(GetType().Name));
                }

                ChoPlugInBuilderProperty p = ChoActivator.CreateInstance(type) as ChoPlugInBuilderProperty;
                if (p == null)
                {
                    throw new ChoPlugInException("Can't find plugin property for '{0}' plugin builder.".FormatString(GetType().Name));
                }

                try
                {
                    InitPlugInBuilderProperty(p);
                }
                catch { }

                p.PropertyChanged += ((s, e) =>
                {
                    ApplyPropertyValues(p, e.PropertyName);
                });

                return(p);
            }, true);
        }