private void OnHostUp(Host h) { if (!Configuration.QueryOptions.IsReprepareOnUp()) { return; } // We should prepare all current queries on the host PrepareHandler.PrepareAllQueries(h, PreparedQueries.Values, _connectedSessions).Forget(); }
/// <inheritdoc /> public async Task <PreparedStatement> PrepareAsync(string query, IDictionary <string, byte[]> customPayload) { var request = new PrepareRequest(query) { Payload = customPayload }; return(await PrepareHandler.Prepare(this, _serializer, request).ConfigureAwait(false)); }
private PrepareHandlerMockResult BuildPrepareHandler(Action <TestConfigurationBuilder> configBuilderAct) { var factory = new FakeConnectionFactory(MockConnection); // create config var configBuilder = new TestConfigurationBuilder { ControlConnectionFactory = new FakeControlConnectionFactory(), ConnectionFactory = factory, Policies = new Cassandra.Policies(new RoundRobinPolicy(), new ConstantReconnectionPolicy(100), new DefaultRetryPolicy()) }; configBuilderAct(configBuilder); var config = configBuilder.Build(); var initializerMock = Mock.Of <IInitializer>(); Mock.Get(initializerMock).Setup(i => i.ContactPoints).Returns(new List <IPEndPoint> { new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9042), new IPEndPoint(IPAddress.Parse("127.0.0.2"), 9042), new IPEndPoint(IPAddress.Parse("127.0.0.3"), 9042) }); Mock.Get(initializerMock).Setup(i => i.GetConfiguration()).Returns(config); // create cluster var cluster = Cluster.BuildFrom(initializerMock, new List <string>()); cluster.Connect(); factory.CreatedConnections.Clear(); // create session var session = new Session(cluster, config, null, SerializerManager.Default, null); // create prepare handler var prepareHandler = new PrepareHandler(new SerializerManager(ProtocolVersion.V3).GetCurrentSerializer(), cluster); // create mock result object var mockResult = new PrepareHandlerMockResult(prepareHandler, session, factory); return(mockResult); }
public void Run(Replica[] activeReplicas, CancellationToken cancellationToken) { // process messages Task.Factory.StartNew(() => { var signedByPrimaryReplicaAheadBlocksOrTreeHashAndCounterViewNumber = new byte[0]; var encryptedViewKey = string.Empty; var viewChangesCount = new ConcurrentDictionary <int, int>(); var replicaSecrets = new Dictionary <int, byte[]>(2); var block = new int[0]; var replicaSecretShare = string.Empty; var secretHash = default(uint); var childSecretHashes = new Dictionary <int, uint>(); var verifiedChildShareSecrets = new ConcurrentDictionary <int, string>(); var secretShareMessageTokenSources = new Dictionary <int, CancellationTokenSource>(); Log("Running..."); while (cancellationToken.IsCancellationRequested == false) { var message = ReceiveMessage(); if (message == null) { Thread.Sleep(10); continue; } if (Tee.ViewKey == 0) { var newViewMessage = message as NewViewMessage; if (newViewMessage != null) { Log("Received NewViewMessage"); NewViewHandler.Handle( newViewMessage, this, activeReplicas, out signedByPrimaryReplicaAheadBlocksOrTreeHashAndCounterViewNumber, out encryptedViewKey); } var viewChangeMessage = message as ViewChangeMessage; if (viewChangeMessage != null) { Log("Received ViewChangeMessage (SourceReplicaId: {0})", viewChangeMessage.ReplicaId); ViewChangeHandler.Handle( viewChangeMessage, this, activeReplicas, viewChangesCount, signedByPrimaryReplicaAheadBlocksOrTreeHashAndCounterViewNumber, encryptedViewKey); } continue; } var preprocessingMessage = message as PreprocessingMessage; if (preprocessingMessage != null) { Log("Received PreprocessingMessage"); childSecretHashes.Clear(); secretShareMessageTokenSources.Clear(); verifiedChildShareSecrets.Clear(); PreprocessingHandler.Handle(preprocessingMessage, replicaSecrets); } var prepareMessage = message as PrepareMessage; if (prepareMessage != null) { Log("Received PrepareMessage"); PrepareHandler.Handle( prepareMessage, this, replicaSecrets[0], out block, out replicaSecretShare, out childSecretHashes, out secretHash, secretShareMessageTokenSources ); } var secretShareMessage = message as SecretShareMessage; if (secretShareMessage != null) { Log("Received SecretShareMessage (SourceReplicaId: {0})", secretShareMessage.ReplicaId); SecretShareHandler.Handle( secretShareMessage, this, replicaSecretShare, childSecretHashes, secretShareMessageTokenSources, verifiedChildShareSecrets); } var commitMessage = message as CommitMessage; if (commitMessage != null) { Log("Received CommitMessage"); childSecretHashes.Clear(); secretShareMessageTokenSources.Clear(); verifiedChildShareSecrets.Clear(); CommitHandler.Handle( commitMessage, this, secretHash, block, Blockchain, replicaSecrets[1], out replicaSecretShare, out childSecretHashes, secretShareMessageTokenSources); replicaSecrets.Clear(); } } Log("Stopped."); }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
public PrepareHandlerMockResult(PrepareHandler prepareHandler, IInternalSession session, FakeConnectionFactory factory) { PrepareHandler = prepareHandler; Session = session; ConnectionFactory = factory; }
/// <summary> /// The prepare fields. /// </summary> /// <param name="fields"> /// The fields. /// </param> /// <param name="initials"> /// The initials. /// </param> /// <param name="documents"> /// The documents. /// </param> /// <exception cref="Exception"> /// </exception> public void PrepareFields(List <SearchField> fields, List <FIO> initials = null, List <IDCard> documents = null) { permittedFields = new List <FieldTypes>(); preparedKeys = new List <PreparedKey>(); preparedFields = new List <SearchField>(); preparedInitials = new List <FIO>(); preparedDocuments = new List <IDCard>(); try { permittedFields = GetPermittedFields(); if (fields != null) { foreach (var field in fields) { if (permittedFields.Contains(field.fieldType) && !string.IsNullOrEmpty(field.value)) { prepareHandler = RetrieveHandler(field.fieldType); preparedFields.Add(prepareHandler(field)); } } } if (initials != null) { foreach (var fio in initials) { var type = FieldTypes.FamilyName; if (permittedFields.Contains(type) && fio.familyName != null && !string.IsNullOrEmpty(fio.familyName.value)) { prepareHandler = RetrieveHandler(type); fio.familyName = prepareHandler(fio.familyName); } type = FieldTypes.FirstName; if (permittedFields.Contains(type) && fio.firstName != null && !string.IsNullOrEmpty(fio.firstName.value)) { prepareHandler = RetrieveHandler(type); fio.firstName = prepareHandler(fio.firstName); } type = FieldTypes.MiddleName; if (permittedFields.Contains(type) && fio.middleName != null && !string.IsNullOrEmpty(fio.middleName.value)) { prepareHandler = RetrieveHandler(type); fio.middleName = prepareHandler(fio.middleName); } preparedInitials.Add(fio); } } if (documents != null) { foreach (var document in documents) { var type = FieldTypes.IdCardType; if (permittedFields.Contains(type) && document.idCardType != null && !string.IsNullOrEmpty(document.idCardType.value)) { prepareHandler = RetrieveHandler(type); document.idCardType = prepareHandler(document.idCardType); } type = FieldTypes.IdCardNumber; if (permittedFields.Contains(type) && document.idCardNumber != null && !string.IsNullOrEmpty(document.idCardNumber.value)) { prepareHandler = RetrieveHandler(type); document.idCardNumber = prepareHandler(document.idCardNumber); } type = FieldTypes.IdCardDate; if (permittedFields.Contains(type) && document.idCardDate != null && !string.IsNullOrEmpty(document.idCardDate.value)) { prepareHandler = RetrieveHandler(type); document.idCardDate = prepareHandler(document.idCardDate); } type = FieldTypes.IdCardDateExp; if (permittedFields.Contains(type) && document.idCardDateExp != null && !string.IsNullOrEmpty(document.idCardDateExp.value)) { prepareHandler = RetrieveHandler(type); document.idCardDateExp = prepareHandler(document.idCardDateExp); } type = FieldTypes.IdCardOrg; if (permittedFields.Contains(type) && document.idCardOrg != null && !string.IsNullOrEmpty(document.idCardOrg.value)) { prepareHandler = RetrieveHandler(type); document.idCardOrg = prepareHandler(document.idCardOrg); } preparedDocuments.Add(document); } } } catch (Exception ex) { throw new Exception("Ошибка при подготовке полей: ", ex); } }