Ejemplo n.º 1
0
        /// <summary>
        /// Возвращает интерфейс для взаимодействия с API ВКонтакте.
        /// </summary>
        /// <returns>Интерфейс для взаимодействия с ВКонтакте.</returns>
        public static IVkApi Get(InstanceMode mode = InstanceMode.Same)
        {
            switch (mode)
            {
            case InstanceMode.New:
            {
                if (_lazy.IsValueCreated)
                {
                    _lazy = CreateNewLazy();
                }

                return(_lazy.Value);
            }

            case InstanceMode.Same:
            {
                return(_lazy.Value);
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(mode));
            }
            }
        }
Ejemplo n.º 2
0
        public DuplexConnectionBuilder(InstanceMode instanceMode)
            : base()
        {
            TypeDescription <TCallback> .ValidateAsCallbackObject();

            _instanceMode = instanceMode;
        }
Ejemplo n.º 3
0
 public InstanceContextFactory(InstanceMode instanceMode, IMessageBuilder msgBuilder, ILoggerFactory loggerFactory)
 {
     _instanceMode  = instanceMode;
     _msgBuilder    = msgBuilder;
     _loggerFactory = loggerFactory;
     _logger        = _loggerFactory.CreateLogger("InstanceContextFactory");
 }
        public InstanceSelector(GameObject target, string initClassName)
        {
            mode         = InstanceMode.FindOnObject;
            targetObject = target;
            targetClass  = initClassName;

            Save();
        }
Ejemplo n.º 5
0
 internal ServiceHost(IList <IListener> listeners, InstanceMode instanceMode, ISerializer serializer,
                      Type callbackType, ILoggerFactory loggerFactory)
     : this(listeners, serializer, callbackType, loggerFactory)
 {
     _instanceContextFactory = new InstanceContextFactory <TService>(instanceMode, _msgBuilder, loggerFactory);
     _instanceContextFactory.InstanceCreated        += OnInstanceFactoryInstanceCreate;
     _instanceContextFactory.SessionInstanceRemoved += OnInstanceFactorySessionInstanceRemoved;
 }
    protected virtual void Reset
        (MonoBehaviour accessTarget, string accessMember, string initClassName)
    {
        mode = InstanceMode.FindOnObject;
        targetObjectAccesor = new PropertyAccessor(accessTarget, accessMember);
        targetClass         = initClassName;

        Save();
    }
 public ComponentRegistration WithInstanceMode(InstanceMode instanceMode)
 {
     if (componentRegistration == null)
     {
         throw new ContainerConfigurationException("Configuration error WithInstanceMode<> MUST be last");
     }
     componentRegistration.InstanceMode = instanceMode;
     return(componentRegistration);
 }
Ejemplo n.º 8
0
 private static double StartMeter(InstanceMode mode)
 {
     if (mode.IsOneCard())
     {
         return(0);
     }
     else
     {
         return(0.7);
     }
 }
        /// <summary>
        /// 根据应用的类型过滤实例的配置
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public IEnumerable<MetaConfigurationSourceInstanceElement> FilterByInstanceMode(InstanceMode mode)
        {
            List<MetaConfigurationSourceInstanceElement> result = new List<MetaConfigurationSourceInstanceElement>();

            foreach (MetaConfigurationSourceInstanceElement inst in this)
            {
                if (inst.GetMode() == mode)
                    result.Add(inst);
            }

            return result;
        }
