예제 #1
0
        public ActionResult Index(FederationModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to save the bond
                try
                {
                    S_Federation federation = new S_Federation();
                    federation.information = model.Information;
                    federation.id          = model.Id;
                    federation.logo        = model.UrlLogo;

                    if (!FederationManager.FederationExistById(1))
                    {
                        FederationManager.Insert(federation);
                        TempData["message"] = "De bond is toegevoegd.";
                    }
                    else
                    {
                        FederationManager.Update(federation);
                        TempData["message"] = "De bond is bijgewerkt.";
                    }

                    return(RedirectToAction("index", "Bond"));
                }
                catch (Exception e)
                {
                    TempData["error"] = "Er is een fout opgetreden.";
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #2
0
        /// <summary>
        /// Ensure a search result source
        /// </summary>
        /// <param name="ssa">The search service application.</param>
        /// <param name="resultSourceName">The result source name</param>
        /// <param name="level">The search object level.</param>
        /// <param name="searchProvider">The search provider for the result source.</param>
        /// <param name="contextWeb">The SPWeb to retrieve the search context.</param>
        /// <param name="query">The search query in KQL format.</param>
        /// <param name="properties">Query properties.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="isDefaultResultSourceForOwner">Whether this result source will be flagged as the default for the current search owner</param>
        /// <returns>
        /// The result source.
        /// </returns>
        private static Source InnerEnsureResultSource(SearchServiceApplication ssa, string resultSourceName, SearchObjectLevel level, string searchProvider, SPWeb contextWeb, string query, QueryTransformProperties properties, bool overwrite, bool isDefaultResultSourceForOwner)
        {
            var federationManager = new FederationManager(ssa);
            var searchOwner       = new SearchObjectOwner(level, contextWeb);

            var resultSource = federationManager.GetSourceByName(resultSourceName, searchOwner);

            if (resultSource != null && overwrite)
            {
                federationManager.RemoveSource(resultSource);
            }

            if (resultSource == null || overwrite)
            {
                resultSource            = federationManager.CreateSource(searchOwner);
                resultSource.Name       = resultSourceName;
                resultSource.ProviderId = federationManager.ListProviders()[searchProvider].Id;
                resultSource.CreateQueryTransform(properties, query);
                resultSource.Commit();

                if (isDefaultResultSourceForOwner)
                {
                    federationManager.UpdateDefaultSource(resultSource.Id, searchOwner);
                }
            }

            return(resultSource);
        }
        public TestPoAMiner(
            IConsensusManager consensusManager,
            IDateTimeProvider dateTimeProvider,
            Network network,
            INodeLifetime nodeLifetime,
            ILoggerFactory loggerFactory,
            IInitialBlockDownloadState ibdState,
            BlockDefinition blockDefinition,
            SlotsManager slotsManager,
            IConnectionManager connectionManager,
            PoABlockHeaderValidator poaHeaderValidator,
            FederationManager federationManager,
            IIntegrityValidator integrityValidator,
            IWalletManager walletManager,
            INodeStats nodeStats,
            VotingManager votingManager) : base(consensusManager, dateTimeProvider, network, nodeLifetime, loggerFactory, ibdState, blockDefinition, slotsManager,
                                                connectionManager, poaHeaderValidator, federationManager, integrityValidator, walletManager, nodeStats, votingManager)
        {
            this.timeProvider = dateTimeProvider as EditableTimeProvider;

            this.cancellation      = new CancellationTokenSource();
            this.slotsManager      = slotsManager;
            this.consensusManager  = consensusManager;
            this.federationManager = federationManager;
        }
        public VotingController(FederationManager fedManager, ILoggerFactory loggerFactory, VotingManager votingManager)
        {
            this.fedManager    = fedManager;
            this.votingManager = votingManager;

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
        }
예제 #5
0
        protected Source GetCurrentSource(Microsoft.SharePoint.SPSite site, SearchResultDefinition definition)
        {
            FederationManager federationManager = null;
            SearchObjectOwner searchOwner       = null;

            return(GetCurrentSource(site, definition, out federationManager, out searchOwner));
        }
예제 #6
0
        public PollResultExecutor(FederationManager federationManager, ILoggerFactory loggerFactory, IWhitelistedHashesRepository whitelistedHashesRepository)
        {
            this.federationManager           = federationManager;
            this.whitelistedHashesRepository = whitelistedHashesRepository;

            this.logger = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode");
        }
        public PollResultExecutor(FederationManager federationManager, ILoggerFactory loggerFactory, IWhitelistedHashesRepository whitelistedHashesRepository)
        {
            this.federationManager           = federationManager;
            this.whitelistedHashesRepository = whitelistedHashesRepository;

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
        }
예제 #8
0
        public void GetMiningTimestamp()
        {
            var tool = new KeyTool(new DataFolder(string.Empty));
            Key key  = tool.GeneratePrivateKey();

            this.network = new TestPoANetwork(new List <PubKey>()
            {
                tool.GeneratePrivateKey().PubKey, key.PubKey, tool.GeneratePrivateKey().PubKey
            });

            FederationManager fedManager = PoATestsBase.CreateFederationManager(this, this.network, new ExtendedLoggerFactory());

            this.slotsManager = new SlotsManager(this.network, fedManager, new LoggerFactory());

            List <PubKey> fedKeys    = this.federationManager.GetFederationMembers();
            uint          roundStart = this.consensusOptions.TargetSpacingSeconds * (uint)fedKeys.Count * 5;

            fedManager.SetPrivatePropertyValue(nameof(FederationManager.IsFederationMember), true);
            fedManager.SetPrivatePropertyValue(nameof(FederationManager.FederationMemberKey), key);

            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart));
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart + 4));

            roundStart += this.consensusOptions.TargetSpacingSeconds * (uint)fedKeys.Count;
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart - 5));
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart - this.consensusOptions.TargetSpacingSeconds + 1));

            Assert.True(this.slotsManager.IsValidTimestamp(this.slotsManager.GetMiningTimestamp(roundStart - 5)));
        }
