Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Mar 02, 2013 @ 21:14
    Kevin Jump
    0

    Serializing Models with the v6 API

    I've been playing about with the serialization and persistance apis in umbraco 6, looking at ways of serializing the DB elements of an umbraco install out (so i can save it to disk, version control, etc..) (basicallt write a verison my uSync package in for 6 using the new API) 

    Anyway. I'm not sure if i'm doing it right, or indeed if this part of the New API is mature yet (it is obscure i will grant you) - 

    The Following works (well i get serialzed xml in files)

    var xmlSerializer = new ServiceStackXmlSerializer();
    var fileSystem = new PhysicalFileSystem(uSyncRoot); 
    
    Umbraco.Core.Persistence.RepositoryFactory persistanceFactory = new RepositoryFactory();
    var db = new PetaPocoUnitOfWorkProvider(); 
    
    var dataDefTypes = persistanceFactory.CreateDataTypeDefinitionRepository(db.GetUnitOfWork()); 
    foreach (var item in dataDefTypes.GetAll())
    {
        var serializer = new SerializationService(xmlSerializer); 
    
        var result = serializer.ToStream(item);
        fileSystem.AddFile( ScrubFileName(item.Name) + ".usync.xml", result.ResultStream, true) ; 
    }

    but if i try to do the same with a ContentTypeRepository or a MediaTypeRepository i get errors

    Type 'System.Lazy`1+Boxed[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'Lazy.BoxedOfintk9wYX3t0:http://schemas.datacontract.org/2004/07/System' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

    so two questions

    1. is this pattern the right way to serialze the Models in the V6 API 

    2. is this API Complete ? is it going to be completed (i can wait, i just need to know if the intention is that this will be possible in the future) 

Please Sign in or register to post replies

Write your reply to:

Draft