示例#1
0
 /// <summary>
 /// Factory method used to instantiating asynchronous producer pool
 /// </summary>
 /// <param name="config">
 /// The asynchronous producer pool configuration.
 /// </param>
 /// <param name="serializer">
 /// The serializer.
 /// </param>
 /// <param name="cbkHandler">
 /// The callback invoked after new broker is added.
 /// </param>
 /// <returns>
 /// Instantiated asynchronous producer pool
 /// </returns>
 public static AsyncProducerPool <TData> CreateAsyncPool(
     ProducerConfiguration config,
     IEncoder <TData> serializer,
     ICallbackHandler cbkHandler)
 {
     return(new AsyncProducerPool <TData>(config, serializer, cbkHandler));
 }
示例#2
0
 public ReplicationService(ICallbackHandler <IReplicationClientCallback <R> > clientCallbackHandler, ICallbackHandler <IReplicationServiceCallback <R> > serviceCallbackHandler, IReplicationServiceProxy <R> proxy)
 {
     this.clientCallbackHandler  = clientCallbackHandler;
     this.serviceCallbackHandler = serviceCallbackHandler;
     this.partnerServiceProxy    = proxy;
     state = State.Hot;
 }
示例#3
0
            public unsafe DelegateSaver(ICallbackHandler handler, CallbackShim *shim)
            {
                this.handler         = handler;
                reportError          = ReportError;
                reportDebug          = ReportDebug;
                profilerBegin        = ProfilerBegin;
                profilerBeginLiteral = ProfilerBegin;
                profilerEnd          = ProfilerEnd;
                getCachedSize        = GetCachedSize;
                getCacheEntry        = GetCacheEntry;
                setCacheEntry        = SetCacheEntry;
                saveScreenShot       = SaveScreenShot;
                captureStarted       = CaptureStarted;
                captureFinished      = CaptureFinished;
                captureFrame         = CaptureFrame;

                shim->reportError          = Marshal.GetFunctionPointerForDelegate(reportError);
                shim->reportDebug          = Marshal.GetFunctionPointerForDelegate(reportDebug);
                shim->profilerBegin        = Marshal.GetFunctionPointerForDelegate(profilerBegin);
                shim->profilerBeginLiteral = Marshal.GetFunctionPointerForDelegate(profilerBeginLiteral);
                shim->profilerEnd          = Marshal.GetFunctionPointerForDelegate(profilerEnd);
                shim->getCachedSize        = Marshal.GetFunctionPointerForDelegate(getCachedSize);
                shim->getCacheEntry        = Marshal.GetFunctionPointerForDelegate(getCacheEntry);
                shim->setCacheEntry        = Marshal.GetFunctionPointerForDelegate(setCacheEntry);
                shim->saveScreenShot       = Marshal.GetFunctionPointerForDelegate(saveScreenShot);
                shim->captureStarted       = Marshal.GetFunctionPointerForDelegate(captureStarted);
                shim->captureFinished      = Marshal.GetFunctionPointerForDelegate(captureFinished);
                shim->captureFrame         = Marshal.GetFunctionPointerForDelegate(captureFrame);
            }
示例#4
0
        public static unsafe IntPtr CreateShim(ICallbackHandler handler)
        {
            if (handler == null)
            {
                return(IntPtr.Zero);
            }

            if (savedDelegates != null)
            {
                throw new InvalidOperationException("Callbacks should only be initialized once; bgfx can only deal with one set at a time.");
            }

            var memory = Marshal.AllocHGlobal(Marshal.SizeOf <CallbackShim>());
            var shim   = (CallbackShim *)memory;
            var saver  = new DelegateSaver(handler, shim);

            // the shim uses the unnecessary ctor slot to act as a vtbl pointer to itself,
            // so that the same block of memory can act as both bgfx_callback_interface_t and bgfx_callback_vtbl_t
            shim->vtbl = memory + IntPtr.Size;

            // cache the data so we can free it later
            shimMemory     = memory;
            savedDelegates = saver;

            return(memory);
        }
