private static void MapMulti(OutputDto answer, Output output) { foreach (var multiValueResult in answer.MultiValues) { var multipleValue = new MultiValue(); var single = multiValueResult.Value as MultiSingleValueResult; var complex = multiValueResult.Value as MultiComplexValueResult; if (single != null) { foreach (var value in single.SingleValues) { multipleValue.SimpleValues.Add(value); } } if (complex != null) { foreach (var value in complex.ComplexValues) { var complexValue = new ComplexValue(); foreach (var singleValue in value.SingleValues) { complexValue.SimpleValues.Add(new SimpleValue(singleValue.Key, singleValue.Value)); } multipleValue.ComplexValues.Add(complexValue); } } multipleValue.Key = multiValueResult.Key; output.MultiValues.Add(multipleValue); } }
private void presentIfListIsEmpty() { Output output = new OutputDto(new Dictionary <String, int>()); output.Message = "you must enter words in the text"; presenter.present(output); }
private static void MapSimple(OutputDto answer, Output output) { foreach (var singleResult in answer.SingleValues) { output.SimpleValues.Add(new SimpleValue(singleResult.Key, singleResult.Value)); } }
private static void MapSimple(Output arg, OutputDto output) { foreach (var value in arg.SimpleValues) { output.SingleValues.Add(value.Key, value.Value); } }
public void when_the_input_is_correct_then_it_should_return_a_successfull_response() { String shapeName = ApplicationConstants.ShapeName.SQUARE; OutputDto expectedOutput = new OutputDto( shapeName, ApplicationConstants.Operation.AREA, 4, ApplicationConstants.Status.SUCCESS, "Operation ran successfully"); List <Double> values = new List <Double>(); values.Add(2); Shape shape = ModuleConfig.createShape(shapeName, values); InputAdapterDto input = new InputAdapterDto(shape, "area", values); Interactor shapeInteractor = new ShapeInteractor(); OutputDto response = shapeInteractor.execute(input); Assert.IsNotNull(response); Assert.AreEqual(expectedOutput.Shape, response.Shape); Assert.AreEqual(expectedOutput.Operation, response.Operation); Assert.AreEqual(expectedOutput.ResponseStatus, response.ResponseStatus); Assert.AreEqual(expectedOutput.ValueResponse, response.ValueResponse); Assert.AreEqual(expectedOutput.Message, response.Message); }
private void TrySaveAnswer(OutputDto output, QuestionId id, uint retries = 25) { try { var questionnaire = Context.QuestionnaireGateway.Get(id.QuestionaireId); if (questionnaire.LockQuestion && Request.IsAnonymousUser && questionnaire.GetSlide(id.Id).IsCompleted) { throw new SlideLockedException("Slide has been locked by calling Slide/Complete while LockQuestion is specified on the experiment", "The requested slide is not available for editing"); } var question = questionnaire.GetQuestion(id.Id); question.Output = OutputMapper.Map(output); Context.QuestionGateway.Save(question); } catch (InvalidRevisionException e) { if (retries > 0) { TrySaveAnswer(output, id, retries - 1); } else { throw new ServerException("Failed to save answer", "Your answer wasn't saved, try again.", e); } } }
public EndpointResult Set(string questionId, OutputDto output) { var id = new QuestionId(questionId); TrySaveAnswer(output, id); return(EndpointResult.Success()); }
public static Output Map(OutputDto arg) { var output = new Output(); MapComplex(arg, output); MapSimple(arg, output); MapMulti(arg, output); return(output); }
public async Task <IResult <OutputDto> > DoSomethingInternal() { _logger.LogWarning("log inside internal DoSomethingInternal"); _logger.LogInformation("log inside DoSomethingInternal"); var result = new OutputDto() { SomeParam = "outputValue" }; return(new Success <OutputDto>(result)); }
public void execute(OutputDto output) { Console.WriteLine("\n-----------------------------------------------"); Console.WriteLine("Response of the process"); Console.WriteLine("-----------------------------------------------"); Console.WriteLine("\nStatus: " + output.ResponseStatus); Console.WriteLine("Message: " + output.Message); Console.WriteLine("Operation: " + output.Operation); Console.WriteLine("Shape: " + output.Shape); Console.WriteLine("Value: " + output.ValueResponse); Console.WriteLine("\n-----------------------------------------------"); }
public Output execute(Input input) { List <String> words = (List <String>)input.getValue(); Dictionary <String, int> wordsOcurrences = convertListToDictionary(words); OutputDto output = new OutputDto(wordsOcurrences); output.Message = "successful response"; return(output); }
private static void MapComplex(Output arg, OutputDto output) { foreach (var value in arg.ComplexValues) { var vals = new ComplexValueResult(); foreach (var simpleValue in value.SimpleValues) { vals.SingleValues.Add(simpleValue.Key, simpleValue.Value); } output.ComplexValues.Add(value.Key, vals); } }
private static void MapComplex(OutputDto answer, Output output) { foreach (var complexResult in answer.ComplexValues) { var item = new ComplexValue(); item.Key = complexResult.Key; foreach (var singleResult in complexResult.Value.SingleValues) { item.Add(new SimpleValue(singleResult.Key, singleResult.Value)); } output.ComplexValues.Add(item); } }
static void Main(string[] args) { Console.WriteLine("Enter the value of the shape:"); string shapeName = Console.ReadLine(); Console.WriteLine("Enter the values of the sides, " + "separated by comma if it's necessary(square:1, rectangle:2, triangle:3):"); string sideValues = Console.ReadLine(); Console.WriteLine("Enter the operation:"); string operation = Console.ReadLine(); InputDto inputDto = new InputDto(shapeName, operation, sideValues); ManageInput manageInput = new ControllerShape(inputDto); OutputDto response = manageInput.execute(); ManageOutput manageOutput = new PresenterResponse(); manageOutput.execute(response); }
private Task HandleExceptionAsync(HttpContext context, Exception e) { var exeptionOutput = new OutputDto(); if (e is OneZeroException) { exeptionOutput.Code = ((OneZeroException)e).Code; exeptionOutput.Message = ((OneZeroException)e).Message; exeptionOutput.ErrorMessage = ((OneZeroException)e)?.GetBaseException().Message; LogExceptionByResponseCode(exeptionOutput.Message, exeptionOutput.Code); } else { string message = "系统消息:未知错误"; switch (context.Response.StatusCode) { case 401: message = "系统消息:没有访问权限"; break; case 404: message = "系统消息:未找到服务"; break; case 500: message = "系统消息:内部错误"; break; } exeptionOutput.Message = message; exeptionOutput.ErrorMessage = e.GetBaseException()?.Message; exeptionOutput.Code = ResponseCode.UnExpectedException; _logger.LogWarning(message, e); } exeptionOutput.StatusCode = (HttpStatusCode)context.Response.StatusCode; var result = JsonConvert.SerializeObject(exeptionOutput); context.Response.ContentType = "application/json;charset=utf-8"; return(context.Response.WriteAsync(result)); }
public void when_the_input_is_correct_then_it_should_return_a_successfull_response() { OutputDto expectedOutput = new OutputDto( ApplicationConstants.ShapeName.SQUARE, ApplicationConstants.Operation.AREA, 4, ApplicationConstants.Status.SUCCESS, "Operation ran successfully"); InputDto inputDto = new InputDto("square", "area", "2"); ManageInput manageInput = new ControllerShape(inputDto); OutputDto response = manageInput.execute(); Assert.IsNotNull(response); Assert.AreEqual(expectedOutput.Shape, response.Shape); Assert.AreEqual(expectedOutput.Operation, response.Operation); Assert.AreEqual(expectedOutput.ResponseStatus, response.ResponseStatus); Assert.AreEqual(expectedOutput.ValueResponse, response.ValueResponse); Assert.AreEqual(expectedOutput.Message, response.Message); }
public void when_the_input_is_not_correct_then_it_should_return_an_error_response() { OutputDto expectedOutput = new OutputDto( "squar", ApplicationConstants.Operation.AREA, 0, ApplicationConstants.Status.ERROR, "The name of the shape is not valid"); InputDto inputDto = new InputDto("squar", "area", "2"); ManageInput manageInput = new ControllerShape(inputDto); OutputDto response = manageInput.execute(); Assert.IsNotNull(response); Assert.AreEqual(expectedOutput.Shape, response.Shape); Assert.AreEqual(expectedOutput.Operation, response.Operation); Assert.AreEqual(expectedOutput.ResponseStatus, response.ResponseStatus); Assert.AreEqual(expectedOutput.ValueResponse, response.ValueResponse); Assert.AreEqual(expectedOutput.Message, response.Message); }
public void when_the_input_is_not_correct_then_it_should_return_an_error_response() { String shapeName = "triangle"; String operation = "area"; OutputDto expectedOutput = new OutputDto( shapeName, ApplicationConstants.Operation.AREA, 0, ApplicationConstants.Status.ERROR, "The values of the sides must not be negative"); double valueA = 2; double valueB = -1; double valueC = 2; List <Double> values = new List <Double>(); values.Add(valueA); values.Add(valueB); values.Add(valueC); Shape shape = new Triangle(valueA, valueB, valueC); InputAdapterDto input = new InputAdapterDto(shape, operation, values); Interactor shapeInteractor = new ShapeInteractor(); OutputDto response = shapeInteractor.execute(input); Assert.IsNotNull(response); Assert.AreEqual(expectedOutput.Shape, response.Shape); Assert.AreEqual(expectedOutput.Operation, response.Operation); Assert.AreEqual(expectedOutput.ResponseStatus, response.ResponseStatus); Assert.AreEqual(expectedOutput.ValueResponse, response.ValueResponse); Assert.AreEqual(expectedOutput.Message, response.Message); }
private static void MapMulti(Output arg, OutputDto output) { foreach (var value in arg.MultiValues) { if (value.SimpleValues.Any()) { var multi = new MultiSingleValueResult(); foreach (var simpleValue in value.SimpleValues) { multi.SingleValues.Add(simpleValue); } output.MultiValues.Add(value.Key, multi); } if (value.ComplexValues.Any()) { var multi = new MultiComplexValueResult(); foreach (var complexValue in value.ComplexValues) { var complexValueResult = new ComplexValueResult(); foreach (var simpleValue in complexValue.SimpleValues) { complexValueResult.SingleValues.Add(simpleValue.Key, simpleValue.Value); } multi.ComplexValues.Add(complexValueResult); } output.MultiValues.Add(value.Key, multi); } } }
public void Set_GivenNewAnswer_SetAnswerOnQuestion() { var extension = Make_AnswerExtension(); var answer = new OutputDto { ComplexValues = new Dictionary <string, ComplexValueResult>() { { "k1", new ComplexValueResult { SingleValues = new Dictionary <string, string>() { { "k2", "v2" } } } }, { "k3", new ComplexValueResult { SingleValues = new Dictionary <string, string>() { { "k4", "v4" }, { "k5", "v5" } } } } }, SingleValues = new Dictionary <string, string>() { { "k6", "v6" } }, MultiValues = new Dictionary <string, IMultiValueResult>() { { "k7", new MultiSingleValueResult { SingleValues = new List <string>() { "v7.1", "v7.2" } } }, { "k8", new MultiComplexValueResult { ComplexValues = new List <ComplexValueResult>() { new ComplexValueResult { SingleValues = new Dictionary <string, string>() { { "k8.1", "v8.1" }, { "k8.2", "v8.2" } } } } } } } }; var question = new Question("TestQuestion") { Id = "00000000-0000-0000-0000-000000000001:0", Version = "", Validation = new OutputValidator { ComplexValueValidator = new [] { new ComplexValueValidator { Id = "k1", SimpleValueValidators = new [] { new SimpleValueValidator { Id = "k2", Validation = ".*" } } } } } }; Context.QuestionnaireGateway.Set(new Questionnaire { Id = "00000000-0000-0000-0000-000000000001", Name = "Test", TargetId = "", TargetName = "1", Slides = new List <Slide> { new Slide { TaskId = "1", Questions = new List <Question> { question } } } }); extension.Set(question.Id, answer); var actual = Context.QuestionGateway.Get(question.Id); Assert.That(actual.Output.ComplexValues[0].Key, Is.EqualTo("k1")); Assert.That(actual.Output.ComplexValues[0].SimpleValues[0].Key, Is.EqualTo("k2")); Assert.That(actual.Output.ComplexValues[0].SimpleValues[0].Value, Is.EqualTo("v2")); Assert.That(actual.Output.ComplexValues[1].Key, Is.EqualTo("k3")); Assert.That(actual.Output.ComplexValues[1].SimpleValues[0].Key, Is.EqualTo("k4")); Assert.That(actual.Output.ComplexValues[1].SimpleValues[0].Value, Is.EqualTo("v4")); Assert.That(actual.Output.ComplexValues[1].SimpleValues[1].Key, Is.EqualTo("k5")); Assert.That(actual.Output.ComplexValues[1].SimpleValues[1].Value, Is.EqualTo("v5")); Assert.That(actual.Output.SimpleValues[0].Key, Is.EqualTo("k6")); Assert.That(actual.Output.SimpleValues[0].Value, Is.EqualTo("v6")); Assert.That(actual.Output.MultiValues[0].Key, Is.EqualTo("k7")); Assert.That(actual.Output.MultiValues[0].SimpleValues[0], Is.EqualTo("v7.1")); Assert.That(actual.Output.MultiValues[0].SimpleValues[1], Is.EqualTo("v7.2")); Assert.That(actual.Output.MultiValues[1].Key, Is.EqualTo("k8")); Assert.That(actual.Output.MultiValues[1].ComplexValues[0].SimpleValues[0].Key, Is.EqualTo("k8.1")); Assert.That(actual.Output.MultiValues[1].ComplexValues[0].SimpleValues[1].Key, Is.EqualTo("k8.2")); }
public void Test(OutputDto output) { }
public void execute(OutputDto output) { ViewPresenter presenter = new ConsoleView(); presenter.execute(output); }
public ActionResult QRCodeVerify(QRCodeVerifyInput model) { OutputDto result = new OutputDto(); string jsonStr = string.Empty; #region 参数验证 if (model == null) { result.Result = -1; result.Message = "参数错误"; jsonStr = JsonConvert.SerializeObject(result); return(Content(jsonStr)); } if (string.IsNullOrEmpty(model.ConnectionId) || model.UUID.Equals(Guid.Empty) || string.IsNullOrEmpty(model.UserName) || string.IsNullOrEmpty(model.Password)) { result.Result = -2; result.Message = "ConnectionId、UUID、UserName、Password不允许为空"; jsonStr = JsonConvert.SerializeObject(result); return(Content(jsonStr)); } #endregion 参数验证 #region 效性判断 //验证ConnectionId合法性 if (!QRCodeAction.QRCodeLists.ContainsKey(model.ConnectionId)) { result.Result = -3; result.Message = "ConnectionId回话id不存在"; jsonStr = JsonConvert.SerializeObject(result); return(Content(jsonStr)); } //验证UUID有效性 var findCode = QRCodeAction.QRCodeLists[model.ConnectionId]; if (!model.UUID.Equals(findCode.UUID)) { result.Result = -4; result.Message = "UUID输入错误"; jsonStr = JsonConvert.SerializeObject(result); return(Content(jsonStr)); } if (!findCode.IsValid()) { result.Result = -5; result.Message = "UUID已过期"; jsonStr = JsonConvert.SerializeObject(result); return(Content(jsonStr)); } //if (!findCode.IsValid) //{ // result.Result = -5; // result.Message = "UUID已过期"; // return result; //} if (findCode.IsLogin) { result.Result = -6; result.Message = "本UUID已登录"; jsonStr = JsonConvert.SerializeObject(result); return(Content(jsonStr)); } #endregion 效性判断 //LoginUserNameInput loginParam = new LoginUserNameInput //{ // UserName = model.UserName, // Password = model.Password, // Platform = model.Platform //}; //LoginOutput loginResult = await new SessionController().LoginUserName(loginParam); //UserModel userModel = new UserModel //{ // UserName = model.UserName, // Password = model.Password //}; LoginOutput loginResult = new LoginOutput() { Result = 1 }; switch (loginResult.Result) { case -1: result.Result = -7; result.Message = "登录账号已停用"; break; case -2: result.Result = -8; result.Message = "登录账号已删除"; break; case -3: result.Result = -9; result.Message = "登录密码输入错误"; break; case -4: result.Result = -10; result.Message = "登录账号不存在"; break; } if (loginResult.Result > 0) //登录成功,值为AccId { result.Result = 0; findCode.IsLogin = true; //更改登录状态 //findCode.UserName = model.UserName; //findCode.Password = model.Password; UserModel userModel = new UserModel { UserName = model.UserName, Password = model.Password }; //1.存入Session //oc.CurrentSessionUserInfo = new UserModel //{ // UserName = model.UserName, // Password = model.Password //}; result.Message = "成功登录"; } jsonStr = JsonConvert.SerializeObject(result); return(Content(jsonStr)); }
public async Task <OutputDto> Upload(LocalIncident report) { OutputDto output = null; var uploadedImages = await UploadPictures(report); if (!report.IsCreated) { var incident = CreateData(report, uploadedImages); await Task.Delay(300); using (await MaterialDialog.Instance.LoadingDialogAsync(message: "UploadingIncident".Translate())) { await WebRequestExecuter.Execute(async() => { output = await _incidentsAppService.Create(incident); }, () => Task.CompletedTask, exception => { UserDialogs.Instance.Toast("IncidentUploadError".Translate()); return(Task.CompletedTask); }); } } else { var incident = EditData(report, uploadedImages); await WebRequestExecuter.Execute(async() => { using (await MaterialDialog.Instance.LoadingDialogAsync(message: "UploadingIncident".Translate())) { output = await _incidentsAppService.Update(incident); } }, () => Task.CompletedTask); } if (output != null && output.Success) { try { report.IsUploaded = true; report.IsCreated = true; report.IncidentId = output.Id; DbService.UpdateItem(report); Analytics.TrackEvent("IncidentUploaded"); var formattedString = new FormattedString(); formattedString.Spans.Add(new Span { Text = "UploadMessage1".Translate(), FontSize = 20 }); formattedString.Spans.Add(new Span { Text = Environment.NewLine }); formattedString.Spans.Add(new Span { Text = "UploadMessage2".Translate(), FontSize = 20, }); formattedString.Spans.Add(new Span { Text = Environment.NewLine }); formattedString.Spans.Add(new Span { Text = "UploadMessage3".Translate(), FontSize = 20 }); var popup = new LottieLoader(formattedString, "success.json", false); //using (new LottieLoader(formattedString, "success.json")) //{ // await Task.Delay(5000); //} //UserDialogs.Instance.Toast("UploadedSuccessfully".Translate()); } catch (Exception e) { Crashes.TrackError(e); } } else if (output != null && output.Message == "AlreadyCreated") { try { report.IsUploaded = true; report.IsCreated = true; report.IncidentId = output.Id; DbService.UpdateItem(report); UserDialogs.Instance.Toast("AlreadyCreated".Translate()); } catch (Exception e) { Crashes.TrackError(e); } } else { UserDialogs.Instance.Toast("IncidentUploadError".Translate()); } return(output); }
public async Task <ActionResult> QRCodeVerifyAsync(QRCodeVerifyInput model, string returnUrl = "") { #region 参数验证 if (!ModelState.IsValid) { return(View(model)); } //if (model == null) //{ // result.Result = -1; // result.Message = "参数错误"; // jsonStr = JsonConvert.SerializeObject(result); // return Content(jsonStr); //} //if (string.IsNullOrEmpty(model.ConnectionId) || model.UUID.Equals(Guid.Empty) || string.IsNullOrEmpty(model.UserName))// || string.IsNullOrEmpty(model.Password)) //{ // result.Result = -2; // result.Message = "ConnectionId、UUID、UserName";//、Password不允许为空"; // jsonStr = JsonConvert.SerializeObject(result); // return Content(jsonStr); //} #endregion 参数验证 OutputDto outPut = new OutputDto(); string jsonStr = string.Empty; #region 效性判断 //验证ConnectionId合法性 if (!QRCodeAction.QRCodeLists.ContainsKey(model.ConnectionId)) { outPut.Result = -3; outPut.Message = "ConnectionId回话id不存在"; jsonStr = JsonConvert.SerializeObject(outPut); return(Content(jsonStr)); } //验证UUID有效性 var findCode = QRCodeAction.QRCodeLists[model.ConnectionId]; if (!model.UUID.Equals(findCode.UUID)) { outPut.Result = -4; outPut.Message = "UUID输入错误"; jsonStr = JsonConvert.SerializeObject(outPut); return(Content(jsonStr)); } if (!findCode.IsValid()) { outPut.Result = -5; outPut.Message = "UUID已过期"; jsonStr = JsonConvert.SerializeObject(outPut); return(Content(jsonStr)); } if (findCode.IsLogin) { outPut.Result = -6; outPut.Message = "本UUID已登录"; jsonStr = JsonConvert.SerializeObject(outPut); return(Content(jsonStr)); } #endregion 效性判断 var user = await UserManager.FindByNameAsync(model.UserName); if (user == null) { // 请不要显示该用户不存在或者未经确认 return(View("Login")); } await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); outPut.Result = 0; findCode.IsLogin = true; //更改登录状态 outPut.Message = "成功登录"; outPut.ReturnUrl = returnUrl; jsonStr = JsonConvert.SerializeObject(outPut); return(Content(jsonStr)); }