public string Connect(string userName) { if (!lowClients.ContainsKey(userName)) { clearClientsQueue.CallBounce(); lowClients.Add(userName, new Queue <string>()); highClients.Add(userName, new Queue <string>()); mediumClients.Add(userName, new Queue <string>()); return(MessageServiceConstants.Success); } else { return(MessageServiceConstants.UserNameBusy); } }
public MessageWorkerService() { int workerAmount = int.Parse(ConfigurationManager.AppSettings["workerAmount"]); int highPriority = int.Parse(ConfigurationManager.AppSettings["highPriority"]); int mediumPriority = int.Parse(ConfigurationManager.AppSettings["mediumPriority"]); int lowPriority = int.Parse(ConfigurationManager.AppSettings["lowPriority"]); int dumpTimeout = int.Parse(ConfigurationManager.AppSettings["dumpTimeout"]); for (int i = 0; i < workerAmount; ++i) { workers.Add(new MessageWorker(lowPriority, mediumPriority, highPriority)); } clearClientsQueue = new Bounce(() => { foreach (var worker in workers) { foreach (var userName in lowClients.Keys) { worker.DoJob(lowClients[userName], mediumClients[userName], highClients[userName]); } } }, dumpTimeout); clearClientsQueue.CallBounce(); }