예제 #9
0
 public SmartContractPoARuleEngine(
     ICallDataSerializer callDataSerializer,
     ConcurrentChain chain,
     ICheckpoints checkpoints,
     ConsensusSettings consensusSettings,
     IDateTimeProvider dateTimeProvider,
     IContractExecutorFactory executorFactory,
     ILoggerFactory loggerFactory,
     Network network,
     NodeDeployments nodeDeployments,
     IStateRepositoryRoot originalStateRoot,
     IReceiptRepository receiptRepository,
     ISenderRetriever senderRetriever,
     ICoinView utxoSet,
     IChainState chainState,
     IInvalidBlockHashStore invalidBlockHashStore,
     INodeStats nodeStats,
     SlotsManager slotsManager,
     PoABlockHeaderValidator poaHeaderValidator,
     VotingManager votingManager,
     FederationManager federationManager)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState,
            invalidBlockHashStore, nodeStats, slotsManager, poaHeaderValidator, votingManager, federationManager)
 {
     this.CallDataSerializer = callDataSerializer;
     this.ExecutorFactory    = executorFactory;
     this.OriginalStateRoot  = originalStateRoot;
     this.ReceiptRepository  = receiptRepository;
     this.SenderRetriever    = senderRetriever;
 }
예제 #10
0
        public void GetMiningTimestamp()
        {
            var tool = new KeyTool(null);
            Key key  = tool.GeneratePrivateKey();

            this.network = new TestPoANetwork(new List <PubKey>()
            {
                tool.GeneratePrivateKey().PubKey, key.PubKey, tool.GeneratePrivateKey().PubKey
            });

            var fedManager = new FederationManager(NodeSettings.Default(this.network), this.network, new LoggerFactory());

            this.slotsManager = new SlotsManager(this.network, fedManager, new LoggerFactory());

            List <PubKey> fedKeys    = this.consensusOptions.FederationPublicKeys;
            uint          roundStart = this.consensusOptions.TargetSpacingSeconds * (uint)fedKeys.Count * 5;

            fedManager.SetPrivatePropertyValue(nameof(FederationManager.IsFederationMember), true);
            fedManager.SetPrivatePropertyValue(nameof(FederationManager.FederationMemberKey), key);

            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart));
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart + 4));

            roundStart += this.consensusOptions.TargetSpacingSeconds * (uint)fedKeys.Count;
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart - 5));
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart - this.consensusOptions.TargetSpacingSeconds + 1));

            Assert.True(this.slotsManager.IsValidTimestamp(this.slotsManager.GetMiningTimestamp(roundStart - 5)));
        }
예제 #11
0
        public SlotsManagerTests()
        {
            this.network          = new TestPoANetwork();
            this.consensusOptions = this.network.ConsensusOptions;

            this.federationManager = PoATestsBase.CreateFederationManager(this);
            this.slotsManager      = new SlotsManager(this.network, this.federationManager, new LoggerFactory());
        }
