public SynchronizationTopologyRootNode Discover()
        {
            var root = new SynchronizationTopologyRootNode(filesystem.SynchronizationTask.FileSystemUrl, filesystem.Storage.Id);

            if (ttl <= 0)
            {
                return(root);
            }

            var syncDestinations = filesystem.SynchronizationTask.GetSynchronizationDestinations().ToList();

            IList <string> sourceNames = null;

            filesystem.Storage.Batch(accessor =>
            {
                int totalResults;
                sourceNames = accessor.GetConfigNamesStartingWithPrefix(SynchronizationConstants.RavenSynchronizationSourcesBasePath, 0, int.MaxValue,
                                                                        out totalResults);
            });

            if (@from.Contains(filesystem.SynchronizationTask.FileSystemUrl) == false)
            {
                @from.Add(filesystem.SynchronizationTask.FileSystemUrl);
            }

            root.Destinations = HandleDestinations(syncDestinations);
            root.Sources      = HandleSources(sourceNames, root);

            return(root);
        }
        private List <SynchronizationTopologySourceNode> HandleSources(IEnumerable <string> sources, SynchronizationTopologyRootNode root)
        {
            var nodes = new List <SynchronizationTopologySourceNode>();

            foreach (var source in sources)
            {
                RavenJObject sourceAsJson = null;

                filesystem.Storage.Batch(accessor =>
                {
                    sourceAsJson = accessor.GetConfig(source);
                });

                SourceSynchronizationInformation sourceInfo = null;
                try
                {
                    sourceInfo = sourceAsJson.JsonDeserialization <SourceSynchronizationInformation>();
                }
                catch (Exception)
                {
                    root.Errors.Add("Could not deserialize source node.");
                }

                var sourceDatabaseId = Guid.Parse(source.Split('/').Last());
                var node             = HandleSource(sourceInfo, sourceDatabaseId);
                nodes.Add(node);
            }

            return(nodes);
        }
        private bool TryGetSchema(string serverUrl, RavenConnectionStringOptions connectionStringOptions, out SynchronizationTopologyRootNode rootNode, out string error)
        {
            var url = $"{serverUrl}/admin/replication/topology/discover?&ttl={ttl - 1}";

            try
            {
                var request = requestFactory.Create(url, HttpMethods.Post, connectionStringOptions);
                request.Write(from);

                error    = null;
                rootNode = request.ExecuteRequest <SynchronizationTopologyRootNode>();

                var visitedNodes = new HashSet <string>();
                FindVisitedNodes(rootNode, visitedNodes);
                foreach (var visitedNode in visitedNodes)
                {
                    if (@from.Contains(visitedNode) == false)
                    {
                        @from.Add(visitedNode);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                error    = e.Message;
                rootNode = null;
                return(false);
            }
        }