示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentStore"/> class.
        /// </summary>
        public DocumentStore()
        {
            ResourceManagerId = new Guid("E749BAA6-6F76-4EEF-A069-40A4378954F8");

            SharedOperationsHeaders = new NameValueCollection();
            Conventions = new DocumentConvention();
        }
示例#2
0
        public void can_use_RavenDB_in_a_remote_process_to_post_batch_operations()
        {
            var documentConvention = new DocumentConvention();

            using (var driver = new RavenDBDriver("HelloShard", documentConvention))
            {
                driver.Start();

                var httpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri(new Uri(driver.Url), "bulk_docs"));
                httpWebRequest.Method = "POST";
                using (var requestStream = new StreamWriter(httpWebRequest.GetRequestStream(), Encoding.UTF8))
                {
                    requestStream.Write("[");

                    requestStream.Write(GetPutCommand().ToJson().ToString());

                    requestStream.Write("]");
                }

                HttpWebResponse webResponse;

                try
                {
                    webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    webResponse.Close();
                }
                catch (WebException e)
                {
                    driver.Should_finish_without_error();
                    driver.TraceExistingOutput();

                    Console.WriteLine(new StreamReader(e.Response.GetResponseStream()).ReadToEnd());
                    throw;
                }

                using (var store = driver.GetDocumentStore())
                {
                    should_find_expected_value_in(store);
                }
            }
        }
 public DirectoryMarkdownProcessor(
     string targetDirectory,
     DocumentConvention convention = DocumentConvention.SourceTransform,
     bool scanForMdFiles           = true,
     bool scanForSnippets          = true,
     bool scanForIncludes          = true,
     Action <string>?log           = null,
     bool?writeHeader = null,
     string?header    = null,
     DirectoryFilter?directoryFilter = null,
     bool?readOnly                           = null,
     LinkFormat linkFormat                   = LinkFormat.GitHub,
     int tocLevel                            = 2,
     IEnumerable <string>?tocExcludes        = null,
     IEnumerable <string>?documentExtensions = null,
     bool treatMissingAsWarning              = false,
     int maxWidth                            = int.MaxValue,
     string?urlPrefix                        = null,
     bool validateContent                    = false,
     string?newLine                          = null) :
     this(
         targetDirectory,
         new SnippetMarkdownHandling(targetDirectory, linkFormat, urlPrefix).Append,
         convention,
         scanForMdFiles,
         scanForSnippets,
         scanForIncludes,
         log,
         writeHeader,
         header,
         directoryFilter,
         readOnly,
         tocLevel,
         tocExcludes,
         documentExtensions,
         treatMissingAsWarning,
         maxWidth,
         validateContent,
         newLine)
 {
 }
 internal HttpJsonRequest(
     CreateHttpJsonRequestParams requestParams,
     HttpJsonRequestFactory factory)
 {
     Url                    = requestParams.Url;
     this.factory           = factory;
     owner                  = requestParams.Owner;
     conventions            = requestParams.Convention;
     Method                 = requestParams.Method;
     webRequest             = (HttpWebRequest)WebRequest.Create(requestParams.Url);
     webRequest.Credentials = requestParams.Credentials;
     webRequest.Method      = requestParams.Method;
     if (factory.DisableRequestCompression == false &&
         (requestParams.Method == "POST" || requestParams.Method == "PUT" || requestParams.Method == "PATCH"))
     {
         webRequest.Headers["Content-Encoding"] = "gzip";
     }
     webRequest.ContentType = "application/json; charset=utf-8";
     WriteMetadata(requestParams.Metadata);
     requestParams.UpdateHeaders(webRequest);
 }
示例#5
0
 static MarkdownProcessor BuildProcessor(
     DocumentConvention convention,
     IReadOnlyList <Snippet>?snippets,
     IReadOnlyList <string>?snippetSourceFiles,
     IReadOnlyList <Include>?includes)
 {
     includes ??= Array.Empty <Include>();
     snippets ??= Array.Empty <Snippet>();
     snippetSourceFiles ??= Array.Empty <string>();
     return(new(
                convention : convention,
                snippets : snippets.ToDictionary(),
                includes : includes,
                appendSnippets : SimpleSnippetMarkdownHandling.Append,
                snippetSourceFiles : snippetSourceFiles,
                tocLevel : 2,
                writeHeader : false,
                targetDirectory : "c:/root",
                validateContent : true,
                allFiles : new List <string>()));
 }