示例#5
0
        private void AddDefaultCallbackHandlers(ICallbackHandler <IActionResult> callbackHandlers)
        {
            callbackHandlers.OnExecuteEvent = async(eventName, screenModel) =>
            {
                await _store.RemoveAsync(LastProcessedTokenKey);

                return(await OnEvent(eventName, screenModel));
            };
            callbackHandlers.OnExecuteRedirection = (redirectTo) =>
                                                    Task.FromResult((IActionResult)RedirectToAction(redirectTo.ActionName,
                                                                                                    redirectTo.ControllerName));
            callbackHandlers.OnExecuteUnauthorized =
                unauthorizedModel => Task.FromResult((IActionResult)Unauthorized());
            callbackHandlers.OnRedirectToRoot = async(type, handler) => RedirectToAction(nameof(Current), type,
                                                                                         await new CurrentViewRequest {
                FlowHandler = handler
            }.ToValidRouteValueAsync(ControllerContext.HttpContext));
            callbackHandlers.OnRedirectToCurrent = async(type, handler) => RedirectToAction(nameof(Current), type,
                                                                                            (object)await Request.Query.ToExpandoObject().MergeObjects(new { FlowHandler = handler })
                                                                                            .ToEncryptedRouteValueAsync(ControllerContext.HttpContext));
            callbackHandlers.OnNewContainedScreen = (containerHandler, containerType, flowType, startInfo) =>
            {
                var requestData = startInfo.MergeObjects(new GetNewContainedViewRequest
                {
                    FlowHandler          = containerHandler,
                    NewContainedFlowType = flowType,
                });
                return(RedirectToAction(nameof(NewContainedView), containerType, requestData));
            };
            callbackHandlers.OnStartNewFlow =
                async(flowType, startInfo) => RedirectToAction(nameof(Init), flowType, await startInfo.ToValidRouteValueAsync(HttpContext));
            callbackHandlers.OnAddModelError =
                (memberName, errorMessage) => ModelState.AddModelError(memberName, errorMessage);
        }
