Example #1
0
        public AccessSafely AfterCompleting(int happenings)
        {
            _access = AccessSafely.AfterCompleting(happenings);

            _access.WritingWith <Response>("response", response => {
                var testId = response.HeaderValueOr(Client.ClientIdCustomHeader, "");

                _logger.WriteLine("ID: {0}", testId);

                if (string.IsNullOrEmpty(testId))
                {
                    _logger.WriteLine("Expected header missing: {0}", Client.ClientIdCustomHeader);
                    //throw new IllegalStateException("Expected header missing: " + Client.ClientIdCustomHeader);
                }

                int existingCount = 0;
                if (_clientCounts.ContainsKey(testId))
                {
                    existingCount = _clientCounts[testId];
                }

                ResponseHolder.Set(response);

                _clientCounts.Add(testId, existingCount + 1);

                ResponseCount.IncrementAndGet();
            });
            _access.ReadingWith("response", () => ResponseHolder.Get());
            _access.ReadingWith("responseCount", () => ResponseCount.Get());
            _access.ReadingWith("responseClientCounts", () => _clientCounts);

            _access.WritingWith <int>("unknownResponseCount", increment => UnknownResponseCount.IncrementAndGet());
            _access.ReadingWith("unknownResponseCount", () => UnknownResponseCount.Get());

            _access.ReadingWith("totalAllResponseCount", () => ResponseCount.Get() + UnknownResponseCount.Get());

            return(_access);
        }
Example #2
0
        public AccessSafely AfterCompleting(int happenings)
        {
            _access = AccessSafely.AfterCompleting(happenings);

            _access.WritingWith <Response>("response", response => {
                var testId = response.HeaderValueOr(Client.ClientIdCustomHeader, "");

                _logger.WriteLine("{0:MM/dd/yyyy hh:mm:ss.fff} ID: {1}", DateTimeOffset.Now, testId);

                if (string.IsNullOrEmpty(testId))
                {
                    _logger.WriteLine("Expected header missing: {0}", Client.ClientIdCustomHeader);
                }

                if (_clientCounts.ContainsKey(testId))
                {
                    _clientCounts[testId] += 1;
                }
                else
                {
                    _clientCounts.Add(testId, 1);
                }

                ResponseHolder.Set(response);

                ResponseCount.IncrementAndGet();
            });
            _access.ReadingWith("response", () => ResponseHolder.Get());
            _access.ReadingWith("responseCount", () => ResponseCount.Get());
            _access.ReadingWith("responseClientCounts", () => _clientCounts);

            _access.WritingWith <int>("unknownResponseCount", increment => UnknownResponseCount.IncrementAndGet());
            _access.ReadingWith("unknownResponseCount", () => UnknownResponseCount.Get());

            _access.ReadingWith("totalAllResponseCount", () => ResponseCount.Get() + UnknownResponseCount.Get());

            return(_access);
        }
Example #3
0
        public Response SendRequest(string ns, Request request, string destinationId)
        {
            int requestId = Interlocked.Increment(ref _requestId);

            request.RequestId = requestId;
            SendMessage(ns, request, destinationId);
            ResponseHolder responseHolder = new ResponseHolder();

            _responses[requestId] = responseHolder;
            // Wait for response
            bool signaled = responseHolder.Signal.WaitOne(REQUEST_TIMEOUT);

            if (!signaled)
            {
                throw new TimeoutException(string.Format("Could not get response for the request {0}", request.GetType().Name));
            }

            responseHolder.Signal.Close();
            ResponseHolder holder;

            _responses.TryRemove(requestId, out holder);
            return(responseHolder.Response);
        }
Example #4
0
 public EzTextingResponse(string status, int code, IList <T> entries)
 {
     _holder = new ResponseHolder <T> {
         Status = status, Code = code, Entries = entries
     };
 }
