public override async Task <SelectPictureResult> ExecuteAsync(ChoosePictureRequest request) { var retResult = new SelectPictureResult(); //NOTE: send suspend event BEFORE page_disappearing event fires to page is not removed from the view stack //... resume will be called by generic life-cycle if (!MediaPicker.IsPickPhotoSupported) { retResult.Notification.Add("No camera available :("); retResult.TaskResult = TaskResult.Failed; return(retResult); } var options = new PickMediaOptions(); options.CompressionQuality = 100; var mediaFile = await MediaPicker.PickPhotoAsync(options); if (mediaFile != null) { byte[] image = null; using (MemoryStream ms = new MemoryStream()) { mediaFile.GetStream().CopyTo(ms); image = ms.ToArray(); } if (request.MaxPixelDimension.HasValue) { IResizeImageCommand resizeCommand = DS.Get <IResizeImageCommand>(); ResizeImageContext context = new ResizeImageContext { Height = request.MaxPixelDimension.Value, Width = request.MaxPixelDimension.Value, OriginalImage = image, UpScaleIfImageIsSmaller = request.UpscaleImageIfSmaller }; var resizeResult = await resizeCommand.ExecuteAsync(context); if (resizeResult.IsValid()) { image = resizeResult.ResizedImage; } } retResult.Image = image; retResult.TaskResult = TaskResult.Success; } else { retResult.TaskResult = TaskResult.Canceled; retResult.Notification.Add("Select picture canceled"); } return(retResult); }
private void OnRestoreJsonCommandExecuted() { Message = ""; IsBusy = false; var code = GetWeb("https://jianghanxia.gitee.io/jpalchemisthan/ver"); var verj = JToken.Parse(GetEncWeb("https://alchemist.gu3.jp", "/chkver2", $"{{\"ver\":\"{code}\"}}")); Task.Factory.StartNew(async() => { try { var path = DependencyService.Get <ISystem>().GetLocalFilePath(); await GetFileAsync($"https://alchemist-dlc2.gu3.jp/assets/{verj.SelectToken("body.environments.alchemist.assets")}/ios/a8a590fa", Path.Combine(path, "a8a590fa")); await GetFileAsync($"https://alchemist-dlc2.gu3.jp/assets/{verj.SelectToken("body.environments.alchemist.assets")}/ios/f8ed758b", Path.Combine(path, "f8ed758b")); IsBusy = true; Message = "还原数据完成"; } catch (Exception ee) { Message = ee.Message; IsBusy = true; } }); }
private async Task GetMealOrderStatus() { try { if (CrossConnectivity.Current.IsConnected == true) { try { MealOrderStatusCollection = new ObservableCollection <meal_order_status>(); HttpClient httpClient = new System.Net.Http.HttpClient(); DateTime dt = SelectedDate; string format_date = dt.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture); var SelectedMealStatusIndex = StatusList.IndexOf(StatusList.First(x => x == SelectedMealStatus)); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Library.URL + "/" + Library.METHODE_GETMEALORDERSTATUS + "/" + SelectedWard.ID + "/" + format_date + "/" + SelectedMealTime.ID + "/" + SelectedMealStatusIndex.ToString() + "/" + Library.KEY_USER_SiteCode); HttpResponseMessage response = await httpClient.SendAsync(request); var data = await response.Content.ReadAsStringAsync(); MealOrderStatusCollection = JsonConvert.DeserializeObject <ObservableCollection <meal_order_status> >(data); if (!MealOrderStatusCollection.Any()) { IsPageEnabled = false; DependencyService.Get <INotify>().ShowToast("No records found!!"); return; } int srNo = 1; foreach (var item in MealOrderStatusCollection) { item.SrNo = srNo++; } // stop } catch (Exception excp) { // stop progressring } } else { await PageDialog.DisplayAlertAsync("Alert!!", "Server is not accessible, please check internet connection.", "OK"); } } catch (Exception excp) { // stop progressring } }
private void FillMealTime() { try { var db = DependencyService.Get <IDBInterface>().GetConnection(); MealTimeList = new List <mstr_meal_time>(db.Query <mstr_meal_time>("Select * From mstr_meal_time where status_id ='1' order by ID")); SelectedMealTime = MealTimeList.FirstOrDefault(); } catch (Exception exp) { PageDialog.DisplayAlertAsync("Alert!!", exp.Message, "OK"); } }
public LoginPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService) { _navigationService = navigationService; _pageDialogService = pageDialogService; _firebaseAuth = DependencyService.Get<IFirebaseAuthentication>(); if (!string.IsNullOrEmpty(Settings.UserEmail)) { Email = Settings.UserEmail; } }
private void FillWard() { try { var db = DependencyService.Get <IDBInterface>().GetConnection(); WardData = new List <mstr_ward_details>(db.Query <mstr_ward_details>("Select ID,ward_name From mstr_ward_details where ward_type_name not like '%staff%' and status_id ='1' order by ID")); SelectedWard = WardData.FirstOrDefault(); } catch (Exception exp) { PageDialog.DisplayAlertAsync("Alert!!", exp.Message, "OK"); } }
private void OnRestoreHanCommandExecuted() { Message = ""; IsBusy = false; IsDownload = true; DownloadProgress = 0; var code = GetWeb("https://jianghanxia.gitee.io/jpalchemisthan/ver"); var verj = JToken.Parse(GetEncWeb("https://alchemist.gu3.jp", "/chkver2", $"{{\"ver\":\"{code}\"}}")); Task.Factory.StartNew(async() => { try { await GetFileAsync($"https://alchemist-dlc2.gu3.jp/assets/{verj.SelectToken("body.environments.alchemist.assets")}/ios/ASSETLIST", Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "ASSETLIST")); var collection = GetCollection(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "ASSETLIST")); var path = DependencyService.Get <ISystem>().GetLocalFilePath(); var cloc = collection.Where(i => i.Path.StartsWith("Loc/")); var nc = cloc.Count(); int ii = 0; foreach (var item in cloc) { await GetFileAsync($"https://alchemist-dlc2.gu3.jp/assets/{verj.SelectToken("body.environments.alchemist.assets")}/ios/{item.IDStr}", Path.Combine(path, item.IDStr)); DownloadProgress = ii / (float)nc; ii += 1; } IsDownload = false; IsBusy = true; Message = "还原文本完成"; } catch (Exception ee) { Message = ee.Message; IsDownload = false; IsBusy = true; } }); }
private async Task TakePhotoCommandHandler() { try { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { await _pageDialogService.DisplayAlertAsync("No Camera", ":( No camera available.", "OK"); return; } var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { Directory = "Sample", Name = "test.jpg" }); if (file == null) { return; } var stream = DependencyService.Get <IDeviceInfoService>().GetFileStream(file); var card = await OcrReader.ReadBusinessCard(stream); var parameters = new NavigationParameters { { "CardDetails", card } }; await _navigationService.NavigateAsync("DetailPage", parameters); } catch (Exception e) { await _pageDialogService.DisplayAlertAsync("Error", e.Message, "Cancel"); } }
public MainPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService) { ServicePointManager.ServerCertificateValidationCallback = CheckValidationResult; NavigationService = navigationService; PageDialogService = pageDialogService; DownloadDataCommand = new DelegateCommand(async() => { try { Message = ""; IsBusy = false; await GetFileAsync("https://jianghanxia.gitee.io/jpalchemisthan/JPResult.xlsx", Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "JPResult.xlsx")); //await GetFileAsync("https://jianghanxia.gitee.io/jpalchemisthan/JSONWord.gz", Path.Combine(DependencyService.Get<ISystem>().GetPersonalPath(), "JSONWord.gz")); await PageDialogService.DisplayAlertAsync("完成", "完成数据下载", "OK"); IsBusy = true; } catch (Exception ee) { Message = ee.Message; IsBusy = true; } }); DownloadSYFontCommand = new DelegateCommand(async() => { try { Message = ""; IsBusy = false; await GetFileAsync("https://jianghanxia.gitee.io/jpalchemisthan/SY", Path.Combine(DependencyService.Get <ISystem>().GetLocalFilePath(), "0c9a8047")); await PageDialogService.DisplayAlertAsync("完成", "完成字体下载", "OK"); IsBusy = true; } catch (Exception ee) { Message = ee.Message; IsBusy = true; } }); DownloadWRFontCommand = new DelegateCommand(async() => { try { Message = ""; IsBusy = false; await GetFileAsync("https://jianghanxia.gitee.io/jpalchemisthan/WR", Path.Combine(DependencyService.Get <ISystem>().GetLocalFilePath(), "0c9a8047")); await PageDialogService.DisplayAlertAsync("完成", "完成字体下载", "OK"); IsBusy = true; } catch (Exception ee) { Message = ee.Message; IsBusy = true; } }); HHCommand = new DelegateCommand(OnHHCommandExecuted); JsonCommand = new DelegateCommand(OnJsonCommandExecuted); RestoreHanCommand = new DelegateCommand(OnRestoreHanCommandExecuted); RestoreJsonCommand = new DelegateCommand(OnRestoreJsonCommandExecuted); }
private void OnHHCommandExecuted() { Message = ""; IsBusy = false; IsDownload = true; DownloadProgress = 0; Task.Factory.StartNew(() => { try { if (!File.Exists(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "JPResult.xlsx"))) { Message = "先下载数据"; return; } List <CBItem> cb = new List <CBItem>(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); using (var stream = File.Open(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "JPResult.xlsx"), FileMode.Open, FileAccess.Read)) { using (var reader = ExcelReaderFactory.CreateReader(stream)) { do { while (reader.Read()) { if (!string.IsNullOrWhiteSpace(reader.GetString(4))) { cb.Add(new CBItem { IDstr = reader.GetString(0), ID = reader.GetString(2), Chinese = reader.GetString(4) }); } } } while (reader.NextResult()); } } var fl = cb.Select(i => i.IDstr).Distinct(); var nc = fl.Count(); int ii = 0; var path = DependencyService.Get <ISystem>().GetLocalFilePath(); Parallel.ForEach(fl, (file) => { if (File.Exists(Path.Combine(path, file))) { var fcb = cb.Where(i => i.IDstr == file); var fstr = DateTime.Now.Ticks.ToString(); using (var sReader = new StreamReader(new ZlibStream(new FileStream(Path.Combine(path, file), FileMode.Open), CompressionMode.Decompress), Encoding.UTF8)) { using (var f = File.Open(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), fstr), FileMode.Create)) { using (var result = new StreamWriter(new ZlibStream(f, CompressionMode.Compress, CompressionLevel.BestCompression), Encoding.UTF8)) { while (!sReader.EndOfStream) { var res = sReader.ReadLine(); var a = res.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (a.Length > 1 && res != "\r") { var h = fcb.Where(i => i.ID == a[0]); if (h.Any()) { a[1] = h.First().Chinese; } var concat = string.Join("\t", a); result.WriteLine(concat); } else { result.WriteLine(res); } } } } } File.Copy(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), fstr), Path.Combine(path, file), true); File.Delete(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), fstr)); } DownloadProgress = ii / (float)nc; ii += 1; }); IsDownload = false; IsBusy = true; Message = "完成文本汉化"; } catch (Exception ee) { Message = ee.Message; IsDownload = false; IsBusy = true; } }); }
private void OnJsonCommandExecuted() { Message = ""; IsBusy = false; IsDownload = true; DownloadProgress = 0; if (!File.Exists(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "JSONWord.gz"))) { Message = "先下载数据"; return; } Task.Factory.StartNew(() => { try { List <CBItem> cb = new List <CBItem>(); using (var sReader = new StreamReader( new GZipStream(File.Open(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "JSONWord.gz"), FileMode.Open), CompressionMode.Decompress), Encoding.UTF8)) { while (!sReader.EndOfStream) { var res = sReader.ReadLine(); var a = res.Split('\t'); cb.Add(new CBItem { IDstr = a[0], ID = a[1], Chinese = a[2] }); } } var fl = cb.Select(i => i.IDstr).Distinct(); var path = DependencyService.Get <ISystem>().GetLocalFilePath(); foreach (var file in fl) { if (File.Exists(Path.Combine(path, file))) { var fcb = cb.Where(i => i.IDstr == file); var nc = fcb.Count(); int ii = 0; using (var sReader = new StreamReader(new ZlibStream(new FileStream(Path.Combine(path, file), FileMode.Open), CompressionMode.Decompress), Encoding.UTF8)) { var json = JToken.Parse(sReader.ReadToEnd()); foreach (var cbi in fcb) { var s = json.SelectToken(cbi.ID); s?.Replace(cbi.Chinese); DownloadProgress = ii / (float)nc; ii += 1; } var sd = json.ToString(Formatting.None); byte[] byteArray = Encoding.UTF8.GetBytes(sd); MemoryStream stream = new MemoryStream(byteArray); using (var f = File.Open(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "temp"), FileMode.Create)) { using (var result = new ZlibStream(f, CompressionMode.Compress, CompressionLevel.BestCompression)) { byte[] buffer = new byte[4096]; int n; while ((n = stream.Read(buffer, 0, buffer.Length)) != 0) { result.Write(buffer, 0, n); } } } } File.Copy(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "temp"), Path.Combine(path, file), true); File.Delete(Path.Combine(DependencyService.Get <ISystem>().GetPersonalPath(), "temp")); } } IsDownload = false; IsBusy = true; Message = "完成数据汉化"; } catch (Exception ee) { Message = ee.Message; IsDownload = false; IsBusy = true; } }); }
public SecondPageViewModel() { _musicPlayer = DependencyService.Get <IMusicPlayer>(); _timer = new CountDownTimer(TimeSpan.FromSeconds(300)); _timer.Interval = TimeSpan.FromSeconds(1); _timer.IntervalPassed += _timer_IntervalPassed; Plus1MinCommand = new DelegateCommand(() => { _timer.CurrentTime.Add(TimeSpan.FromMinutes(1)); UpdateTimer(); }); Plus10SecCommand = new DelegateCommand(() => { _timer.CurrentTime.Add(TimeSpan.FromSeconds(10)); UpdateTimer(); }); Minus10SecCommand = new DelegateCommand(() => { _timer.CurrentTime.Subtract(TimeSpan.FromSeconds(10)); UpdateTimer(); }); Minus1MinCommand = new DelegateCommand(() => { _timer.CurrentTime.Subtract(TimeSpan.FromMinutes(1)); UpdateTimer(); }); StartTimerCommand = new DelegateCommand(() => { _timer.Start(); UpdateTimer(); }); StopTimerCommand = new DelegateCommand(() => { _timer.Stop(); UpdateTimer(); }); ResetTimerCommand = new DelegateCommand(() => { _timer.Reset(); UpdateTimer(); }); BGMStopCommand = new DelegateCommand(() => { _musicPlayer.Stop(); }); BGMOpeningCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("openingBGM"); }); BGMRoleCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("confirmBGM"); }); BGMMorningCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("morningBGM"); }); BGMDayTimeCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("discussionBGM"); }); BGMVoteCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("voteBGM"); }); BGMExecuteCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("executionBGM"); }); BGMNightCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("nightBGM"); }); BGMVillagerWinCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("victoryBGM_villagers"); }); BGMWerewolfWinCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("victoryBGM_werewolf"); }); BGMThirdPartyWinCommand = new DelegateCommand(() => { _musicPlayer.Stop(); _musicPlayer.PlayAsync("victoryBGM_3rdParty"); }); }