Exemplo n.º 1
0
        public object ReadData(AMFReader reader)
        {
            object instance       = null;
            string typeIdentifier = reader.ReadString();

#if LOGGING
            if (log.IsDebugEnabled)
            {
                string msg = string.Format("Attempt to read custom object {0}", typeIdentifier);
                log.Debug(msg);
            }
#endif
            IReflectionOptimizer reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer;
            if (reflectionOptimizer == null)
            {
                lock (_optimizedReaders)
                {
                    if (!_optimizedReaders.Contains(typeIdentifier))
                    {
#if LOGGING
                        if (log.IsDebugEnabled)
                        {
                            string msg = string.Format("Generating optimizer for type {0}", typeIdentifier);
                            log.Debug(msg);
                        }
#endif

                        //Temporary reader
                        _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader();
                        Type type = ObjectFactory.Locate(typeIdentifier);
                        if (type != null)
                        {
                            instance = ObjectFactory.CreateInstance(type);
                            reader.AddReference(instance);
                            if (type != null)
                            {
                                IBytecodeProvider bytecodeProvider = null;
#if NET_1_1
                                //codedom only
                                if (FluorineConfiguration.Instance.OptimizerSettings != null)
                                {
                                    bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider();
                                }
#else
                                if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "codedom")
                                {
                                    bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider();
                                }
                                if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "il")
                                {
                                    bytecodeProvider = new FluorineFx.IO.Bytecode.Lightweight.BytecodeProvider();
                                }
#endif

                                reflectionOptimizer = bytecodeProvider.GetReflectionOptimizer(type, null, reader, instance);
                                //Fixup
                                if (reflectionOptimizer != null)
                                {
                                    _optimizedReaders[typeIdentifier] = reflectionOptimizer;
                                }
                                else
                                {
                                    _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader();
                                }
                            }
                        }
                        else
                        {
#if LOGGING
                            if (log.IsWarnEnabled)
                            {
                                log.Warn("Custom object " + typeIdentifier + " could not be loaded. An ActionScript typed object (ASObject) will be created");
                            }
#endif

                            reflectionOptimizer = new AMF0TypedASObjectReader(typeIdentifier);
                            _optimizedReaders[typeIdentifier] = reflectionOptimizer;
                            instance = reflectionOptimizer.ReadData(reader, null);
                        }
                    }
                    else
                    {
                        reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer;
                        instance            = reflectionOptimizer.ReadData(reader, null);
                    }
                }
            }
            else
            {
                instance = reflectionOptimizer.ReadData(reader, null);
            }
            return(instance);
        }
Exemplo n.º 2
0
		public object ReadData(AMFReader reader)
		{
			object instance = null;
			string typeIdentifier = reader.ReadString();
			if(log.IsDebugEnabled )
			{
				string msg = string.Format("Attempt to read custom object {0}", typeIdentifier);
				log.Debug(msg);
			}
            IReflectionOptimizer reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer;
			if( reflectionOptimizer == null )
			{
				lock(_optimizedReaders)
				{
                    if (!_optimizedReaders.Contains(typeIdentifier))
                    {
						if(log.IsDebugEnabled )
						{
							string msg = string.Format("Generating optimizer for type {0}", typeIdentifier);
							log.Debug(msg);
						}

                        //Temporary reader
                        _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader();
                        Type type = ObjectFactory.Locate(typeIdentifier);
						if( type != null )
						{
							instance = ObjectFactory.CreateInstance(type);
							reader.AddReference(instance);
							if (type != null)
							{
								IBytecodeProvider bytecodeProvider = null;
#if NET_1_1
								//codedom only
								if( FluorineConfiguration.Instance.OptimizerSettings != null )
									bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider();
#else
								if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "codedom")
									bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider();
								if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "il")
									bytecodeProvider = new FluorineFx.IO.Bytecode.Lightweight.BytecodeProvider();
#endif

								reflectionOptimizer = bytecodeProvider.GetReflectionOptimizer(type, null, reader, instance);
								//Fixup
								if (reflectionOptimizer != null)
									_optimizedReaders[typeIdentifier] = reflectionOptimizer;
								else
                                    _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader();
							}
						}
						else
						{
							if( log.IsWarnEnabled )
								log.Warn("Custom object " + typeIdentifier + " could not be loaded. An ActionScript typed object (ASObject) will be created");

                            reflectionOptimizer = new AMF0TypedASObjectReader(typeIdentifier);
                            _optimizedReaders[typeIdentifier] = reflectionOptimizer;
                            instance = reflectionOptimizer.ReadData(reader, null);
						}
                    }
                    else
                    {
                        reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer;
                        instance = reflectionOptimizer.ReadData(reader, null);
                    }
				}
			}
			else
			{
				instance = reflectionOptimizer.ReadData(reader, null);
			}
			return instance;
		}
        public object ReadData(AMFReader reader)
        {
            object instance = null;
            string str2;
            string str = reader.ReadString();

            if (log.get_IsDebugEnabled())
            {
                str2 = string.Format("Attempt to read custom object {0}", str);
                log.Debug(str2);
            }
            IReflectionOptimizer optimizer = this._optimizedReaders[str] as IReflectionOptimizer;

            if (optimizer == null)
            {
                lock (this._optimizedReaders)
                {
                    if (!this._optimizedReaders.Contains(str))
                    {
                        if (log.get_IsDebugEnabled())
                        {
                            str2 = string.Format("Generating optimizer for type {0}", str);
                            log.Debug(str2);
                        }
                        this._optimizedReaders[str] = new AMF0TempObjectReader();
                        Type type = ObjectFactory.Locate(str);
                        if (type != null)
                        {
                            instance = ObjectFactory.CreateInstance(type);
                            reader.AddReference(instance);
                            if (type != null)
                            {
                                IBytecodeProvider provider = null;
                                if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "codedom")
                                {
                                    provider = new BytecodeProvider();
                                }
                                if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "il")
                                {
                                    provider = new BytecodeProvider();
                                }
                                optimizer = provider.GetReflectionOptimizer(type, null, reader, instance);
                                if (optimizer != null)
                                {
                                    this._optimizedReaders[str] = optimizer;
                                    return(instance);
                                }
                                this._optimizedReaders[str] = new AMF0TempObjectReader();
                            }
                            return(instance);
                        }
                        if (log.get_IsWarnEnabled())
                        {
                            log.Warn("Custom object " + str + " could not be loaded. An ActionScript typed object (ASObject) will be created");
                        }
                        optimizer = new AMF0TypedASObjectReader(str);
                        this._optimizedReaders[str] = optimizer;
                        return(optimizer.ReadData(reader, null));
                    }
                    optimizer = this._optimizedReaders[str] as IReflectionOptimizer;
                    return(optimizer.ReadData(reader, null));
                }
                return(instance);
            }
            return(optimizer.ReadData(reader, null));
        }