private static void Display(ConverterResponse response) { if (response.Result != null && response.Error == null) { var successColor = ConsoleColor.Green; var timezone = response.Result.TimeZone < 0 ? $"МСК{response.Result.TimeZone}" : response.Result.TimeZone == 0 ? "МСК" : $"МСК+{response.Result.TimeZone}"; var info = response.Result != null ? $"{timezone}, {response.Result.Region.Name}, {response.Result.Operator.Name}" : "null"; Console.WriteLine($"Вход: {response.Input}"); Console.WriteLine($"Статус: {response.Status}"); Console.Write($"Телефон: "); Colorize(response.Result.Phone.FullNumber, successColor); Console.Write($"Инфо: "); Colorize(info, successColor); } else { var failColor = ConsoleColor.Red; var successColor = ConsoleColor.Green; var phone = response.Result != null ? response.Result.Phone.FullNumber : "null"; Console.WriteLine($"Вход: {response.Input}"); Console.Write($"Статус: "); Colorize(response.Status, failColor); Console.Write($"Телефон: "); Colorize(phone, response.Result != null ? successColor : failColor); Console.Write($"Инфо: "); Colorize(response.ErrorString, failColor); } }
public ConverterResponse CompileCode(ConverterRequest request) { string snippet = @" var csharp = __$chshar-snippet$__; Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(csharp)); ".Replace("__$chshar-snippet$__", request.Csharp); try { var result = Executor.ExecuteSnippet(snippet.Split(Environment.NewLine)); var responseObject = System.Text.Json.JsonSerializer.Deserialize <Dictionary <string, object> >(result); return(ConverterResponse.ForSuccess(responseObject)); } catch (DynamicCompilationException e) { return(ConverterResponse.ForError(e)); } }
private ConverterResponse GetPhoneInfoResponse(Phone phone, Operator @operator, Region region, Exception error, string input) { var response = new ConverterResponse(); response.Input = input; response.Result = new PhoneInfo(); response.Result.Phone = phone; if (@operator == null) { response.Status = GetStatus(Status.Error); response.Error = new FormatException("Оператор не найден", error); return(response); } response.Result.OperatorId = @operator.Id; response.Result.Operator = @operator; if (region == null) { response.Status = GetStatus(Status.Error); response.Error = new FormatException("Регион не найден", error); return(response); } response.Result.RegionId = region.Id; response.Result.Region = region; response.Result.TimeZone = region.TimeZoneSpan; if (error != null) { response.Status = GetStatus(Status.Error); response.Error = error; return(response); } response.Status = GetStatus(Status.Complete); return(response); }
public ConverterResponse Convert(string currency) { var response = new ConverterResponse(); try { response.ConvertedText = this._converter.ConvertToWords(currency); response.Status = (int)ConversionStatusCode.OK; response.ErrorMessage = string.Empty; } catch (ArgumentException argumentException) { response.Status = (int)ConversionStatusCode.Error; response.ErrorMessage = argumentException.Message; } catch (Exception) { response.Status = (int)ConversionStatusCode.Error; response.ErrorMessage = "Error while doing conversion"; // Some logging stuff here log.Error(exception); } return(response); }
public ResultWithResponse(string message, ConverterResponse status) { Status = status; Message = message; }