Ejemplo n.º 1
0
        public T[] LoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, string transformer, Dictionary <string, object> transformerParameters = null)
        {
            if (transformer == null)
            {
                throw new ArgumentNullException("transformer");
            }
            if (ids.Length == 0)
            {
                return(new T[0]);
            }

            var loadTransformerOeration = new LoadTransformerOperation(this);

            loadTransformerOeration.ByIds(ids);
            loadTransformerOeration.WithTransformer(transformer, transformerParameters);
            loadTransformerOeration.WithIncludes(includes?.Select(x => x.Key).ToArray());

            var command = loadTransformerOeration.CreateRequest();

            if (command != null)
            {
                RequestExecuter.Execute(command, Context);
                loadTransformerOeration.SetResult(command.Result);
            }

            return(loadTransformerOeration.GetTransformedDocuments <T>(command?.Result));
        }
Ejemplo n.º 2
0
        public TResult[] LoadStartingWith <TTransformer, TResult>(string keyPrefix, string matches = null, int start = 0,
                                                                  int pageSize     = 25, string exclude = null, RavenPagingInformation pagingInformation = null, Action <ILoadConfiguration> configure = null,
                                                                  string skipAfter = null) where TTransformer : AbstractTransformerCreationTask, new()
        {
            IncrementRequestCount();
            var transformer = new TTransformer().TransformerName;

            var configuration = new RavenLoadConfiguration();

            configure?.Invoke(configuration);

            var loadStartingWithOperation = new LoadStartingWithOperation(this);

            loadStartingWithOperation.WithStartWith(keyPrefix, matches, start, pageSize, exclude, pagingInformation, configure, skipAfter);
            loadStartingWithOperation.WithTransformer(transformer, configuration.TransformerParameters);


            var command = loadStartingWithOperation.CreateRequest();

            if (command != null)
            {
                RequestExecuter.Execute(command, Context);
            }

            return(loadStartingWithOperation.GetTransformedDocuments <TResult>(command?.Result));
        }
Ejemplo n.º 3
0
        public async Task <Token> TokenAsync(string code)
        {
            var token = await _requestExecuter.Execute <Token>(() => _requestGenerator.AccessToken(_options.ClientId, _options.ClientSecret, _options.RedirectUri, code)).ConfigureAwait(false);

            _options.AccessToken = token.access_token;
            return(token);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves all the changes to the Raven server.
        /// </summary>
        public void SaveChanges()
        {
            var saveChangesOperation = new BatchOperation(this);

            var command = saveChangesOperation.CreateRequest();

            if (command != null)
            {
                RequestExecuter.Execute(command, Context);
                saveChangesOperation.SetResult(command.Result);
            }
        }
Ejemplo n.º 5
0
        public T[] LoadInternal <T>(string[] ids)
        {
            var loadOeration = new LoadOperation(this);

            loadOeration.ByIds(ids);

            var command = loadOeration.CreateRequest();

            if (command != null)
            {
                RequestExecuter.Execute(command, Context);
                loadOeration.SetResult(command.Result);
            }

            return(loadOeration.GetDocuments <T>());
        }
Ejemplo n.º 6
0
        public IEnumerator <StreamResult <T> > Stream <T>(IDocumentQuery <T> query)
        {
            var streamOperation = new StreamOperation(this);
            var command         = streamOperation.CreateRequest((IRavenQueryInspector)query);

            RequestExecuter.Execute(command, Context);
            using (var result = streamOperation.SetResult(command.Result))
            {
                while (result.MoveNext())
                {
                    var res         = result.Current;
                    var stremResult = CreateStreamResult <T>(res);

                    yield return(stremResult);
                }
            }
        }
Ejemplo n.º 7
0
        private bool HasEtagInDatabaseDocumentResponse(string url, string databaseName, JsonOperationContext context)
        {
            var command = new GetDatabaseDocumentTestCommand();

            using (var requestExecuter = new RequestExecuter(url, databaseName, null))
            {
                requestExecuter.Execute(command, context);
            }

            var result = command.Result;
            BlittableJsonReaderObject metadata;
            var  hasMetadataProperty = result.TryGet("@metadata", out metadata);
            long etag;
            var  hasEtagProperty = metadata.TryGet("@etag", out etag);

            return(hasMetadataProperty && hasEtagProperty && etag > 0);
        }
Ejemplo n.º 8
0
        public T[] LoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes)
        {
            var loadOeration = new LoadOperation(this);

            loadOeration.ByIds(ids);
            loadOeration.WithIncludes(includes?.Select(x => x.Key).ToArray());

            var command = loadOeration.CreateRequest();

            if (command != null)
            {
                RequestExecuter.Execute(command, Context);
                loadOeration.SetResult(command.Result);
            }

            return(loadOeration.GetDocuments <T>());
        }
