예제 #1
0
        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (_org == null)
            {
                return;
            }
            info.AddValue("OrganismType", _org.GetType().AssemblyQualifiedName);

            var m = new MemoryStream();

            (_org).InternalOrganismSerialize(m);
            info.AddValue("OrganismInfo", m.ToArray());

            // Let the animal contribute to serialization.  We don't use BinarySerialization
            // here because we don't want animals to be able to put bogus items in their
            // serialization stream that we will deserialize on their behalf later and
            // cause security problems.
            if (_org is Animal)
            {
                m = new MemoryStream();
                ((Animal)_org).InternalAnimalSerialize(m);
                info.AddValue("AnimalInfo", m.ToArray());

                m = new MemoryStream();

                try
                {
                    ((Animal)_org).SerializeAnimal(m);
                }
                catch (Exception e)
                {
                    ErrorLog.LogHandledException(e);
                    if (GameEngine.Current != null)
                    {
                        GameEngine.Current.OnEngineStateChanged(
                            new EngineStateChangedEventArgs(EngineStateChangeType.Other,
                                                            "Animal Serialization Failure.",
                                                            _org.GetType().Assembly.GetName().Name +
                                                            "was frost bitten while being Cryogenically Frozen (aka Serialized)."));
                    }
                    m = new MemoryStream();
                }
                info.AddValue("UserInfo", m.ToArray());
            }
            else
            {
                m = new MemoryStream();
                ((Plant)_org).InternalPlantSerialize(m);
                info.AddValue("PlantInfo", m.ToArray());

                m = new MemoryStream();
                try
                {
                    ((Plant)_org).SerializePlant(m);
                }
                catch (Exception e)
                {
                    ErrorLog.LogHandledException(e);
                    if (GameEngine.Current != null)
                    {
                        GameEngine.Current.OnEngineStateChanged(
                            new EngineStateChangedEventArgs(EngineStateChangeType.Other,
                                                            "Plant Serialization Failure.",
                                                            _org.GetType().Assembly.GetName().Name +
                                                            "was frost bitten while being Cryogenically Frozen (aka Serialized)."));
                    }
                    m = new MemoryStream();
                }

                info.AddValue("UserInfo", m.ToArray());
            }
        }