예제 #12
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var siteModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull());
            var definition    = model.WithAssertAndCast <SearchResultDefinition>("model", value => value.RequireNotNull());

            FederationManager federationManager = null;
            SearchObjectOwner searchOwner       = null;

            var spObject = GetCurrentSource(siteModelHost.HostSite, definition, out federationManager, out searchOwner);

            var assert = ServiceFactory.AssertService
                         .NewAssert(definition, spObject)
                         .ShouldNotBeNull(spObject)
                         .ShouldBeEqual(m => m.Name, o => o.Name)
                         .ShouldBeEqual(m => m.Query, o => o.GetQuery())
                         .ShouldBeEqual(m => m.Description, o => o.Description);

            if (definition.ProviderId.HasValue)
            {
                assert.ShouldBeEqual(m => m.ProviderId, o => o.ProviderId);
            }
            else
            {
                assert.SkipProperty(m => m.ProviderId, "ProviderId is NULL. Skipping.");
            }

            assert.ShouldBeEqual((p, s, d) =>
            {
                var srcProp        = s.GetExpressionValue(m => m.ProviderName);
                var searchProvider = GetProviderByName(federationManager, s.ProviderName);

                var isValid = searchProvider.Name == s.ProviderName;

                return(new PropertyValidationResult
                {
                    Tag = p.Tag,
                    Src = srcProp,
                    Dst = null,
                    IsValid = isValid
                });
            });

            assert.ShouldBeEqual((p, s, d) =>
            {
                var srcProp       = s.GetExpressionValue(m => m.IsDefault);
                var defaultSource = GetDefaultSource(federationManager, searchOwner);

                var isValid = defaultSource.Name == d.Name;

                return(new PropertyValidationResult
                {
                    Tag = p.Tag,
                    Src = srcProp,
                    Dst = null,
                    IsValid = isValid
                });
            });
        }
예제 #13
0
        public VotingController(FederationManager fedManager, ILoggerFactory loggerFactory, VotingManager votingManager,
                                IWhitelistedHashesRepository whitelistedHashesRepository)
        {
            this.fedManager    = fedManager;
            this.votingManager = votingManager;
            this.whitelistedHashesRepository = whitelistedHashesRepository;

            this.logger = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode");
        }
예제 #14
0
        public VotingController(FederationManager fedManager, ILoggerFactory loggerFactory, VotingManager votingManager,
                                IWhitelistedHashesRepository whitelistedHashesRepository)
        {
            this.fedManager    = fedManager;
            this.votingManager = votingManager;
            this.whitelistedHashesRepository = whitelistedHashesRepository;

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
        }
예제 #15
0
        public SlotsManagerTests()
        {
            this.network          = new TestPoANetwork();
            this.consensusOptions = this.network.ConsensusOptions;

            var fedManager = new FederationManager(NodeSettings.Default(this.network), this.network, new LoggerFactory());

            this.slotsManager = new SlotsManager(this.network, fedManager, new LoggerFactory());
        }
예제 #16
0
        public void EnsureResultSource_WhenRevertingAppendedQuery_ShouldRevertToPreviousQuery()
        {
            const string ResultSourceName = "Test Result Source";
            const string Query            = "{?{searchTerms} -ContentClass=urn:content-class:SPSPeople}";
            const string AppendedQuery    = "{?{|owstaxidmetadataalltagsinfo:{User.SPSResponsibility}}}";

            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var resultSourceInfo = new ResultSourceInfo()
                {
                    Name       = ResultSourceName,
                    Level      = SearchObjectLevel.SPSite,
                    Query      = Query,
                    UpdateMode = ResultSourceUpdateBehavior.OverwriteResultSource
                };

                var appendedResultSourceInfo = new ResultSourceInfo()
                {
                    Name       = ResultSourceName,
                    Level      = SearchObjectLevel.SPSite,
                    Query      = AppendedQuery,
                    UpdateMode = ResultSourceUpdateBehavior.AppendToQuery
                };

                var revertedResultSourceInfo = new ResultSourceInfo()
                {
                    Name       = ResultSourceName,
                    Level      = SearchObjectLevel.SPSite,
                    Query      = AppendedQuery,
                    UpdateMode = ResultSourceUpdateBehavior.RevertQuery
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var searchHelper      = injectionScope.Resolve <ISearchHelper>();
                    var ssa               = searchHelper.GetDefaultSearchServiceApplication(testScope.SiteCollection);
                    var federationManager = new FederationManager(ssa);
                    var searchOwner       = new SearchObjectOwner(SearchObjectLevel.SPSite, testScope.SiteCollection.RootWeb);

                    // Act
                    searchHelper.EnsureResultSource(testScope.SiteCollection, resultSourceInfo);
                    searchHelper.EnsureResultSource(testScope.SiteCollection, appendedResultSourceInfo);
                    searchHelper.EnsureResultSource(testScope.SiteCollection, revertedResultSourceInfo);

                    // Assert
                    var source = federationManager.GetSourceByName(ResultSourceName, searchOwner);

                    Assert.IsNotNull(source);
                    Assert.IsNotNull(source.QueryTransform);
                    Assert.AreEqual(ResultSourceName, source.Name);
                    Assert.AreEqual(Query, source.QueryTransform.QueryTemplate);
                }
            }
        }
