Пример #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;
		}
Пример #2
0
		public object ReadData(AMFReader reader)
		{
			int handle = reader.ReadAMF3IntegerData();
			bool inline = ((handle & 1) != 0 ); handle = handle >> 1;
			if (!inline)
			{
				//An object reference
				return reader.ReadAMF3ObjectReference(handle);
			}
			else
			{
				ClassDefinition classDefinition = reader.ReadClassDefinition(handle);
				object instance = null;
                IReflectionOptimizer reflectionOptimizer = _optimizedReaders[classDefinition.ClassName] as IReflectionOptimizer;
				if (reflectionOptimizer == null)
				{
					lock (_optimizedReaders)
					{
						if (classDefinition.IsTypedObject)
						{
							if (!_optimizedReaders.Contains(classDefinition.ClassName))
							{
								//Temporary reader
                                _optimizedReaders[classDefinition.ClassName] = new AMF3TempObjectReader();
								Type type = ObjectFactory.Locate(classDefinition.ClassName);
								if (type != null)
								{
									instance = ObjectFactory.CreateInstance(type);
                                    if (classDefinition.IsExternalizable)
                                    {
                                        reflectionOptimizer = new AMF3ExternalizableReader();
                                        _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                                        instance = reflectionOptimizer.ReadData(reader, classDefinition);
                                    }
                                    else
                                    {
                                        reader.AddAMF3ObjectReference(instance);

                                        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, classDefinition, reader, instance);
                                        //Fixup
                                        if (reflectionOptimizer != null)
                                            _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                                        else
                                            _optimizedReaders[classDefinition.ClassName] = new AMF3TempObjectReader();
                                    }
								}
								else
								{
                                    reflectionOptimizer = new AMF3TypedASObjectReader(classDefinition.ClassName);
                                    _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                                    instance = reflectionOptimizer.ReadData(reader, classDefinition);
								}
							}
							else
							{
                                reflectionOptimizer = _optimizedReaders[classDefinition.ClassName] as IReflectionOptimizer;
								instance = reflectionOptimizer.ReadData(reader, classDefinition);
							}
						}
						else
						{
                            reflectionOptimizer = new AMF3TypedASObjectReader(classDefinition.ClassName);
                            _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                            instance = reflectionOptimizer.ReadData(reader, classDefinition);
						}
					}
				}
				else
				{
					instance = reflectionOptimizer.ReadData(reader, classDefinition);
				}
				return instance;
			}
		}
        public object ReadData(AMFReader reader)
        {
            int  handle = reader.ReadAMF3IntegerData();
            bool inline = ((handle & 1) != 0); handle = handle >> 1;

            if (!inline)
            {
                //An object reference
                return(reader.ReadAMF3ObjectReference(handle));
            }
            else
            {
                ClassDefinition      classDefinition     = reader.ReadClassDefinition(handle);
                object               instance            = null;
                IReflectionOptimizer reflectionOptimizer = _optimizedReaders[classDefinition.ClassName] as IReflectionOptimizer;
                if (reflectionOptimizer == null)
                {
                    lock (_optimizedReaders)
                    {
                        if (classDefinition.IsTypedObject)
                        {
                            if (!_optimizedReaders.Contains(classDefinition.ClassName))
                            {
                                //Temporary reader
                                _optimizedReaders[classDefinition.ClassName] = new AMF3TempObjectReader();
                                Type type = ObjectFactory.Locate(classDefinition.ClassName);
                                if (type != null)
                                {
                                    instance = ObjectFactory.CreateInstance(type);
                                    if (classDefinition.IsExternalizable)
                                    {
                                        reflectionOptimizer = new AMF3ExternalizableReader();
                                        _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                                        instance = reflectionOptimizer.ReadData(reader, classDefinition);
                                    }
                                    else
                                    {
                                        reader.AddAMF3ObjectReference(instance);

                                        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, classDefinition, reader, instance);
                                        //Fixup
                                        if (reflectionOptimizer != null)
                                        {
                                            _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                                        }
                                        else
                                        {
                                            _optimizedReaders[classDefinition.ClassName] = new AMF3TempObjectReader();
                                        }
                                    }
                                }
                                else
                                {
                                    reflectionOptimizer = new AMF3TypedASObjectReader(classDefinition.ClassName);
                                    _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                                    instance = reflectionOptimizer.ReadData(reader, classDefinition);
                                }
                            }
                            else
                            {
                                reflectionOptimizer = _optimizedReaders[classDefinition.ClassName] as IReflectionOptimizer;
                                instance            = reflectionOptimizer.ReadData(reader, classDefinition);
                            }
                        }
                        else
                        {
                            reflectionOptimizer = new AMF3TypedASObjectReader(classDefinition.ClassName);
                            _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                            instance = reflectionOptimizer.ReadData(reader, classDefinition);
                        }
                    }
                }
                else
                {
                    instance = reflectionOptimizer.ReadData(reader, classDefinition);
                }
                return(instance);
            }
        }
Пример #4
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);
        }