Example #1
0
        public static NotifierHandle CreateHandle(GCHandle managedNotifier, NotifierConfiguration configuration)
        {
            var nativeConfig = configuration.ToNative();
            var result       = NativeMethods.create_notifier(GCHandle.ToIntPtr(managedNotifier), nativeConfig, configuration.EncryptionKey,
                                                             out var nativeException);

            nativeException.ThrowIfNecessary();

            return(new NotifierHandle(result));
        }
Example #2
0
            internal static Task <INotifier> StartAsync(NotifierConfiguration config)
            {
                Directory.CreateDirectory(config.WorkingDirectory);

                var thread = new AsyncContextThread();

                return(thread.Factory.Run(() =>
                {
                    var notifier = new Impl(config, thread);
                    return notifier._start.Task;
                }));
            }
Example #3
0
            private Impl(NotifierConfiguration config, AsyncContextThread notificationsThread)
            {
                _handlers            = config.Handlers.ToArray();
                _notificationsThread = notificationsThread;
                _gcHandle            = GCHandle.Alloc(this);
                Configuration        = config;
                _start = new TaskCompletionSource <INotifier>();
                try
                {
                    _notifierHandle = NotifierHandle.CreateHandle(_gcHandle, config);
                }
                catch
                {
                    _gcHandle.Free();
                    throw;
                }

                _processor = new CalculationProcessor <string, IntPtr>(CalculateAsync);
            }
Example #4
0
 /// <summary>
 /// Creates a new <see cref="INotifier"/> with the supplied <see cref="NotifierConfiguration"/>.
 /// </summary>
 /// <param name="config">
 /// A <see cref="NotifierConfiguration"/> describing the various <see cref="INotifier"/> settings.
 /// </param>
 /// <returns>
 /// An awaitable task, that, upon completion, will contain the fully initialized <see cref="INotifier"/>
 /// instance.
 /// </returns>
 public static Task <INotifier> StartAsync(NotifierConfiguration config)
 {
     Argument.NotNull(config, nameof(config));
     Argument.Ensure(config.Handlers?.Any() == true, "The list of handlers cannot be empty.", nameof(config));
     return(Impl.StartAsync(config));
 }