예제 #17
0
        private void DeploySearchResult(object modelHost, Microsoft.SharePoint.SPSite site, SearchResultDefinition definition)
        {
            FederationManager federationManager = null;
            SearchObjectOwner searchOwner       = null;

            var currentSource = GetCurrentSource(site, definition, out federationManager, out searchOwner);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = currentSource,
                ObjectType       = typeof(Source),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            if (currentSource == null)
            {
                currentSource      = federationManager.CreateSource(searchOwner);
                currentSource.Name = definition.Name;

                if (definition.ProviderId.HasValue)
                {
                    currentSource.ProviderId = definition.ProviderId.Value;
                }
                else
                {
                    currentSource.ProviderId = GetProviderByName(federationManager, definition.ProviderName).Id;
                }
            }

            currentSource.Description = definition.Description ?? string.Empty;
            currentSource.CreateQueryTransform(new QueryTransformProperties(), definition.Query);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = currentSource,
                ObjectType       = typeof(Source),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            currentSource.Commit();

            if (definition.IsDefault)
            {
                federationManager.UpdateDefaultSource(currentSource.Id, searchOwner);
            }
        }
예제 #18
0
        public VotingManager(FederationManager federationManager, ILoggerFactory loggerFactory, IKeyValueRepository keyValueRepo, SlotsManager slotsManager)
        {
            this.federationManager   = federationManager;
            this.keyValueRepo        = keyValueRepo;
            this.locker              = new object();
            this.votingDataEncoder   = new VotingDataEncoder(loggerFactory);
            this.slotsManager        = slotsManager;
            this.scheduledVotingData = new List <VotingData>();

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
        }
예제 #19
0
        public static (IFederationManager federationManager, IFederationHistory federationHistory) CreateFederationManager(object caller, Network network, LoggerFactory loggerFactory, ISignals signals)
        {
            string dir = TestBase.CreateTestDir(caller);

            var dbreezeSerializer = new DBreezeSerializer(network.Consensus.ConsensusFactory);

            var nodeSettings = new NodeSettings(network, args: new string[] { $"-datadir={dir}" });

            Key federationKey = new Mnemonic("lava frown leave wedding virtual ghost sibling able mammal liar wide wisdom").DeriveExtKey().PrivateKey;

            new KeyTool(nodeSettings.DataFolder).SavePrivateKey(federationKey);

            var consensusManager = new Mock <IConsensusManager>();

            consensusManager.Setup(c => c.Tip).Returns(new ChainedHeader(network.GetGenesis().Header, network.GenesisHash, 0));

            var fullNode = new Mock <IFullNode>();

            fullNode.Setup(x => x.NodeService <IConsensusManager>(false)).Returns(consensusManager.Object);

            var counterChainSettings = new CounterChainSettings(nodeSettings, new CounterChainNetworkWrapper(new StraxRegTest()));

            var federationManager = new FederationManager(fullNode.Object, network, nodeSettings, signals, counterChainSettings);
            var asyncProvider     = new AsyncProvider(loggerFactory, signals);

            var chainIndexerMock = new Mock <ChainIndexer>();
            var header           = new BlockHeader();

            chainIndexerMock.Setup(x => x.Tip).Returns(new ChainedHeader(header, header.GetHash(), 0));
            var votingManager = new VotingManager(federationManager, loggerFactory,
                                                  new Mock <IPollResultExecutor>().Object, new Mock <INodeStats>().Object, nodeSettings.DataFolder, dbreezeSerializer, signals, network, null, chainIndexerMock.Object, null, nodeSettings);

            var federationHistory = new Mock <IFederationHistory>();

            federationHistory.Setup(x => x.GetFederationMemberForBlock(It.IsAny <ChainedHeader>())).Returns <ChainedHeader>((chainedHeader) =>
            {
                List <IFederationMember> members = ((PoAConsensusOptions)network.Consensus.Options).GenesisFederationMembers;
                return(members[chainedHeader.Height % members.Count]);
            });

            federationHistory.Setup(x => x.GetFederationForBlock(It.IsAny <ChainedHeader>())).Returns <ChainedHeader>((chainedHeader) =>
            {
                return(((PoAConsensusOptions)network.Consensus.Options).GenesisFederationMembers);
            });

            federationHistory.Setup(x => x.CanGetFederationForBlock(It.IsAny <ChainedHeader>())).Returns <ChainedHeader>((chainedHeader) => true);

            votingManager.Initialize(federationHistory.Object);
            fullNode.Setup(x => x.NodeService <VotingManager>(It.IsAny <bool>())).Returns(votingManager);
            federationManager.Initialize();

            return(federationManager, federationHistory.Object);
        }
