Ejemplo n.º 1
0
        public void ProcessQueue(QueueMetaData queueMetaData)
        {
            Console.WriteLine(queueMetaData.ChatEntryTime);

            if (queueMetaData.Function == Constants.MessageFunctionType.Start)
            {
                var exists = _queueDataModel.HasKey(queueMetaData.ClientID);

                if (!exists)
                {
                    queueMetaData.ChatEntryTime = DateTime.UtcNow;
                    queueMetaData.ExpiryTime    = DateTime.UtcNow.AddMinutes(Constants.DefaultChatExpiry);
                    queueMetaData.CurrentAgent  = null;
                    queueMetaData.Function      = Constants.MessageFunctionType.Waiting;

                    _queueDataModel.Insert(queueMetaData);
                }
            }

            if (queueMetaData.Function == Constants.MessageFunctionType.Stop)
            {
                _queueDataModel.Delete(queueMetaData.ClientID);
            }

            if (queueMetaData.Function == Constants.MessageFunctionType.Update)
            {
            }
        }
Ejemplo n.º 2
0
        public bool Update(QueueMetaData queue)
        {
            var list = _cacheHelper.GetValue <Dictionary <Guid, QueueMetaData> >(Constants.CacheKeys.QueueMetaDataList.ToString());

            if (!list.ContainsKey(queue.ClientID))
            {
                return(false);
            }

            list.Remove(queue.ClientID);
            list.Add(queue.ClientID, queue);

            _cacheHelper.SetValue(Constants.CacheKeys.QueueMetaDataList.ToString(), list);
            return(true);
        }
Ejemplo n.º 3
0
        public QueueMetaData Get(Guid id)
        {
            var list = _cacheHelper.GetValue <Dictionary <Guid, QueueMetaData> >(Constants.CacheKeys.QueueMetaDataList.ToString());

            if (list == null)
            {
                return(null);
            }

            QueueMetaData queue = null;

            list.TryGetValue(id, out queue);

            return(queue);
        }
Ejemplo n.º 4
0
        public bool Insert(QueueMetaData queue)
        {
            var list = _cacheHelper.GetValue <Dictionary <Guid, QueueMetaData> >(Constants.CacheKeys.QueueMetaDataList.ToString());

            if (list == null)
            {
                list = new Dictionary <Guid, QueueMetaData>();
            }

            if (list.ContainsKey(queue.ClientID))
            {
                return(false);
            }

            list.Add(queue.ClientID, queue);

            _cacheHelper.SetValue(Constants.CacheKeys.QueueMetaDataList.ToString(), list);
            return(true);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// This method populates/refreshes the QueueMetaData collection.
    /// </summary>
    /// <param name="queueMetaDataCacheLimit">Specifies the length of time to cache the MetaData before refreshing it.</param>
    private void PopulateQueueMetaData(TimeSpan queueMetaDataCacheLimit)
    {
        if (QueueMetaData == null)
        {
            QueueMetaData = new Dictionary <Type, AzureQueueMetaData>();
        }
        var queuesWithoutMetaData = QueueWeights.Keys.Except(QueueMetaData.Keys).ToList();
        var expiredQueueMetaData  = QueueMetaData.Where(qmd => qmd.Value.TimeMetaDataWasPopulated < (DateTime.Now - queueMetaDataCacheLimit)).Select(qmd => qmd.Key).ToList();
        var validQueueData        = QueueMetaData.Where(x => !expiredQueueMetaData.Contains(x.Key)).ToList();
        var results = new Dictionary <Type, AzureQueueMetaData>();

        foreach (var queueProcessorType in queuesWithoutMetaData)
        {
            if (!results.ContainsKey(queueProcessorType))
            {
                var queueProcessor = ObjectFactory.GetInstance(queueProcessorType) as IProcessQueues;
                if (queueProcessor != null)
                {
                    var queue    = new AzureQueue(queueProcessor.PrimaryQueueName);
                    var metaData = queue.GetMetaData();
                    results.Add(queueProcessorType, metaData);
                    QueueWeights[queueProcessorType] = (metaData.ApproximateMessageCount) == 0
                                                      ? 1
                                                      : (int)Math.Log(metaData.ApproximateMessageCount, _resistance_to_scaling_larger_queues) + 1;
                }
            }
        }
        foreach (var queueProcessorType in expiredQueueMetaData)
        {
            if (!results.ContainsKey(queueProcessorType))
            {
                var queueProcessor = ObjectFactory.GetInstance(queueProcessorType) as IProcessQueues;
                if (queueProcessor != null)
                {
                    var queue    = new AzureQueue(queueProcessor.PrimaryQueueName);
                    var metaData = queue.GetMetaData();
                    results.Add(queueProcessorType, metaData);
                }
            }
        }
        QueueMetaData = results.Union(validQueueData).ToDictionary(data => data.Key, data => data.Value);
    }
Ejemplo n.º 6
0
        public dynamic Delete(Guid id)
        {
            try
            {
                if (id != Guid.Empty)
                {
                    QueueMetaData queueMeta = new QueueMetaData();
                    queueMeta.ClientID = id;
                    queueMeta.Function = Common.Constants.MessageFunctionType.Stop;
                    _messageQueueHelper.PushMessage <QueueMetaData>(_applicationConfig, queueMeta);

                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError());
            }

            return(BadRequest());
        }
Ejemplo n.º 7
0
        public dynamic Post([FromBody] ChatQueuePostRequest request)
        {
            try
            {
                if (request.ChatQueueKey != Guid.Empty)
                {
                    QueueMetaData queueMeta = new QueueMetaData();
                    queueMeta.ClientID = request.ChatQueueKey;
                    queueMeta.Function = Common.Constants.MessageFunctionType.Start;
                    queueMeta.Username = request.Username;
                    _messageQueueHelper.PushMessage <QueueMetaData>(_applicationConfig, queueMeta);

                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError());
            }

            return(BadRequest());
        }