//public static readonly RoutedEvent AllControllerInfoUploadedEvent = EventManager.RegisterRoutedEvent( // "AllControllerInfoUploaded", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SummaryInfoView) //); //public event RoutedEventHandler AllControllerInfoUploaded //{ // add { AddHandler(AllControllerInfoUploadedEvent, value); } // remove { RemoveHandler(AllControllerInfoUploadedEvent, value); } //} private void btnSave_Click(object sender, RoutedEventArgs e) { // if (TheController != null) // { // ControllerModel controller=new ControllerModel(); // //controller.ID = TheController.ID; // ControllerModel controller = ((SCA.WPF.ViewModelsRoot.ViewModels.Query.SummaryInfoViewModel)this.DataContext).TheController; // TheController.Name = ControllerNameInputTextBox.Text; // TheController.MachineNumber = MachineNumberInputTextBox.Text; // TheController.BaudRate = Convert.ToInt32(BaudsRateComboBox.SelectedItem); // TheController.PortName = ComPortComboBox.SelectedItem.ToString(); SCA.WPF.ViewModelsRoot.ViewModels.Query.SummaryInfoViewModel vm = (SCA.WPF.ViewModelsRoot.ViewModels.Query.SummaryInfoViewModel) this.DataContext; ControllerModel controller = vm.TheController; controller.Name = ControllerNameInputTextBox.Text; controller.MachineNumber = MachineNumberInputTextBox.Text; controller.PortName = ComPortComboBox.SelectedItem.ToString(); controller.BaudRate = Convert.ToInt32(BaudsRateComboBox.SelectedItem); vm.SaveExecute(controller); controller.IsDirty = true; EventMediator.NotifyColleagues("RefreshNavigator", controller); RaiseEvent(new RoutedEventArgs(AddButtonClickEvent, controller)); // } }
/// <summary> /// 添加工艺项集 /// </summary> /// <param name="packCrafts">工艺项集</param> public void AddPackCrafts(IEnumerable <DecorationPackCraft> packCrafts) { #region # 验证 packCrafts = packCrafts == null ? new DecorationPackCraft[0] : packCrafts.ToArray(); if (!packCrafts.Any()) { throw new ArgumentNullException("packCrafts", "套餐模板商品工艺项集不可为空!"); } if (packCrafts.Count() != packCrafts.DistinctBy(x => x.CraftEntityId).Count()) { throw new InvalidOperationException("同一选区内,工艺实体不可重复!"); } #endregion //先清空 foreach (DecorationPackCraft craftItem in this.PackCraftEntities.ToArray()) { this.PackCraftEntities.Remove(craftItem); } //再添加 this.PackCraftEntities.AddRange(packCrafts); foreach (DecorationPackCraft packCraft in packCrafts) { packCraft.PackItem = this; } //挂起领域事件 处理套餐上是否包含下架|变价商品|工艺属性 EventMediator.Suspend(new PackShelvedChangedEvent(this.PackId)); }
public void CreateProduct() { const int runCount = 1000; IList <Guid> sessionIds = new List <Guid>(); Parallel.For(0, runCount, i => { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { Initializer.InitSessionId(); sessionIds.Add(GlobalSetting.CurrentSessionId); Product product = new Product(i.ToString(), "测试商品" + i, 19); EventMediator.HandleUncompletedEvents(); //断言会触发领域事件,并修改目标参数的值 Assert.IsTrue(ProductCreatedEventHandler.ProductName.Value == product.Name); Assert.IsTrue(ServiceCreatedEventHandler.ServiceName.Value == product.Name); scope.Complete(); } }); Assert.IsTrue(sessionIds.Count == runCount); Assert.IsTrue(sessionIds.Distinct().Count() == runCount); }
void ReadingExcelComplete(ControllerModel controller, string errorMessage) { EventMediator.NotifyColleagues("DisappearProgressBar", null); SCA.BusinessLib.ProjectManager.GetInstance.TheControllerViaImporting = controller; ToggleButtonStateForReadingExcel(false); DisplayContentSelectorPage(errorMessage); }
public void Show() { if (GameManager.CurrentScene.name.Equals(GlobalHelper.CombatScene)) { var combatInput = FindObjectOfType <CombatInputController>(); if (combatInput.TileSelected() || combatInput.AbilitySelected()) { return; } uiContainer.SetActive(true); GameManager.Instance.AddActiveWindow(uiContainer); var combatManager = FindObjectOfType <CombatManager>(); QuitButton.interactable = combatManager.IsPlayerTurn(); RetreatButton.interactable = combatManager.IsPlayerTurn(); return; } uiContainer.SetActive(true); GameManager.Instance.AddActiveWindow(uiContainer); EventMediator eventMediator = FindObjectOfType <EventMediator>(); eventMediator.Broadcast(GlobalHelper.PauseTimer, this); }
/// <summary> /// 整体定价 /// </summary> /// <param name="square">标准面积(使用面积)</param> /// <param name="totalPrice">总价</param> /// <param name="buildingSquare">标准面积(建筑面积)</param> /// <param name="buildingTotalPrice">建筑面积总价</param> /// <param name="isBuilding">是否整体建筑面积定价</param> /// <param name="isActual">是否整体使用面积定价</param> /// <param name="isManageFee">设置管理费参考价</param> /// <param name="manageFee">管理费参考价</param> /// <param name="isWaterElectricityFee">设置水电预收参考价</param> /// <param name="waterElectricityFee">水电预收参考价</param> public void SetPriceTotally(float square, decimal totalPrice, float buildingSquare, decimal buildingTotalPrice, bool isBuilding, bool isActual, bool isManageFee, decimal manageFee, bool isWaterElectricityFee, decimal waterElectricityFee) { //验证 if (isActual) { Assert.IsTrue(totalPrice >= 0, "总价不可小于0!"); } if (isBuilding) { Assert.IsTrue(buildingTotalPrice >= 0, "建筑面积总价不可小于0!"); } Assert.IsFalse(isManageFee && manageFee <= 0, "管理费参考价请填写大于0的数!"); Assert.IsFalse(isWaterElectricityFee && waterElectricityFee <= 0, "水电预收参考价请填写大于0的数!"); this.Square = square; this.TotalPrice = totalPrice; this.BuildingSquare = buildingSquare; this.BuildingTotalPrice = buildingTotalPrice; this.Priced = true; this.PricingType = DecorationPackPricingType.Total; this.IsBuilding = isBuilding; this.IsActual = isActual; this.IsManageFee = isManageFee; this.ManageFee = manageFee; this.IsWaterElectricityFee = isWaterElectricityFee; this.WaterElectricityFee = waterElectricityFee; //清空平米定价 this.ClearUnitPrice(); //TODO 领域事件处理套餐商品|工艺成本价 更新 this.HasChangedSku = false; EventMediator.Suspend(new PackPricedEvent(this.Id)); }
/// <summary> /// 审核 /// </summary> public void Check() { this.Checked = true; //挂起领域事件 EventMediator.Suspend(new OrderCheckedEvent(base.Number)); }
public ManualControlBoardViewModel() { _manualControlBoardService = new SCA.BusinessLib.BusinessLogic.ManualControlBoardService(TheController); EventMediator.Register("AddMoreLines", AddMoreLines); EventMediator.Register("RefreshCollection", RefreshCollection); EventMediator.Register("RefreshDeviceCode", RefreshDeviceCode); }
/// <summary> /// UnitOfWork联合提交(包含处理领域事件)扩展方法 /// </summary> /// <param name="unitOfWork">工作单元实例</param> public static void UnitedCommit(this IUnitOfWork unitOfWork) { try { //开启事务 using (TransactionScope scope = new TransactionScope()) { //提交工作单元 unitOfWork.Commit(); //处理领域事件 EventMediator.HandleUncompletedEvents(); //事务完成 scope.Complete(); } } catch { //不参与事务 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) { //回滚工作单元 unitOfWork.RollBack(); //清空未处理的领域事件 EventMediator.ClearUncompletedEvents(); //事务完成 scope.Complete(); } throw; } }
private async void ImportExcelDataIntoDatabase() { try { var message = "The program will read into memory all rows from the spreadsheet, " + "and then process saving them to the database.\n" + "Ready to begin the import process?"; var dr = XtraMessageBox.Show(message, "Begin Import?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.No) { return; } var importer = new ExcelImporter(gridViewExcelSource, MappingInfo, Persistent); EventMediator.GetInstance().OnImportStarted(); EventMediator.GetInstance().ImportProgressUpdated += OnProgressUpdated; marquee.Properties.Stopped = false; await importer.Import(); message = "Data has been imported successfully!"; XtraMessageBox.Show(message, "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); marquee.Properties.Stopped = true; EventMediator.GetInstance().OnImportComplete(); } catch (Exception ex) { ex.Report(); } }
/// <summary> /// 处理未处理的领域事件 /// </summary> public void HandleUncompletedEvents() { lock (_Sync) { //如果缓存中没有数据,则终止方法 if (this.MemoryEventSources == null) { return; } //如果有未处理的 if (this.MemoryEventSources.Any(x => !x.Handled)) { foreach (Event eventSource in this.MemoryEventSources.Where(x => !x.Handled)) { EventMediator.Handle((IEvent)eventSource); eventSource.Handled = true; } } //递归 if (this.MemoryEventSources.Any(x => !x.Handled)) { this.HandleUncompletedEvents(); } //处理完毕后置空缓存 this.FreeMemoryEventSources(); } }
public void UpdateProgressBarUI(int currentValue) { object[] args = new object[2]; args[0] = currentValue; args[1] = 100; EventMediator.NotifyColleagues("UpdateProgressBarStatusForExcelReading", args);//读取EXCEL时的进度条 }
/// <summary> /// 添加商品SKU项集 /// </summary> /// <param name="packSkus">商品SKU项集</param> public void AddPackSkus(IEnumerable <DecorationPackSku> packSkus) { #region # 验证 packSkus = packSkus == null ? new DecorationPackSku[0] : packSkus.ToArray(); if (!packSkus.Any()) { throw new ArgumentNullException("packSkus", "套餐模板商品SKU项集不可为空!"); } if (packSkus.Count() != packSkus.DistinctBy(x => x.SkuId).Count()) { throw new InvalidOperationException("同一选区内,商品SKU不可重复!"); } #endregion //先清空 foreach (DecorationPackSku skuItem in this.PackSkus.ToArray()) { this.PackSkus.Remove(skuItem); } //再添加 this.PackSkus.AddRange(packSkus); foreach (DecorationPackSku packSku in packSkus) { packSku.PackItem = this; } //挂起领域事件 处理套餐上是否包含下架|变价商品|工艺属性 EventMediator.Suspend(new PackShelvedChangedEvent(this.PackId)); }
/// <summary> /// 工作单元联合处理领域事件提交 /// </summary> /// <param name="unitOfWork">工作单元实例</param> /// <remarks>采用分布式事务</remarks> public static async Task DistributedCommitAsync(this IUnitOfWork unitOfWork) { try { //开启事务 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, AsyncFlowOption)) { //提交工作单元 await unitOfWork.CommitAsync(); //处理领域事件 await EventMediator.HandleUncompletedEventsAsync(); //事务完成 scope.Complete(); } } catch { //不参与事务 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress, AsyncFlowOption)) { //回滚工作单元 unitOfWork.RollBack(); //清空未处理的领域事件 EventMediator.ClearUncompletedEvents(); //事务完成 scope.Complete(); } throw; } }
private void UpdateProcessBarStatus(int currentValue, int totalValue, ControllerNodeType nodeType) { object[] status = new object[3]; status[0] = currentValue; status[1] = totalValue; status[2] = nodeType; EventMediator.NotifyColleagues("UpdateProgressBarStatusEvent", status); }
/// <summary> /// 设置套餐上架 /// </summary> public void SetPackShelfed() { Assert.IsTrue(this.DiscountRatio.IsPercentage(), "折扣比例必须大于0"); this.PackShelfStatus = ShelfStatus.Shelfed; //TODO 克隆套餐副本 EventMediator.Suspend(new OnShelfBalePackEvent(this.Id)); }
public void ReadingExcelErrorHandler(string errorMessage) { EventMediator.NotifyColleagues("DisappearProgressBar", null); ToggleButtonStateForReadingExcel(false); if (errorMessage != "" && errorMessage != null) //需要显示错误信息 { DisplayContentSelectorPage(errorMessage); } }
/// <summary> /// 领域事件处理方法 /// </summary> /// <param name="eventSource">领域事件源</param> public void Handle(ProductCreatedEvent eventSource) { lock (_Sync) { ProductName = eventSource.ProductName; EventMediator.Suspend(new ProductCreatedEvent2(eventSource.ProductNo, eventSource.ProductName, eventSource.Price)); } }
/// <summary> /// 创建商品构造器 /// </summary> /// <param name="productNo">商品编号</param> /// <param name="productName">商品名称</param> /// <param name="price">价格</param> public Product(string productNo, string productName, decimal price) : this() { base.Number = productNo; base.Name = productName; this.Price = price; //挂起领域事件 EventMediator.Suspend(new ProductCreatedEvent(this.Number, this.Name, this.Price)); }
/// <summary> /// 商品下架 /// </summary> public void ProductShelfOff() { if (!this.Shelved) { return; } this.Shelved = false; //挂起领域事件 EventMediator.Suspend(new BalePackProductShelvedEvent(this.BalePackCategory.BalePackGroup.ChoiceAreaId, this.Shelved)); }
/// <summary> /// 删除品类下已配置的所有商品集 /// </summary> public void DeleteBalePackAllProduct() { foreach (BalePackProduct product in this.BalePackProducts.ToList()) { this.BalePackProducts.Remove(product); } //挂起领域事件(类似上架商品)——修改套餐是否存在下架商品 EventMediator.Suspend(new BalePackProductShelvedEvent(this.BalePackGroup.ChoiceAreaId, true)); }
/// <summary> /// 创建服务构造器 /// </summary> /// <param name="serviceNo">服务编号</param> /// <param name="serviceName">服务名称</param> /// <param name="price">价格</param> public Service(string serviceNo, string serviceName, decimal price) : this() { base.Number = serviceNo; base.Name = serviceName; this.Price = price; //挂起领域事件 EventMediator.Suspend(new ServiceCreatedEvent(this.Number, this.Name, this.Price)); }
private void SubscribeToEvents() { EventMediator mediator = EventMediator.GetEventMediator(); mediator.ClockChange += ControllerForm_ClockChange; mediator.FoulsChange += ControllerForm_FoulsChange; mediator.ScoreChange += ControllerForm_ScoreChange; mediator.TimeoutChange += ControllerForm_TimeoutChange; mediator.PossessionChange += ControllerForm_PossessionChange; mediator.PeriodChange += ControllerForm_PeriodChange; }
public void SubscribeToEvent_IncrementShouldFireEvent() { //Arrange EventMediator.GetEventMediator().FoulsChange += FoulControllerTests_FoulsChanged; //Act _foulController.IncrementFouls(Team.Away); //Assert Assert.IsTrue(methodWasCalled); }
private void btnSetMasterController_Click(object sender, RoutedEventArgs e) { if (this.HierarchyTreeView.SelectedItem.GetType() == typeof(SCA.WPF.ViewModelsRoot.ViewModels.Navigator.NavigatorItemViewModel)) { if (((SCA.WPF.ViewModelsRoot.ViewModels.Navigator.NavigatorItemViewModel) this.HierarchyTreeView.SelectedItem).DataItem.GetType() == typeof(SCA.Model.ControllerModel)) { ProjectManager.GetInstance.SetPrimaryControllerByID(((SCA.Model.ControllerModel)((SCA.WPF.ViewModelsRoot.ViewModels.Navigator.NavigatorItemViewModel) this.HierarchyTreeView.SelectedItem).DataItem).ID); EventMediator.NotifyColleagues("RefreshNavigator", true); } } }
public void SubscribeToEvent_ScoreEventShouldFire() { //Arrange EventMediator.GetEventMediator().ScoreChange += ScoreControllerTests_ScoreChange; //Act scoreController.ScoreEvent(Team.Away, 0); //Assert Assert.IsTrue(methodWasCalled); }
public void SubscribeToEvent_SetGameScoreShouldFire() { //Arrange EventMediator.GetEventMediator().ScoreChange += ScoreControllerTests_ScoreChange; //Act scoreController.SetGameScore(new GameScore()); //Assert Assert.IsTrue(methodWasCalled); }
public void SubscribeToEvent_MethodShouldBeCalled() { //Arrange EventMediator.GetEventMediator().PossessionChange += PossessionControllerTests_PossessionChange; //Act _possessionController.ChangePossession(); //Assert Assert.IsTrue(methodWasCalled); }
public void SubscribeToEvent_DecrementShouldFireEvent() { //Arrange EventMediator.GetEventMediator().ClockChange += ClockControllerTests_ClockChange; //Act clockController.DecrementGameTimeByTenth(); //Assert Assert.IsTrue(methodWasCalled); }
public void SubscribeToEvent_SetGameTimeShouldFireEvent() { //Arrange EventMediator.GetEventMediator().ClockChange += ClockControllerTests_ClockChange; //Act clockController.SetGameTime(new GameTime()); //Assert Assert.IsTrue(methodWasCalled); }