public async Task SwallowsReleaseException() { var processorException = new InvalidOperationException("Fail!"); ValidationSetProcessor .Setup(x => x.ProcessValidationsAsync(It.IsAny <PackageValidationSet>())) .Throws(processorException); var leaseException = new ArgumentException("Release fail!"); LeaseService .Setup(x => x.ReleaseAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())) .Throws(leaseException); var actual = await Assert.ThrowsAsync <InvalidOperationException>(() => Target.HandleAsync(Message)); Assert.Same(processorException, actual); VerifyAcquire(Times.Once); ValidationSetProcessor.Verify( x => x.ProcessValidationsAsync(It.IsAny <PackageValidationSet>()), Times.Once); ValidationOutcomeProcessor.Verify( x => x.ProcessValidationOutcomeAsync( It.IsAny <PackageValidationSet>(), It.IsAny <IValidatingEntity <TestEntity> >(), It.IsAny <ValidationSetProcessorResult>(), It.IsAny <bool>()), Times.Never); VerifyRelease(Times.Once); }
private void SetupStructure(LeaseService leaseService, AppSettings appSettings) { _leaseService = leaseService; _discount = appSettings.DiscountPercentage; _minLeaseCount = appSettings.MinLeaseCount; _minLeaseMonths = appSettings.MinLeaseMonths; }
public void VerifyRelease(Func <Times> times) { LeaseService.Verify( x => x.ReleaseAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()), times); LeaseService.Verify( x => x.ReleaseAsync(LeaseResourceName, LeaseResult.LeaseId, It.IsAny <CancellationToken>()), times); }
public void VerifyAcquire(Func <Times> times) { LeaseService.Verify( x => x.TryAcquireAsync(It.IsAny <string>(), It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>()), times); LeaseService.Verify( x => x.TryAcquireAsync(LeaseResourceName, It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>()), times); }
public AddLeaseWindow(LeaseService leaseService, TenantService tenantService, PropertyService propertyService, AppSettings appSettings) { SetupStructure(leaseService, appSettings); InitializeComponent(); PropertyCBox.ItemsSource = propertyService.Properties; TenantCBox.ItemsSource = tenantService.Tenants; MonthsBox.Text = _minLeaseMonths.ToString(); }
public MainWindow() { AppDomain.CurrentDomain.UnhandledException += ProcessException; _appSettings = SettingsManager.GetUserSettings(); var connectionString = string.IsNullOrEmpty(_appSettings.UserDatabasePath) ? ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString : $"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename={_appSettings.UserDatabasePath};Integrated Security=True;Connect Timeout=30"; _settingsWindow = new SettingsWindow(_appSettings); _leaseService = new LeaseService(connectionString); _tenantService = new TenantService(connectionString); _propertyService = new PropertyService(connectionString); InitializeComponent(); SetupControls(); }
public LeaseControl(LeaseService leaseService, TenantService tenantService, PropertyService propertyService, AppSettings appSettings) { _leaseService = leaseService; _tenantService = tenantService; _propertyService = propertyService; _appSettings = appSettings; InitializeComponent(); var allLeases = _leaseService.Leases; LeaseListView.ItemsSource = allLeases; TenantCBox.ItemsSource = _tenantService.Tenants; CityCBox.ItemsSource = _propertyService.AllCities; _view = (CollectionView)CollectionViewSource.GetDefaultView(LeaseListView.ItemsSource); _view.SortDescriptions.Add(new SortDescription("Id", ListSortDirection.Ascending)); }
public static void Main(string[] args) { GrpcEnvironment.SetLogger(new ConsoleLogger()); Server server = new Server { Services = { AuthService.BindService(new SpotAuthService()), RobotIdService.BindService(new SpotRobotIdService()), DirectoryService.BindService(new SpotDirectoryService()), TimeSyncService.BindService(new SpotTimeSyncService()), EstopService.BindService(new SpotEstopService()), LeaseService.BindService(new SpotLeaseService()), PowerService.BindService(new SpotPowerService()), RobotStateService.BindService(new SpotRobotStateService()), RobotCommandService.BindService(new SpotRobotCommandService()), ImageService.BindService(new SpotImageService()) }, Ports = { new ServerPort( "0.0.0.0", Port, new SslServerCredentials( new List <KeyCertificatePair>() { new KeyCertificatePair( File.ReadAllText(@"server.crt"), File.ReadAllText(@"server.key") ) }, File.ReadAllText(@"ca.crt"), false ) ) }, }; server.Start(); Console.WriteLine("Virtual spot 001 is active on port " + Port); Console.WriteLine("Press any key to shutdown"); Console.ReadKey(); server.ShutdownAsync().Wait(); }
protected void Button1_Click(object sender, EventArgs e) { Database db = new Database(); LeaseService leaseService = new LeaseService(false); string product = this.ProductTextBox.Text; int maxUsers = int.Parse(this.CountTextBox.Text); StringReader reader = new StringReader(unparsedNames); List <User> users = new List <User>(); string line; while ((line = reader.ReadLine()) != null) { string[] parts = line.Split(','); User user = new User { UserName = string.Format("{0}.{1}", parts[0], parts[1]).ToUpper(), AuthenticatedName = string.Format("CONTOSO\\{0}.{1}", parts[0], parts[1]).ToUpper(), WorksOnWeekend = random.NextDouble() }; double machineProb = random.NextDouble(); if (machineProb < 0.7) { user.Machines.Add(string.Format("DESKTOP-{0:x}", random.Next(0, ushort.MaxValue))); } else { user.Machines.Add(string.Format("DESKTOP-{0:x}", random.Next(0, ushort.MaxValue))); user.Machines.Add(string.Format("NOTEBOOK-{0:x}", random.Next(0, ushort.MaxValue))); } users.Add(user); } const int days = 90; DateTime startDate = DateTime.Today.AddDays(-days); int numberNewUsersPerDay = (int)Math.Ceiling(2 * random.NextDouble() * maxUsers / days); List <User> activeUsers = new List <User>(); for (int i = 0; i < days; i++) { DateTime day = startDate.AddDays(i); DateTime time = day.AddHours(7); List <User> removeList = new List <User>(); foreach (User user in activeUsers) { double probWorksToday; switch (day.DayOfWeek) { case DayOfWeek.Sunday: probWorksToday = user.WorksOnWeekend * 0.3; break; case DayOfWeek.Saturday: probWorksToday = user.WorksOnWeekend * 0.7; break; default: probWorksToday = 0.9; break; } if (random.NextDouble() < probWorksToday) { // Which machine will he use this day? int machineIndex = (int)Math.Floor(random.NextDouble() * user.Machines.Count); string machine = user.Machines[machineIndex]; Dictionary <int, string> errors = new Dictionary <int, string>(); time = time.AddHours(random.NextDouble() * 3.0 / activeUsers.Count); DateTime buildDate = time; Lease lease = leaseService.GetLease(db, product, buildDate, machine, user.UserName, user.AuthenticatedName, time, errors); if (lease != null) { db.SubmitChanges(); LeaseService.CheckAssertions(db, lease.License, time); } } // Will this user stop using the product? if (random.NextDouble() * activeUsers.Count < 0.02) { removeList.Add(user); } } // Enlist new users. for (int j = 0; j < numberNewUsersPerDay; j++) { if (users.Count > 0) { activeUsers.Add(users[0]); users.RemoveAt(0); } } // Remove users. foreach (User user in removeList) { activeUsers.Remove(user); users.Add(user); } } }
public LeasesController(LeaseService leaseService) { _leaseService = leaseService; }
protected void Button1_Click( object sender, EventArgs e ) { Database db = new Database(); LeaseService leaseService = new LeaseService( false ); string product = this.ProductTextBox.Text; int maxUsers = int.Parse( this.CountTextBox.Text ); StringReader reader = new StringReader( unparsedNames ); List<User> users = new List<User>(); string line; while ( (line = reader.ReadLine()) != null ) { string[] parts = line.Split( ',' ); User user = new User { UserName = string.Format( "{0}.{1}", parts[0], parts[1] ).ToUpper(), AuthenticatedName = string.Format( "CONTOSO\\{0}.{1}", parts[0], parts[1] ).ToUpper(), WorksOnWeekend = random.NextDouble() }; double machineProb = random.NextDouble(); if ( machineProb < 0.7 ) { user.Machines.Add( string.Format( "DESKTOP-{0:x}", random.Next( 0, ushort.MaxValue ) ) ); } else { user.Machines.Add( string.Format( "DESKTOP-{0:x}", random.Next( 0, ushort.MaxValue ) ) ); user.Machines.Add( string.Format( "NOTEBOOK-{0:x}", random.Next( 0, ushort.MaxValue ) ) ); } users.Add( user ); } const int days = 90; DateTime startDate = DateTime.Today.AddDays( -days ); int numberNewUsersPerDay = (int) Math.Ceiling( 2*random.NextDouble()*maxUsers/days ); List<User> activeUsers = new List<User>(); for ( int i = 0; i < days; i++ ) { DateTime day = startDate.AddDays( i ); DateTime time = day.AddHours( 7 ); List<User> removeList = new List<User>(); foreach ( User user in activeUsers ) { double probWorksToday; switch ( day.DayOfWeek ) { case DayOfWeek.Sunday: probWorksToday = user.WorksOnWeekend*0.3; break; case DayOfWeek.Saturday: probWorksToday = user.WorksOnWeekend*0.7; break; default: probWorksToday = 0.9; break; } if ( random.NextDouble() < probWorksToday ) { // Which machine will he use this day? int machineIndex = (int) Math.Floor( random.NextDouble()*user.Machines.Count ); string machine = user.Machines[machineIndex]; Dictionary<int, string> errors = new Dictionary<int, string>(); time = time.AddHours( random.NextDouble()*3.0/activeUsers.Count ); DateTime buildDate = time; Lease lease = leaseService.GetLease( db, product, buildDate, machine, user.UserName, user.AuthenticatedName, time, errors ); if ( lease != null ) { db.SubmitChanges(); LeaseService.CheckAssertions( db, lease.License, time ); } } // Will this user stop using the product? if ( random.NextDouble()*activeUsers.Count < 0.02 ) removeList.Add( user ); } // Enlist new users. for ( int j = 0; j < numberNewUsersPerDay; j++ ) { if ( users.Count > 0 ) { activeUsers.Add( users[0] ); users.RemoveAt( 0 ); } } // Remove users. foreach ( User user in removeList ) { activeUsers.Remove( user ); users.Add( user ); } } }
/// <summary> /// 提交添加 /// </summary> private bool SubmintAdd() { var lease = LeaseService.Where(p => p.KeyId == txtKeyId.Text.Trim() && p.FCompanyId == CurrentUser.AccountComId).FirstOrDefault(); if (lease != null) { ModifiedGrid(); lease.FCode = txtFCode.Text; lease.FName = tbxFCustomer.Text; lease.FAddress = txtFAddress.Text.Trim(); lease.FCompanyId = CurrentUser.AccountComId; lease.FFlag = 1; lease.FDeleteFlag = 0; lease.FFreight = string.IsNullOrEmpty(txtFFreight.Text.Trim()) ? 0 : Convert.ToDecimal(txtFFreight.Text.Trim()); lease.FLinkman = txtFLinkman.Text.Trim(); lease.FMemo = txtFMemo.Text.Trim(); lease.FPhone = txtFPhone.Text.Trim(); lease.FDate = txtFDate.SelectedDate; lease.FShipper = !ddlFShipper.SelectedValue.Equals("-1") ? ddlFShipper.SelectedText : ""; lease.FVehicleNum = !ddlFVehicleNum.SelectedValue.Equals("-1") ? ddlFVehicleNum.SelectedText : ""; var parms = new Dictionary <string, object>(); parms.Clear(); parms.Add("@companyId", CurrentUser.AccountComId); parms.Add("@keyID", lease.KeyId); var amt = Convert.ToDecimal(SqlService.ExecuteProcedureCommand("proc_LeaseAmt", parms).Tables[0].Rows[0][0]); lease.FAmount = amt; lease.FSalesman = ddlFSalesman.SelectedValue; lease.FArea = ddlFArea.SelectedValue; lease.FAmt = string.IsNullOrEmpty(txtFAmt.Text.Trim()) ? 0 : Convert.ToDecimal(txtFAmt.Text.Trim()); lease.FDeliveryMethod = ddlDeliveryMethod.SelectedValue; lease.FLogisticsNumber = txtFLogisticsNumber.Text; lease.FSupercargo = GasHelper.GetDropDownListArrayString(ddlFSupercargo.SelectedItemArray); lease.FDriver = GasHelper.GetDropDownListArrayString(ddlFDriver.SelectedItemArray); //发货单号 lease.FSalesNum = tbxFSalesNum.Text; lease.FSubjectCode = ddlSubject.SelectedValue; lease.FSubjectName = ddlSubject.SelectedText; lease.FSKNum = ""; lease.FCate = hfdClass.Text; LeaseService.SaveChanges(); if (txtKeyId.Text.Contains("TM")) { //单据号问题 string newKeyId = SequenceService.CreateSequence(Convert.ToDateTime(txtFDate.SelectedDate), "ZL", CurrentUser.AccountComId); var orderParms = new Dictionary <string, object>(); orderParms.Clear(); orderParms.Add("@oldKeyId", txtKeyId.Text); orderParms.Add("@newKeyId", newKeyId); orderParms.Add("@Bill", "7"); orderParms.Add("@companyId", CurrentUser.AccountComId); SqlService.ExecuteProcedureCommand("proc_num", orderParms); txtKeyId.Text = newKeyId; //新增日志 var billStatus = new LHBillStatus { KeyId = newKeyId, FCompanyId = CurrentUser.AccountComId, FActionName = "新增", FDate = DateTime.Now, FDeptId = CurrentUser.AccountOrgId, FOperator = CurrentUser.AccountName, FMemo = String.Format("单据号{0},{1}新增租赁单据。", newKeyId, CurrentUser.AccountName) }; GasHelper.AddBillStatus(billStatus); //收款部分 var parmsAuto = new Dictionary <string, object>(); parmsAuto.Clear(); parmsAuto.Add("@KeyId", newKeyId); parmsAuto.Add("@companyId", CurrentUser.AccountComId); parmsAuto.Add("@FCate", hfdClass.Text); parmsAuto.Add("@date", Convert.ToDateTime(lease.FDate).ToString("yyyyMMdd")); parmsAuto.Add("@FSKNum", lease.FSKNum); parmsAuto.Add("@FAbstract", "收押金款"); SqlService.ExecuteProcedureCommand("proc_SKLeaseAuto", parmsAuto); } return(true); } return(false); }
/// <summary> /// 提交编辑 /// </summary> private bool SubmintEdit() { if (Lease != null) { ModifiedGrid(); Lease.FCode = txtFCode.Text; Lease.FName = tbxFCustomer.Text; Lease.FAddress = txtFAddress.Text.Trim(); Lease.FCompanyId = CurrentUser.AccountComId; Lease.FShipper = !ddlFShipper.SelectedValue.Equals("-1") ? ddlFShipper.SelectedText : ""; Lease.FVehicleNum = !ddlFVehicleNum.SelectedValue.Equals("-1") ? ddlFVehicleNum.SelectedText : ""; Lease.FFlag = 1; Lease.FFreight = Convert.ToDecimal(txtFFreight.Text.Trim()); Lease.FLinkman = txtFLinkman.Text.Trim(); Lease.FMemo = txtFMemo.Text.Trim(); Lease.FPhone = txtFPhone.Text.Trim(); var parms = new Dictionary <string, object>(); parms.Clear(); parms.Add("@keyID", Lease.KeyId); parms.Add("@companyId", CurrentUser.AccountComId); var amt = Convert.ToDecimal(SqlService.ExecuteProcedureCommand("proc_LeaseAmt", parms).Tables[0].Rows[0][0]); Lease.FAmount = amt; Lease.FDate = txtFDate.SelectedDate; Lease.FSalesman = ddlFSalesman.SelectedValue; Lease.FArea = ddlFArea.SelectedValue; Lease.FAmt = string.IsNullOrEmpty(txtFAmt.Text.Trim()) ? 0 : Convert.ToDecimal(txtFAmt.Text.Trim()); Lease.FDeliveryMethod = ddlDeliveryMethod.SelectedValue; Lease.FLogisticsNumber = txtFLogisticsNumber.Text; Lease.FSupercargo = GasHelper.GetDropDownListArrayString(ddlFSupercargo.SelectedItemArray); Lease.FDriver = GasHelper.GetDropDownListArrayString(ddlFDriver.SelectedItemArray); //发货单号 Lease.FSalesNum = tbxFSalesNum.Text; Lease.FSubjectCode = ddlSubject.SelectedValue; Lease.FSubjectName = ddlSubject.SelectedText; Lease.FCate = hfdClass.Text; Lease.CreateBy = CurrentUser.AccountName; LeaseService.SaveChanges(); //收款部分 var parmsAuto = new Dictionary <string, object>(); parmsAuto.Clear(); parmsAuto.Add("@KeyId", Lease.KeyId); parmsAuto.Add("@companyId", CurrentUser.AccountComId); parmsAuto.Add("@FCate", hfdClass.Text); parmsAuto.Add("@date", Convert.ToDateTime(Lease.FDate).ToString("yyyyMMdd")); parmsAuto.Add("@FSKNum", Lease.FSKNum); parmsAuto.Add("@FAbstract", "收押金款"); SqlService.ExecuteProcedureCommand("proc_SKLeaseAuto", parmsAuto); return(true); } return(false); }
/// <summary> /// 加载页面数据 /// </summary> private void LoadData() { switch (Actions) { case WebAction.Add: Region1.Title = "添加气瓶租赁单"; txtKeyId.Text = SequenceService.CreateSequence("TM", CurrentUser.AccountComId); var temp = new LHLease { KeyId = txtKeyId.Text, FFlag = 1, FDeleteFlag = 1, //发货单 FType = Convert.ToInt32(GasEnumBill.Lease), CreateBy = CurrentUser.AccountName, FDate = txtFDate.SelectedDate, FCompanyId = CurrentUser.AccountComId, FStatus = Convert.ToInt32(GasEnumBillStauts.Add), FProgress = Convert.ToInt32(GasEnumBillStauts.Add), }; //临时写入单据 LeaseService.Add(temp); break; case WebAction.Edit: Region1.Title = "编辑气瓶租赁单"; txtKeyId.Text = KeyId; if (Lease != null) { WebControlHandler.BindObjectToControls(Lease, SimpleForm1); txtFDate.SelectedDate = Lease.FDate; tbxFCustomer.Text = Lease.FName; if (!string.IsNullOrEmpty(Lease.FDriver)) { ddlFDriver.SelectedValueArray = Lease.FDriver.Split(','); } if (!string.IsNullOrEmpty(Lease.FShipper)) { ddlFShipper.SelectedValueArray = Lease.FShipper.Split(','); } if (!string.IsNullOrEmpty(Lease.FSupercargo)) { ddlFSupercargo.SelectedValueArray = Lease.FSupercargo.Split(','); } if (!string.IsNullOrEmpty(Lease.FSalesman)) { ddlFSalesman.SelectedValueArray = Lease.FSalesman.Split(','); } ddlFVehicleNum.SelectedValue = Lease.FVehicleNum; ddlFArea.SelectedValue = Lease.FArea; ddlDeliveryMethod.SelectedValue = Lease.FDeliveryMethod; hfdClass.Text = Lease.FCate; tbxFSalesNum.Text = Lease.FSalesNum; BindDataGrid(); } break; } }