/**********************************************************************************/
        /// <summary>
        /// Convert DTO to Crate instance
        /// </summary>
        /// <param name="proxy"></param>
        /// <returns></returns>
        public Crate ConvertFromDto(CrateDTO proxy)
        {
            if (proxy == null)
            {
                return(null);
            }

            var manifestType = new CrateManifestType(proxy.ManifestType, proxy.ManifestId);
            IManifestSerializer serializer = GetSerializer(manifestType);
            Crate crate;

            if (serializer != null)
            {
                var content = proxy.Contents != null?serializer.Deserialize(proxy.Contents) : null;

                if (content != null)
                {
                    crate = Crate.FromContent(content, proxy.Id);
                }
                else
                {
                    crate = new Crate(manifestType, proxy.Id);
                }
            }
            else
            {
                crate = Crate.FromJson(manifestType, proxy.Id, proxy.Contents);
            }

            crate.Label            = proxy.Label;
            crate.SourceActivityId = proxy.SourceActivityId;
            return(crate);
        }
示例#2
0
        /**********************************************************************************/

        public static Crate <T> Add <T>(this ICrateStorage storage, string label, T content)
        {
            var crate = Crate.FromContent(label, content);

            storage.Add(crate);

            return(crate);
        }
示例#3
0
 /**********************************************************************************/
 /// <summary>
 /// Create new create from content. Manifest type is deduced from the content. This method guaranties than manifest type can be correctly deduced
 /// </summary>
 /// <param name="label"></param>
 /// <param name="content"></param>
 /// <returns></returns>
 public static Crate <T> FromContent <T>(string label, T content)
 {
     return(Crate <T> .FromContent(label, content));
 }