예제 #1
0
        /// <summary>
        /// Writes an event into the pipeline. This method returns immediately.
        /// </summary>
        /// <param name="request">The emit event request</param>
        public bool IntakeEvent(IPlayFabEmitEventRequest request)
        {
            try
            {
                this.ThrowIfDisposed();
                if (request == null)
                {
                    // We don't want to throw and break pipeline because of a bad event
                    logger.Error("Request passed to event pipeline is null");
                    return(false);
                }

                if (!this.isActive)
                {
                    logger.Warning("Event pipeline is not active");
                    return(false);
                }

                // Non-blocking add, return immediately and report a dropped event
                // if event buffer is full or marked as complete for adding.
                if (!this.eventBuffer.TryAdd(request))
                {
                    logger.Error("Event buffer is full or complete and event {0} cannot be added", ((PlayFabEmitEventRequest)request).Event.Name);
                    return(false);
                }

                return(true);
            }
            catch (Exception e)
            {
                logger.Error($"Exception in synchronous WriteEvent from {e.Source} with message: {e.Message}");
            }

            return(false);
        }
예제 #2
0
        public IEnumerable <Task <IPlayFabEmitEventResponse> > RouteEvent(IPlayFabEmitEventRequest request)
        {
            var tasks = new List <Task <IPlayFabEmitEventResponse> >();

            // only events based on PlayFabEmitEventRequest are supported by default pipelines
            var eventRequest = request as PlayFabEmitEventRequest;

            if (eventRequest == null || eventRequest.Event == null)
            {
                return(tasks);
            }

            foreach (var pipeline in this.Pipelines)
            {
                switch (eventRequest.Event.EventType)
                {
                case PlayFabEventType.Default:
                case PlayFabEventType.Lightweight:
                    // route lightweight (and default) events to OneDS pipeline only
                    if (pipeline.Key == EventPipelineKey.OneDS)
                    {
                        tasks.Add(pipeline.Value.IntakeEventAsync(request));
                    }
                    break;

                default:
                    logger.Error($"Not supported event type {eventRequest.Event.EventType}.");
                    break;
                }
            }

            return(tasks);
        }
예제 #3
0
        public async Task <IPlayFabEmitEventResponse> IntakeEventAsync(IPlayFabEmitEventRequest request)
#endif
        {
            try
            {
                this.ThrowIfDisposed();
                var resultPromise = new TaskCompletionSource <IPlayFabEmitEventResponse>();

                if (request == null)
                {
                    // We don't want to throw and break pipeline because of a bad event
                    logger.Error("Request passed to event pipeline is null");
                    resultPromise.SetCanceled();
                }
                else if (!this.isActive)
                {
                    logger.Warning("Event pipeline is not active");
                    resultPromise.SetCanceled();
                }

                // Non-blocking add, return immediately and report a dropped event
                // if event buffer is full or marked as complete for adding.
                else
                {
                    ((PlayFabEmitEventRequest)request).ResultPromise = resultPromise;
                    if (!this.eventBuffer.TryAdd(request))
                    {
                        logger.Error("Event buffer is full or complete and event {0} cannot be added", ((PlayFabEmitEventRequest)request).Event.Name);
                        resultPromise.SetCanceled();
                    }
                }

#if TPL_35
                return(resultPromise.Task);
#else
                return(await resultPromise.Task);
#endif
            }
            catch (Exception e)
            {
                logger.Error(string.Format("Exception in IntakeEventAsync from {0} with message: {1}", e.Source, e.Message));
                var taskCompletionSource = new TaskCompletionSource <IPlayFabEmitEventResponse>();
                taskCompletionSource.SetResult(new PlayFabEmitEventResponse());
#if TPL_35
                return(taskCompletionSource.Task);
#else
                return(await taskCompletionSource.Task);
#endif
            }
        }
예제 #4
0
        /// <summary>
        /// Writes an event into the pipeline and returns a task that allows user to wait for a result
        /// when this particular event is processed by pipeline and sent out to backend.
        /// </summary>
        /// <param name="request">The emit event request</param>
        /// <returns>A task that allows user to wait for a result.</returns>
#if TPL_35
        public Task <IPlayFabEmitEventResponse> IntakeEventAsync(IPlayFabEmitEventRequest request)