示例#6
0
        /// <summary>
        /// Toes the index definition.
        /// </summary>
        /// <param name="convention">The convention.</param>
        /// <returns></returns>
        public IndexDefinition ToIndexDefinition(DocumentConvention convention)
        {
            if (Map == null)
            {
                throw new InvalidOperationException(
                          "Map is required to generate an index, you cannot create an index without a valid Map property (in index " +
                          this.GetType().Name + ").");
            }
            string querySource = (typeof(TDocument) == typeof(object) || ContainsWhereEntityIs(Map.Body)) ? "docs" : "docs." + convention.GetTypeTagName(typeof(TDocument));

            return(new IndexDefinition
            {
                Map = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode(Map, convention, querySource, translateIdentityProperty: true),
                Reduce = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode(Reduce, convention, "results", translateIdentityProperty: false),
                TransformResults = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode(TransformResults, convention, "results", translateIdentityProperty: false),
                Indexes = ConvertToStringDictionary(Indexes),
                Stores = ConvertToStringDictionary(Stores),
                SortOptions = ConvertToStringDictionary(SortOptions),
                Analyzers = ConvertToStringDictionary(Analyzers)
            });
        }
示例#7
0
 internal HttpJsonRequest(
     string url,
     string method,
     RavenJObject metadata,
     ICredentials credentials,
     HttpJsonRequestFactory factory,
     IHoldProfilingInformation owner,
     DocumentConvention conventions)
 {
     this.Url               = url;
     this.factory           = factory;
     this.owner             = owner;
     this.conventions       = conventions;
     this.Method            = method;
     webRequest             = (HttpWebRequest)WebRequest.Create(url);
     webRequest.Credentials = credentials;
     WriteMetadata(metadata);
     webRequest.Method = method;
     webRequest.Headers["Accept-Encoding"] = "deflate,gzip";
     webRequest.ContentType = "application/json; charset=utf-8";
 }
示例#8
0
 public static IDocumentStore CreateDocumentStore()
 {
     try
     {
         ServiceStartupLogger.LogMessage("Start RavenHelper.CreateDocumentStore, creating document store");
         var documentStore = new DocumentStore
         {
             ConnectionStringName = "RavenDB",
             Conventions          =
             {
                 FindTypeTagName               = type =>
                 {
                     if (typeof(SettingsBase).IsAssignableFrom(type))
                     {
                         return("SettingsBases");
                     }
                     if (typeof(ConnectionSettingBase).IsAssignableFrom(type))
                     {
                         return("ConnectionSettingBases");
                     }
                     return(DocumentConvention.DefaultTypeTagName(type));
                 },
                 MaxNumberOfRequestsPerSession = AppSettingsHelper.GetIntSetting("RavenMaxNumberOfRequestsPerSession", 30000)
             }
         };
         ServiceStartupLogger.LogMessage("RavenHelper.CreateDocumentStore, calling Initialize");
         documentStore.Initialize();
         ServiceStartupLogger.LogMessage("RavenHelper.CreateDocumentStore, creating indexes");
         IndexCreation.CreateIndexes(typeof(MMDB.DataService.Data.Jobs.DataServiceJobBase <>).Assembly, documentStore);
         ServiceStartupLogger.LogMessage("RavenHelper.CreateDocumentStore, diabling all caching");
         documentStore.DatabaseCommands.DisableAllCaching();
         ServiceStartupLogger.LogMessage("Done RavenHelper.CreateDocumentStore");
         return(documentStore);
     }
     catch (Exception err)
     {
         ServiceStartupLogger.LogMessage("RavenHelper.CreateDocumentStore error: " + err.ToString());
         throw;
     }
 }
        /// <summary>
        /// Creates the index definition.
        /// </summary>
        /// <returns></returns>
        public override IndexDefinition CreateIndexDefinition()
        {
            if (Conventions == null)
            {
                Conventions = new DocumentConvention();
            }

            var indexDefinition = new IndexDefinitionBuilder <object, TReduceResult>()
            {
                Indexes                    = Indexes,
                SortOptions                = IndexSortOptions,
                SortOptionsStrings         = IndexSortOptionsStrings,
                Analyzers                  = Analyzers,
                Reduce                     = Reduce,
                Stores                     = Stores,
                TermVectors                = TermVectors,
                SpatialIndexes             = SpatialIndexes,
                SuggestionsOptions         = IndexSuggestions,
                AnalyzersStrings           = AnalyzersStrings,
                IndexesStrings             = IndexesStrings,
                StoresStrings              = StoresStrings,
                TermVectorsStrings         = TermVectorsStrings,
                SpatialIndexesStrings      = SpatialIndexesStrings,
                DisableInMemoryIndexing    = DisableInMemoryIndexing,
                MaxIndexOutputsPerDocument = MaxIndexOutputsPerDocument
            }.ToIndexDefinition(Conventions, validateMap: false);

            foreach (var map in maps.Select(generateMap => generateMap()))
            {
                string formattedMap = map;
#if !DNXCORE50
                if (Conventions.PrettifyGeneratedLinqExpressions)
                {
                    formattedMap = IndexPrettyPrinter.TryFormat(formattedMap);
                }
#endif
                indexDefinition.Maps.Add(formattedMap);
            }
            return(indexDefinition);
        }