示例#6
0
 public BotService(
     IMessageHandler messageHandler,
     ICallbackHandler callbackHandler)
 {
     _messageHandler  = messageHandler ?? throw new System.ArgumentNullException(nameof(messageHandler));
     _callbackHandler = callbackHandler ?? throw new System.ArgumentNullException(nameof(callbackHandler));
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncProducerPool{TData}"/> class.
 /// </summary>
 /// <param name="config">
 /// The asynchronous producer pool configuration.
 /// </param>
 /// <param name="serializer">
 /// The serializer.
 /// </param>
 /// <param name="cbkHandler">
 /// The callback invoked after new broker is added.
 /// </param>
 private AsyncProducerPool(
     ProducerConfiguration config,
     IEncoder <TData> serializer,
     ICallbackHandler cbkHandler)
     : this(config, serializer, new Dictionary <int, IAsyncProducer>(), cbkHandler)
 {
 }
示例#8
0
        /// <summary>
        /// Produce a unique id and register a <see cref="ICallbackHandler"/> with it.
        /// </summary>
        /// <param name="callbackHandler">The handler to register.</param>
        /// <returns>A unique id associated with the handler.</returns>
        internal int RegisterCallback(ICallbackHandler callbackHandler)
        {
            int callbackId = Interlocked.Increment(ref _callbackCounter);

            _callbackHandlers[callbackId] = callbackHandler;

            return(callbackId);
        }
        public Broker(State state, ICallbackHandler <INotifyCallback> clientCallbackHandler)
        {
            this.state = state;
            this.clientCallbackHandler = clientCallbackHandler;

            streamData       = new Dictionary <T, List <Record <T> > >();
            streamDataLocker = new ReaderWriterLockSlim();
        }
示例#10
0
 public static Task Callback <E>(this Task task, [NotNull] ICallbackHandler <E> callback) where E : Exception
 {
     if (callback == null)
     {
         throw new ArgumentNullException(nameof(callback));
     }
     return(Callback <E>(task, callback.OnSuccess, callback.OnFailure));
 }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncProducerPool{TData}"/> class.
 /// </summary>
 /// <param name="config">
 /// The asynchronous producer pool configuration.
 /// </param>
 /// <param name="serializer">
 /// The serializer.
 /// </param>
 /// <param name="asyncProducers">
 /// The list of asynchronous producers.
 /// </param>
 /// <param name="cbkHandler">
 /// The callback invoked after new broker is added.
 /// </param>
 /// <remarks>
 /// Should be used for testing purpose only
 /// </remarks>
 private AsyncProducerPool(
     ProducerConfiguration config,
     IEncoder <TData> serializer,
     IDictionary <int, IAsyncProducer> asyncProducers,
     ICallbackHandler cbkHandler)
     : base(config, serializer, cbkHandler)
 {
     this.asyncProducers = asyncProducers;
 }
示例#12
0
        protected virtual void ComponentReleased(object component, ICallbackHandler composer)
        {
            var disposable = component as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
        }
示例#13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AsyncProducer"/> class.
        /// </summary>
        /// <param name="config">
        /// The producer config.
        /// </param>
        /// <param name="callbackHandler">
        /// The callback invoked when a request is finished being sent.
        /// </param>
        public AsyncProducer(
            AsyncProducerConfig config,
            ICallbackHandler callbackHandler)
        {
            Guard.Assert<ArgumentNullException>(() => config != null);

            this.config = config;
            this.callbackHandler = callbackHandler;
        }
 /// <summary>
 /// Constructor with parameters.
 /// </summary>
 /// <param name="commandService">Interface to use the command service.</param>
 /// <param name="telegramBotClient">Interface to use the Telegram Bot API.</param>
 /// <param name="userManager">Manager of application users.</param>
 /// <param name="callbackHandler">Handler of user callbacks.</param>
 /// <exception cref="ArgumentNullException"></exception>
 public BotController(ICommandService commandService,
                      ITelegramBotClient telegramBotClient,
                      IUserManager userManager,
                      ICallbackHandler callbackHandler)
 {
     _commandService    = commandService ?? throw new ArgumentNullException(nameof(commandService));
     _telegramBotClient = telegramBotClient ?? throw new ArgumentNullException(nameof(telegramBotClient));
     _userManager       = userManager ?? throw new ArgumentNullException(nameof(userManager));
     _callbackHandler   = callbackHandler ?? throw new ArgumentNullException(nameof(callbackHandler));
 }
示例#15
0
        public CallbackServiceContext(HttpRequestMessage request, ICallbackHandler callbackHandler)
        {
            lock (sync)
            {
                requestId = Guid.NewGuid();

                request.Properties.Add(requestIdPropertyKey, requestId);
                callbackHanders.Add(requestId, callbackHandler);
            }
        }
        public PublishManager(IBrokerPublishProxy <T> proxy, ICallbackHandler <INotifyCallback> cbHandler, Queue <Message <T> > queue)
        {
            this.brokerPublishProxy      = proxy;
            this.producerCallbackHandler = cbHandler;
            this.asyncQueue = queue;

            SendData        = true;
            NotifyStatus    = NotifyStatus.Failed;
            Waitingtime     = 500;
            notifySemaphore = new Semaphore(0, 1);
        }
示例#17
0
        public Producer(ProducerConfiguration config)
        {
            this.Config = config;

            syncProducerPool     = new SyncProducerPool(config);
            this.callbackHandler = new DefaultCallbackHandler <TKey, TData>(config,
                                                                            ReflectionHelper.Instantiate <IPartitioner <TKey> >(config.PartitionerClass),
                                                                            ReflectionHelper.Instantiate <IEncoder <TData> >(config.SerializerClass),
                                                                            new BrokerPartitionInfo(syncProducerPool, topicPartitionInfo, topicPartitionInfoLastUpdateTime, Config.TopicMetaDataRefreshIntervalMS, syncProducerPool.zkClient),
                                                                            syncProducerPool);
        }
        public PublishManager()
        {
            SendData     = true;
            NotifyStatus = NotifyStatus.Failed;
            Waitingtime  = 500;

            producerCallbackHandler = new CallbackHandler <INotifyCallback>();

            notifySemaphore = new Semaphore(0, 1);

            asyncQueue = new Queue <Message <T> >(queueCapacity);
        }
示例#19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProducerPool&lt;TData&gt;"/> class.
        /// </summary>
        /// <param name="config">
        /// The config.
        /// </param>
        /// <param name="serializer">
        /// The serializer.
        /// </param>
        /// <param name="callbackHandler">
        /// The callback invoked after new broker is added.
        /// </param>
        protected ProducerPool(
            ProducerConfiguration config,
            IEncoder <TData> serializer,
            ICallbackHandler callbackHandler)
        {
            Guard.NotNull(config, "config");
            Guard.NotNull(serializer, "serializer");

            this.Config          = config;
            this.Serializer      = serializer;
            this.CallbackHandler = callbackHandler;
        }
示例#20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Producer&lt;TKey, TData&gt;"/> class.
 /// </summary>
 /// <param name="config">The config object.</param>
 /// <param name="partitioner">The partitioner that implements <see cref="IPartitioner&lt;TKey&gt;" />
 /// used to supply a custom partitioning strategy based on the message key.</param>
 /// <param name="encoder">The encoder that implements <see cref="IEncoder&lt;TData&gt;" />
 /// used to convert an object of type TData to <see cref="Message" />.</param>
 /// <param name="callbackHandler">The callback handler that implements <see cref="ICallbackHandler" />, used
 /// to supply callback invoked when sending asynchronous request is completed.</param>
 /// <remarks>
 /// Can be used to provide pre-instantiated objects for all config parameters
 /// that would otherwise be instantiated via reflection.
 /// </remarks>
 public Producer(
     ProducerConfiguration config,
     IPartitioner <TKey> partitioner,
     IEncoder <TData> encoder,
     ICallbackHandler callbackHandler)
     : this(
         config,
         partitioner,
         ProducerPool <TData> .CreatePool(config, encoder, callbackHandler))
 {
     Guard.NotNull(config, "config");
     Guard.NotNull(encoder, "encoder");
 }
示例#21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AsyncProducer"/> class.
        /// </summary>
        /// <param name="config">
        /// The producer config.
        /// </param>
        /// <param name="callbackHandler">
        /// The callback invoked when a request is finished being sent.
        /// </param>
        public AsyncProducer(
            AsyncProducerConfiguration config,
            ICallbackHandler callbackHandler)
        {
            Guard.NotNull(config, "config");

            this.Config          = config;
            this.callbackHandler = callbackHandler;
            this.connection      = new KafkaConnection(
                this.Config.Host,
                this.Config.Port,
                this.Config.BufferSize,
                this.Config.SocketTimeout);
        }
        public static ICallbackHandler <TResult> CopyCallbacksFrom <TResult>(this ICallbackHandler <TResult> destination,
                                                                             ICallbackHandler <TResult> from)
        {
            destination.OnExecuteEvent        = from.OnExecuteEvent;
            destination.OnExecuteRedirection  = from.OnExecuteRedirection;
            destination.OnExecuteUnauthorized = from.OnExecuteUnauthorized;
            destination.OnRedirectToRoot      = from.OnRedirectToRoot;
            destination.OnRedirectToCurrent   = from.OnRedirectToCurrent;
            destination.OnNewContainedScreen  = from.OnNewContainedScreen;
            destination.OnStartNewFlow        = from.OnStartNewFlow;
            destination.OnAddModelError       = from.OnAddModelError;

            return(destination);
        }
示例#23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AsyncProducer"/> class.
        /// </summary>
        /// <param name="config">
        /// The producer config.
        /// </param>
        /// <param name="callbackHandler">
        /// The callback invoked when a request is finished being sent.
        /// </param>
        public AsyncProducer(
            AsyncProducerConfiguration config,
            ICallbackHandler callbackHandler)
        {
            Guard.NotNull(config, "config");

            this.Config = config;
            this.callbackHandler = callbackHandler;
            this.connection = new KafkaConnection(
                this.Config.Host,
                this.Config.Port,
                this.Config.BufferSize,
                this.Config.SocketTimeout);
        }
示例#24
0
        /// <summary>
        /// Factory method used to instantiating either,
        /// synchronous or asynchronous, producer pool based on configuration.
        /// </summary>
        /// <param name="config">
        /// The producer pool configuration.
        /// </param>
        /// <param name="serializer">
        /// The serializer.
        /// </param>
        /// <param name="cbkHandler">
        /// The callback invoked after new broker is added.
        /// </param>
        /// <returns>
        /// Instantiated either, synchronous or asynchronous, producer pool
        /// </returns>
        public static ProducerPool <TData> CreatePool(
            ProducerConfiguration config,
            IEncoder <TData> serializer,
            ICallbackHandler cbkHandler)
        {
            if (config.ProducerType == ProducerTypes.Async)
            {
                return(AsyncProducerPool <TData> .CreateAsyncPool(config, serializer, cbkHandler));
            }

            if (config.ProducerType == ProducerTypes.Sync)
            {
                return(SyncProducerPool <TData> .CreateSyncPool(config, serializer, cbkHandler));
            }

            throw new InvalidOperationException("Not supported producer type " + config.ProducerType);
        }
示例#25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AsyncProducer"/> class.
        /// </summary>
        /// <param name="config">
        /// The producer config.
        /// </param>
        /// <param name="callbackHandler">
        /// The callback invoked when a request is finished being sent.
        /// </param>
        public AsyncProducer(
            AsyncProducerConfiguration config,
            ICallbackHandler callbackHandler)
        {
            Guard.NotNull(config, "config");

            this.Config          = config;
            this.callbackHandler = callbackHandler;
            this.connection      = new KafkaConnection(
                this.Config.Host,
                this.Config.Port,
                this.Config.BufferSize,
                this.Config.SocketTimeout,
                this.Config.IdleTimeToKeepAlive,
                this.Config.KeepAliveInterval,
                this.Config.SocketPollingTimeout,
                this.Config.SocketPollingLevel);
        }
示例#26
0
        public ReplicationService(State state)
        {
            this.state = state;

            clientCallbackHandler  = new CallbackHandler <IReplicationClientCallback <R> >();
            serviceCallbackHandler = new CallbackHandler <IReplicationServiceCallback <R> >();

            if (this.state == State.StandBy)
            {
                var partnerIpAddress = ConfigurationManager.AppSettings["partnerIpAddress"];
                var partnerPort      = ConfigurationManager.AppSettings["partnerPort"];
                var partnerEndpoint  = ConfigurationManager.AppSettings["endpoint"];

                partnerServiceProxy = new ReplicationServiceProxy <R>();
                partnerServiceProxy.ForwardReplicaEvent += DeliverReplica;
                partnerServiceProxy.Initialize(partnerIpAddress, partnerPort, partnerEndpoint);
                partnerServiceProxy.RegisterToPartner();
            }
        }
示例#27
0
        public void GetNumberOfUploadedImage()
        {
            callback = OperationContext.Current.GetCallbackChannel
                       <ICallbackHandler>();
            Console.WriteLine("Znajdowanie elementów- start");
            Thread.Sleep(4 * 1000); // tu 4 sekundy (40000 ms)
            int sum = 0;

            for (int i = 0; i < images.Count; i++)
            {
                if (images[i].IsUploaded == true)
                {
                    sum++;
                }
            }
            Console.WriteLine("Znajdowanie elementów - stop");
            result = sum;
            callback.ZwrotGetNumberOfUploadedImage(result);
        }
示例#28
0
文件: Bgfx.cs 项目: prepare/SharpBgfx
 /// <summary>
 /// Initializes the graphics library on the specified adapter.
 /// </summary>
 /// <param name="backend">The backend API to use for rendering.</param>
 /// <param name="adapter">The adapter on which to create the device.</param>
 /// <param name="callbackHandler">A set of handlers for various library callbacks.</param>
 public static void Init(RendererBackend backend = RendererBackend.Default, Adapter adapter = default(Adapter), ICallbackHandler callbackHandler = null)
 {
     NativeMethods.bgfx_init(
         backend,
         (ushort)adapter.Vendor,
         (ushort)adapter.DeviceId,
         CallbackShim.CreateShim(callbackHandler),
         IntPtr.Zero
     );
 }
示例#29
0
        public static unsafe IntPtr CreateShim(ICallbackHandler handler)
        {
            if (handler == null)
                return IntPtr.Zero;

            if (savedDelegates != null)
                throw new InvalidOperationException("Callbacks should only be initialized once; bgfx can only deal with one set at a time.");

            var memory = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CallbackShim)));
            var shim = (CallbackShim*)memory;
            var saver = new DelegateSaver(handler, shim);

            // the shim uses the unnecessary ctor slot to act as a vtbl pointer to itself,
            // so that the same block of memory can act as both bgfx_callback_interface_t and bgfx_callback_vtbl_t
            shim->vtbl = memory + IntPtr.Size;

            // cache the data so we can free it later
            shimMemory = memory;
            savedDelegates = saver;

            return memory;
        }
