Ejemplo n.º 1
0
        public Task <string[]> Persist <T>(
            IEnumerable <T> insert,
            IEnumerable <KeyValuePair <T, T> > update,
            IEnumerable <T> delete)
            where T : IAggregateRoot
        {
            var insertList = insert != null?insert.ToList() : new List <T>();

            var updateList = update != null?update.ToList() : new List <KeyValuePair <T, T> >();

            var deleteList = delete != null?delete.ToList() : new List <T>();

            if (insertList.Count == 0 && updateList.Count == 0 && deleteList.Count == 0)
            {
                return(Task.Factory.StartNew(() => new string[0]));
            }
            foreach (var it in insertList)
            {
                if (it != null)
                {
                    it.Validate();
                }
                else
                {
                    throw new ArgumentNullException("Provided null value in insert collection");
                }
            }
            foreach (var it in updateList)
            {
                if (it.Value != null)
                {
                    it.Value.Validate();
                }
                else
                {
                    throw new ArgumentNullException("Provided null value in update collection");
                }
            }
            foreach (var it in deleteList)
            {
                if (it != null)
                {
                    it.Validate();
                }
                else
                {
                    throw new ArgumentNullException("Provided null value in delete collection");
                }
            }
            var arg = new PersistArg
            {
                RootName = typeof(T).FullName,
                ToInsert = insertList.Count > 0 ? Protobuf.Serialize(insertList.ToArray()) : null,
                ToUpdate = updateList.Count > 0 ? Protobuf.Serialize(updateList.ToArray()) : null,
                ToDelete = deleteList.Count > 0 ? Protobuf.Serialize(deleteList.ToArray()) : null
            };

            return(Application.Post <PersistArg, string[]>("PersistAggregateRoot", arg));
        }
Ejemplo n.º 2
0
        public Task <Stream> Call <TArgument>(
            string command,
            string method,
            TArgument argument,
            HttpStatusCode[] expectedStatus,
            string accept)
        {
            var request = (HttpWebRequest)HttpWebRequest.Create(Server + command);

            request.Method = method;
            if (Auhtorization != null)
            {
#if !PORTABLE
                request.PreAuthenticate = true;
#endif
                request.Headers[HttpRequestHeader.Authorization] = Auhtorization;
            }
            request.ContentType = "application/x-protobuf";
            request.Accept      = accept;
            return(Task.Factory.StartNew(() =>
            {
                if (argument != null)
                {
                    using (var ms = Protobuf.Serialize(argument))
                        using (var stream = request.GetRequestStream())
                        {
                            ms.CopyTo(stream);
                        }
                }
                return ExecuteRequest(expectedStatus, request, MaxRetryCount);
            }));
        }
Ejemplo n.º 3
0
        internal GenericSpecification <T> Match <TArg>(string property, GenericSearchFilter filter, TArg value)
        {
            if (string.IsNullOrEmpty(property))
            {
                throw new ArgumentException("property can't be empty");
            }
            MemoryStream arg = value != null?Protobuf.Serialize(value) : null;

            Filters.Add(property, new KeyValuePair <int, MemoryStream>((int)filter, arg));
            return(this);
        }