示例#10
0
        public RequestHandling()
        {
            var store = new DocumentStore();

            DocumentConvention Conventions = store.Conventions;

            #region use_paraller_multi_get
            Conventions.UseParallelMultiGet = true;
            #endregion

            #region allow_multiple_async_ops
            Conventions.AllowMultipuleAsyncOperations = false;
            #endregion

            #region handle_forbidden_response_async
            Conventions.HandleForbiddenResponseAsync = (forbiddenResponse, credentials) =>
                                                       #endregion
                                                       null;

            #region handle_unauthorized_response_async
            Conventions.HandleUnauthorizedResponseAsync = (unauthorizedResponse, credentials) =>
                                                          #endregion
                                                          null;

            #region customize_json_serializer
            Conventions.CustomizeJsonSerializer = serializer => { };
            #endregion

            #region json_contract_resolver
            Conventions.JsonContractResolver = new CustomJsonContractResolver();
            #endregion

            #region preserve_doc_props_not_found_on_model
            Conventions.PreserveDocumentPropertiesNotFoundOnModel = true;
            #endregion

            #region request_threshold_sla
            Conventions.RequestTimeSlaThresholdInMilliseconds = 75;
            #endregion
        }
示例#11
0
        internal async Task UpdateIndexInReplicationAsync(IAsyncDatabaseCommands asyncDatabaseCommands,
                                                          DocumentConvention documentConvention,
                                                          Func <AsyncServerClient, OperationMetadata, Task> action)
        {
            var asyncServerClient = asyncDatabaseCommands as AsyncServerClient;

            if (asyncServerClient == null)
            {
                return;
            }
            var doc = await asyncServerClient.GetAsync("Raven/Replication/Destinations");

            if (doc == null)
            {
                return;
            }
            var replicationDocument =
                documentConvention.CreateSerializer().Deserialize <ReplicationDocument>(new RavenJTokenReader(doc.DataAsJson));

            if (replicationDocument == null || replicationDocument.Destinations == null || replicationDocument.Destinations.Count == 0)
            {
                return;
            }
            var tasks = (
                from replicationDestination in replicationDocument.Destinations
                where !replicationDestination.Disabled && !replicationDestination.IgnoredClient
                select action(asyncServerClient, GetReplicationOperation(replicationDestination))
                )
                        .ToArray();
            await Task.Factory.ContinueWhenAll(tasks, indexingTask =>
            {
                foreach (var indexTask in indexingTask)
                {
                    if (indexTask.IsFaulted)
                    {
                        Logger.WarnException("Could not put index in replication server", indexTask.Exception);
                    }
                }
            });
        }
示例#12
0
        public virtual async Task SideBySideExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null, CancellationToken token = default(CancellationToken))
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            var replaceIndexName = Constants.SideBySideIndexNamePrefix + IndexName;
            //check if side by side index exists
            var sideBySideDef = await asyncDatabaseCommands.GetIndexAsync(replaceIndexName, token).ConfigureAwait(false);

            if (sideBySideDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, sideBySideDef, indexDefinition))
                {
                    return;
                }

                await UpdateSideBySideIndexAsync(asyncDatabaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, token, replaceIndexName, indexDefinition, documentConvention);

                return;
            }

            var serverDef = await asyncDatabaseCommands.GetIndexAsync(IndexName, token).ConfigureAwait(false);

            if (serverDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    return;
                }

                await UpdateSideBySideIndexAsync(asyncDatabaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, token, replaceIndexName, indexDefinition, documentConvention);
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                await asyncDatabaseCommands.PutIndexAsync(IndexName, indexDefinition, token).ConfigureAwait(false);
                await AfterExecuteAsync(asyncDatabaseCommands, documentConvention, token);
            }
        }
