Пример #1
0
        public object Find(Type type)
        {
            XAopComponent xcomponent = FindFaceConfig(type.FullName);

            if (xcomponent != null)
            {
                if (xcomponent.Scope == EScope.Global)
                {
                    if (xcomponent.Instance == null)
                    {
                        xcomponent.Instance = _factory.CreateInstance(xcomponent);
                    }
                    return(xcomponent.Instance);
                }
                else if (xcomponent.Scope == EScope.Session)
                {
                    return(_factory.CreateInstance(xcomponent));
                }
                else if (xcomponent.Scope == EScope.Local)
                {
                    return(_factory.CreateInstance(xcomponent));
                }
            }
            return(null);
        }
Пример #2
0
        public void ProcessReleases(FAopComponentBuilder builder)
        {
            XAopComponent xcomponent = builder.Component;

            if (xcomponent.HasRelease)
            {
                foreach (XAopMethod xmethod in xcomponent.Releases)
                {
                    ProcessMethod(builder, xmethod);
                }
            }
        }
Пример #3
0
        public void ProcessInitializes(FAopComponentBuilder builder)
        {
            XAopComponent xcomponent = builder.Component;

            if (xcomponent.HasInitialize)
            {
                foreach (XAopMethod xmethod in xcomponent.Initializes)
                {
                    ProcessMethod(builder, xmethod);
                }
            }
        }
Пример #4
0
        public object CreateInstance(XAopComponent xcomponent)
        {
            FAopComponentBuilder builder = new FAopComponentBuilder(xcomponent);

            if (xcomponent.HasConstructor)
            {
                object[] args = BuildParameters(builder, xcomponent.Constructor.Parameters);
                builder.Instance = xcomponent.CreateInstance(args);
            }
            else
            {
                builder.Instance = xcomponent.CreateInstance();
            }
            // Build proxy
            // Builder
            builder.Faces[xcomponent.LinkFace.FullName] = builder.Instance;
            LinkProperties(builder);
            LinkInterfaces(builder);
            ProcessInitializes(builder);
            return(builder.Instance);
        }
Пример #5
0
        public void LinkInterfaces(FAopComponentBuilder builder)
        {
            XAopComponent  xcomponent = builder.Component;
            FAopDescriptor descriptor = xcomponent.Descriptor;

            if (descriptor.HasLinker)
            {
                foreach (FAopLinker linker in descriptor.Linkers.Values)
                {
                    // Find
                    object find = null;
                    if (builder.Faces.Contains(linker.Face.FullName))
                    {
                        find = builder.Faces[linker.Face.FullName];
                    }
                    else
                    {
                        find = _components.Find(linker.Face.Type);
                        builder.Faces[linker.Face.FullName] = find;
                    }
                    // Check
                    if (find == null)
                    {
                        if (_logger.WarnAble)
                        {
                            _logger.Warn(this, "LinkInterfaces", "Linker instance is null. {0}", linker.Name);
                        }
                    }
                    else
                    {
                        if (_logger.DebugAble)
                        {
                            _logger.Debug(this, "LinkInterfaces", "Set linker {0} = {1}", linker.Name, RClass.Dump(find));
                        }
                        linker.Field.SetValue(builder.Instance, find);
                    }
                }
            }
        }
Пример #6
0
        public void LinkProperties(FAopComponentBuilder builder)
        {
            XAopComponent xcomponent = builder.Component;

            if (xcomponent.HasProperty)
            {
                FAopDescriptor descriptor = xcomponent.Descriptor;
                foreach (XAopProperty xproperty in xcomponent.Properties)
                {
                    FAopProperty property = descriptor.Properties[xproperty.Name];
                    if (property == null)
                    {
                        throw new FFatalException("Config has property. but instance has'nt this property({0}).", xproperty.Name);
                    }
                    if (_logger.DebugAble)
                    {
                        _logger.Debug(this, "LinkProperties", "Set property {0} = {1}", xproperty.Name, xproperty.Value);
                    }
                    object fieldValue = Convert.ChangeType(xproperty.Value, property.FieldType);
                    property.Field.SetValue(builder.Instance, fieldValue);
                }
            }
        }
Пример #7
0
 public FAopComponentBuilder(XAopComponent xcomponent)
 {
     _xcomponent = xcomponent;
 }