/// <summary> /// Create event subscription. /// </summary> /// <param name="connection">native connection pointer</param> /// <param name="eventType">type of event to create</param> /// <param name="eventSubscriptionFlags">event subscription flags</param> /// <param name="listener">event listener</param> /// <exception cref="ArgumentException">One of passed parameters is not valid.</exception> /// <exception cref="DxException"></exception> public NativeSubscription(NativeConnection connection, EventType eventType, EventSubscriptionFlag eventSubscriptionFlags, IDxEventListener listener) { if (listener == null) { throw new ArgumentNullException(nameof(listener)); } connectionPtr = connection.Handler; this.eventType = eventType; eventListener = listener; C.CheckOk(eventSubscriptionFlags == EventSubscriptionFlag.Default ? C.Instance.dxf_create_subscription(connectionPtr, eventType, out subscriptionPtr) : C.Instance.dxf_create_subscription_with_flags(connectionPtr, eventType, eventSubscriptionFlags, out subscriptionPtr)); try { C.CheckOk(C.Instance.dxf_attach_event_listener_v2(subscriptionPtr, callback = OnEvent, IntPtr.Zero)); } catch (DxException) { C.Instance.dxf_close_subscription(subscriptionPtr); throw; } this.connection = connection; }
/// <summary> /// Create Candle event subscription. /// For rest events use another constructor. /// </summary> /// <param name="connection">Native connection pointer.</param> /// <param name="time">Date time in the past.</param> /// <param name="eventSubscriptionFlags">event subscription flags</param> /// <param name="listener">Candle event listener.</param> /// <exception cref="ArgumentException">One of passed parameters is not valid.</exception> /// <exception cref="DxException"></exception> public NativeSubscription(NativeConnection connection, DateTime?time, EventSubscriptionFlag eventSubscriptionFlags, IDxCandleListener listener) { if (listener == null) { throw new ArgumentNullException(nameof(listener)); } connectionPtr = connection.Handler; eventType = EventType.Candle; eventListener = listener; var unixTimestamp = time == null ? 0 : Tools.DateToUnixTime((DateTime)time); C.CheckOk(eventSubscriptionFlags == EventSubscriptionFlag.Default ? C.Instance.dxf_create_subscription_timed(connectionPtr, eventType, unixTimestamp, out subscriptionPtr) : C.Instance.dxf_create_subscription_timed_with_flags(connectionPtr, eventType, unixTimestamp, eventSubscriptionFlags, out subscriptionPtr)); try { C.CheckOk(C.Instance.dxf_attach_event_listener_v2(subscriptionPtr, callback = OnEvent, IntPtr.Zero)); } catch (DxException) { C.Instance.dxf_close_subscription(subscriptionPtr); throw; } }
/// <summary> /// Creates an event subscription. /// </summary> /// <remarks> /// Don't call this method inside any listeners and callbacks of NativeSubscription, NativeConnection, /// NativeRegionalBook, NativeSnapshotSubscription classes /// </remarks> /// <param name="type">Event type.</param> /// <param name="eventSubscriptionFlags">Event subscription flags</param> /// <param name="listener">Event listener callback.</param> /// <returns>Subscription object.</returns> /// <exception cref="ArgumentNullException">Listener is null.</exception> /// <exception cref="DxException"></exception> public IDxSubscription CreateSubscription(EventType type, EventSubscriptionFlag eventSubscriptionFlags, IDxEventListener listener) { if (handle == IntPtr.Zero) { throw new NativeDxException("not connected"); } IDxSubscription result = new NativeSubscription(this, type, eventSubscriptionFlags, listener); subscriptions.Add(result); return(result); }
internal override int dxf_create_subscription_timed_with_flags(IntPtr connection, EventType event_types, Int64 time, EventSubscriptionFlag subscr_flags, out IntPtr subscription) { return(__dxf_create_subscription_timed_with_flags(connection, event_types, time, subscr_flags, out subscription)); }
private static extern int __dxf_create_subscription_timed_with_flags(IntPtr connection, EventType event_types, Int64 time, EventSubscriptionFlag subscr_flags, out IntPtr subscription);
/// <summary> /// Create time event subscription. /// </summary> /// <param name="connection">Native connection pointer.</param> /// <param name="eventType">Type of event to create.</param> /// <param name="time">Time to getting events from.</param> /// <param name="eventSubscriptionFlags">event subscription flags</param> /// <param name="listener">Event listener.</param> /// <exception cref="ArgumentException">One of passed parameters is not valid.</exception> /// <exception cref="DxException"></exception> public NativeSubscription(NativeConnection connection, EventType eventType, DateTime time, EventSubscriptionFlag eventSubscriptionFlags, IDxEventListener listener) : this(connection, eventType, Tools.DateToUnixTime(time), eventSubscriptionFlags, listener) { }
/// <summary> /// Creates a timed subscription with the specified parameters and the subscription flags. /// </summary> /// <param name="connection">A handle of a previously created connection which the subscription will be using</param> /// <param name="event_types">A bitmask of the subscription event types. See: EventType</param> /// <param name="time">UTC time in the past (unix time in milliseconds)</param> /// <param name="subscr_flags">A bitmask of the subscription event flags. See: EventSubscriptionFlag</param> /// <param name="subscription">A handle of the created subscription</param> /// <returns>DX_OK (1) on successful subscription creation or DX_ERR (0) on error; /// dxf_get_last_error can be used to retrieve the error code and description in case of failure; a handle to /// newly created subscription is returned via ```subscription``` out parameter</returns> internal abstract int dxf_create_subscription_timed_with_flags(IntPtr connection, EventType event_types, Int64 time, EventSubscriptionFlag subscr_flags, out IntPtr subscription);