示例#13
0
        /// <summary>
        /// Executes the index creation using in side-by-side mode.
        /// </summary>
        /// <param name="databaseCommands"></param>
        /// <param name="documentConvention"></param>
        public virtual void SideBySideExecute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            var replaceIndexName = Constants.SideBySideIndexNamePrefix + IndexName;
            //check if side by side index exists
            var sideBySideDef = databaseCommands.GetIndex(replaceIndexName);

            if (sideBySideDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, sideBySideDef, indexDefinition))
                {
                    return;
                }

                UpdateSideBySideIndex(databaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, replaceIndexName, indexDefinition, documentConvention);
                return;
            }

            //check if "regular" index exists
            var serverDef = databaseCommands.GetIndex(IndexName);

            if (serverDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    return;
                }

                UpdateSideBySideIndex(databaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, replaceIndexName, indexDefinition, documentConvention);
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                databaseCommands.PutIndex(IndexName, indexDefinition);
                AfterExecute(databaseCommands, documentConvention);
            }
        }
示例#14
0
        internal HttpJsonRequest(string url, string method, RavenJObject metadata, DocumentConvention conventions)
        {
            this.url         = url;
            this.conventions = conventions;
            webRequest       = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(url));

            var tcs = new TaskCompletionSource <object>();

            tcs.SetResult(null);
            WaitForTask = tcs.Task;

            WriteMetadata(metadata);
            webRequest.Method = method;
            if (method != "GET")
            {
                webRequest.ContentType = "application/json; charset=utf-8";
            }
            if (method == "POST" || method == "PUT")
            {
                webRequest.Headers["Content-Encoding"] = "gzip";
            }
        }
示例#15
0
        protected override void ConfigureApplicationContainer(global::Nancy.TinyIoc.TinyIoCContainer container)
        {
            // TODO: support multiple doc-stores
            var docStore = new DocumentStore {
                ConnectionStringName = "RavenDB"
            };
            var conventions = docStore.Conventions;

            conventions.FindFullDocumentKeyFromNonStringIdentifier = (o, type, arg3) =>
            {
                var ret         = conventions.DefaultFindFullDocumentKeyFromNonStringIdentifier(o, type, arg3);
                var areaConfigs = HttpContext.Current.Items["AreaConfigs"] as AreaConfigs;
                if (areaConfigs != null)
                {
                    ret = areaConfigs.DocumentsPrefix + ret;
                }

                return(ret);
            };

            conventions.TransformTypeTagNameToDocumentKeyPrefix = s =>
            {
                var ret         = DocumentConvention.DefaultTransformTypeTagNameToDocumentKeyPrefix(s);
                var areaConfigs = HttpContext.Current.Items["AreaConfigs"] as AreaConfigs;
                if (areaConfigs != null)
                {
                    ret = areaConfigs.DocumentsPrefix + ret;
                }

                return(ret);
            };

            AppDomainAssemblyTypeScanner.LoadAssembliesWithNancyReferences();

            docStore.Initialize();
            container.Register <IDocumentStore>(docStore, "DocStore");

            base.ConfigureApplicationContainer(container);
        }
示例#16
0
        public void load_object_with_byte_array_with_default_TypeNameHandling()
        {
            using (var store = NewRemoteDocumentStore())
            {
                var json           = GetResourceText("DocumentWithBytes.txt");
                var jsonSerializer = new DocumentConvention().CreateSerializer();
                var item           = jsonSerializer.Deserialize <DesignResources>(new JsonTextReader(new StringReader(json)));

                using (var session = store.OpenSession())
                {
                    item.Id       = "resources/123";
                    item.DesignId = "designs/123";
                    session.Store(item);
                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    session.Load <DesignResources>("resources/123");
                }
            }
        }
示例#17
0
        internal void UpdateIndexInReplication(IDatabaseCommands databaseCommands, DocumentConvention documentConvention,
                                               Action <ServerClient, OperationMetadata> action)
        {
            var serverClient = databaseCommands as ServerClient;

            if (serverClient == null)
            {
                return;
            }
            var doc = serverClient.Get("Raven/Replication/Destinations");

            if (doc == null)
            {
                return;
            }
            var replicationDocument =
                documentConvention.CreateSerializer().Deserialize <ReplicationDocument>(new RavenJTokenReader(doc.DataAsJson));

            if (replicationDocument == null)
            {
                return;
            }

            foreach (var replicationDestination in replicationDocument.Destinations)
            {
                try
                {
                    if (replicationDestination.Disabled || replicationDestination.IgnoredClient)
                    {
                        continue;
                    }
                    action(serverClient, GetReplicationOperation(replicationDestination));
                }
                catch (Exception e)
                {
                    Logger.WarnException("Could not put index in replication server", e);
                }
            }
        }
        private void UpdateIndexInReplication(IDatabaseCommands databaseCommands, DocumentConvention documentConvention,
                                              IndexDefinition indexDefinition)
        {
            var serverClient = databaseCommands as ServerClient;

            if (serverClient == null)
            {
                return;
            }
            var doc = serverClient.Get("Raven/Replication/Destinations");

            if (doc == null)
            {
                return;
            }
            var replicationDocument =
                documentConvention.CreateSerializer().Deserialize <ReplicationDocument>(new RavenJTokenReader(doc.DataAsJson));

            if (replicationDocument == null)
            {
                return;
            }

            foreach (var replicationDestination in replicationDocument.Destinations)
            {
                if (replicationDestination.Disabled || replicationDestination.IgnoredClient)
                {
                    continue;
                }
                try
                {
                    serverClient.DirectPutIndex(IndexName, GetReplicationUrl(replicationDestination), true, indexDefinition);
                }
                catch (Exception e)
                {
                    Logger.WarnException("Could not put index in replication server", e);
                }
            }
        }
