public static void UpdateNode(NodeDto pNode, out Result pResult) { pResult = new Result(); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { //TODO: TO BE removed //NodeRow _original = PlatformManager.GetNode(_db, pNode.NodeId); //if (_original.NodeRole == NodeRole.H323 && pNode.NodeRole != NodeRole.H323) { // LoadBalancingMapManager.Delete(_db, pNode); //} var _nodeRow = MapToNodeRow(pNode); PlatformManager.UpdateNode(_db, _nodeRow); //TODO: //if (pNode.NodeId == CurrentNode.Instance.Id) { // CurrentNode.Instance.Reload(_db); //} _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); pResult.Success = false; pResult.ErrorMessage = _ex.Message; TimokLogger.Instance.LogRbr(LogSeverity.Critical, "PlatformController.UpdateNode", string.Format("Exception:\r\n{0}", _ex)); } } }
public static bool Init() { using (var _db = new Rbr_Db()) { var _nodeCount = PlatformManager.GetNodeCount(_db); if (_nodeCount == 0) { _db.BeginTransaction(); try { //add DEFAULT Platform - PlatformConfiguration.Instance.Standalone PlatformManager.CreateDefaultPlatform(_db); //TODO: remove - not needed, Currrent Node is not singleton anymore //reset CusrrentNode to load new(created) Node //CurrentNode.Instance.Reload(_db); _db.CommitTransaction(); } catch { _db.RollbackTransaction(); throw; } } return(true); } }
/* * call time line: * * x---------------x--------------x-------------------------------x * setup alerting connected completed * * (1) Time between 'setup' and 'alerting' is delay added by our server * * (2) Time between 'alerting' and 'connected' * this is variable (enduser dependent), but together with (1) represents length of * the call that has a cost to it (mostly for the cases when inbound line is T1 * (ie 800#... Joe) for the service provider. VoIP origination doesn't have per minute * origination cost. * * (3) Time between 'connected' and 'completed' * this is part of the call that will be billed to enduser but also it has to be payed for * to the terminating carrier. * * here is how would we calculate call cost: * * callcost=(1) + (2) * originationCost + (3) * terminationCost * (1) + (2) can be used to adjust end user prices if ratio between connected * time and setup time was not originally built in correctly to the enduser pricing. * So, I think that it would be great if we can start measuring 'alerting' event too. * It gives us a measure of how long it takes for call to reach far end. */ #endregion //-- ctor, called by Serializer public static bool DeserializeAndImport(string pFilePath) { using (var _fs = new FileStream(pFilePath, FileMode.Open, FileAccess.Read)) { var _serializer = new XmlSerializer(typeof(CdrAggregate[])); var _cdrAggregates = (CdrAggregate[])_serializer.Deserialize(_fs); if (_cdrAggregates != null && _cdrAggregates.Length > 0) { var _cdrAggregateRows = map(_cdrAggregates); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { foreach (var _cdrAggregateRow in _cdrAggregateRows) { _db.CdrAggregateCollection.Insert(_cdrAggregateRow); } _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CdrAggregate.ImportToDb", string.Format("Exception:\r\n{0}", _ex)); throw; } } } } return(true); }
static void importBatch(Rbr_Db pDb, PhoneCardBatch pPhoneCardBatch, BackgroundWorker pBackgroundWorker) { if (pPhoneCardBatch.InventoryStatus != InventoryStatus.Activated) { throw new ArgumentException("Unexpected pPhoneCardBatch.InventoryStatus [" + pPhoneCardBatch.InventoryStatus + "]"); } pPhoneCardBatch.DateCreated = DateTime.Now; int _index = 0; pDb.BeginTransaction(); try { foreach (PhoneCardDto _phoneCard in pPhoneCardBatch.PhoneCards) { _index++; importPhoneCardAndRetailAccount(pDb, _phoneCard, pPhoneCardBatch.InventoryStatus, pPhoneCardBatch); reportProgress(_index * 100 / pPhoneCardBatch.PhoneCards.Count, pBackgroundWorker); if (_index % 100 == 0) { reportStatus("Loaded " + _index + " Phone Cards", pBackgroundWorker); } } } catch { pDb.RollbackTransaction(); throw; } pDb.CommitTransaction(); }
public static bool AddLot(RetailAccountGenResponse pResponse, PersonDto pPerson) { bool _result = false; using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { InventoryLotRow _lotRow = _db.InventoryLotCollection.GetByServiceIdDenomination(pResponse.Request.ServiceId, pResponse.Request.Denomination); if (_lotRow == null) { _lotRow = new InventoryLotRow(); _lotRow.Service_id = pResponse.Request.ServiceId; _lotRow.Denomination = pResponse.Request.Denomination; _db.InventoryLotCollection.Insert(_lotRow); } var _requestRow = new GenerationRequestRow(); _requestRow.Date_requested = DateTime.Now; _requestRow.Date_completed = DateTime.Now; _requestRow.Date_to_process = DateTime.Now; _requestRow.Number_of_batches = pResponse.Request.NumberOfBatches; _requestRow.Batch_size = pResponse.Request.BatchSize; _requestRow.Lot_id = _lotRow.Lot_id; _db.GenerationRequestCollection.Insert(_requestRow); foreach (var _batch in pResponse.BatchList) { var _batchRow = new BatchRow(); _batchRow.Batch_id = _batch.BatchId; _batchRow.First_serial = _batch.FirstSerial; _batchRow.Last_serial = _batch.LastSerial; _batchRow.Request_id = _requestRow.Request_id; //_batchRow.Box_id = ???? xxx; NOT SET for now //_batchRow.Customer_acct_id = WILL BE SET ON LOAD/ACTIVATE; _batchRow.InventoryStatus = InventoryStatus.Generated; _db.BatchCollection.Insert(_batchRow); logInventoryHistory(_db, pPerson, DateTime.Now, _lotRow.Service_id, _lotRow.Denomination, _batchRow.Batch_id, _batchRow.NumberOfCards, InventoryCommand.Generate, 0, //CustomerAcctId - N/A FOR THIS COMMAND 0, //ResellerPartnerId - N/A FOR THIS COMMAND 0 //ResellerAgentId - N/A FOR THIS COMMAND ); } _db.CommitTransaction(); _result = true; } catch (Exception _ex) { _db.RollbackTransaction(); TimokLogger.Instance.LogRbr(LogSeverity.Critical, "InventoryController.AddLot", string.Format("Exception: {0}", _ex)); } } return(_result); }
void importRouteDialCodes(RouteRecord pRouteRecord) { Host.ReportStatus(string.Format("Importing Dial Codes for Route: {0}", pRouteRecord.FullName)); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { int _countryId = getCountryId(_db, pRouteRecord.CountryName, pRouteRecord.CountryCode); int _routeId = getRouteId(_db, _countryId, pRouteRecord); int _indexDialCode = 0; foreach (long _dialCode in pRouteRecord.DialCodes.Values) { if (Host.CancellationPending) { throw new Exception("Import canceled"); } if (!_dialCode.ToString().StartsWith(pRouteRecord.CountryCode.ToString())) { throw new Exception(string.Format("Invalid Dial Code={0}, CCode={1}", _dialCode, pRouteRecord.CountryCode)); } var _dialCodeDto = new DialCodeDto(); _dialCodeDto.Code = _dialCode; _dialCodeDto.BaseRouteId = _routeId; _dialCodeDto.CallingPlanId = args.CallingPlanId; _dialCodeDto.Version = 0; try { CallingPlanManager.AddDialCode(_db, _dialCodeDto); } catch (Exception _ex) { TimokLogger.Instance.LogRbr(LogSeverity.Debug, "", string.Format("Error inserting dial code: {0}\r\n{1}", _dialCodeDto.Code, _ex)); } if (++_indexDialCode % 10 == 0) { Host.ReportProgress(_indexDialCode * 100 / pRouteRecord.DialCodes.Values.Count); } } Host.ReportStatus(string.Format("Imported total of {0} Dial Codes for Route: {1}", pRouteRecord.DialCodes.Values.Count, pRouteRecord.FullName)); _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); reportStatus(LogSeverity.Error, "DialPlanImporter.importRouteDialCodes", _ex.Message); throw; } } }
public static void AddNode(NodeDto pNode, out Result pResult) { pResult = new Result(); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { var _nodeRow = MapToNodeRow(pNode); PlatformManager.AddNode(_db, _nodeRow); _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); pResult.Success = false; pResult.ErrorMessage = _ex.Message; TimokLogger.Instance.LogRbr(LogSeverity.Critical, "PlatformController.AddNode", string.Format("Exception:\r\n{0}", _ex)); } } }
public static void ExecuteCommand(object sender, DoWorkEventArgs pEvtArg) { using (var _db = new Rbr_Db()) { _db.BeginTransaction(); var _backgroundWorker = (BackgroundWorker)sender; var _inventoryCommandRequest = (InventoryCommandRequest)pEvtArg.Argument; _backgroundWorker.ReportStatus("Executing Batch Command: [" + _inventoryCommandRequest.InventoryCommand + "]"); switch (_inventoryCommandRequest.InventoryCommand) { case InventoryCommand.Load: executeLoadCommand(_db, _backgroundWorker, pEvtArg, _inventoryCommandRequest); break; case InventoryCommand.Activate: case InventoryCommand.Deactivate: case InventoryCommand.Archive: executeCommand(_db, _backgroundWorker, pEvtArg, _inventoryCommandRequest); break; case InventoryCommand.Export: executeExport(_db, _backgroundWorker, pEvtArg, _inventoryCommandRequest); break; default: throw new ArgumentException("Unexpected InventoryCommand [" + _inventoryCommandRequest.InventoryCommand + "]"); } if (pEvtArg.Cancel) { pEvtArg.Result = new InventoryCommandResponse(_inventoryCommandRequest, false); return; } _db.CommitTransaction(); pEvtArg.Result = new InventoryCommandResponse(_inventoryCommandRequest, true); _backgroundWorker.ReportStatus("Finished Batch Command: [" + _inventoryCommandRequest.InventoryCommand + "]"); } }
public static void Deactivate(int pRetailAcctId) { using (var _db = new Rbr_Db()) { _db.BeginTransaction(); //-- get account var _retailAcct = RetailAccountManager.Instance.GetAcct(_db, pRetailAcctId); if (_retailAcct == null) { throw new RbrException(RbrResult.POSA_AcctNotFound, string.Empty); } if (_retailAcct.Status == Status.Active) { _retailAcct.Status = Status.Blocked; RetailAccountManager.Instance.UpdateAcct(_db, _retailAcct); } _db.CommitTransaction(); } }
public static void Recharge(int pRetailAcctId, decimal pAmount) { using (var _db = new Rbr_Db()) { _db.BeginTransaction(); //-- get account var _retailAcct = RetailAccountManager.Instance.GetAcct(_db, pRetailAcctId); if (_retailAcct == null) { throw new RbrException(RbrResult.POSA_AcctNotFound, string.Empty); } if (_retailAcct.Status != Status.Active) { throw new RbrException(RbrResult.POSA_InvalidAcctStatus, string.Empty); } _retailAcct.Status = Status.Active; RetailAccountManager.Instance.UpdateAcct(_db, _retailAcct); _db.CommitTransaction(); } }
public static void Activate(int pRetailAcctId, decimal pAmount, List <long> pPhoneNumbers, out long pPIN, out long pSerialNumber) { pPIN = 0; pSerialNumber = 0; using (var _db = new Rbr_Db()) { _db.BeginTransaction(); //-- get account var _retailAcct = RetailAccountManager.Instance.GetAcct(_db, pRetailAcctId); if (_retailAcct == null) { throw new RbrException(RbrResult.POSA_AcctNotFound, string.Empty); } if (_retailAcct.Status != Status.Active) { _retailAcct.Status = Status.Active; RetailAccountManager.Instance.UpdateAcct(_db, _retailAcct); } _db.CommitTransaction(); } }
public static void UpdatePlatform(PlatformDto pPlatform, out Result pResult) { pResult = new Result(); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { if (PlatformManager.IsLocationInUse(_db, pPlatform.Location, pPlatform.PlatformId)) { throw new Exception("Platform with the same name already exists."); } var _platformRow = MapToPlatformRow(pPlatform); PlatformManager.UpdatePlatform(_db, _platformRow); _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); pResult.Success = false; pResult.ErrorMessage = _ex.Message; TimokLogger.Instance.LogRbr(LogSeverity.Critical, "PlatformController.UpdatePlatform", string.Format("Exception:\r\n{0}", _ex)); } } }
public void ImportToDb(CdrAggregate[] pCdrAggregates) { if (pCdrAggregates != null && pCdrAggregates.Length > 0) { var _cdrAggregateRows = map(pCdrAggregates); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { foreach (var _cdrAggregateRow in _cdrAggregateRows) { _db.CdrAggregateCollection.Insert(_cdrAggregateRow); } _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CdrAggregate.ImportToDb", string.Format("Exception:\r\n{0}", _ex)); throw; } } } }
void importRouteRates(RouteRecord pRouteRecord) //}, int pCallingPlanId, short pId, RouteType pRouteType, int pRoutingPlanId) { { if (pRouteRecord.RatingInfo == null) { throw new Exception(string.Format("ERROR: No Rating Info found for Route={0}", pRouteRecord.FullName)); } reportStatus(LogSeverity.Status, "DialPlanImporter.importRouteRates", string.Format("Importing Route={0}", pRouteRecord.FullName)); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { //-- get base RouteRow var _routeRow = RoutingManager.GetByName(_db, args.CallingPlanId, pRouteRecord.FullName); if (_routeRow == null) { reportStatus(LogSeverity.Status, "DialPlanImporter.importRouteRates", string.Format("SKIPPING: Route={0}, doesn't exists in CallingPlan={1}.", pRouteRecord.FullName, args.CallingPlanId)); return; } var _routeType = getRouteType(); int _rateRouteId = getBaseRouteId(_db, _routeType, args.AccountId, args.RoutingPlanId, _routeRow.Route_id); //-- Expects that imported file has records for Routes whose rates are changing only. //-- If the rate import record for existing Route is missing; Route is skipped //-- If the route record is not found we create a new record and add rates to it //-- Add/Update ratingHistory: default time period today, maxTime used var _ratingHistoryEntry = new RatingHistoryEntry(_routeType, _rateRouteId, args.From, args.To, pRouteRecord.RatingInfo); RatingManager.SaveRatingHistoryEntry(_db, _ratingHistoryEntry); _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); reportStatus(LogSeverity.Error, "DialPlanImporter.importRouteRates", _ex.Message); throw; } } }
public static void DeleteNode(NodeDto pNode, out Result pResult) { pResult = new Result(); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { if (pNode.NodeId == (new CurrentNode()).Id) { throw new Exception("Cannot Delete Current Node."); } //LoadBalancingMapManager.Delete(_db, pNode); var _nodeRow = MapToNodeRow(pNode); PlatformManager.DeleteNode(_db, _nodeRow); _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); pResult.Success = false; pResult.ErrorMessage = _ex.Message; TimokLogger.Instance.LogRbr(LogSeverity.Critical, "PlatformController.DeleteNode", string.Format("Exception:\r\n{0}", _ex)); } } }
public static void DeletePlatform(PlatformDto pPlatform, out Result pResult) { pResult = new Result(); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { var _currNode = PlatformManager.GetNode(_db, CurrentPlatformNode.Id); if (_currNode.Platform_id == pPlatform.PlatformId) { throw new Exception("Cannot delete Current Platform."); } var _platformRow = MapToPlatformRow(pPlatform); PlatformManager.DeletePlatform(_db, _platformRow); _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); pResult.Success = false; pResult.ErrorMessage = _ex.Message; TimokLogger.Instance.LogRbr(LogSeverity.Critical, "PlatformController.DeletePlatform", string.Format("Exception:\r\n{0}", _ex)); } } }