Ejemplo n.º 10
0
        protected override void CreateChildControls()
        {
            if (String.IsNullOrEmpty(Code))
            {
                return;
            }

            if (String.IsNullOrEmpty(Code.Trim()))
            {
                return;
            }

            BaristaHelper.EnsureExecutionInTrustedLocation();

            string codePath;
            var    codeToExecute = Tamp(Code, out codePath);

            var client = new BaristaServiceClient(SPServiceContext.Current);

            var request = BrewRequest.CreateServiceApplicationRequestFromHttpRequest(HttpContext.Current.Request);

            request.ScriptEngineFactory = "Barista.SharePoint.SPBaristaJurassicScriptEngineFactory, Barista.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a2d8064cb9226f52";
            request.Code     = codeToExecute;
            request.CodePath = codePath;

            var headers = new Dictionary <string, IEnumerable <string> >
            {
                { "barista_instancemode", new[] { InstanceMode.ToString() } },
                { "barista_instancename", new[] { InstanceName } },
                { "barista_instanceabsoluteexpiration", new[] { InstanceAbsoluteExpiration.ToString() } },
                { "barista_instanceslidingexpiration", new[] { InstanceSlidingExpiration.ToString() } }
            };

            if (String.IsNullOrEmpty(InstanceInitializationCode) == false)
            {
                string filePath;
                request.InstanceInitializationCode     = Tamp(InstanceInitializationCode, out filePath);
                request.InstanceInitializationCodePath = filePath;
            }
            request.Headers = new BrewRequestHeaders(headers);
            request.SetExtendedPropertiesFromCurrentSPContext();

            var result     = client.Eval(request);
            var resultText = System.Text.Encoding.UTF8.GetString(result.Content);

            //TODO: Based on the content type of the result, emit the contents differently.
            var cntrl = new LiteralControl(resultText);

            Controls.Add(cntrl);
        }
        public object Invoke(IContainer owner, Type requestedType, InstanceMode instanceMode)
        {
            ArrayList arr = new ArrayList();
            foreach (IListItemConfiguration itemConfig in ListItemConfigurations)
            {
                if (itemConfig.Type == null)
                    itemConfig.Type = typeof (string);

                object value = itemConfig.GetValue(owner);
                arr.Add(value);
            }

            return arr;
        }
Ejemplo n.º 12
0
 private static int StartBombs(InstanceMode mode)
 {
     if (mode == InstanceMode.CAMPAIGN || mode == InstanceMode.TUTORIAL || mode == InstanceMode.STAGE_PRACTICE)
     {
         return(2);
     }
     else if (mode.OneLife())
     {
         return(0);
     }
     else
     {
         return(3);
     }
 }
Ejemplo n.º 13
0
 private static double StartPower(InstanceMode mode, ShotConfig?shot)
 {
     if (mode.OneLife() || !PowerMechanicEnabled)
     {
         return(powerMax);
     }
     else if (shot != null)
     {
         return(M.Clamp(powerMin, powerMax, shot.defaultPower));
     }
     else
     {
         return(M.Clamp(powerMin, powerMax, powerDefault));
     }
 }
Ejemplo n.º 14
0
        internal ServiceHost(IList <IListener> listeners, InstanceMode instanceMode, ISerializer serializer,
                             Type callbackType, ILoggerFactory loggerFactory)
        {
            TypeDescription <TService> .ValidateAsService(callbackType);

            _listeners    = new ReadOnlyCollection <IListener>(listeners);
            _serializer   = serializer;
            _msgBuilder   = new MessageBuilder(_serializer);
            _callbackType = callbackType;
            _logger       = loggerFactory.CreateLogger("ServiceHost");

            _instanceContextFactory = new InstanceContextFactory <TService>(instanceMode, _msgBuilder, loggerFactory);
            _instanceContextFactory.InstanceCreated        += OnInstanceFactoryInstanceCreate;
            _instanceContextFactory.SessionInstanceRemoved += OnInstanceFactorySessionInstanceRemoved;
        }
        public object Invoke(IContainer owner, Type requestedType, InstanceMode instanceMode)
        {
            if (TypeConverter != null && value is string)
            {
                string typeString = (string) this.Value;
                return TypeConverter.ConvertFromString(typeString);
            }

            if (requestedType.IsEnum && Value is string)
            {
                return Enum.Parse(requestedType, Value.ToString());
            }
            else
            {
                return Convert.ChangeType(Value, requestedType);
            }
        }
        public object Invoke(IContainer owner, Type requestedType, InstanceMode instanceMode)
        {
            ArrayList arr = new ArrayList();

            foreach (IListItemConfiguration itemConfig in ListItemConfigurations)
            {
                if (itemConfig.Type == null)
                {
                    itemConfig.Type = typeof(string);
                }

                object value = itemConfig.GetValue(owner);
                arr.Add(value);
            }

            return(arr);
        }
