Example #1
0
        public static Either <object> ParseGenericSpecification <TFormat>(this IWireSerialization serializer, Either <Type> domainType, Stream data)
        {
            if (domainType.IsFailure)
            {
                return(domainType.Error);
            }
            var genSer   = serializer.GetSerializer <TFormat>();
            var specType = typeof(GenericSpecification <,>).MakeGenericType(domainType.Result, typeof(TFormat));

            try
            {
                var arg = ParseObject(serializer, typeof(Dictionary <string, List <KeyValuePair <int, TFormat> > >), data, true, null);
                if (arg.IsFailure)
                {
                    return(arg.Error);
                }
                return(Activator.CreateInstance(specType, genSer, arg.Result));
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                var specArg = new Dictionary <string, List <KeyValuePair <int, TFormat> > >();
                specArg["URI"] = new List <KeyValuePair <int, TFormat> >(new[] { new KeyValuePair <int, TFormat>(1, genSer.Serialize("1001")) });
                return(@"Error deserializing specification. " + ex.Message + @"
Example: 
" + serializer.SerializeToString(specArg));
            }
        }
Example #2
0
 public static Either <object> ParseExpressionSpecification(IWireSerialization serializer, Either <Type> domainType, Stream data)
 {
     if (domainType.IsFailure)
     {
         return(domainType.Error);
     }
     try
     {
         var expressionNode = serializer.Deserialize <LambdaExpressionNode>(data, ThreadContext.Request.ContentType);
         return(Activator.CreateInstance(typeof(SpecificationFromNode <>).MakeGenericType(domainType.Result), expressionNode));
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null)
         {
             ex = ex.InnerException;
         }
         return(@"Error deserializing expression. " + ex.Message);
     }
 }
Example #3
0
        public static Either <object> ParseGenericSpecification(this IWireSerialization serialization, Either <Type> target, Stream data)
        {
            if (target.IsFailure)
            {
                return(target.Error);
            }
            switch (GetIncomingFormat())
            {
            case MessageFormat.Json:
                return(ParseGenericSpecification <string>(serialization, target, data));

            case MessageFormat.ProtoBuf:
                return(ParseGenericSpecification <MemoryStream>(serialization, target, data));

            default:
                return(ParseGenericSpecification <XElement>(serialization, target, data));
            }
        }