示例#19
0
        public void CanBeDeSerializedProperly()
        {
            var jsonSerializer = new DocumentConvention().CreateSerializer();

            using (var stringWriter = new StringWriter())
            {
                var item = new WithDic
                {
                    Items = new Dictionary <DateTime, int>
                    {
                        { new DateTime(2011, 11, 24), 1 }
                    }
                };

                jsonSerializer.Serialize(stringWriter, item);

                var s       = stringWriter.GetStringBuilder().ToString();
                var withDic = jsonSerializer.Deserialize <WithDic>(new JsonTextReader(new StringReader(s)));

                Assert.Equal(1, withDic.Items[new DateTime(2011, 11, 24)]);
            }
        }
        /// <summary>
        /// Perform the actual generation
        /// </summary>
        public static string PruneToFailureLinqQueryAsStringToWorkableCode <TQueryRoot, TReduceResult>(
            LambdaExpression expr,
            DocumentConvention convention,
            string querySource, bool translateIdentityProperty)
        {
            if (expr == null)
            {
                return(null);
            }
            var expression = expr.Body;

            string queryRootName = null;

            switch (expression.NodeType)
            {
            case ExpressionType.ConvertChecked:
            case ExpressionType.Convert:
                expression = ((UnaryExpression)expression).Operand;
                break;

            case ExpressionType.Call:
                var methodCallExpression = GetFirstMethodCallExpression(expression);
                switch (methodCallExpression.Method.Name)
                {
                case "Select":
                    queryRootName = TryCaptureQueryRoot(methodCallExpression.Arguments.FirstOrDefault(x => x.NodeType == ExpressionType.Call || x.NodeType == ExpressionType.Lambda) ?? methodCallExpression.Arguments[0]);
                    break;

                case "SelectMany":
                    queryRootName = TryCaptureQueryRoot(methodCallExpression.Arguments[1]);
                    break;
                }
                break;
            }

            var linqQuery = ExpressionStringBuilder.ExpressionToString(convention, translateIdentityProperty, typeof(TQueryRoot), queryRootName, expression);

            return(FormatLinqQuery(expr, querySource, linqQuery));
        }
示例#21
0
        public void query_for_object_with_byte_array_with_TypeNameHandling_All()
        {
            using (var server = GetNewServer())
                using (var store = new DocumentStore {
                    Url = "http://localhost:8079"
                })
                {
                    store.Conventions = new DocumentConvention
                    {
                        CustomizeJsonSerializer = serializer =>
                        {
                            serializer.TypeNameHandling = TypeNameHandling.All;
                        },
                    };
                    store.Initialize();

                    var json           = GetResourceText("DocumentWithBytes.txt");
                    var jsonSerializer = new DocumentConvention().CreateSerializer();
                    var item           = jsonSerializer.Deserialize <DesignResources>(new JsonTextReader(new StringReader(json)));

                    using (var session = store.OpenSession())
                    {
                        item.Id       = "resources/123";
                        item.DesignId = "designs/123";
                        session.Store(item);
                        session.SaveChanges();
                    }

                    using (var session = store.OpenSession())
                    {
                        session
                        .Query <DesignResources>()
                        .Customize(x => x.WaitForNonStaleResultsAsOfNow())
                        .Where(x => x.DesignId == "designs/123")
                        .ToList();
                    }
                }
        }