Ejemplo n.º 17
0
        public object Invoke(IContainer owner, Type requestedType, InstanceMode instanceMode)
        {
            if (TypeConverter != null && value is string)
            {
                string typeString = (string)this.Value;
                return(TypeConverter.ConvertFromString(typeString));
            }

            if (requestedType.IsEnum && Value is string)
            {
                return(Enum.Parse(requestedType, Value.ToString()));
            }
            else
            {
                return(Convert.ChangeType(Value, requestedType));
            }
        }
        public object Invoke(IContainer owner, Type requestedType, InstanceMode instanceMode)
        {
            object[] parameters = new object[ParameterConfigurations.Count];
            ParameterInfo[] parameterInfos = method.GetParameters();
            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterConfiguration paramConfig = (ParameterConfiguration) ParameterConfigurations[i];
                paramConfig.Type = parameterInfos[i].ParameterType;
                parameters[i] = paramConfig.GetValue(owner);
            }

            object target = null;
            if (Object != null)
                target = owner.GetObject(Object.Name);

            object res = method.Invoke(target, parameters);

            return res;
        }
Ejemplo n.º 19
0
 private static int StartLives(InstanceMode mode)
 {
     if (mode == InstanceMode.CAMPAIGN || mode == InstanceMode.TUTORIAL || mode == InstanceMode.STAGE_PRACTICE)
     {
         return(7);
     }
     else if (mode.OneLife())
     {
         return(1);
     }
     else if (mode == InstanceMode.NULL)
     {
         return(14);
     }
     else
     {
         return(1);
     }
 }
Ejemplo n.º 20
0
        private void CreateFactory(ComponentRegistration key, Delegate @delegate, InstanceMode instanceMode)
        {
            IFactoryProvider factoryProvider = null;

            if (instanceMode == InstanceMode.Transient)
            {
                factoryProvider = new TransientFactory(@delegate);
            }

            if (instanceMode == InstanceMode.Singleton)
            {
                factoryProvider = new SingletonFactory(@delegate);
            }

            lock (syncLock)
            {
                components[key] = factoryProvider;
            }
        }
Ejemplo n.º 21
0
        public object Invoke(IContainer owner, Type requestedType, InstanceMode instanceMode)
        {
            object[]        parameters     = new object[ParameterConfigurations.Count];
            ParameterInfo[] parameterInfos = method.GetParameters();
            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterConfiguration paramConfig = (ParameterConfiguration)ParameterConfigurations[i];
                paramConfig.Type = parameterInfos[i].ParameterType;
                parameters[i]    = paramConfig.GetValue(owner);
            }


            object target = null;

            if (Object != null)
            {
                target = owner.GetObject(Object.Name);
            }

            object res = method.Invoke(target, parameters);

            return(res);
        }
 public FactoryMethodAttribute(string factoryId, InstanceMode instanceMode)
 {
     FactoryId = factoryId;
     InstanceMode = instanceMode;
 }
 public FactoryMethodAttribute(FactoryType registerAs,InstanceMode instanceMode)
 {
     RegisterAs = registerAs;
     InstanceMode = instanceMode;
 }