예제 #20
0
        protected Source GetCurrentSource(Microsoft.SharePoint.SPSite site, SearchResultDefinition definition,
            out FederationManager federationManager,
            out SearchObjectOwner searchOwner)
        {
            var context = SPServiceContext.GetContext(site);
            var searchAppProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;

            federationManager = new FederationManager(searchAppProxy);
            searchOwner = new SearchObjectOwner(SearchObjectLevel.SPSite, site.RootWeb);

            return federationManager.GetSourceByName(definition.Name, searchOwner);
        }
예제 #21
0
        public static FederationManager CreateFederationManager(object caller, Network network, LoggerFactory loggerFactory)
        {
            string dir          = TestBase.CreateTestDir(caller);
            var    keyValueRepo = new KeyValueRepository(dir, new DBreezeSerializer(network));

            var settings          = new NodeSettings(network, args: new string[] { $"-datadir={dir}" });
            var federationManager = new FederationManager(settings, network, loggerFactory, keyValueRepo);

            federationManager.Initialize();

            return(federationManager);
        }
예제 #22
0
        protected Source GetCurrentSource(Microsoft.SharePoint.SPSite site, SearchResultDefinition definition,
                                          out FederationManager federationManager,
                                          out SearchObjectOwner searchOwner)
        {
            var context        = SPServiceContext.GetContext(site);
            var searchAppProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;

            federationManager = new FederationManager(searchAppProxy);
            searchOwner       = new SearchObjectOwner(SearchObjectLevel.SPSite, site.RootWeb);

            return(federationManager.GetSourceByName(definition.Name, searchOwner));
        }
예제 #23
0
        public static IFederationManager CreateFederationManager(object caller, Network network, LoggerFactory loggerFactory, ISignals signals)
        {
            string dir          = TestBase.CreateTestDir(caller);
            var    keyValueRepo = new LeveldbKeyValueRepository(dir, new DataStoreSerializer(network.Consensus.ConsensusFactory));

            var settings          = new NodeSettings(network, args: new string[] { $"-datadir={dir}" });
            var federationManager = new FederationManager(settings, network, loggerFactory, keyValueRepo, signals);

            federationManager.Initialize();

            return(federationManager);
        }
