private void StopAlgorithmProcessing() { try { if ((object)m_subscriber != null) { m_subscriber.Stop(); m_subscriber.StatusMessage -= StatusMessageHandler; m_subscriber.ProcessException -= ProcessExceptionHandler; m_subscriber = null; } if ((object)m_concentrator != null) { m_concentrator.Stop(); m_concentrator.ProcessException -= ProcessExceptionHandler; m_concentrator = null; } AlgorithmHostingEnvironment.Shutdown(); } catch (Exception ex) { HandleException(new InvalidOperationException($"Exception while shutting down algorithm hosting environment: {ex.Message}", ex)); } }
public void InitializeFramework(Framework framework) { m_mapper = framework.Mapper; m_concentrator = framework.Concentrator; m_subscriber = framework.Subscriber; m_shouldTakeSample = false; }
public ActionResult Insert_server(Concentrator info) { //检查用户是否有权限,否则抛出MyDenyAccessException异常 base.CheckAuthorized(AuthorizeKey.InsertKey); CommonResult result = new CommonResult(); //厂家编码 var endcode = Session["EndCode"] ?? "0"; info.IntEndCode = endcode.ToString().ToInt32(); try { //调用后台服务获取集中器信息 ServiceDbClient DbServer = new ServiceDbClient(); var flg = DbServer.ArcConcentrator_Ins(info); if (flg == "0") { result.Success = true; } else { result.ErrorMessage = flg; result.Success = false; } } catch (Exception ex) { result.ErrorMessage = ex.Message; } return(ToJsonContent(result)); }
private void StartAlgorithmProcessing() { try { AlgorithmHostingEnvironment.Start(); Framework framework = AlgorithmHostingEnvironment.Framework; m_concentrator = framework.Concentrator; m_subscriber = framework.Subscriber; m_concentrator.ProcessException += ProcessExceptionHandler; m_concentrator.FramesPerSecond = SystemSettings.FramesPerSecond; m_concentrator.LagTime = SystemSettings.LagTime; m_concentrator.LeadTime = SystemSettings.LeadTime; m_concentrator.RoundToNearestTimestamp = true; m_concentrator.Start(); m_subscriber.StatusMessage += StatusMessageHandler; m_subscriber.ProcessException += ProcessExceptionHandler; m_subscriber.Start(); } catch (Exception ex) { HandleException(new InvalidOperationException($"Exception while creating framework for algorithm hosting environment: {ex.Message}", ex)); } }
public void NewUnit(string _) { var newUnit = new Concentrator { Name = "New unit " + (this.Concentrators.Count + 1).ToString() }; Concentrators.Add(newUnit); }
public ActionResult Update_Server(string id, Concentrator info) { //检查用户是否有权限,否则抛出MyDenyAccessException异常 base.CheckAuthorized(AuthorizeKey.UpdateKey); //赋值 info.IntID = Convert.ToInt32(id); CommonResult result = new CommonResult(); if (info.IntUpID == info.IntID) { result.ErrorMessage = "不能选择自己作为父级设备"; return(ToJsonContent(result)); } //判断当前 选择的父级 是否为当前设备下的子级 var listChilden = new List <int>(); GetChilden(info.IntID.ToString(), ref listChilden); if (listChilden.Contains(info.IntUpID)) { result.ErrorMessage = "父级设备不能是当前设备下的子级设备!请重新选择!"; return(ToJsonContent(result)); } //厂家编码 var endcode = Session["EndCode"] ?? "0"; info.IntEndCode = endcode.ToString().ToInt32(); try { //调用后台服务获取集中器信息 ServiceDbClient DbServer = new ServiceDbClient(); var flg = DbServer.ArcConcentrator_Upd(info); if (flg == "0") { result.Success = true; } else { result.ErrorMessage = flg; result.Success = false; } } catch (Exception ex) { result.ErrorMessage = ex.Message; } return(ToJsonContent(result)); }
/// <summary> /// 根据参数创建设备(简单工厂-参数工厂) /// </summary> /// <param name="typeValue"></param> /// <returns></returns> public static Device DeviceFactory(int typeValue) { Device refEntity = null; if (typeValue % 3 == 0) { refEntity = new Router(); } else if (typeValue % 3 == 1) { refEntity = new Switcher(); } else { refEntity = new Concentrator(); } return(refEntity); }
//存储集中器信息 private void SavaConcentrator(Socket con, byte[] message) { //保存集中器IP、编号 string ConcerIP = ((IPEndPoint)(con.RemoteEndPoint)).Address.ToString(); Concentrator concer = new Concentrator(); concer.Unit_Id = (message[0] * 256 + message[1]).ToString(); concer.Unit_IpAddress = ConcerIP; concer.Unit_Status = "1"; concer.Unit_Latitude = ""; concer.Unit_Longitude = ""; ConcentratorServer SaveConcen = new ConcentratorServer(); string sql = "select * from concentrator where UnitID = " + concer.Unit_Id; if (db.Select(sql) != null) { string sqlSave = string.Format("insert into sensordata values('{0}','{1}','{2}','{3}','{4}')", concer.Unit_Id, concer.Unit_IpAddress, concer.Unit_Status, concer.Unit_Longitude, concer.Unit_Latitude); db.Insert(sqlSave); } }
private static void InitializeApi() { var expirationTime = DateTimeOffset.UtcNow.AddDays(5); var c1 = new Concentrator(expirationTime) { DeviceInfo = new DeviceInfo(expirationTime) { DeviceLabel = "Concentrator 1", DeviceType = "Concentrator", Manufacturer = "Kamstrup", Model = "OMNICON", HardwareVersion = "A1", SoftwareVersion = "J6" } }; var c2 = new Concentrator(expirationTime) { DeviceInfo = new DeviceInfo(expirationTime) { DeviceLabel = "Concentrator 2", DeviceType = "Concentrator", Manufacturer = "Kamstrup", Model = "OMNICON", HardwareVersion = "A1", SoftwareVersion = "H15" } }; var firmware = new Firmware(DateTimeOffset.UtcNow.AddDays(2), "J6", "the new shit!", new Uri("http://localhost:52480/api/concentrators")); c2.CreateFirmwareJob(firmware); m2m = new CSEBase(); m2m.AddNode(c1); m2m.AddNode(c2); }
public ActionResult ListJson_Server() { var info = new Concentrator() { NvcName = Request["WHC_NvcName"] ?? "", NvcAddr = Request["WHC_NvcAddr"] ?? "", VcSimNo = Request["WHC_VcSimNo"] ?? "", VcAddr = Request["WHC_VcAddr"] ?? "" }; var endcode = Session["EndCode"] ?? "0"; //调用后台服务获取集中器信息 ServiceDbClient DbServer = new ServiceDbClient(); var dts = DbServer.ArcConcentrator_Qry(endcode.ToString().ToInt32(), info); int rows = Request["rows"] == null ? 10 : int.Parse(Request["rows"]); int page = Request["page"] == null ? 1 : int.Parse(Request["page"]); //复制源的架构和约束 var dat = dts.Clone(); // 清除目标的所有数据 dat.Clear(); //对数据进行分页 for (int i = (page - 1) * rows; i < page * rows && i < dts.Rows.Count; i++) { dat.ImportRow(dts.Rows[i]); } //最重要的是在后台取数据放在json中要添加个参数total来存放数据的总行数,如果没有这个参数则不能分页 int total = dts.Rows.Count; var result = new { total = total, rows = dat }; return(ToJsonContentDate(result)); }
public CanPlayDto CanPlayV2( IServiceProvider serviceProvider, Concentrator concentrator, ControllerConfigRelay gameController, Card card, IList <ScheduleDay> scheduleDays, bool shouldPay, IEnumerable <CurrencyTemplate> currencyTemplates) { var result = new CanPlayDto(); if (concentrator == null) { result.HasError = true; result.Message = "111|Invalid requirements! Concentrator is null"; return(result); } if (gameController == null) { result.HasError = true; result.Message = "112|Invalid requirements! Game controller is null"; return(result); } if (gameController.EGM == null || concentrator.GameCenterId != gameController.EGM.GameCenterId) { result.HasError = true; result.Message = "114|Invalid requirements! gameController.EGM == null or concentrator.GameCenterId != gameController.EGM.GameCenterId"; return(result); } if (card == null) { result.HasError = true; result.Message = "113|Invalid requirements! Card is null"; return(result); } if (!IsCardValidV2(card)) { result.HasError = true; result.Message = "104|Card is not valid!"; return(result); } if (gameController.MinTransactionTime <= 0) { result.HasError = true; result.Message = "105|Controller's MinTransactionTime <= 0"; return(result); } if ((DateTime.UtcNow - card.LastTransactionTime).TotalSeconds < gameController.MinTransactionTime) { result.HasError = true; result.Message = "106|Transaction timespan is too low!"; return(result); } decimal pricePerGame = GetPricePerGame(serviceProvider, scheduleDays, gameController.EGM); int discount = 0; if (card.CardMode != null) { discount = card.CardMode.DiscountPercent; } if (discount != 0) { pricePerGame = CalculateByDiscount(pricePerGame, discount); } if (card.FreePeriod) { #region Free-Period if (card.FreePeriodStart < DateTime.UtcNow && DateTime.UtcNow < card.FreePeriodEnd) //is Active Free Period { result.CanPlay = true; result.GameCenterName = gameController.EGM.GameCenter?.Name; result.GameName = gameController.EGM.MachineName; result.CurrencyInfo = "FP"; result.RemainingBalance = card.GetBalanceFromSomeCurrency(); if (shouldPay) { card.LastTransactionTime = DateTime.UtcNow; var updateResult = UpdateCurrency(serviceProvider, card); if (!updateResult.IsSuccess) { result.CanPlay = false; result.HasError = true; result.Message = "117|Cannot update Card with ActiveFreePeriod"; return(result); } } return(result); } else { card.FreePeriod = false; card.FreePeriodStart = null; card.FreePeriodEnd = null; var updateResult = UpdateCurrency(serviceProvider, card); if (!updateResult.IsSuccess) { result.CanPlay = false; result.HasError = true; result.Message = "107|Cannot update Card"; return(result); } } #endregion } bool tempCanPlay = false; string tempCurrencyName = null; AllowedCurrency[] egmCurrencies = gameController.EGM.AllowedCurrencies.OrderByDescending(x => x.Order).ToArray(); string currencyType = string.Empty; foreach (var egmC in egmCurrencies) { if (egmC.Type == CCurrency.Credit) { currencyType = CCurrency.Credit; tempCanPlay = card.CurrencyPrimaryBalance + card.CurrencyPrimaryBalanceBonus >= pricePerGame; } else if (egmC.Type == CCurrency.Courtesy) { tempCanPlay = card.CurrencyCreditBalance + card.CurrencyCreditBalanceBonus >= pricePerGame; currencyType = CCurrency.Courtesy; } else if (egmC.Type == CCurrency.Bonus) { tempCanPlay = card.CurrencyBonusBalance + card.CurrencyBonusBalanceBonus >= pricePerGame; currencyType = CCurrency.Bonus; } else if (egmC.Type == CCurrency.TicketBonus) { tempCanPlay = card.CurrencyTicketBalance + card.CurrencyTicketBalanceBonus >= pricePerGame; currencyType = CCurrency.TicketBonus; } else if (egmC.Type == CCurrency.Minutes) { tempCanPlay = card.CurrencyTimeBalance + card.CurrencyTimeBalanceBonus >= pricePerGame; currencyType = CCurrency.Minutes; } else if (egmC.Type == CCurrency.TicketUsedBonus) { tempCanPlay = card.Currency1Balance + card.Currency1BalanceBonus >= pricePerGame; currencyType = CCurrency.TicketUsedBonus; } if (tempCanPlay) { tempCurrencyName = egmC.Type; break; } } if (!tempCanPlay) { result.Message = "108|Balance is to low or game does not support current currency!"; result.HasError = true; } if (result.HasError) { result.CanPlay = false; result.PricePerGame = pricePerGame; result.GameCenterName = gameController.EGM.GameCenter?.Name; result.GameName = gameController.EGM.MachineName; if (!string.IsNullOrWhiteSpace(tempCurrencyName)) { // TODO: get currency code by currency template result.CurrencyInfo = "";// tempCurrency.Code; result.RemainingBalance = GetBalanceByCurrencyType(card, tempCurrencyName); } return(result); } try { if (shouldPay) { (decimal paidFromPrimary, decimal paidFromBonus) = PaymentByCurrencyType(card, tempCurrencyName, pricePerGame); result.PaidFromPrimaryBalance = paidFromPrimary; result.PaidFromBonusBalance = paidFromBonus; card.LastTransactionTime = DateTime.UtcNow; if (gameController.EGM.BonusAfterPlay > 0) { card.CurrencyCreditBalanceBonus += gameController.EGM.BonusAfterPlay; result.HasBonusAfterPlay = true; result.BonusAfterPlay = gameController.EGM.BonusAfterPlay; } var updateResult = UpdateCurrency(serviceProvider, card); if (!updateResult.IsSuccess) { result.CanPlay = false; result.HasError = true; result.Message = "127|Cannot update Card with shouldPay = true"; return(result); } } result.CanPlay = true; result.PricePerGame = pricePerGame; result.GameCenterName = gameController.EGM.GameCenter?.Name; result.GameId = gameController.EGM.Id; result.GameName = gameController.EGM.MachineName; CurrencyTemplate currencyTemplate = currencyTemplates.FirstOrDefault(x => x.Type == currencyType); if (currencyTemplate != null) { result.CurrencyInfo = currencyTemplate.Code; } result.RemainingBalance = GetBalanceByCurrencyType(card, tempCurrencyName); result.CardId = card.Id; result.CardNumber = card.Number; result.CardType = card.TypeName; } catch (Exception ex) { Logger logger = new Logger(); logger.LogException($"BusinessServices.CanPlayService.CanPlayV2 throws: {ex}"); result.HasError = true; result.Message = "109|Internal Server Error! Cannot update card state!"; } return(result); }
public ClientViewModel(Client client, Concentrator concentrator) { Client = client; Client.OnMessage += Client_OnMessage; Concentrator = concentrator; }
public void InitializeFramework(Framework framework) { m_mapper = framework.Mapper; m_concentrator = framework.Concentrator; m_subscriber = framework.Subscriber; }