public void RunRoute(IRouteConfig routeConfig)
        {
            try
            {
                var route = _routeProvider.GetRoute(routeConfig);

                var completeMoment = (routeConfig.ForceAllContents ? DateTimeOffset.MinValue : _completeMomentProvider.GetCompleteMoment(route.Source.ID, route.Destination.ID));

                DateTimeOffset sourceLastModifiedMoment;
                var            contentIdentifiersList = GetReplicateContentIdentifiers(routeConfig, route, completeMoment, out sourceLastModifiedMoment).ToList();

                if (contentIdentifiersList.Any())
                {
                    _routeReplicator.ReplicateRouteContents(route, contentIdentifiersList, routeConfig.ConnectionCountLimit);
                }
                else
                {
                    var newCompleteMoment = new[] { completeMoment, sourceLastModifiedMoment }.Max();
                    _completeMomentProvider.SetCompleteMoment(route.Source.ID, route.Destination.ID, newCompleteMoment);
                }
            }
            finally
            {
                _completeMomentProvider.Finish();
            }
        }
Beispiel #2
0
 public static IRouteConfig GetRoutConfig()
 {
     if (routeConfig == null)
     {
         routeConfig = new RouteConfigClass();
     }
     return(routeConfig);
 }
        public IRoute GetRoute(IRouteConfig routeConfig)
        {
            _logger.LogTrace("Start getting route");

            var result = _routeProvider.GetRoute(routeConfig);

            _logger.LogTrace("End getting route");

            return(result);
        }
Beispiel #4
0
        public void RegisterRoute()
        {
            IRouteConfig config = Substitute.For <IRouteConfig>();

            DependencyResolver.Current.GetService <IRouteConfig>().Returns(config);

            application.RegisterRoute();

            config.Received().RegisterRoutes(RouteTable.Routes);
        }
        public void RegisterRoute_RegistersLowercaseUrls()
        {
            IRouteConfig routeConfig = Substitute.For <IRouteConfig>();

            DependencyResolver.Current.GetService <IRouteConfig>().Returns(routeConfig);

            application.RegisterRoute();

            Assert.True(RouteTable.Routes.LowercaseUrls);
        }
Beispiel #6
0
 private Task ProcessRouteAsync(IRouteConfig routeConfig)
 {
     if (routeConfig.HashCheckMoment != null)
     {
         return(HashCheckRouteAsync(routeConfig));
     }
     else
     {
         return(RunRouteAsync(routeConfig));
     }
 }
 public IRouteConfig GetRouteConfig(IRouteConfig routeConfig1, IRouteConfig routeConfig2)
 {
     return
         (_routeConfigFactory(
              routeConfig2.SourceConfig ?? routeConfig1.SourceConfig,
              routeConfig2.DestinationConfig ?? routeConfig1.DestinationConfig,
              Math.Max(routeConfig2.ContentCountLimit, routeConfig1.ContentCountLimit),
              Math.Max(routeConfig2.ConnectionCountLimit, routeConfig1.ConnectionCountLimit),
              routeConfig2.ForceAllContents || routeConfig1.ForceAllContents,
              routeConfig2.SkipDestinationCheck || routeConfig1.SkipDestinationCheck,
              routeConfig2.ParallelGetLists || routeConfig1.ParallelGetLists,
              routeConfig2.HashCheckMoment ?? routeConfig1.HashCheckMoment
              ));
 }
        public void HashCheckRoute(IRouteConfig routeConfig)
        {
            try
            {
                _logger.LogInfo($"Hash check until {routeConfig.HashCheckMoment}");

                _routeWorker.HashCheckRoute(routeConfig);

                _logger.LogInfo("Hash check succeeded.");
            }
            catch (Exception e)
            {
                _logger.LogFatal("Hash check failed.", e);
            }
        }
        public void HashCheckRoute(IRouteConfig routeConfig)
        {
            var route = _routeProvider.GetRoute(routeConfig);

            var sourceContentsHashTask      = route.Source.GetContentsHashAsync(routeConfig.HashCheckMoment.Value);
            var destinationContentsHashTask = route.Destination.GetContentsHashAsync(routeConfig.HashCheckMoment.Value);

            Task.WaitAll(sourceContentsHashTask, destinationContentsHashTask);

            var sourceContentsHash      = sourceContentsHashTask.Result;
            var destinationContentsHash = destinationContentsHashTask.Result;

            if (!string.Equals(sourceContentsHash, destinationContentsHash, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new UserException("Hashes do not match.");
            }
        }
        public IRoute GetRoute(IRouteConfig routeConfig)
        {
            if (routeConfig.SourceConfig == null)
            {
                RouteNotSpecifiedError("Invalid source!");
            }

            if (routeConfig.DestinationConfig == null)
            {
                RouteNotSpecifiedError("Invalid destination!");
            }

            var sourceResolver      = _sourceResolverProvider.GetResolver(routeConfig.SourceConfig);
            var destinationResolver = _destinationResolverProvider.GetResolver(routeConfig.DestinationConfig);

            var source      = sourceResolver.GetSource(routeConfig.SourceConfig);
            var destination = destinationResolver.GetDestination(routeConfig.DestinationConfig);

            return(_routeFactory(source, destination));
        }
        private IEnumerable <IContentIdentifier> GetReplicateContentIdentifiers(IRouteConfig routeConfig, IRoute route, DateTimeOffset completeMoment, out DateTimeOffset sourceLastModifiedMoment)
        {
            var sourceContentIdentifiersTask = route.Source.GetContentIdentifiersAsync(completeMoment);

            if (!routeConfig.ParallelGetLists)
            {
                sourceContentIdentifiersTask.Wait();
            }

            var destinationContentIdentifiersTask = route.Destination.GetContentIdentifiersAsync(completeMoment);

            Task.WaitAll(sourceContentIdentifiersTask, destinationContentIdentifiersTask);

            var sourceContentIdentifiers      = sourceContentIdentifiersTask.Result.ToList();      // ToList() to get the list once
            var destinationContentIdentifiers = destinationContentIdentifiersTask.Result.ToList(); // ToList() to get the list once

            sourceLastModifiedMoment = sourceContentIdentifiers.Select(x => x.ModifiedMoment).LastOrDefault();

            if (!routeConfig.SkipDestinationCheck)
            {
                var extraContentIdentifiers = destinationContentIdentifiers.Except(sourceContentIdentifiers);

                if (extraContentIdentifiers.Any())
                {
                    var contentIdentifier = extraContentIdentifiers.First();
                    throw new UserException(string.Format("Unknown destination content: {0}/{1}", contentIdentifier.Hash, contentIdentifier.Extension));
                }
            }

            var contentIdentifiers = sourceContentIdentifiers.Except(destinationContentIdentifiers);

            if (routeConfig.ContentCountLimit > 0)
            {
                contentIdentifiers = contentIdentifiers.Take(routeConfig.ContentCountLimit);
            }

            return(contentIdentifiers);
        }
 public void RunRoute(IRouteConfig routeConfig)
 {
     _routeWorker.RunRoute(routeConfig);
 }
Beispiel #13
0
 private Task HashCheckRouteAsync(IRouteConfig routeConfig)
 {
     return(Task.Factory.StartNew(() => _routeWorker.HashCheckRoute(routeConfig)));
 }
Beispiel #14
0
 public RouteDecideClass(IRouteConfig config)
 {
     this.routeConfig = config;
 }