Ejemplo n.º 1
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;
		}
Ejemplo n.º 2
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);
        }