Пример #1
0
 /// <summary>
 /// Creates and schedules an execution of a request for the given beacon event.
 /// </summary>
 /// <param name="beaconEventArgs">The beacon event details.</param>
 /// <returns>The request ID.</returns>
 public int CreateRequest(BeaconEventArgs beaconEventArgs)
 {
     int requestId = SDKData.Instance.NextId();
     Request request = new Request(beaconEventArgs, requestId);
     request.Result += OnRequestResult;
     _requestQueue.Add(request);
     return requestId;
 }
Пример #2
0
        public void Add(Request request)
        {
            lock(_listLocker)
            {
                _requestList.Add(request);

                if (_requestList.Count > 0 && _serveRequestTimer == null)
                {
                    _serveRequestTimer = new Timer(ServeNextRequestAsync, null, 0, ServeRequestIntervalInMilliseconds);
                }
                if (QueueCountChanged != null)
                {
                    QueueCountChanged(this, _requestList.Count);
                }
            }
        }
Пример #3
0
        internal async Task<RequestResultState> InternalExecuteRequestAsync(Request request)
        {
            System.Diagnostics.Debug.WriteLine("LayoutManager.InternalExecuteRequestAsync(): Request ID is " + request.RequestId);
            RequestResultState resultState = RequestResultState.Failed;

            if (request != null && request.BeaconEventArgs != null && request.BeaconEventArgs.Beacon != null)
            {
                if (await VerifyLayoutAsync(false))
                {
                    request.ResolvedActions = _layout.GetResolvedActionsForPidAndEvent(
                        request.BeaconEventArgs.Beacon.Pid, request.BeaconEventArgs.EventType);

                    foreach (ResolvedAction resolvedAction in request.ResolvedActions)
                    {
                        if (resolvedAction != null && resolvedAction.BeaconAction != null)
                        {
                            resolvedAction.BeaconAction.Id = request.RequestId;
                        }
                    }

                    resultState = RequestResultState.Success;
                }
            }

            return resultState;
        }
Пример #4
0
        /// <summary>
        /// Sets the request result and removes it from the queue.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="resultState"></param>
        /// <returns>True, if the request was successfully removed from the queue.</returns>
        private bool OnRequestServed(Request request, RequestResultState resultState)
        {
            bool wasRemoved = false;

            if (request != null)
            {
                lock (_listLocker)
                {
                    wasRemoved = _requestList.Remove(request);
                    request.NotifyResult(resultState);

                    if (_requestList.Count == 0 && _serveRequestTimer != null)
                    {
                        _serveRequestTimer.Dispose();
                        _serveRequestTimer = null;
                    }
                    if (QueueCountChanged != null)
                    {
                        QueueCountChanged(this, _requestList.Count);
                    }
                }
            }

            return wasRemoved;
        }
Пример #5
0
 /// <summary>
 /// Executes the given request.
 /// </summary>
 /// <param name="request"></param>
 /// <returns>The result state (success or failure).</returns>
 public IAsyncOperation<RequestResultState> ExecuteRequestAsync(Request request)
 {
     IAsyncOperation<RequestResultState> resultState = InternalExecuteRequestAsync(request).AsAsyncOperation<RequestResultState>();
     return resultState;
 }