public DialogMenuViewModel( ApplicationState applicationState, IApplicationDialog dialog) : base(applicationState) { InformationCommand = MakeAsyncCommand(async() => { await dialog.Information("message"); }); ConfirmCommand = MakeAsyncCommand(async() => { var ret = await dialog.Confirm("message"); await dialog.Information($"result=[{ret}]"); }); SelectCommand = MakeAsyncCommand(async() => { selected = await dialog.Select(Enumerable.Range(1, 15).Select(x => $"Item-{x}").ToArray(), selected); await dialog.Information($"result=[{selected}]"); }); }
private async ValueTask <IResult <T> > Execute <T>(Func <NetworkService, ValueTask <IRestResponse <T> > > func, bool verbose) { while (true) { if (!deviceManager.GetNetworkState().IsConnected()) { if (verbose) { await dialogs.Information("Network is not connected."); } return(Result.Failed <T>()); } IRestResponse <T> response; using (dialogs.Loading("Connecting")) { response = await func(networkService); } switch (response.RestResult) { case RestResult.Success: return(Result.Success(response.Content)); case RestResult.Cancel: if (!verbose) { return(Result.Failed <T>()); } else if (!await dialogs.Confirm("Canceled.\r\nRetry ?")) { return(Result.Failed <T>()); } break; case RestResult.RequestError: case RestResult.HttpError: if (verbose) { var message = new StringBuilder(); message.AppendLine("Network error."); if (response.StatusCode > 0) { message.AppendLine($"StatusCode={(int)response.StatusCode}"); } message.AppendLine("Retry ?"); if (!await dialogs.Confirm(message.ToString())) { return(Result.Failed <T>()); } } else { return(Result.Failed <T>()); } break; default: if (verbose) { await dialogs.Information("Unknown error."); } return(Result.Failed <T>()); } } }