Ejemplo n.º 9
0
        private IEnumerator <StreamResult <T> > Stream <T>(long?fromEtag, string startsWith, string matches, int start, int pageSize, RavenPagingInformation pagingInformation,
                                                           string skipAfter, string transformer, Dictionary <string, object> transformerParameters)
        {
            var streamOperation = new StreamOperation(this);
            var command         = streamOperation.CreateRequest(fromEtag, startsWith, matches, start, pageSize, null, pagingInformation, skipAfter, transformer,
                                                                transformerParameters);

            RequestExecuter.Execute(command, Context);
            using (var result = streamOperation.SetResult(command.Result))
            {
                while (result.MoveNext())
                {
                    var res         = result.Current;
                    var stremResult = CreateStreamResult <T>(res);
                    yield return(stremResult);
                }
            }
        }
Ejemplo n.º 10
0
        public Operation DeleteByIndex <T>(string indexName, Expression <Func <T, bool> > expression)
        {
            var query      = Query <T>(indexName).Where(expression);
            var indexQuery = new IndexQuery()
            {
                Query = query.ToString()
            };

            var deleteByIndexOperation = new DeleteByIndexOperation();
            var command = deleteByIndexOperation.CreateRequest(indexName, indexQuery,
                                                               new QueryOperationOptions(), (DocumentStore)this.DocumentStore);

            if (command != null)
            {
                RequestExecuter.Execute(command, Context);
                return(new Operation(command.Result.OperationId));
            }
            return(null);
        }
Ejemplo n.º 11
0
        public T[] LoadStartingWith <T>(string keyPrefix, string matches = null, int start = 0, int pageSize = 25, string exclude = null,
                                        RavenPagingInformation pagingInformation = null, string skipAfter = null)
        {
            IncrementRequestCount();

            var loadStartingWithOperation = new LoadStartingWithOperation(this);

            loadStartingWithOperation.WithStartWith(keyPrefix, matches, start, pageSize, exclude, pagingInformation, skipAfter: skipAfter);

            var command = loadStartingWithOperation.CreateRequest();

            if (command != null)
            {
                RequestExecuter.Execute(command, Context);
                loadStartingWithOperation.SetResult(command.Result);
            }

            return(loadStartingWithOperation.GetDocuments <T>());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Refreshes the specified entity from Raven server.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">The entity.</param>
        public void Refresh <T>(T entity)
        {
            DocumentInfo documentInfo;

            if (DocumentsByEntity.TryGetValue(entity, out documentInfo) == false)
            {
                throw new InvalidOperationException("Cannot refresh a transient instance");
            }
            IncrementRequestCount();

            var command = new GetDocumentCommand
            {
                Ids     = new[] { documentInfo.Id },
                Context = this.Context
            };

            RequestExecuter.Execute(command, Context);

            RefreshInternal(entity, command, documentInfo);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Loads the specified entity with the specified id.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public T Load <T>(string id)
        {
            if (id == null)
            {
                return(default(T));
            }
            var loadOeration = new LoadOperation(this);

            loadOeration.ById(id);

            var command = loadOeration.CreateRequest();

            if (command != null)
            {
                RequestExecuter.Execute(command, Context);
                loadOeration.SetResult(command.Result);
            }

            return(loadOeration.GetDocument <T>());
        }
Ejemplo n.º 14
0
        public void Admin_databases_endpoint_should_refuse_document_with_lower_etag_with_concurrency_Exception()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Load <object>("users/1");// just waiting for the db to load
                }

                TransactionOperationContext context;
                using (Server.ServerStore.ContextPool.AllocateOperationContext(out context))
                {
                    var getCommand = new GetDatabaseDocumentTestCommand();
                    using (var requestExecuter = new RequestExecuter(store.Url, store.DefaultDatabase, null))
                    {
                        requestExecuter.Execute(getCommand, context);
                        var putCommand = new PutDatabaseDocumentTestCommand(getCommand.Result);

                        var exception = Assert.Throws <InternalServerErrorException>(() => requestExecuter.Execute(putCommand, context));
                        Assert.Contains("ConcurrencyException", exception.Message);
                    }
                }
            }
        }