Example #5
0
 public EzTextingResponse(string status, int code, T entry)
 {
     _holder = new ResponseHolder <T> {
         Status = status, Code = code, Entry = entry
     };
 }
        private void SendRequest(RequestMode query)
        {
            string receivedMessage = null;

            ResultList = null;

            try
            {
                switch (query)
                {
                case RequestMode.registry:
                    receivedMessage = HL7Helper.GenerateTeamRegistry(TeamName, RegistryIP, RegistryPort);
                    break;

                case RequestMode.service:
                    receivedMessage = HL7Helper.GenerateQueryService(TeamName, TeamID, RegistryIP, RegistryPort, ServiceTag);
                    break;

                case RequestMode.request:
                    receivedMessage = HL7Helper.SendRequest(SelectedService);
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error("Failed to send HL7 request", e);
                _dialogService.ShowMessageBox("Failed to send HL7 request.");

                IsLoading = false;
                return;
            }

            LoadingMessage = "Analyzing";

            string error = string.Empty;

            ResponseHolder serviceResult = null;
            IWebService    queryResult   = null;

            switch (query)
            {
            case RequestMode.registry:
                break;

            case RequestMode.service:
                queryResult = HL7Helper.AnalyzeQueryResponse(receivedMessage, out error);
                break;

            case RequestMode.request:
                serviceResult = HL7Helper.AnalyzeResponse(receivedMessage, out error);
                break;
            }

            if (!string.IsNullOrWhiteSpace(error))
            {
                _dialogService.ShowMessageBox(string.Format("Bad response: {0}", error));
                Logger.Error(error, new Exception(receivedMessage));
            }
            else
            {
                switch (query)
                {
                case RequestMode.registry:
                    break;

                case RequestMode.service:
                    Teams = new List <ITeam>()
                    {
                        new Team(TeamName, new List <IWebService>()
                        {
                            queryResult
                        })
                    };
                    break;

                case RequestMode.request:
                    ResultList = new List <ResponseHolder>()
                    {
                        serviceResult
                    };
                    break;
                }
            }

            IsLoading = false;
            return;
        }
Example #7
0
        public string ResponseProcess(string response)
        {
            FoundKeyWords  = new Dictionary <string, string>();
            ResponseHolder = response.ToLower();
            string result = "";
            Dictionary <string, string> keywords = GetKeywordList();
            int    keywordCounter  = 0;
            string keyword         = "";
            string keywordCategory = "";

            result = "I'm sorry, I couldn't quite understand that. If you want some examples of what to ask for, try typing !help.";

            //string[] responseArray = ResponseHolder.Split(".");
            //string tempString = string.Join(' ', responseArray);
            //responseArray = tempString.Split(",");
            //tempString = string.Join(' ', responseArray);
            //responseArray = tempString.Split("!");
            //tempString = string.Join(' ', responseArray);
            //responseArray = tempString.Split("?");
            //tempString = string.Join(' ', responseArray);
            //responseArray = tempString.Split(";");
            //tempString = string.Join(' ', responseArray);
            //responseArray = tempString.Split(":");
            //tempString = string.Join(' ', responseArray);

            //responseArray = tempString.Split(" ");

            foreach (KeyValuePair <string, string> item in keywords)
            {
                //    foreach(string word in responseArray)
                //    {
                //        if(word == item.Key)
                //        {
                //            keywordCounter++;
                //            keyword = item.Key;
                //            keywordCategory = item.Value;
                //            FoundKeyWords.Add(keyword, keywordCategory);
                //        }
                //    }

                if (ResponseHolder == item.Key.ToLower())
                {
                    keywordCounter++;
                    keyword         = item.Key;
                    keywordCategory = item.Value;
                    keywordCounter  = 0;
                    FoundKeyWords   = new Dictionary <string, string>();
                    FoundKeyWords.Add(keyword, keywordCategory);
                    break;
                }

                else if (ResponseHolder.Contains(item.Key.ToLower()))
                {
                    keywordCounter++;
                    keyword         = item.Key;
                    keywordCategory = item.Value;
                    FoundKeyWords.Add(keyword, keywordCategory);
                }
            }

            if (keywordCounter > 1)
            {
                result = ResponseToMultipleKeyWords();
            }
            else
            {
                result = ResponseToOneKeyWord();
            }

            if (result == "" || result == null)
            {
                result = "I'm sorry, I couldn't quite understand that. If you want some examples of what to ask for, try typing !help.";
            }
            return(result);
        }
Example #8
0
        public string ResponseToMultipleKeyWords()
        {
            string result = "";

            if (ResponseHolder.ToLower().Contains("motivation") || ResponseHolder.ToLower().Contains("quote") || ResponseHolder.ToLower().Contains("tired"))
            {
                result = GetMotivation();
            }
            else if (ResponseHolder.ToLower().Contains("calendar") || ResponseHolder.ToLower().Contains("events"))
            {
                result       = GetCalendarEvents();
                HoldOverItem = new DatabaseItem();
            }
            else if (ResponseHolder.ToLower().Contains("job") || ResponseHolder.ToLower().Contains("position") || ResponseHolder.ToLower().Contains("opening"))
            {
                result = GetAllJobListings();
            }
            else
            {
                List <DatabaseItem> keywordList = new List <DatabaseItem>();
                foreach (KeyValuePair <string, string> item in FoundKeyWords)
                {
                    if (item.Key != "")
                    {
                        DatabaseItem keyItem = GetItemList(item.Key, item.Value);
                        keywordList.Add(keyItem);

                        //result = keyItem.Description;
                        //if (keyItem.CategoryDescription != null && keyItem.CategoryName != null)
                        //{
                        //    result += " . \nThe information you requested was under the category " + keyItem.CategoryName + ". " + keyItem.CategoryDescription;
                        //}
                    }
                }

                keywordList = (keywordList.OrderBy(x => x.Weight)).ToList();

                List <DatabaseItem> positionList = keywordList.FindAll(x => x.CategoryName == "positions");
                if (positionList.Count > 0)
                {
                    foreach (DatabaseItem item in positionList)
                    {
                        result += item.Name + "\n\n" + item.Website + "\n\n";
                    }
                }
                else if (keywordList[keywordList.Count - 1].Weight - keywordList[keywordList.Count - 2].Weight >= 5)
                {
                    result       = keywordList[keywordList.Count - 1].Description + "<a target = '_blank' href = " + keywordList[keywordList.Count - 1].Website + ">" + keywordList[keywordList.Count - 1].Website + "</a>";
                    result      += " . \n\nThe information you requested was under the category " + keywordList[keywordList.Count - 1].CategoryName + ". " + keywordList[keywordList.Count - 1].CategoryDescription;
                    result      += "\n\n" + "Is this what you were looking for (please click yes or no)?";
                    HoldOverItem = keywordList[keywordList.Count - 1];
                    HoldOverList = keywordList;
                }
                else
                {
                    HoldOverItem = new DatabaseItem();
                    result       = "What do you want to learn more about? \n";
                    foreach (DatabaseItem item in keywordList)
                    {
                        result += item.Name + "\n";
                    }

                    //result = result.Substring(0, result.Length - 2);
                }
            }

            return(result);
        }
Example #9
0
        public string ResponseToOneKeyWord()
        {
            string result = "";


            if (ResponseHolder.ToLower().Contains("motivation") || ResponseHolder.ToLower().Contains("quote") || ResponseHolder.ToLower().Contains("tired"))
            {
                result       = GetMotivation();
                HoldOverItem = new DatabaseItem();
            }
            else if (ResponseHolder.ToLower().Contains("calendar") || ResponseHolder.ToLower().Contains("events"))
            {
                result       = GetCalendarEvents();
                HoldOverItem = new DatabaseItem();
            }
            else if (ResponseHolder.ToLower().Contains("job") || ResponseHolder.ToLower().Contains("position") || ResponseHolder.ToLower().Contains("opening"))
            {
                result       = GetAllJobListings();
                HoldOverItem = new DatabaseItem();
            }
            else if (ResponseHolder.ToLower() == "no" && HoldOverItem.Name != null)
            {
                HoldOverItem.Weight--;
                UpdateWeight(HoldOverItem);
                HoldOverItem = new DatabaseItem();
                result       = "What did you want to learn more about? " + "\n";
                foreach (DatabaseItem item in HoldOverList)
                {
                    result += item.Name + "\n";
                }

                HoldOverList = new List <DatabaseItem>();
            }
            else if (ResponseHolder.ToLower() == "yes" && HoldOverItem.Name != null)
            {
                HoldOverList = new List <DatabaseItem>();
                HoldOverItem = new DatabaseItem();
                result       = "Thank you";
            }
            else
            {
                HoldOverItem = new DatabaseItem();
                foreach (KeyValuePair <string, string> item in FoundKeyWords)
                {
                    if (item.Key != "")
                    {
                        DatabaseItem keyItem = GetItemList(item.Key, item.Value);

                        if (keyItem.Website == null)
                        {
                            keyItem.Website = "";
                        }

                        if (keyItem.Website.Contains("|"))
                        {
                            string[] websiteList = keyItem.Website.Split("|");
                            for (int i = 0; i < websiteList.Length; i++)
                            {
                                websiteList[i] = "<a target = '_blank' href = " + websiteList[i] + ">" + websiteList[i] + "</a>";
                            }
                            result = string.Join("\n", websiteList);
                        }
                        else
                        {
                            result = keyItem.Description + "\n" + "<a target = '_blank' href = " + keyItem.Website + ">" + keyItem.Website + "</a>";
                        }


                        if (keyItem.CategoryDescription != null && keyItem.CategoryName != null)
                        {
                            result += " \n\nThe information you requested was under the category " + keyItem.CategoryName + ": " + keyItem.CategoryDescription;
                            int updatedWeight = keyItem.Weight++;
                            UpdateWeight(keyItem);
                        }
                    }
                }
            }


            return(result);
        }