예제 #24
0
        private void InitializeCollateralChecker([CallerMemberName] string callingMethod = "")
        {
            var loggerFactory = new LoggerFactory();
            IHttpClientFactory clientFactory = new Bitcoin.Controllers.HttpClientFactory();

            Network network = CirrusNetwork.NetworksSelector.Regtest();

            this.collateralFederationMembers = new List <CollateralFederationMember>()
            {
                new CollateralFederationMember(new PubKey("036317d97f911ce899fd0a360866d19f2dca5252c7960d4652d814ab155a8342de"), false, new Money(100), "addr1"),
                new CollateralFederationMember(new PubKey("02a08d72d47b3103261163c15aa2f6b0d007e1872ad9f5fddbfbd27bdb738156e9"), false, new Money(500), "addr2"),
                new CollateralFederationMember(new PubKey("03634c79d4e8e915cfb9f7bbef57bed32d715150836b7845b1a14c93670d816ab6"), false, new Money(100_000), "addr3")
            };

            List <IFederationMember> federationMembers = (network.Consensus.Options as PoAConsensusOptions).GenesisFederationMembers;

            federationMembers.Clear();
            federationMembers.AddRange(this.collateralFederationMembers);

            var dataFolder = TestBase.CreateTestDir(callingMethod);
            FederatedPegSettings fedPegSettings = FedPegTestsHelper.CreateSettings(network, KnownNetworks.StraxRegTest, dataFolder, out NodeSettings nodeSettings);

            var counterChainSettings = new CounterChainSettings(nodeSettings, new CounterChainNetworkWrapper(Networks.Strax.Regtest()));
            var asyncMock            = new Mock <IAsyncProvider>();

            asyncMock.Setup(a => a.RegisterTask(It.IsAny <string>(), It.IsAny <Task>()));

            ISignals signals            = new Signals(loggerFactory, new DefaultSubscriptionErrorHandler(loggerFactory));
            var      dbreezeSerializer  = new DBreezeSerializer(network.Consensus.ConsensusFactory);
            var      asyncProvider      = new AsyncProvider(loggerFactory, signals);
            var      finalizedBlockRepo = new FinalizedBlockInfoRepository(new LevelDbKeyValueRepository(nodeSettings.DataFolder, dbreezeSerializer), asyncProvider);

            finalizedBlockRepo.LoadFinalizedBlockInfoAsync(network).GetAwaiter().GetResult();

            var chainIndexerMock = new Mock <ChainIndexer>();
            var header           = new BlockHeader();

            chainIndexerMock.Setup(x => x.Tip).Returns(new ChainedHeader(header, header.GetHash(), 0));
            var fullNode = new Mock <IFullNode>();

            IFederationManager federationManager = new FederationManager(fullNode.Object, network, nodeSettings, signals, counterChainSettings);
            var votingManager     = new VotingManager(federationManager, new Mock <IPollResultExecutor>().Object, new Mock <INodeStats>().Object, nodeSettings.DataFolder, dbreezeSerializer, signals, finalizedBlockRepo, network);
            var federationHistory = new FederationHistory(federationManager, votingManager);

            votingManager.Initialize(federationHistory);

            fullNode.Setup(x => x.NodeService <VotingManager>(It.IsAny <bool>())).Returns(votingManager);

            federationManager.Initialize();

            this.collateralChecker = new CollateralChecker(clientFactory, counterChainSettings, federationManager, signals, network, asyncMock.Object, (new Mock <INodeLifetime>()).Object);
        }
예제 #25
0
 public FederationGatewayController(
     ILoggerFactory loggerFactory,
     IMaturedBlocksProvider maturedBlocksProvider,
     IFederationGatewaySettings federationGatewaySettings,
     IFederationWalletManager federationWalletManager,
     FederationManager federationManager = null)
 {
     this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
     this.maturedBlocksProvider     = maturedBlocksProvider;
     this.federationGatewaySettings = federationGatewaySettings;
     this.federationWalletManager   = federationWalletManager;
     this.federationManager         = federationManager;
 }
예제 #26
0
 public FederationGatewayController(
     ILoggerFactory loggerFactory,
     IMaturedBlocksProvider maturedBlocksProvider,
     IFederationGatewaySettings federationGatewaySettings,
     IFederationWalletManager federationWalletManager,
     FederationManager federationManager = null)
 {
     this.logger = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode");
     this.maturedBlocksProvider     = maturedBlocksProvider;
     this.federationGatewaySettings = federationGatewaySettings;
     this.federationWalletManager   = federationWalletManager;
     this.federationManager         = federationManager;
 }
예제 #27
0
        /// <summary>
        /// Deletes the result source.
        /// </summary>
        /// <param name="contextSite">Current site collection</param>
        /// <param name="resultSourceName">Name of the result source.</param>
        /// <param name="level">The level.</param>
        public void DeleteResultSource(SPSite contextSite, string resultSourceName, SearchObjectLevel level)
        {
            var searchApp         = this.GetDefaultSearchServiceApplication(contextSite);
            var federationManager = new FederationManager(searchApp);
            var searchOwner       = new SearchObjectOwner(level, contextSite.RootWeb);

            var resultSource = federationManager.GetSourceByName(resultSourceName, searchOwner);

            if (resultSource != null)
            {
                federationManager.RemoveSource(resultSource);
            }
        }
        public IdleFederationMembersKicker(ISignals signals, Network network, IKeyValueRepository keyValueRepository, IConsensusManager consensusManager,
                                           FederationManager federationManager, SlotsManager slotsManager, VotingManager votingManager, ILoggerFactory loggerFactory)
        {
            this.signals            = signals;
            this.network            = network;
            this.keyValueRepository = keyValueRepository;
            this.consensusManager   = consensusManager;
            this.federationManager  = federationManager;
            this.slotsManager       = slotsManager;
            this.votingManager      = votingManager;

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
            this.federationMemberMaxIdleTimeSeconds = ((PoAConsensusOptions)network.Consensus.Options).FederationMemberMaxIdleTimeSeconds;
        }