示例#30
0
文件: Service1.cs 项目: Valvar00/CSA
 public myCallbackCalculator()
 {
     callback = OperationContext.Current.GetCallbackChannel
                <ICallbackHandler>();
 }
示例#31
0
 /// <summary>
 /// Initializes the graphics library on the specified adapter.
 /// </summary>
 /// <param name="backend">The backend API to use for rendering.</param>
 /// <param name="adapter">The adapter on which to create the device.</param>
 /// <param name="callbackHandler">A set of handlers for various library callbacks.</param>
 public static void Init(RendererBackend backend = RendererBackend.Default, Adapter adapter = default(Adapter), ICallbackHandler callbackHandler = null)
 {
     NativeMethods.bgfx_init(
         backend,
         (ushort)adapter.Vendor,
         (ushort)adapter.DeviceId,
         CallbackShim.CreateShim(callbackHandler ?? new DefaultCallbackHandler()),
         IntPtr.Zero
         );
 }
示例#32
0
 /// <summary>
 /// Adds a handler
 /// </summary>
 /// <param name="handler">The handler to add</param>
 public void AddHandler(ICallbackHandler handler)
 {
     callbackHandlers.Add(handler);
 }
示例#33
0
文件: Steam.cs 项目: EIREXE/discord
 public static void AddHandler(ICallbackHandler handler)
 {
     Callbacks.Add(handler);
 }
