/// <summary> /// Excute sending request to destination by <paramref name="url"/>. /// <paramref name="postData"/> is null if method option is GET /// </summary> /// <param name="methodOption"></param> /// <param name="url"></param> /// <param name="postData">null if method option is GET</param> /// <returns></returns> public async Task <ApiJsonResultCrossRequest <T> > DoRequest(MethodOption methodOption, string url, object postData = null, Dictionary <string, string> headerValues = null) { if (methodOption == MethodOption.Post && postData == null) { ApiJsonResultCrossRequest <T> exeptionResult = new ApiJsonResultCrossRequest <T>() { Success = false, ErrorMessage = "DATA_POST_NULL" }; return(exeptionResult); } try { var response = new HttpResponseMessage(); if (methodOption == MethodOption.Get) { response = await GetAsync(url); } else { if (_requestDataFormatOption == RequestDataFormatOption.MultiFormFormat) { var data = postData.GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public) .ToDictionary(prop => prop.Name, prop => prop.GetValue(postData, null) != null ? prop.GetValue(postData).ToString() : ""); response = await PostWithMultiFormAsync(url, data, headerValues); } else { response = await PostAsync(url, postData, headerValues); } } var result = ReadResponse(response); return(result); } catch (Exception ex) { ApiJsonResultCrossRequest <T> exeptionResult = new ApiJsonResultCrossRequest <T>() { Success = false, ErrorMessage = ex.Message }; return(exeptionResult); } }
public void Create() { InnerMenu inMain = (InnerMenu)m_MainMenu.InnerMenu; InnerMenu versionAndCapitalsMenu = new InnerMenu("Version and Capitals"); MethodOption countCapitalsMethodOption = new MethodOption("Count Capitals"); MethodOption showVersionMethodOption = new MethodOption("Show Version"); countCapitalsMethodOption.OptionChosen += new CountCapital().Action; showVersionMethodOption.OptionChosen += new ShowVersion().Action; InnerMenu showDateOrTimeMenu = new InnerMenu("Show Date/Time"); MethodOption showTimeMethodOption = new MethodOption("Show Time"); MethodOption showDateMethodOption = new MethodOption("Show Date"); showTimeMethodOption.OptionChosen += new ShowTimeOrDate(TimeTypes.eTypeOfTime.Time).Action; showDateMethodOption.OptionChosen += new ShowTimeOrDate(TimeTypes.eTypeOfTime.Date).Action; versionAndCapitalsMenu.AddToMenu(countCapitalsMethodOption); versionAndCapitalsMenu.AddToMenu(showVersionMethodOption); showDateOrTimeMenu.AddToMenu(showTimeMethodOption); showDateOrTimeMenu.AddToMenu(showDateMethodOption); inMain.AddToMenu(versionAndCapitalsMenu); inMain.AddToMenu(showDateOrTimeMenu); m_MainMenu.Show(); }