Ejemplo n.º 15
0
 public async Task <StorageInfo> GetStorageAsync(DateTime?start_date, DateTime?end_date)
 {
     return(await _requestExecuter.Execute <StorageInfo>(() => _requestGenerator.GetStorage(start_date, end_date)).ConfigureAwait(false));
 }
Ejemplo n.º 16
0
        public async Task <MetaData> FilesAsync(string path, Stream targetStream, string rev = null, string asTeamMember = null)
        {
            MetaData fileMetadata = null;

            using (var restResponse = await _requestExecuter.Execute(() => _requestGenerator.Files(_options.Root, path, rev, asTeamMember)).ConfigureAwait(false))
            {
                await _requestExecuter.CheckForError(restResponse, false).ConfigureAwait(false);

                long?length = restResponse.Content.Headers.ContentLength;
                if (length == null)
                {
                    IEnumerable <string> metadatas;
                    if (restResponse.Headers.TryGetValues("x-dropbox-metadata", out metadatas))
                    {
                        string metadata = metadatas.FirstOrDefault();
                        if (metadata != null)
                        {
                            fileMetadata = JsonConvert.DeserializeObject <MetaData>(metadata);
                            length       = fileMetadata.bytes;
                        }
                    }
                }
                string etag = "";
                IEnumerable <string> etags;
                if (restResponse.Headers.TryGetValues("etag", out etags))
                {
                    etag = etags.FirstOrDefault();
                }


                long?read    = 0;
                bool hasMore = true;
                do
                {
                    long?from = read;
                    long?to   = read + _options.ChunkSize;
                    if (to > length)
                    {
                        to = length;
                    }
                    if (from >= length)
                    {
                        break;
                    }

                    using (var restResponse2 = await _requestExecuter.Execute(() => _requestGenerator.FilesRange(_options.Root, path, from.Value, to.Value - 1, etag, rev, asTeamMember)).ConfigureAwait(false))
                    {
                        await restResponse2.Content.CopyToAsync(targetStream).ConfigureAwait(false);

                        read += restResponse2.Content.Headers.ContentLength;

                        if (read >= length)
                        {
                            hasMore = false;
                        }
                        else if (restResponse2.StatusCode == HttpStatusCode.OK)
                        {
                            hasMore = false;
                        }
                    }
                } while (hasMore);
            }
            return(fileMetadata);
        }
Ejemplo n.º 17
0
 public async Task <Events> GetEventsAsync(int limit         = 1000, string cursor   = null, string member_id = null, string user_id = null, string user_email = null, string category = null,
                                           DateTime?start_ts = null, DateTime?end_ts = null)
 {
     return(await _requestExecuter.Execute <Events>(() => _requestGenerator.GetEvents(limit, cursor, member_id, user_id, user_email, category, start_ts, end_ts)).ConfigureAwait(false));
 }
Ejemplo n.º 18
0
 public async Task <TeamInfo> GetInfoAsync()
 {
     return(await _requestExecuter.Execute <TeamInfo>(() => _requestGenerator.GetInfo()).ConfigureAwait(false));
 }
Ejemplo n.º 19
0
 public async Task <MetaData> CopyAsync(string from_path, string to_path, string from_copy_ref = null, string locale = null, string asTeamMember = null)
 {
     return(await _requestExecuter.Execute <MetaData>(() => _requestGenerator.Copy(_options.Root, from_path, to_path, from_copy_ref, locale, asTeamMember)).ConfigureAwait(false));
 }
Ejemplo n.º 20
0
 public async Task <AccountInfo> AccountInfoAsync(string locale = null, string asTeamMember = null)
 {
     return(await _requestExecuter.Execute <AccountInfo>(() => _requestGenerator.AccountInfo(locale, asTeamMember)).ConfigureAwait(false));
 }
Ejemplo n.º 21
0
 public async Task <MemberInfo> AddAsync(string member_email, string member_given_name, string member_surname, string member_external_id = null,
                                         bool?send_welcome_email = null)
 {
     return(await _requestExecuter.Execute <MemberInfo>(() => _requestGenerator.Add(member_email, member_given_name, member_surname, member_external_id, send_welcome_email)).ConfigureAwait(false));
 }