示例#22
0
        private Task UpdateIndexInReplicationAsync(IAsyncDatabaseCommands asyncDatabaseCommands,
                                                   DocumentConvention documentConvention, IndexDefinition indexDefinition)
        {
            var asyncServerClient = asyncDatabaseCommands as AsyncServerClient;

            if (asyncServerClient == null)
            {
                return(new CompletedTask());
            }
            return(asyncServerClient.GetAsync("Raven/Replication/Destinations").ContinueWith(doc =>
            {
                if (doc == null)
                {
                    return new CompletedTask();
                }
                var replicationDocument =
                    documentConvention.CreateSerializer().Deserialize <ReplicationDocument>(new RavenJTokenReader(doc.Result.DataAsJson));
                if (replicationDocument == null)
                {
                    return new CompletedTask();
                }
                var tasks = new List <Task>();
                foreach (var replicationDestination in replicationDocument.Destinations)
                {
                    tasks.Add(asyncServerClient.DirectPutIndexAsync(IndexName, indexDefinition, true, replicationDestination.Url));
                }
                return Task.Factory.ContinueWhenAll(tasks.ToArray(), indexingTask =>
                {
                    foreach (var indexTask in indexingTask)
                    {
                        if (indexTask.IsFaulted)
                        {
                            Logger.WarnException("Could not put index in replication server", indexTask.Exception);
                        }
                    }
                });
            }).Unwrap());
        }
示例#23
0
        private TcpConnectionInfo GetTcpInfo()
        {
            var convention = new DocumentConvention();

            //since we use it only once when the connection is initialized, no reason to keep requestFactory around for long
            using (var requestFactory = new HttpJsonRequestFactory(1))
                using (var request = requestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(null, string.Format("{0}/info/tcp",
                                                                                                                              MultiDatabase.GetRootDatabaseUrl(_destination.Url)),
                                                                                                          HttpMethod.Get,
                                                                                                          new OperationCredentials(_destination.ApiKey, CredentialCache.DefaultCredentials), convention)
                {
                    Timeout = TimeSpan.FromSeconds(15)
                }))
                {
                    var result            = request.ReadResponseJson();
                    var tcpConnectionInfo = convention.CreateSerializer().Deserialize <TcpConnectionInfo>(new RavenJTokenReader(result));
                    if (_log.IsInfoEnabled)
                    {
                        _log.Info($"Will replicate to {_destination.Database} @ {_destination.Url} via {tcpConnectionInfo.Url}");
                    }
                    return(tcpConnectionInfo);
                }
        }
示例#24
0
        public void DecreasingTimeMetricDecreasedRequestTimeMetricAfterEachRequest()
        {
            var conventions = new DocumentConvention
            {
                RequestTimeSlaThresholdInMilliseconds = 100 // switch back threshold will be 75
            };

            var metric = new RequestTimeMetric();

            UpdateMetric(metric, 500, 60); // 500

            Assert.True(metric.RateSurpassed(conventions));

            var decreasingMetric = new DecreasingTimeMetric(metric);

            UpdateMetric(decreasingMetric, 500, 30); // 77+

            Assert.True(metric.RateSurpassed(conventions));

            UpdateMetric(decreasingMetric, 500, 1); // 73

            Assert.False(metric.RateSurpassed(conventions));
        }
示例#25
0
        public void RequestTimeMetricRequiresLowerThresholdToSwitchBackIfItHasSurpassed()
        {
            var conventions = new DocumentConvention
            {
                RequestTimeSlaThresholdInMilliseconds = 100                   // switch back threshold will be 75
            };

            var metric = new RequestTimeMetric();

            Assert.False(metric.RateSurpassed(conventions));

            UpdateMetric(metric, 500, 60); // 500

            Assert.True(metric.RateSurpassed(conventions));

            UpdateMetric(metric, 15, 24); // 75+

            Assert.True(metric.RateSurpassed(conventions));

            UpdateMetric(metric, 15, 1); // 70

            Assert.False(metric.RateSurpassed(conventions));
        }
示例#26
0
        private bool CurrentOrLegacyIndexDefinitionEquals(DocumentConvention documentConvention, IndexDefinition serverDef, IndexDefinition indexDefinition)
        {
            var oldIndexId = serverDef.IndexId;

            try
            {
                serverDef.IndexId = indexDefinition.IndexId;

                if (serverDef.Equals(indexDefinition, false))
                {
                    return(true);
                }

                // now we need to check if this is a legacy index...
                var legacyIndexDefinition = GetLegacyIndexDefinition(documentConvention);

                return(serverDef.Equals(legacyIndexDefinition, compareIndexIds: false, ignoreFormatting: true, ignoreMaxIndexOutput: true));
            }
            finally
            {
                serverDef.IndexId = oldIndexId;
            }
        }
