public ReservationStats ReservationShortReport(Members member) { var reservationStat = new ReservationStats(); //Get All Reservation var allReservations = _reservationRepository.GetListReportForMember(member.ID); if (allReservations.Count > 0) { //Week Reservation var weekReservation = allReservations.Where(x => GetWeekOfYear(x.TeeTime.StartDate) == GetWeekOfYear(DateTime.Now)).Count(); //Month Reservation var monthReservation = allReservations.Where(x => x.TeeTime.StartDate.Month == DateTime.Now.Month).Count(); //Year Reservation var yearReservation = allReservations.Where(x => x.TeeTime.StartDate.Year == DateTime.Now.Year).Count(); reservationStat.ReservationAll = allReservations.Count; reservationStat.ReservationMonth = monthReservation; reservationStat.ReservationWeek = weekReservation; reservationStat.ReservationYear = yearReservation; } return(reservationStat); }
private async void ReserveBtn_Click(object sender, RoutedEventArgs e) { bool success = await this.checkConnection(); if (!success) { return; } this.tokenSource = new CancellationTokenSource(); CancellationToken ct = this.tokenSource.Token; CancelBtn.IsEnabled = true; SettingsGrid.IsEnabled = false; OperationsGrid.IsEnabled = false; // The Progress<T> constructor captures our UI context, so the lambda will be run on the UI thread. var progress = new Progress <int>(percent => { OperationProgress.Value = percent; ProgressLabel.Content = percent + "%"; }); var stats = new ReservationStats() { Processed = 0, MyNumbers = 0, NewNumbers = 0 }; try { // reserveSerialNumbers is run on the thread pool. stats = await Task.Run(() => this.reserveSerialNumbers(progress, ct)); OperationProgress.Value = 100; StatusTextBlock.Text = "Done!"; StatusTextBlock.Foreground = this.defaultColor; } catch (OperationCanceledException) { StatusTextBlock.Text = "Stopped!"; StatusTextBlock.Foreground = this.errorColor; } catch (EmercoinWalletException ex) { StatusTextBlock.Text = "Emercoin operation error"; StatusTextBlock.Foreground = this.errorColor; AppUtils.ShowException(ex, this); } ProgressLabel.Content = string.Empty; SettingsGrid.IsEnabled = true; OperationsGrid.IsEnabled = true; CancelBtn.IsEnabled = false; this.tokenSource.Dispose(); MessageBox.Show( this, "Total serial numbers processed: " + stats.Processed + "\n" + "Records you owned before: " + stats.MyNumbers + "\n" + "New records created: " + stats.NewNumbers, AppUtils.AppName); }
private ReservationStats reserveSerialNumbers(IProgress <int> progress, CancellationToken ct) { var stats = new ReservationStats(); int i = 0; foreach (string[] row in this.snData.Rows) { string sn = row[0]; string name = this.settings.RootDPOName + ":" + sn; // iterate through unique names for (int j = 0; j < 100; j++) { string nameUnique = name + ":" + j.ToString(CultureInfo.InvariantCulture); EmercoinWallet.NameCreationStatusEnum result = this.wallet.CreateOrCheckName(nameUnique, this.settings.DpoLifetime); if (result == EmercoinWallet.NameCreationStatusEnum.Created) { stats.NewNumbers++; break; } else if (result == EmercoinWallet.NameCreationStatusEnum.Exists) { stats.MyNumbers++; break; } } stats.Processed++; if (i > 0 && i % 10 == 0) { Thread.Sleep(5000); } i++; if (progress != null) { progress.Report(getPercent(i, this.snData.Rows.Count)); } ct.ThrowIfCancellationRequested(); } return(stats); }