Ejemplo n.º 24
0
        /// <summary>
        /// 依照路径类型(文件/目录)和格式筛选路径
        /// </summary>
        /// <param name="instances">MetaConfigurationSourceInstanceElementCollection</param>
        /// <param name="isDirectory">是否目录</param>
        /// <returns>KeyValuePair 中 Value 为 meta.config 文件, key 为application 路径</returns>
        protected IList <KeyValuePair <string, string> > FileterPath(MetaConfigurationSourceInstanceElementCollection instances, bool isDirectory)
        {
            if ((instances == null) || (instances.Count <= 0))
            {
                return(null);
            }

            IList <KeyValuePair <string, string> > result = new List <KeyValuePair <string, string> >();
            InstanceMode mode = EnvironmentHelper.Mode;

            Uri pathAbsolute = null;

            foreach (MetaConfigurationSourceInstanceElement instance in instances)
            {
                if ((instance == null) || (instance.Mappings == null) ||
                    (instance.Mappings.Count <= 0) || (instance.GetMode() != mode))
                {
                    continue;
                }

                string metaConfig = FormatPath(instance.Path);

                foreach (MetaConfigurationSourceMappingElement mapping in instance.Mappings)
                {
                    string applicationPath = mapping.Application;
                    if (false == (isDirectory ^ IsDirectory(applicationPath)))
                    {
                        if (mode == InstanceMode.Web)
                        {
                            //当web访问时,将路径都转化为通过相对路径进行匹配
                            if (pathAbsolute == null)
                            {
                                pathAbsolute = new Uri(path, UriKind.Absolute);
                            }

                            Uri appAbsolute = new Uri(applicationPath, UriKind.RelativeOrAbsolute);

                            if (appAbsolute.IsAbsoluteUri)
                            {
                                if (pathAbsolute.Scheme == appAbsolute.Scheme &&
                                    pathAbsolute.Port == appAbsolute.Port &&
                                    pathAbsolute.UserInfo == appAbsolute.UserInfo &&
                                    pathAbsolute.Host == appAbsolute.Host &&
                                    pathAbsolute.HostNameType == appAbsolute.HostNameType)
                                {
                                    applicationPath = appAbsolute.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
                                }
                            }

                            applicationPath = FormatPath(applicationPath);
                        }
                        else
                        {
                            applicationPath = FormatPath(Path.GetFullPath(applicationPath));
                        }

                        KeyValuePair <string, string> item = new KeyValuePair <string, string>(applicationPath, metaConfig);
                        result.Add(item);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 25
0
 public RegistAttribute(InstanceMode mode) {
     this.Mode = mode;
 }
Ejemplo n.º 26
0
 /// <summary>
 /// 注册类型
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="createInstance">创建实例的方法的委托</param>
 /// <param name="mode">创建方式</param>
 public static void RegisterType <T>(Func <T> createInstance, InstanceMode mode = InstanceMode.InstanceSingleton)
 {
     ObjectFactory <T> .CreateInstance = createInstance;
     ObjectFactory <T> .InstanceMode   = mode;
 }
Ejemplo n.º 27
0
        /// <summary>
        /// 根据应用的类型过滤实例的配置
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public IEnumerable <MetaConfigurationSourceInstanceElement> FilterByInstanceMode(InstanceMode mode)
        {
            List <MetaConfigurationSourceInstanceElement> result = new List <MetaConfigurationSourceInstanceElement>();

            foreach (MetaConfigurationSourceInstanceElement inst in this)
            {
                if (inst.GetMode() == mode)
                {
                    result.Add(inst);
                }
            }

            return(result);
        }
Ejemplo n.º 28
0
        public object GetObjectInternal(string name, InstanceMode instanceMode, IContainer rootContainer)
        {
            lock (syncRoot)
            {
                IObjectConfiguration objectConfig = Configuration.GetObjectConfiguration(name);

                if (rootContainer != null)
                {
                    IObjectConfiguration overrideConfig = rootContainer.GetConfiguration(name);

                    if (overrideConfig == objectConfig || overrideConfig == null)
                    {
                        //not overridden
                    }
                    else
                    {
                        objectConfig = overrideConfig;
                    }
                }



                if (objectConfig == null)
                {
                    if (ParentContainer == null)
                    {
                        throw new Exception(string.Format("Object not found '{0}'", name));
                    }
                    else
                    {
                        return(ParentContainer.GetObjectInternal(name, instanceMode, rootContainer));
                    }
                }

                if (instanceMode == InstanceMode.Default)
                {
                    instanceMode = objectConfig.InstanceMode;
                }

                if (instanceMode == InstanceMode.Default)
                {
                    instanceMode = InstanceMode.PerContainer;
                }

                //fetch object from container cache
                if (instanceMode == InstanceMode.PerContainer)
                {
                    //only fetch from cache if we dont need a new instance
                    if (containerObjects[name] != null)
                    {
                        return(containerObjects[name]);
                    }
                }

                //fetch object from graph cache
                if (instanceMode == InstanceMode.PerGraph)
                {
                    //only fetch from cache if we dont need a new instance
                    if (graphObjects[name] != null)
                    {
                        return(graphObjects[name]);
                    }
                }

                object instance = CreateInstance(objectConfig);

                //store instance in container cache
                if (instanceMode == InstanceMode.PerContainer)
                {
                    containerObjects[objectConfig.Name] = instance;
                }

                //store instance in graph cache
                if (instanceMode == InstanceMode.PerGraph)
                {
                    graphObjects[objectConfig.Name] = instance;
                }

                ConfigureObject(objectConfig, instance);

                return(instance);
            }
        }
 public object Invoke(IContainer owner, Type requestedType, InstanceMode instanceMode)
 {
     return owner.GetObjectInternal(this.Name, instanceMode,null);
 }
Ejemplo n.º 30
0
        /// <summary>
        /// 依照路径类型(文件/目录)和格式筛选路径
        /// </summary>
        /// <param name="instances">MetaConfigurationSourceInstanceElementCollection</param>
        /// <param name="isDirectory">是否目录</param>
        /// <returns>KeyValuePair 中 Value 为 meta.config 文件, key 为application 路径</returns>
        protected IList <KeyValuePair <string, string> > FileterPath(MetaConfigurationSourceInstanceElementCollection instances, bool isDirectory)
        {
            if ((instances == null) || (instances.Count <= 0))
            {
                return(null);
            }

            IList <KeyValuePair <string, string> > result = new List <KeyValuePair <string, string> >();

            InstanceMode mode = EnvironmentHelper.IsUsingWebConfig ? InstanceMode.Web : InstanceMode.Windows;

            IEnumerable <MetaConfigurationSourceInstanceElement> matchedInstances = GetMatchedInstances(instances, mode);

            foreach (MetaConfigurationSourceInstanceElement instance in matchedInstances)
            {
                if (instance.Mappings == null || (instance.Mappings.Count == 0))
                {
                    continue;
                }

                string metaConfig = FormatPath(instance.Path);

                foreach (MetaConfigurationSourceMappingElement mapping in instance.Mappings)
                {
                    string applicationPath = mapping.Application;

                    if (false == (isDirectory ^ IsDirectory(applicationPath)))
                    {
                        if (EnvironmentHelper.IsUsingWebConfig)
                        {
                            ////当web访问时,将路径都转化为通过相对路径进行匹配
                            //if (pathAbsolute == null)
                            //    pathAbsolute = new Uri(path, UriKind.Relative);

                            //Uri appAbsolute = new Uri(applicationPath, UriKind.RelativeOrAbsolute);

                            //if (appAbsolute.IsAbsoluteUri)
                            //{
                            //    if (pathAbsolute.Scheme == appAbsolute.Scheme &&
                            //        pathAbsolute.Port == appAbsolute.Port &&
                            //        pathAbsolute.UserInfo == appAbsolute.UserInfo &&
                            //        pathAbsolute.Host == appAbsolute.Host &&
                            //        pathAbsolute.HostNameType == appAbsolute.HostNameType)
                            //    {
                            //        applicationPath = appAbsolute.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
                            //    }
                            //}

                            applicationPath = FormatPath(applicationPath);
                        }
                        else
                        {
                            applicationPath = FormatPath(Path.GetFullPath(applicationPath));
                        }

                        KeyValuePair <string, string> item = new KeyValuePair <string, string>(applicationPath, metaConfig);
                        result.Add(item);
                    }
                }
            }

            return(result);
        }
        private void ConfigureElement(XmlNode node, ElementConfiguration config, IContainer container, Type valueType)
        {
            config.Type = valueType;

            if (node.Attributes["value"] != null)
            {
                string propertyValueString = node.Attributes["value"].Value;

                ValueConfiguration propertyValueConfig = new ValueConfiguration();
                propertyValueConfig.Value = propertyValueString;
                config.Value = propertyValueConfig;

                if (node.Attributes["type-converter"] != null)
                {
                    string typeConverterString = node.Attributes["type-converter"].Value;
                    Type   typeConverterType   = ResolveType(typeConverterString);

                    TypeConverter typeConverter = (TypeConverter)Activator.CreateInstance(typeConverterType);
                    propertyValueConfig.TypeConverter = typeConverter;
                }

                if (node.Attributes["type"] != null)
                {
                    string typeString = node.Attributes["type"].Value;
                    Type   type       = ResolveType(typeString);

                    config.Type = type;
                }
            }

            if (node.Attributes["object"] != null)
            {
                string propertyObjectName = node.Attributes["object"].Value;
                IObjectConfiguration propertyObjectConfig = GetObjectConfiguration(propertyObjectName, container);

                config.Value = propertyObjectConfig;

                //done
                if (node.Attributes["instance-mode"] != null)
                {
                    string instanceModeString = node.Attributes["instance-mode"].Value;
                    config.InstanceMode = (InstanceMode)InstanceMode.Parse(typeof(InstanceMode), instanceModeString);
                }
            }

            if (node.Attributes["list"] != null)
            {
                string             propertyListName   = node.Attributes["list"].Value;
                IListConfiguration propertyListConfig = GetListConfiguration(propertyListName, container);

                config.Value = propertyListConfig;
                config.Type  = typeof(IList);
            }

            if (node.Attributes["factory"] != null)
            {
                string itemFactoryName = node.Attributes["factory"].Value;
                IFactoryConfiguration propertyFactoryConfig = GetFactoryConfiguration(itemFactoryName, container);

                config.Value = propertyFactoryConfig;
            }
        }
 public FactoryMethodAttribute(InstanceMode instanceMode)
 {
     InstanceMode = instanceMode;
 }
Ejemplo n.º 33
0
        private static IEnumerable <MetaConfigurationSourceInstanceElement> GetMatchedInstances(MetaConfigurationSourceInstanceElementCollection instances, InstanceMode mode)
        {
            List <MetaConfigurationSourceInstanceElement> modeMatched = new List <MetaConfigurationSourceInstanceElement>(instances.FilterByInstanceMode(mode));

            List <MetaConfigurationSourceInstanceElement> result = null;

            if (mode == InstanceMode.Web)
            {
                //匹配站点名称
                List <MetaConfigurationSourceInstanceElement> matchedItems = modeMatched.FindAll(i => string.Compare(i.Name, HostingEnvironment.SiteName, true) == 0);

                if (matchedItems.Count == 0)
                {
                    //如果站点名称没有匹配到,则添加默认项
                    if (modeMatched.Count > 0)
                    {
                        matchedItems.Add(modeMatched[0]);
                    }
                }

                result = new List <MetaConfigurationSourceInstanceElement>(matchedItems);
            }
            else
            {
                result = modeMatched;
            }

            return(result);
        }
Ejemplo n.º 34
0
        private ObjectFactoryInfo CreateObjectFactory(string displayName, FactoryDelegate factoryDelegate, InstanceMode instanceMode)
        {
            ObjectFactoryInfo factory = new ObjectFactoryInfo();

            factory.FactoryDelegate = factoryDelegate;
            factory.InstanceMode    = instanceMode;
            factory.DisplayName     = displayName;
            return(factory);
        }
        private IFactoryConfiguration ConfigureFactory(XmlNode configNode, IContainer container)
        {
            string factoryName                  = configNode.Attributes["name"].Value;
            string factoryMethodName            = configNode.Attributes["method"].Value;
            IFactoryConfiguration factoryConfig = GetFactoryConfiguration(factoryName, container);

            factoryConfig.Name       = factoryName;
            factoryConfig.MethodName = factoryMethodName;


            if (configNode.Attributes["type"] != null)             //
            {
                string objectTypeString = configNode.Attributes["type"].Value;
                Type   objectType       = ResolveType(objectTypeString);

                factoryConfig.Type = objectType;
            }
            else if (configNode.Attributes["object"] != null)             //instance
            {
                string objectName = configNode.Attributes["object"].Value;
                IObjectConfiguration objectConfig = GetObjectConfiguration(objectName, container);
                factoryConfig.Object = objectConfig;
            }

            foreach (XmlNode factoryNode in configNode)
            {
                #region Parameter

                if (factoryNode.Name == "parameter")
                {
                    ParameterConfiguration parameterConfig = new ParameterConfiguration();
                    parameterConfig.Index = Convert.ToInt32(factoryNode.Attributes["index"].Value);


                    if (factoryNode.Attributes["value"] != null)
                    {
                        string             propertyValueString = factoryNode.Attributes["value"].Value;
                        ValueConfiguration propertyValueConfig = new ValueConfiguration();
                        if (factoryNode.Attributes["type"] != null)
                        {
                            //typed parameter
                            string parameterTypeString = factoryNode.Attributes["type"].Value;
                            Type   parameterType       = ResolveType(parameterTypeString);
                            parameterConfig.Type      = parameterType;
                            propertyValueConfig.Value = Convert.ChangeType(propertyValueString, parameterConfig.Type);
                        }
                        else
                        {
                            //untyped parameter
                            propertyValueConfig.Value = propertyValueString;
                            //		parameterConfig.UntypedStringValue = propertyValueString;
                            parameterConfig.Type = null;
                        }

                        parameterConfig.Value = propertyValueConfig;
                    }

                    if (factoryNode.Attributes["object"] != null)
                    {
                        string parameterObjectName = factoryNode.Attributes["object"].Value;
                        IObjectConfiguration propertyObjectConfig = GetObjectConfiguration(parameterObjectName, container);

                        parameterConfig.Value = propertyObjectConfig;

                        //done
                        if (factoryNode.Attributes["instance-mode"] != null)
                        {
                            string instanceModeString = factoryNode.Attributes["instance-mode"].Value;
                            parameterConfig.InstanceMode = (InstanceMode)InstanceMode.Parse(typeof(InstanceMode), instanceModeString);
                        }
                    }

                    factoryConfig.ParameterConfigurations.Add(parameterConfig);
                }

                #endregion
            }

            return(factoryConfig);
        }
 public InstanceSelector()
 {
     mode = InstanceMode.Specify;
 }
Ejemplo n.º 37
0
 public ServiceHostBuilder(InstanceMode instanceMode)
 {
     InstanceMode = instanceMode;
 }
        private IObjectConfiguration ConfigureObject(XmlNode configNode, IContainer container)
        {
            string objectName = configNode.Attributes["name"].Value;
            IObjectConfiguration objectConfig = GetObjectConfiguration(objectName, container);

            objectConfig.Name = objectName;


            if (configNode.Attributes["aop-config"] != null)
            {
                string  sectionName = configNode.Attributes["aop-config"].Value;
                IEngine engine      = NAspect.Framework.ApplicationContext.ConfigureFromSection(sectionName);
                objectConfig.AopEngine = engine;
            }

            if (configNode.Attributes["type"] != null)
            {
                string objectTypeString = configNode.Attributes["type"].Value;
                Type   objectType       = ResolveType(objectTypeString);
                objectConfig.Type = objectType;
            }

            if (configNode.Attributes["factory"] != null)
            {
                string factoryName = configNode.Attributes["factory"].Value;
                IFactoryConfiguration factoryConfig = GetFactoryConfiguration(factoryName, container);
                objectConfig.InstanceValue = factoryConfig;
            }


            //done
            if (configNode.Attributes["instance-mode"] != null)
            {
                string instanceModeString = configNode.Attributes["instance-mode"].Value;
                objectConfig.InstanceMode = (InstanceMode)InstanceMode.Parse(typeof(InstanceMode), instanceModeString);
            }

            container.Configuration.AddObjectConfiguration(objectConfig);

            foreach (XmlNode objectNode in configNode)
            {
                #region property

                if (objectNode.Name == "property")
                {
                    PropertyConfiguration propertyConfig = new PropertyConfiguration();
                    propertyConfig.Name = objectNode.Attributes["name"].Value;
                    ConfigureElement(objectNode, propertyConfig, container, null);
                    if (objectNode.Attributes["action"] != null)
                    {
                        string action = objectNode.Attributes["action"].Value;
                        if (action == "Add")
                        {
                            propertyConfig.ListAction = ListAction.Add;
                        }

                        if (action == "Replace")
                        {
                            propertyConfig.ListAction = ListAction.Replace;
                        }
                    }

                    objectConfig.PropertyConfigurations.Add(propertyConfig);
                }

                #endregion

                #region Ctor Parameter

                if (objectNode.Name == "ctor-parameter")
                {
                    ParameterConfiguration parameterConfig = new ParameterConfiguration();
                    parameterConfig.Index = Convert.ToInt32(objectNode.Attributes["index"].Value);
                    ConfigureElement(objectNode, parameterConfig, container, null);
                    objectConfig.CtorParameterConfigurations.Add(parameterConfig);
                }

                #endregion
            }
            return(objectConfig);
        }
Ejemplo n.º 39
0
        private void RegisterObjectFactoryMethod(string factoryId, FactoryDelegate factoryDelegate, InstanceMode instanceMode)
        {
            ObjectFactoryInfo factory = CreateObjectFactory(factoryId, factoryDelegate, instanceMode);

            state.NamedObjectFactories.Add(factoryId, factory);
        }