示例#27
0
        /// <summary>
        /// Creates the HTTP json request.
        /// </summary>
        public HttpJsonRequest CreateHttpJsonRequest(IHoldProfilingInformation self, string url, string method, RavenJObject metadata,
                                                     ICredentials credentials, DocumentConvention convention)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(typeof(HttpJsonRequestFactory).FullName);
            }
            var request = new HttpJsonRequest(url, method, metadata, credentials, this, self, convention)
            {
                ShouldCacheRequest = convention.ShouldCacheRequest(url)
            };

            if (request.ShouldCacheRequest && method == "GET" && !DisableHttpCaching)
            {
                var cachedRequestDetails = ConfigureCaching(url, request.webRequest.Headers.Set);
                request.CachedRequestDetails = cachedRequestDetails.CachedRequest;
                request.SkipServerCheck      = cachedRequestDetails.SkipServerCheck;
            }
            ConfigureRequest(self, new WebRequestEventArgs {
                Request = request.webRequest
            });
            return(request);
        }
示例#28
0
        void LoadPlugins()
        {
            var jsonRequestFactory = new HttpJsonRequestFactory();
            var baseUrl            = (Address + "/silverlight/plugins").NoCache();
            var credentials        = new NetworkCredential();
            var convention         = new DocumentConvention();

            var request  = jsonRequestFactory.CreateHttpJsonRequest(this, baseUrl, "GET", credentials, convention);
            var response = request.ReadResponseStringAsync();

            response.ContinueWith(_ => Execute.OnUIThread(() =>
            {
                {
                    var urls                     = from item in JArray.Parse(_.Result)
                                         let url = item.Value <string>()
                                                   select url;

                    var catalogs = from url in urls
                                   let fullUrl                     = Address + "/silverlight/plugin" + url.Replace('\\', '/')
                                                           let uri = new Uri(fullUrl, UriKind.Absolute)
                                                                     select new DeploymentCatalog(uri);

                    foreach (var deployment in catalogs)
                    {
                        deployment.DownloadCompleted += (s, e) =>
                        {
                            if (e.Error != null)
                            {
                                throw e.Error;
                            }
                        };
                        deployment.DownloadAsync();
                        catalog.Catalogs.Add(deployment);
                    }
                }
            }));
        }
        internal async Task UpdateIndexInReplicationAsync(IAsyncDatabaseCommands asyncDatabaseCommands,
                                                          DocumentConvention documentConvention,
                                                          Func <AsyncServerClient, OperationMetadata, Task> action)
        {
            var asyncServerClient = asyncDatabaseCommands as AsyncServerClient;

            if (asyncServerClient == null)
            {
                return;
            }
            var replicationDocument = await asyncServerClient.ExecuteWithReplication("GET", asyncServerClient.DirectGetReplicationDestinationsAsync);

            if (replicationDocument == null)
            {
                return;
            }
            if (replicationDocument == null || replicationDocument.Destinations == null || replicationDocument.Destinations.Count == 0)
            {
                return;
            }
            var tasks = (
                from replicationDestination in replicationDocument.Destinations
                where !replicationDestination.Disabled && !replicationDestination.IgnoredClient
                select action(asyncServerClient, GetReplicationOperation(replicationDestination))
                )
                        .ToArray();
            await Task.Factory.ContinueWhenAll(tasks, indexingTask =>
            {
                foreach (var indexTask in indexingTask)
                {
                    if (indexTask.IsFaulted)
                    {
                        Logger.WarnException("Could not put index in replication server", indexTask.Exception);
                    }
                }
            });
        }
示例#30
0
        public Misc()
        {
            var store = new DocumentStore();

            DocumentConvention Conventions = store.Conventions;

            #region disable_profiling
            Conventions.DisableProfiling = true;
            #endregion


            #region enlist_in_dist_tx
            Conventions.EnlistInDistributedTransactions = true;
            #endregion

            #region max_number_of_requests_per_session
            Conventions.MaxNumberOfRequestsPerSession = 30;
            #endregion

            #region save_enums_as_integers
            Conventions.SaveEnumsAsIntegers = false;
            #endregion

            #region use_optimistic_concurrency_by_default
            Conventions.DefaultUseOptimisticConcurrency = false;
            #endregion

            #region prettify_generated_linq_expressions
            Conventions.PrettifyGeneratedLinqExpressions = true;
            #endregion

            #region index_and_transformer_replication_mode
            Conventions.IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.Indexes
                                                             | IndexAndTransformerReplicationMode.Transformers;
            #endregion
        }