예제 #29
0
        /// <inheritdoc />
        public override void Initialize()
        {
            base.Initialize();

            PoAConsensusRuleEngine engine = this.Parent as PoAConsensusRuleEngine;

            this.slotsManager      = engine.SlotsManager;
            this.validator         = engine.PoaHeaderValidator;
            this.votingManager     = engine.VotingManager;
            this.federationManager = engine.FederationManager;
            this.chainState        = engine.ChainState;

            this.maxReorg      = this.Parent.Network.Consensus.MaxReorgLength;
            this.votingEnabled = ((PoAConsensusOptions)this.Parent.Network.Consensus.Options).VotingEnabled;
        }
        public FederationGatewayControllerTests()
        {
            this.network = FederatedPegNetwork.NetworksSelector.Regtest();

            this.loggerFactory = Substitute.For <ILoggerFactory>();
            this.logger        = Substitute.For <ILogger>();
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.leaderProvider            = Substitute.For <ILeaderProvider>();
            this.depositExtractor          = Substitute.For <IDepositExtractor>();
            this.leaderReceiver            = Substitute.For <ILeaderReceiver>();
            this.consensusManager          = Substitute.For <IConsensusManager>();
            this.federationGatewaySettings = Substitute.For <IFederationGatewaySettings>();
            this.federationWalletManager   = Substitute.For <IFederationWalletManager>();
            this.federationManager         = new FederationManager(NodeSettings.Default(this.network), this.network, this.loggerFactory);
        }
예제 #31
0
        public ActionResult Index()
        {
            S_Federation    federation;
            FederationModel federationModel = new FederationModel();

            if (FederationManager.FederationExistById(1))
            {
                federation                  = FederationManager.GetFederationById(1);
                federationModel.Id          = federation.id;
                federationModel.Information = federation.information;
                federationModel.UrlLogo     = federation.logo;
            }

            return(View(federationModel));
        }
예제 #32
0
        public void EnsureResultSource_WhenSortingByRank_ShouldApplySpecifiedRankingModel()
        {
            const string ResultSourceName = "Test Result Source";

            // Arrange
            using (var testScope = SiteTestScope.BlankSite())
            {
                var resultSourceInfo = new ResultSourceInfo()
                {
                    Name = ResultSourceName,
                    Level = SearchObjectLevel.SPSite,
                    Query = "{?{searchTerms} -ContentClass=urn:content-class:SPSPeople}",
                    SortSettings = new Dictionary<string, SortDirection>()
                    {
                        { BuiltInManagedProperties.Rank.Name, SortDirection.Descending }
                    },
                    RankingModelId = BuiltInRankingModels.DefaultSearchModelId,
                    UpdateMode = ResultSourceUpdateBehavior.OverwriteResultSource
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var searchHelper = injectionScope.Resolve<ISearchHelper>();
                    var ssa = searchHelper.GetDefaultSearchServiceApplication(testScope.SiteCollection);
                    var federationManager = new FederationManager(ssa);
                    var searchOwner = new SearchObjectOwner(SearchObjectLevel.SPSite, testScope.SiteCollection.RootWeb);

                    // Act
                    searchHelper.EnsureResultSource(testScope.SiteCollection, resultSourceInfo);

                    // Assert
                    var source = federationManager.GetSourceByName(ResultSourceName, searchOwner);

                    Assert.IsNotNull(source);
                    Assert.AreEqual(ResultSourceName, source.Name);
                    Assert.AreEqual(BuiltInRankingModels.DefaultSearchModelId.ToString(), source.QueryTransform.OverrideProperties["RankingModelId"]);
                }
            }
        }
