Exemplo n.º 1
0
        private Stream Persist(MethodEnum method, Either <Type> maybeRoot, Stream data)
        {
            if (maybeRoot.IsFailure)
            {
                return(maybeRoot.Error);
            }
            var rootType = maybeRoot.Result;
            var array    = Utility.ParseObject(Serialization, Either <Type> .Succes(rootType.MakeArrayType()), data, false, Locator);

            if (array.IsFailure)
            {
                return(array.Error);
            }
            var arg = (object[])array.Result;

            return
                (Converter.PassThrough <PersistAggregateRoot, PersistAggregateRoot.Argument <object> >(
                     new PersistAggregateRoot.Argument <object>
            {
                RootName = rootType.FullName,
                ToInsert = method == MethodEnum.Insert ? arg : null,
                ToUpdate = method == MethodEnum.Update ? CreateKvMethod.MakeGenericMethod(rootType).Invoke(this, new[] { arg }) : null,
                ToDelete = method == MethodEnum.Delete ? arg : null
            }));
        }
Exemplo n.º 2
0
        public static Either <XElement> ParseXml(Stream data)
        {
            if (data == null)
            {
                return(Either <XElement> .Succes(null));
            }
            try
            {
                return(XElement.Load(data));
            }
            catch (Exception ex)
            {
                return(@"Sent data is not a valid Xml. 
Set Content-type header to correct format or fix sent data.
Error: " + ex.Message);
            }
        }