Пример #1
0
 private void OnSerializing(StreamingContext context)
 {
     _templateSerializationContainer = new TemplateSerializationContainer()
     {
         Templates = Templates
     };
 }
Пример #2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            TemplateSerializationContainer container = (TemplateSerializationContainer)value;

            List <ContentTemplateSerializationFormat> formats = new List <ContentTemplateSerializationFormat>();

            foreach (ITemplate template in container.Templates)
            {
                ContentTemplate content = template as ContentTemplate ?? new ContentTemplate(template);
                formats.Add(content.GetSerializedFormat());
            }

            serializer.Serialize(writer, formats);
        }
Пример #3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            TemplateSerializationContainer container =
                (TemplateSerializationContainer)existingValue ?? new TemplateSerializationContainer();

            List <ContentTemplateSerializationFormat> serializedTemplates = serializer.Deserialize <List <ContentTemplateSerializationFormat> >(reader);

            // We need to get our conversion context
            GeneralStreamingContext   generalContext    = (GeneralStreamingContext)serializer.Context.Context;
            TemplateConversionContext conversionContext = generalContext.Get <TemplateConversionContext>();
            GameEngineContext         engineContext     = generalContext.Get <GameEngineContext>();

            // TODO: if this method is really slow, then we can combine VerifyReferenceDefinitions
            //       and the
            // actual restoration process

            // Verify that we have restored all of our referenced templates
            VerifyReferenceDefinitions(engineContext, conversionContext, serializedTemplates);

            // Restore our created template instances
            foreach (ContentTemplateSerializationFormat format in serializedTemplates)
            {
                int       templateId = format.TemplateId;
                ITemplate template   = conversionContext.GetTemplateInstance(templateId, engineContext);

                if (template is ContentTemplate)
                {
                    ((ContentTemplate)template).Initialize(format);
                }
                else
                {
                    ((RuntimeTemplate)template).Initialize(format);
                }
            }

            container.Templates = conversionContext.CreatedTemplates.Select(p => p.Value).ToList();
            return(container);
        }
Пример #4
0
 private void OnDeserialized(StreamingContext context) {
     Templates = _templateSerializationContainer.Templates;
     _templateSerializationContainer = null;
 }
Пример #5
0
 private void OnSerializing(StreamingContext context) {
     _templateSerializationContainer = new TemplateSerializationContainer() {
         Templates = Templates
     };
 }
Пример #6
0
 private void OnDeserialized(StreamingContext context)
 {
     Templates = _templateSerializationContainer.Templates;
     _templateSerializationContainer = null;
 }