示例#34
0
文件: Steam.cs 项目: EIREXE/discord
 public static void RemoveHandler(ICallbackHandler handler)
 {
     Callbacks.Remove(handler);
 }
示例#35
0
 /// <summary>
 /// Removes a handler
 /// </summary>
 /// <param name="handler">The handler to remove</param>
 public void RemoveHandler(ICallbackHandler handler)
 {
     callbackHandlers.Remove(handler);
 }
示例#36
0
            public unsafe DelegateSaver(ICallbackHandler handler, CallbackShim* shim)
            {
                this.handler = handler;
                reportError = ReportError;
                reportDebug = ReportDebug;
                getCachedSize = GetCachedSize;
                getCacheEntry = GetCacheEntry;
                setCacheEntry = SetCacheEntry;
                saveScreenShot = SaveScreenShot;
                captureStarted = CaptureStarted;
                captureFinished = CaptureFinished;
                captureFrame = CaptureFrame;

                shim->reportError = Marshal.GetFunctionPointerForDelegate(reportError);
                shim->reportDebug = Marshal.GetFunctionPointerForDelegate(reportDebug);
                shim->getCachedSize = Marshal.GetFunctionPointerForDelegate(getCachedSize);
                shim->getCacheEntry = Marshal.GetFunctionPointerForDelegate(getCacheEntry);
                shim->setCacheEntry = Marshal.GetFunctionPointerForDelegate(setCacheEntry);
                shim->saveScreenShot = Marshal.GetFunctionPointerForDelegate(saveScreenShot);
                shim->captureStarted = Marshal.GetFunctionPointerForDelegate(captureStarted);
                shim->captureFinished = Marshal.GetFunctionPointerForDelegate(captureFinished);
                shim->captureFrame = Marshal.GetFunctionPointerForDelegate(captureFrame);
            }
示例#37
0
 public Producer(ICallbackHandler <TKey, TData> callbackHandler)
 {
     this.callbackHandler = callbackHandler;
 }
示例#38
0
 public CallbackLista()
 {
     callback = OperationContext.Current.GetCallbackChannel <ICallbackHandler>();
 }
示例#39
0
 public CallbackServiceContextMessageHandler(ICallbackHandler callbackHandler)
 {
     this.callbackHandler = callbackHandler;
 }