示例#31
0
        public Replication()
        {
            var store = new DocumentStore();

            DocumentConvention Conventions = store.Conventions;

            #region failover_behavior
            Conventions.FailoverBehavior = FailoverBehavior.AllowReadsFromSecondaries;
            #endregion

            #region cluster_failover_behavior
            Conventions.FailoverBehavior = FailoverBehavior.ReadFromAllWriteToLeader;
            #endregion

            #region replication_informer
            Conventions.ReplicationInformerFactory = (url, jsonRequestFactory, requestTimeMetricGetter) =>
                                                     new ReplicationInformer(Conventions, jsonRequestFactory, requestTimeMetricGetter);
            #endregion

            #region index_and_transformer_replication_mode
            Conventions.IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.Indexes |
                                                             IndexAndTransformerReplicationMode.Transformers;
            #endregion
        }
示例#32
0
		/// <summary>
		/// Initializes a new instance of the <see cref="AsyncServerClient"/> class.
		/// </summary>
		/// <param name="url">The URL.</param>
		/// <param name="convention">The convention.</param>
		/// <param name="credentials">The credentials.</param>
		public AsyncServerClient(string url, DocumentConvention convention, ICredentials credentials)
		{
			this.url = url.EndsWith("/") ? url.Substring(0, url.Length - 1) : url;
			this.convention = convention;
			this.credentials = credentials;
		}
        public AsyncAttachmentSession(string databaseAddress)
        {
            Convention = new DocumentConvention();

            Client = new AsyncServerClient(databaseAddress, Convention, Credentials);
        }
示例#34
0
		IEnumerable<Task> ExportData(SaveFileDialog saveFile, bool indexesOnly)
		{
			Output("Exporting to {0}", saveFile.SafeFileName);
			Output("- Indexes only, documents will be excluded");

			var stream = saveFile.OpenFile();
			var jsonRequestFactory = new HttpJsonRequestFactory();
			var baseUrl = Server.CurrentDatabaseAddress;
			var credentials = new NetworkCredential();
			var convention = new DocumentConvention();

			var streamWriter = new StreamWriter(new GZipStream(stream, CompressionMode.Compress));
			var jsonWriter = new JsonTextWriter(streamWriter)
								{
									Formatting = Formatting.Indented
								};

			Output("Begin reading indexes");

			jsonWriter.WriteStartObject();
			jsonWriter.WritePropertyName("Indexes");
			jsonWriter.WriteStartArray();

			int totalCount = 0;
			const int batchSize = 128;
			var completed = false;

			while (!completed)
			{
				var url = (baseUrl + "/indexes/?start=" + totalCount + "&pageSize=" + batchSize).NoCache();
				var request = jsonRequestFactory.CreateHttpJsonRequest(this, url, "GET", credentials, convention);
				var response = request.ReadResponseStringAsync();
				yield return response;

				var documents = response.Result;
				var array = JArray.Parse(documents);
				if (array.Count == 0)
				{
					Output("Done with reading indexes, total: {0}", totalCount);
					completed = true;
				}
				else
				{
					totalCount += array.Count;
					Output("Reading batch of {0,3} indexes, read so far: {1,10:#,#}", array.Count, totalCount);
					foreach (JToken item in array)
					{
						item.WriteTo(jsonWriter);
					}
				}
			}

			jsonWriter.WriteEndArray();
			jsonWriter.WritePropertyName("Docs");
			jsonWriter.WriteStartArray();

			if (indexesOnly)
			{
				Output("Skipping documents");
			}
			else
			{
				Output("Begin reading documents");

				var lastEtag = Guid.Empty;
				totalCount = 0;
				completed = false;
				while (!completed)
				{
					var url = (baseUrl + "/docs/?pageSize=" + batchSize + "&etag=" + lastEtag).NoCache();
					var request = jsonRequestFactory.CreateHttpJsonRequest(this, url, "GET", credentials, convention);
					var response = request.ReadResponseStringAsync();
					yield return response;

					var array = JArray.Parse(response.Result);
					if (array.Count == 0)
					{
						Output("Done with reading documents, total: {0}", totalCount);
						completed = true;
					}
					else
					{
						totalCount += array.Count;
						Output("Reading batch of {0,3} documents, read so far: {1,10:#,#}", array.Count,
									totalCount);
						foreach (JToken item in array)
						{
							item.WriteTo(jsonWriter);
						}
						lastEtag = new Guid(array.Last.Value<JObject>("@metadata").Value<string>("@etag"));
					}
				}
			}

			Execute.OnUIThread(() =>
								{
									jsonWriter.WriteEndArray();
									jsonWriter.WriteEndObject();
									streamWriter.Flush();
									streamWriter.Dispose();
									stream.Dispose();
								});
			Output("Export complete");
		}