public ActionResult <StringListResponse> Get(int ClientID, int ClientTransactionID)
        {
            List <string> list             = new List <string>();
            string        concatenatedList = null;

            try
            {
                if (list != null && list.Count > 0)
                {
                    foreach (string supportedAction in Program.Simulator.SupportedActions)
                    {
                        list.Add(supportedAction);
                    }
                    concatenatedList = string.Join(" ", list);
                }

                Program.TraceLogger.LogMessage(methodName + " Get", concatenatedList);
                return(new StringListResponse(ClientTransactionID, ClientID, methodName, list));
            }
            catch (Exception ex)
            {
                Program.TraceLogger.LogMessage(methodName, string.Format("Exception calling {0}: {1}", methodName, ex.ToString()));
                StringListResponse response = new StringListResponse(ClientTransactionID, ClientID, methodName, new List <string>());
                response.ErrorMessage = ex.Message;
                response.ErrorNumber  = ex.HResult - Program.ASCOM_ERROR_NUMBER_OFFSET;
                return(response);
            }
        }
예제 #2
0
        private string BuildListJsonString(StringListResponse responseList)
        {
            // JsonConvert.SerializeObject does not work with responseList.List.
            StringBuilder jsonArrayString = new StringBuilder();

            foreach (string s in responseList.List)
            {
                Logger.Log("Found: " + s, LoggingLevel.Verbose);
                if (jsonArrayString.Length > 0)
                {
                    jsonArrayString.Append(",\n");
                }
                jsonArrayString.Append("\"" + s + "\"");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("    \"" + JsonNamesList + "\": [\n");
            if (jsonArrayString.Length > 0)
            {
                sb.Append(jsonArrayString.ToString());
                sb.Append("\n");
            }
            sb.Append("    ]\n");

            Logger.Log("Json List: " + sb.ToString(), LoggingLevel.Verbose);

            return(sb.ToString());
        }
예제 #3
0
        public async Task <StringListResponse> GetYearsList()
        {
            StringListResponse response = new StringListResponse();
            List <string>      years    = new List <string>();

            try
            {
                var questionAccessor = new QuestionAccessor(_dbContext);

                years = await questionAccessor.GetYearsList();

                response.Success = true;
                response.Message = "";
                response.Data    = years;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                response.Data    = null;
            }

            return(response);
        }