/// <inheritdoc /> /// <summary> /// Set data from data reader to entity property /// </summary> /// <param name="entity"> instance of the entity </param> /// <param name="reader"> data reader </param> /// <returns> the same instance as was passed to the entity param. (To make builder pattern)</returns> public override TEntity SetProperty(TEntity entity, DbDataReader reader, ReadSession session, int recursionDepth) { if (entity != null) { // Get collection, if not exists create it var collection = Getter(entity); if (collection == null) { if (Setter != null) { Setter(entity, (collection = new List <TProperty>())); } else { throw new InvalidOperationException($"Please make sure that navigation property {typeof(TProperty)} collection is initialized or has ICollection<TProperty> signature"); } } // Get previous entity // Check collection is List for optimized access of previous entity var previousProperty = default(TProperty); if (typeof(List <TProperty>) == collection.GetType()) { var pkIdx = ForeignTable.PrimaryKey.GetColumnIndexByAlias(reader); if (pkIdx.HasValue) { // TODO: Think about more effective way of reading previous entity if (!ForeignTable.PrimaryKey.IsNull(reader, pkIdx.Value)) { var pkValue = ForeignTable.PrimaryKey.GetValue(reader, /*shift*/ pkIdx.Value - ForeignTable.PrimaryKey.Index.Value); previousProperty = collection.FirstOrDefault(e => ForeignTable.PrimaryKey.GetField(e).Equals(pkValue)); } } //if (collection.Count > 0) // previousProperty = ((List<TProperty>)collection)[collection.Count - 1]; } else { // Try to find entity with the same key in collection var pkIdx = ForeignTable.PrimaryKey.GetColumnIndexByAlias(reader); if (pkIdx.HasValue) { // TODO: Think about more effective way of reading previous entity if (!ForeignTable.PrimaryKey.IsNull(reader, pkIdx.Value)) { var pkValue = ForeignTable.PrimaryKey.GetValue(reader, /*shift*/ pkIdx.Value - ForeignTable.PrimaryKey.Index.Value); previousProperty = collection.FirstOrDefault(e => ForeignTable.PrimaryKey.GetField(e).Equals(pkValue)); } } } var propertyInstance = ForeignTable.ToEntity(reader, previousProperty, session, ++recursionDepth); if (propertyInstance != null && propertyInstance != previousProperty) { collection?.Add(propertyInstance); } } return(entity); }
public async stt::Task CreateReadSessionRequestObjectAsync() { moq::Mock <BigQueryStorage.BigQueryStorageClient> mockGrpcClient = new moq::Mock <BigQueryStorage.BigQueryStorageClient>(moq::MockBehavior.Strict); CreateReadSessionRequest request = new CreateReadSessionRequest { TableReference = new TableReference(), TableModifiers = new TableModifiers(), RequestedStreams = -1338971660, ReadOptions = new TableReadOptions(), Format = DataFormat.Arrow, ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"), ShardingStrategy = ShardingStrategy.Balanced, }; ReadSession expectedResponse = new ReadSession { ReadSessionName = ReadSessionName.FromProjectLocationSession("[PROJECT]", "[LOCATION]", "[SESSION]"), ExpireTime = new wkt::Timestamp(), Streams = { new Stream(), }, AvroSchema = new AvroSchema(), ArrowSchema = new ArrowSchema(), TableReference = new TableReference(), TableModifiers = new TableModifiers(), ShardingStrategy = ShardingStrategy.Balanced, }; mockGrpcClient.Setup(x => x.CreateReadSessionAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <ReadSession>(stt::Task.FromResult(expectedResponse), null, null, null, null)); BigQueryStorageClient client = new BigQueryStorageClientImpl(mockGrpcClient.Object, null); ReadSession responseCallSettings = await client.CreateReadSessionAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); ReadSession responseCancellationToken = await client.CreateReadSessionAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async stt::Task CreateReadSessionRequestObjectAsync() { moq::Mock <BigQueryRead.BigQueryReadClient> mockGrpcClient = new moq::Mock <BigQueryRead.BigQueryReadClient>(moq::MockBehavior.Strict); CreateReadSessionRequest request = new CreateReadSessionRequest { ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"), ReadSession = new ReadSession(), MaxStreamCount = 1813871107, }; ReadSession expectedResponse = new ReadSession { ReadSessionName = ReadSessionName.FromProjectLocationSession("[PROJECT]", "[LOCATION]", "[SESSION]"), ExpireTime = new wkt::Timestamp(), DataFormat = DataFormat.Arrow, AvroSchema = new AvroSchema(), ArrowSchema = new ArrowSchema(), TableAsTableName = TableName.FromProjectDatasetTable("[PROJECT]", "[DATASET]", "[TABLE]"), TableModifiers = new ReadSession.Types.TableModifiers(), ReadOptions = new ReadSession.Types.TableReadOptions(), Streams = { new ReadStream(), }, }; mockGrpcClient.Setup(x => x.CreateReadSessionAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <ReadSession>(stt::Task.FromResult(expectedResponse), null, null, null, null)); BigQueryReadClient client = new BigQueryReadClientImpl(mockGrpcClient.Object, null); ReadSession responseCallSettings = await client.CreateReadSessionAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); ReadSession responseCancellationToken = await client.CreateReadSessionAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public void CreateReadSession() { moq::Mock <BigQueryRead.BigQueryReadClient> mockGrpcClient = new moq::Mock <BigQueryRead.BigQueryReadClient>(moq::MockBehavior.Strict); CreateReadSessionRequest request = new CreateReadSessionRequest { ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"), ReadSession = new ReadSession(), MaxStreamCount = 1813871107, }; ReadSession expectedResponse = new ReadSession { ReadSessionName = ReadSessionName.FromProjectLocationSession("[PROJECT]", "[LOCATION]", "[SESSION]"), ExpireTime = new wkt::Timestamp(), DataFormat = DataFormat.Arrow, AvroSchema = new AvroSchema(), ArrowSchema = new ArrowSchema(), TableAsTableName = TableName.FromProjectDatasetTable("[PROJECT]", "[DATASET]", "[TABLE]"), TableModifiers = new ReadSession.Types.TableModifiers(), ReadOptions = new ReadSession.Types.TableReadOptions(), Streams = { new ReadStream(), }, }; mockGrpcClient.Setup(x => x.CreateReadSession(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); BigQueryReadClient client = new BigQueryReadClientImpl(mockGrpcClient.Object, null); ReadSession response = client.CreateReadSession(request.Parent, request.ReadSession, request.MaxStreamCount); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
private void DataChunk(CancellationToken token, ReadSession session) { var chunk = new List <Data>(); var readTime = session.StopWatch(); var realTime = DateTime.Now.TimeOfDay; foreach (var item in session.RawDataCollection.GetConsumingEnumerable(token)) { if (item.Timestamp != readTime) { if (!chunk.Any()) { realTime = DateTime.Now.TimeOfDay; } if (DateTime.Now.TimeOfDay - realTime > TimeSpan.FromSeconds(1) && ( session.ChunkDataCollection.Count < 10 || chunk.Count > 20000)) { realTime = DateTime.Now.TimeOfDay; session.ChunkDataCollection.Add(chunk.ToList(), token); chunk.Clear(); } readTime = item.Timestamp; } var data = GetData(item); chunk.Add(data); } if (chunk.Any()) { session.ChunkDataCollection.Add(chunk, token); } }
public void CreateReadSessionResourceNames() { moq::Mock <BigQueryStorage.BigQueryStorageClient> mockGrpcClient = new moq::Mock <BigQueryStorage.BigQueryStorageClient>(moq::MockBehavior.Strict); CreateReadSessionRequest request = new CreateReadSessionRequest { TableReference = new TableReference(), RequestedStreams = -1338971660, ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"), }; ReadSession expectedResponse = new ReadSession { ReadSessionName = ReadSessionName.FromProjectLocationSession("[PROJECT]", "[LOCATION]", "[SESSION]"), ExpireTime = new wkt::Timestamp(), Streams = { new Stream(), }, AvroSchema = new AvroSchema(), ArrowSchema = new ArrowSchema(), TableReference = new TableReference(), TableModifiers = new TableModifiers(), ShardingStrategy = ShardingStrategy.Balanced, }; mockGrpcClient.Setup(x => x.CreateReadSession(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); BigQueryStorageClient client = new BigQueryStorageClientImpl(mockGrpcClient.Object, null); ReadSession response = client.CreateReadSession(request.TableReference, request.ParentAsProjectName, request.RequestedStreams); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
private void UpdateSession(CancellationToken token, ReadSession session) { while (!session.Completed) { token.ThrowIfCancellationRequested(); if (token.WaitHandle.WaitOne(TimeSpan.FromSeconds(30))) { break; } var prev = new { session.AllTime, session.Velocity }; dataFactory.Value.WithRepository <ISettingsRepository>(repo => { session.AllTime = repo.GetAllTime(); session.Velocity = repo.GetReadVelocity() ?? 1.0; }); if (prev.AllTime != session.AllTime || Math.Abs(prev.Velocity - session.Velocity) > 1e-10) { logger.Value.InfoFormat("Read settings has been changed: AllTime={0}\tVelocity={1}", session.AllTime, session.Velocity); } } }
internal ReadOnlySequenceSource(FileBufferingWriter writer, int segmentLength) { var buffer = writer.buffer; tail = buffer.Memory.Slice(0, writer.position); accessor = writer.fileBackend is null ? null : new ReadOnlySequenceAccessor(writer.fileBackend, segmentLength); session = writer.EnterReadMode(this); }
/// <inheritdoc /> /// <summary> /// Set data from data reader to entity property /// </summary> /// <param name="entity"> instance of the entity </param> /// <param name="reader"> data reader </param> /// <returns> the same instance as was passed to the entity param. (To make builder pattern)</returns> public override TEntity SetProperty(TEntity entity, DbDataReader reader, ReadSession session, int recursionDepth) { if (entity != null) { var previousProperty = Getter(entity); var currentProperty = ForeignTable.ToEntity(reader, previousProperty, session, ++recursionDepth); Setter(entity, currentProperty); } return(entity); }
/// <summary>Snippet for BatchCreateReadSessionStreams</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void BatchCreateReadSessionStreams() { // Create client BigQueryStorageClient bigQueryStorageClient = BigQueryStorageClient.Create(); // Initialize request argument(s) ReadSession session = new ReadSession(); int requestedStreams = 0; // Make the request BatchCreateReadSessionStreamsResponse response = bigQueryStorageClient.BatchCreateReadSessionStreams(session, requestedStreams); }
internal MemoryMappedFileManager(FileBufferingWriter writer, long offset, long length) { Debug.Assert(length <= int.MaxValue); Debug.Assert(writer.fileBackend != null); mappedFile = CreateMemoryMappedFile(writer.fileBackend); accessor = mappedFile.CreateViewAccessor(offset, length, MemoryMappedFileAccess.ReadWrite); accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr); Debug.Assert(ptr != default); session = writer.EnterReadMode(this); Debug.Assert(writer.IsReading); }
/// <summary>Snippet for CreateReadSession</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void CreateReadSessionResourceNames() { // Create client BigQueryStorageClient bigQueryStorageClient = BigQueryStorageClient.Create(); // Initialize request argument(s) TableReference tableReference = new TableReference(); ProjectName parent = ProjectName.FromProject("[PROJECT]"); int requestedStreams = 0; // Make the request ReadSession response = bigQueryStorageClient.CreateReadSession(tableReference, parent, requestedStreams); }
/// <summary>Snippet for CreateReadSession</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void CreateReadSession() { // Create client BigQueryReadClient bigQueryReadClient = BigQueryReadClient.Create(); // Initialize request argument(s) string parent = "projects/[PROJECT]"; ReadSession readSession = new ReadSession(); int maxStreamCount = 0; // Make the request ReadSession response = bigQueryReadClient.CreateReadSession(parent, readSession, maxStreamCount); }
/// <summary>Snippet for CreateReadSession</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void CreateReadSession() { // Create client BigQueryStorageClient bigQueryStorageClient = BigQueryStorageClient.Create(); // Initialize request argument(s) TableReference tableReference = new TableReference(); string parent = "projects/[PROJECT]"; int requestedStreams = 0; // Make the request ReadSession response = bigQueryStorageClient.CreateReadSession(tableReference, parent, requestedStreams); }
/// <summary>Snippet for CreateReadSession</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void CreateReadSessionResourceNames() { // Create client BigQueryReadClient bigQueryReadClient = BigQueryReadClient.Create(); // Initialize request argument(s) ProjectName parent = ProjectName.FromProject("[PROJECT]"); ReadSession readSession = new ReadSession(); int maxStreamCount = 0; // Make the request ReadSession response = bigQueryReadClient.CreateReadSession(parent, readSession, maxStreamCount); }
/// <summary>Snippet for BatchCreateReadSessionStreamsAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task BatchCreateReadSessionStreamsAsync() { // Create client BigQueryStorageClient bigQueryStorageClient = await BigQueryStorageClient.CreateAsync(); // Initialize request argument(s) ReadSession session = new ReadSession(); int requestedStreams = 0; // Make the request BatchCreateReadSessionStreamsResponse response = await bigQueryStorageClient.BatchCreateReadSessionStreamsAsync(session, requestedStreams); }
/// <inheritdoc/> protected override void Dispose(bool disposing) { if (disposing) { accessor?.Dispose(); accessor = null; session.Dispose(); session = default; } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { accessor.SafeMemoryMappedViewHandle.ReleasePointer(); accessor.Dispose(); mappedFile.Dispose(); session.Dispose(); session = default; } ptr = default; }
/// <summary>Snippet for CreateReadSession</summary> public void CreateReadSession_ResourceNames() { // Snippet: CreateReadSession(ProjectName, ReadSession, int, CallSettings) // Create client BigQueryReadClient bigQueryReadClient = BigQueryReadClient.Create(); // Initialize request argument(s) ProjectName parent = new ProjectName("[PROJECT]"); ReadSession readSession = new ReadSession(); int maxStreamCount = 0; // Make the request ReadSession response = bigQueryReadClient.CreateReadSession(parent, readSession, maxStreamCount); // End snippet }
/// <summary>Snippet for CreateReadSession</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void CreateReadSessionRequestObject() { // Create client BigQueryReadClient bigQueryReadClient = BigQueryReadClient.Create(); // Initialize request argument(s) CreateReadSessionRequest request = new CreateReadSessionRequest { ParentAsProjectName = ProjectName.FromProject("[PROJECT]"), ReadSession = new ReadSession(), MaxStreamCount = 0, }; // Make the request ReadSession response = bigQueryReadClient.CreateReadSession(request); }
/// <summary>Snippet for BatchCreateReadSessionStreamsAsync</summary> public async Task BatchCreateReadSessionStreamsAsync() { // Snippet: BatchCreateReadSessionStreamsAsync(ReadSession, int, CallSettings) // Additional: BatchCreateReadSessionStreamsAsync(ReadSession, int, CancellationToken) // Create client BigQueryStorageClient bigQueryStorageClient = await BigQueryStorageClient.CreateAsync(); // Initialize request argument(s) ReadSession session = new ReadSession(); int requestedStreams = 0; // Make the request BatchCreateReadSessionStreamsResponse response = await bigQueryStorageClient.BatchCreateReadSessionStreamsAsync(session, requestedStreams); // End snippet }
public void IntegrationTest2() { ConsumerProducerLock @lock = new ConsumerProducerLock(); Assert.True(@lock.CanRead); Assert.Equal(0, @lock.ReaderCount); using (ReadSession readSession = @lock.CreateReadSession()) { Assert.True(@lock.CanRead); Assert.Equal(1, @lock.ReaderCount); } Assert.True(@lock.CanRead); Assert.Equal(0, @lock.ReaderCount); }
/// <summary>Snippet for CreateReadSession</summary> public void CreateReadSession_RequestObject() { // Snippet: CreateReadSession(CreateReadSessionRequest, CallSettings) // Create client BigQueryReadClient bigQueryReadClient = BigQueryReadClient.Create(); // Initialize request argument(s) CreateReadSessionRequest request = new CreateReadSessionRequest { ParentAsProjectName = new ProjectName("[PROJECT]"), ReadSession = new ReadSession(), MaxStreamCount = 0, }; // Make the request ReadSession response = bigQueryReadClient.CreateReadSession(request); // End snippet }
/// <summary>Snippet for CreateReadSessionAsync</summary> public async Task CreateReadSessionResourceNamesAsync() { // Snippet: CreateReadSessionAsync(TableReference, ProjectName, int, CallSettings) // Additional: CreateReadSessionAsync(TableReference, ProjectName, int, CancellationToken) // Create client BigQueryStorageClient bigQueryStorageClient = await BigQueryStorageClient.CreateAsync(); // Initialize request argument(s) TableReference tableReference = new TableReference(); ProjectName parent = ProjectName.FromProject("[PROJECT]"); int requestedStreams = 0; // Make the request ReadSession response = await bigQueryStorageClient.CreateReadSessionAsync(tableReference, parent, requestedStreams); // End snippet }
/// <summary>Snippet for CreateReadSessionAsync</summary> public async Task CreateReadSessionResourceNamesAsync() { // Snippet: CreateReadSessionAsync(ProjectName, ReadSession, int, CallSettings) // Additional: CreateReadSessionAsync(ProjectName, ReadSession, int, CancellationToken) // Create client BigQueryReadClient bigQueryReadClient = await BigQueryReadClient.CreateAsync(); // Initialize request argument(s) ProjectName parent = ProjectName.FromProject("[PROJECT]"); ReadSession readSession = new ReadSession(); int maxStreamCount = 0; // Make the request ReadSession response = await bigQueryReadClient.CreateReadSessionAsync(parent, readSession, maxStreamCount); // End snippet }
/// <summary>Snippet for CreateReadSessionAsync</summary> public async Task CreateReadSessionAsync() { // Snippet: CreateReadSessionAsync(TableReference, string, int, CallSettings) // Additional: CreateReadSessionAsync(TableReference, string, int, CancellationToken) // Create client BigQueryStorageClient bigQueryStorageClient = await BigQueryStorageClient.CreateAsync(); // Initialize request argument(s) TableReference tableReference = new TableReference(); string parent = "projects/[PROJECT]"; int requestedStreams = 0; // Make the request ReadSession response = await bigQueryStorageClient.CreateReadSessionAsync(tableReference, parent, requestedStreams); // End snippet }
/// <summary>Snippet for CreateReadSessionAsync</summary> public async Task CreateReadSessionAsync() { // Snippet: CreateReadSessionAsync(string, ReadSession, int, CallSettings) // Additional: CreateReadSessionAsync(string, ReadSession, int, CancellationToken) // Create client BigQueryReadClient bigQueryReadClient = await BigQueryReadClient.CreateAsync(); // Initialize request argument(s) string parent = "projects/[PROJECT]"; ReadSession readSession = new ReadSession(); int maxStreamCount = 0; // Make the request ReadSession response = await bigQueryReadClient.CreateReadSessionAsync(parent, readSession, maxStreamCount); // End snippet }
public static RestRequest GetRequestBody(string method) { ReadConfig readConfig = new ReadConfig(); List <Config> _config = readConfig.GetAllConfigs(); if (_config[0].session_data != "") { ReadSession readSession = new ReadSession(); Session _sessionData = readSession.GetSession(); string token = _sessionData.token; if (method == "post") { var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); if (token != null) { request.AddHeader("Authorization", "Bearer " + token); } return(request); } else { var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", "application/json"); if (token != null) { request.AddHeader("Authorization", "Bearer " + token); } return(request); } } else { if (method == "post") { var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); return(request); } else { var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", "application/json"); return(request); } } }
/// <summary>Snippet for CreateReadSession</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void CreateReadSessionRequestObject() { // Create client BigQueryStorageClient bigQueryStorageClient = BigQueryStorageClient.Create(); // Initialize request argument(s) CreateReadSessionRequest request = new CreateReadSessionRequest { TableReference = new TableReference(), TableModifiers = new TableModifiers(), RequestedStreams = 0, ReadOptions = new TableReadOptions(), Format = DataFormat.Unspecified, ParentAsProjectName = ProjectName.FromProject("[PROJECT]"), ShardingStrategy = ShardingStrategy.Unspecified, }; // Make the request ReadSession response = bigQueryStorageClient.CreateReadSession(request); }
/// <summary>Snippet for CreateReadSessionAsync</summary> public async Task CreateReadSessionRequestObjectAsync() { // Snippet: CreateReadSessionAsync(CreateReadSessionRequest, CallSettings) // Additional: CreateReadSessionAsync(CreateReadSessionRequest, CancellationToken) // Create client BigQueryReadClient bigQueryReadClient = await BigQueryReadClient.CreateAsync(); // Initialize request argument(s) CreateReadSessionRequest request = new CreateReadSessionRequest { ParentAsProjectName = ProjectName.FromProject("[PROJECT]"), ReadSession = new ReadSession(), MaxStreamCount = 0, }; // Make the request ReadSession response = await bigQueryReadClient.CreateReadSessionAsync(request); // End snippet }