//========================================================= // Peer eventing public Task PeerVentAsync(TransactionContext tcontext, CancellationToken token = default(CancellationToken)) { try { SeekPosition start = new SeekPosition(); if (peerOptions.Newest != null) { start.Newest = new SeekNewest(); } else if (peerOptions.StartEventsBlock != null) { start.Specified = new SeekSpecified { Number = (ulong)peerOptions.StartEventsBlock.Value }; } else { start.Newest = new SeekNewest(); } // properties. Envelope envelope = ProtoUtils.CreateSeekInfoEnvelope(tcontext, start, new SeekPosition { Specified = new SeekSpecified { Number = (ulong)peerOptions.StopEventsBlock } }, SeekInfo.Types.SeekBehavior.BlockUntilReady, clientTLSCertificateDigest); return(ConnectEnvelopeAsync(envelope, token)); } catch (CryptoException e) { throw new TransactionException($"{ToString()} error message {e.Message}", e); } }
public static Envelope CreateSeekInfoEnvelope(TransactionContext transactionContext, SeekPosition startPosition, SeekPosition stopPosition, SeekInfo.Types.SeekBehavior seekBehavior, byte[] tlsCertHash) { return(CreateSeekInfoEnvelope(transactionContext, new SeekInfo { Start = startPosition, Behavior = seekBehavior, Stop = stopPosition }, tlsCertHash)); }
// read public void Seek(int Pos, SeekPosition origin) { if (origin == SeekPosition.Begin) { stream.Seek(Pos, SeekOrigin.Begin); } else if (origin == SeekPosition.Current) { stream.Seek(Pos, SeekOrigin.Current); } else { stream.Seek(Pos, SeekOrigin.End); } }
private static IObservable <ConsumeResult <TKey, TValue> > CreateObservable <TKey, TValue>( IConsumer <TKey, TValue> consumer, TopicPartition tp, SeekPosition startingPosition, CancellationToken cancellationToken) { return(Observable.Create <ConsumeResult <TKey, TValue> >(o => { var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); var innerCancellationToken = cts.Token; _ = Task.Run( () => { ConfluentKafkaOffset confluentKafkaOffset = startingPosition switch { SeekPosition.FromWatermark o => new ConfluentKafkaOffset(o.Watermark.Item), _ => ConfluentKafkaOffset.End, }; var tpo = new TopicPartitionOffset(tp, confluentKafkaOffset); if (tpo.Partition.Value == -1 && tpo.Offset.Value == -1) { consumer.Subscribe(topic: tp.Topic); } else { Console.Out.WriteLine($"consumerAssign(topic={tpo.Topic} partition={tpo.Partition.Value} offset={tpo.Offset.Value})"); consumer.Assign(tpo); } while (!innerCancellationToken.IsCancellationRequested) { var msg = consumer.Consume(innerCancellationToken); Console.WriteLine($"Received {msg.Topic}#{msg.Partition.Value}#{msg.Offset.Value}: {msg.Message.Value}"); o.OnNext(msg); innerCancellationToken.ThrowIfCancellationRequested(); } o.OnCompleted(); }, innerCancellationToken); return new CancellationDisposable(cts); })); }
public override long Seek(long offset, SeekOrigin origin) { if (!CanSeek) { throw new NotSupportedException("The stream does not support seeking"); } if (IsAsync && origin == SeekOrigin.Current) { throw new NotSupportedException("Cannot tell what the offset is in async mode"); } SeekPosition seekPos = SeekPosition.Start; long newOffset = -1; switch (origin) { case SeekOrigin.Begin: seekPos = SeekPosition.Start; newOffset = offset; break; case SeekOrigin.Current: seekPos = SeekPosition.Current; break; case SeekOrigin.End: seekPos = SeekPosition.End; newOffset = Length + offset; break; } Result result; if (async) { Async.Seek(handle, seekPos, offset, callback); Wait(); result = asyncResult; } else { result = Sync.Seek(handle, seekPos, offset); } Vfs.ThrowException(Uri, result); return(newOffset); }
public async Task <IObservable <BusinessData <TBusinessData> > > CreateObservable(CancellationToken cancellationToken = default) { this.cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); this.deletetionTask = Task.Run(() => this.DeleteOldSnapshots( maxAge: TimeSpan.FromDays(1), sleepTime: TimeSpan.FromMinutes(1), cancellationToken: this.cts.Token)); var updateFunc = this.applyUpdate.ToFSharpFunc(); FSharpResult <BusinessData <TBusinessData>, BusinessDataUpdateError> snapshotResult = await this.FetchBusinessDataSnapshot(this.cts.Token); if (snapshotResult.IsError) { return(Observable.Throw <BusinessData <TBusinessData> >(((BusinessDataUpdateError.SnapshotDownloadError)snapshotResult.ErrorValue).Item)); } var snapshot = snapshotResult.ResultValue; IConnectableObservable <BusinessData <TBusinessData> > connectableObservable = this.updateMessagingClient .CreateWatermarkObervable( startingPosition: SeekPosition.NewFromWatermark( snapshot.Watermark.Add(1)), cancellationToken: this.cts.Token) .Scan( seed: snapshotResult, accumulator: (businessData, updateMessage) => updateBusinessData(updateFunc, businessData, updateMessage)) // .Where(d => d.IsOk) .Select(d => d.ResultValue) .StartWith(snapshot) .Publish(initialValue: snapshot); _ = connectableObservable.Connect(); return(connectableObservable.AsObservable()); }
public static Result Seek(Handle handle, SeekPosition whence, long offset) { return(gnome_vfs_seek(handle.Handle, whence, offset)); }
private static extern void gnome_vfs_async_seek(IntPtr handle, SeekPosition whence, long offset, AsyncCallbackNative callback, IntPtr data);
/// <summary> /// シークする /// </summary> public void Seek(SeekPosition seekPosition) { manager.Seek(seekPosition == SeekPosition.Start ? manager.StartFrame : manager.StartFrame + manager.FrameLength); }
public static Result Seek (Handle handle, SeekPosition whence, long offset) { return gnome_vfs_seek (handle.Handle, whence, offset); }
private static extern Result gnome_vfs_seek (IntPtr handle, SeekPosition whence, long offset);
public static extern int gpgme_data_seek(IntPtr dh, int offset, SeekPosition whence);
public static void Seek (Handle handle, SeekPosition whence, long offset, AsyncCallback callback) { AsyncCallbackWrapper wrapper = new AsyncCallbackWrapper (callback, null); gnome_vfs_async_seek (handle.Handle, whence, offset, wrapper.NativeDelegate, IntPtr.Zero); }
private static extern void gnome_vfs_async_seek (IntPtr handle, SeekPosition whence, long offset, AsyncCallbackNative callback, IntPtr data);
IObservable <WatermarkMessage <TMessagePayload> > IWatermarkMessageClient <TMessagePayload> .CreateWatermarkObervable(SeekPosition startingPosition, CancellationToken cancellationToken) { return(CreateObservable( consumer: this.consumer, tp: this.topicPartition.Value, startingPosition: startingPosition, cancellationToken: cancellationToken) .Select(consumeResult => new WatermarkMessage <TMessagePayload>( watermark: Watermark.NewWatermark(consumeResult.Offset.Value), payload: consumeResult.Message.Value.DeserializeJSON <TMessagePayload>()))); }
private static extern Result gnome_vfs_seek(IntPtr handle, SeekPosition whence, long offset);
public static void Seek(Handle handle, SeekPosition whence, long offset, AsyncCallback callback) { AsyncCallbackWrapper wrapper = new AsyncCallbackWrapper(callback, null); gnome_vfs_async_seek(handle.Handle, whence, offset, wrapper.NativeDelegate, IntPtr.Zero); }