예제 #33
0
        public void EnsureResultSource_WhenRevertingAppendedQuery_ShouldRevertToPreviousQuery()
        {
            const string ResultSourceName = "Test Result Source";
            const string Query = "{?{searchTerms} -ContentClass=urn:content-class:SPSPeople}";
            const string AppendedQuery = "{?{|owstaxidmetadataalltagsinfo:{User.SPSResponsibility}}}";

            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var resultSourceInfo = new ResultSourceInfo()
                {
                    Name = ResultSourceName,
                    Level = SearchObjectLevel.SPSite,
                    Query = Query,
                    UpdateMode = ResultSourceUpdateBehavior.OverwriteResultSource
                };

                var appendedResultSourceInfo = new ResultSourceInfo()
                {
                    Name = ResultSourceName,
                    Level = SearchObjectLevel.SPSite,
                    Query = AppendedQuery,
                    UpdateMode = ResultSourceUpdateBehavior.AppendToQuery
                };

                var revertedResultSourceInfo = new ResultSourceInfo()
                {
                    Name = ResultSourceName,
                    Level = SearchObjectLevel.SPSite,
                    Query = AppendedQuery,
                    UpdateMode = ResultSourceUpdateBehavior.RevertQuery
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var searchHelper = injectionScope.Resolve<ISearchHelper>();
                    var ssa = searchHelper.GetDefaultSearchServiceApplication(testScope.SiteCollection);
                    var federationManager = new FederationManager(ssa);
                    var searchOwner = new SearchObjectOwner(SearchObjectLevel.SPSite, testScope.SiteCollection.RootWeb);

                    // Act
                    searchHelper.EnsureResultSource(testScope.SiteCollection, resultSourceInfo);
                    searchHelper.EnsureResultSource(testScope.SiteCollection, appendedResultSourceInfo);
                    searchHelper.EnsureResultSource(testScope.SiteCollection, revertedResultSourceInfo);

                    // Assert
                    var source = federationManager.GetSourceByName(ResultSourceName, searchOwner);

                    Assert.IsNotNull(source);
                    Assert.IsNotNull(source.QueryTransform);
                    Assert.AreEqual(ResultSourceName, source.Name);
                    Assert.AreEqual(Query, source.QueryTransform.QueryTemplate);
                }
            }
        }
예제 #34
0
        /// <summary>
        /// Deletes the result source.
        /// </summary>
        /// <param name="contextSite">Current site collection</param>
        /// <param name="resultSourceName">Name of the result source.</param>
        /// <param name="level">The level.</param>
        public void DeleteResultSource(SPSite contextSite, string resultSourceName, SearchObjectLevel level)
        {
            var searchApp = this.GetDefaultSearchServiceApplication(contextSite);
            var federationManager = new FederationManager(searchApp);
            var searchOwner = new SearchObjectOwner(level, contextSite.RootWeb);

            var resultSource = federationManager.GetSourceByName(resultSourceName, searchOwner);
            if (resultSource != null)
            {
                federationManager.RemoveSource(resultSource);
            }
        }
예제 #35
0
 protected Source GetDefaultSource(FederationManager federationManager, SearchObjectOwner owner)
 {
     return federationManager.GetDefaultSource(owner);
 }
예제 #36
0
        /// <summary>
        /// Ensure a search result source
        /// </summary>
        /// <param name="ssa">The search service application.</param>
        /// <param name="resultSourceName">The result source name</param>
        /// <param name="level">The search object level.</param>
        /// <param name="searchProvider">The search provider for the result source.</param>
        /// <param name="contextWeb">The SPWeb to retrieve the search context.</param>
        /// <param name="query">The search query in KQL format.</param>
        /// <param name="properties">Query properties.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="isDefaultResultSourceForOwner">Whether this result source will be flagged as the default for the current search owner</param>
        /// <returns>
        /// The result source.
        /// </returns>
        private static Source InnerEnsureResultSource(SearchServiceApplication ssa, string resultSourceName, SearchObjectLevel level, string searchProvider, SPWeb contextWeb, string query, QueryTransformProperties properties, bool overwrite, bool isDefaultResultSourceForOwner)
        {
            var federationManager = new FederationManager(ssa);
            var searchOwner = new SearchObjectOwner(level, contextWeb);

            var resultSource = federationManager.GetSourceByName(resultSourceName, searchOwner);

            if (resultSource != null && overwrite)
            {
                federationManager.RemoveSource(resultSource);
            }

            if (resultSource == null || overwrite)
            {
                resultSource = federationManager.CreateSource(searchOwner);
                resultSource.Name = resultSourceName;
                resultSource.ProviderId = federationManager.ListProviders()[searchProvider].Id;
                resultSource.CreateQueryTransform(properties, query);
                resultSource.Commit();

                if (isDefaultResultSourceForOwner)
                {
                    federationManager.UpdateDefaultSource(resultSource.Id, searchOwner);
                }
            }

            return resultSource;
        }
예제 #37
0
 protected SearchProvider GetProviderByName(FederationManager federationManager, string providerName)
 {
     return federationManager.ListProviders()[providerName];
 }