public override void SendFinalResponse(SIPResponse sipResponse) { try { base.SendFinalResponse(sipResponse); if (CDR != null) { CDR.Answered(sipResponse.StatusCode, sipResponse.Status, sipResponse.ReasonPhrase, null, null); } } catch (Exception excp) { logger.Error("Exception UASInviteTransaction SendFinalResponse. " + excp.Message); throw; } }
private async Task <SocketError> UACInviteTransaction_TransactionFinalResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { DeliveryPending = false; base.UpdateTransactionState(SIPTransactionStatesEnum.Confirmed); // BranchId for 2xx responses needs to be a new one, non-2xx final responses use same one as original request. if (sipResponse.StatusCode >= 200 && sipResponse.StatusCode < 299) { if (_sendOkAckManually == false) { AckRequest = Get2xxAckRequest(null, null); await SendRequestAsync(AckRequest).ConfigureAwait(false); } } else { // ACK for non 2xx response is part of the INVITE transaction and gets routed to the same endpoint as the INVITE. AckRequest = GetInTransactionACKRequest(sipResponse, m_transactionRequest.URI); await SendRequestAsync(AckRequest).ConfigureAwait(false); } if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Answered(sipResponse.StatusCode, sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } if (UACInviteTransactionFinalResponseReceived != null) { return(await UACInviteTransactionFinalResponseReceived(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse).ConfigureAwait(false)); } else { return(SocketError.Success); } } catch (Exception excp) { logger.LogError($"Exception UACInviteTransaction_TransactionFinalResponseReceived. {excp.Message}"); return(SocketError.Fault); } }
public void Genereate_WhenGivingPackageACustomerAndOneCDRWihtLocalCallInOffPeakHoursLessThanAMiniuteCallDuration_ShouldReturnTheBill() { // Arrange CDR cdrForTest = new CDR(0711593912, 0711535724, new DateTime(2017, 12, 23, 21, 0, 0), 58); listOfCallDetails.Add(cdrForTest); string expected = "Customer Name: FirstName SecondName" + "\nPhone number: 711593912" + "\nAddress: Address1, Address2." + "\nTotal Amount to Pay: LKR: 122.4"; // Act _sut.Generate(listOfCallDetails); // Assert Assert.AreEqual(expected, _sut.getTheBill(0711593912).PrintThebill()); }
private void UACInviteTransaction_TransactionInformationResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { UACInviteTransactionInformationResponseReceived?.Invoke(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse); if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Progress(sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } } catch (Exception excp) { logger.Error("Exception UACInviteTransaction_TransactionInformationResponseReceived. " + excp.Message); } }
public void Genereate_WhenGivingPackageACustomerAndOneCDRWihtLongDistanceCallInBetweenOffPeakHoursAndPeakHours_ShouldReturnTheBill() { // Arrange CDR cdrForTest = new CDR(0711593917, 0721535724, new DateTime(2017, 12, 23, 17, 59, 0), 185); listOfCallDetails.Add(cdrForTest); string expected = "Customer Name: FirstName SecondName" + "\nPhone number: 711593917" + "\nAddress: Address1, Address2." + "\nTotal Amount to Pay: LKR: 140.4"; // Act _sut.Generate(listOfCallDetails); // Assert Assert.AreEqual(expected, _sut.getTheBill(0711593917).PrintThebill()); }
private void HangupDialogue(SIPDialogue dialogue, string hangupCause, bool sendBye) { if (dialogue.CDRId != Guid.Empty) { CDR cdr = m_cdrDataLayer.Get(dialogue.CDRId); if (cdr != null) { //cdr.BridgeID = dialogue.BridgeId; //cdr.Hungup(hangupCause); m_cdrDataLayer.Hangup(cdr.ID, hangupCause); } else { logger.LogWarning("CDR could not be found for remote dialogue in SIPCallManager CallHungup."); } } else { logger.LogWarning("There was no CDR attached to orphaned dialogue in SIPCallManager CallHungup."); } if (sendBye) { // In order to help cope with IPv4 NAT's apply some logic to determine if the Contact header URI looks likely // to fail which in turn would result in any in-dialgoue requests not being delivered. //var target = dialogue.RemoteTarget; //var mangledTarget = SIPURI.Mangle(target, dialogue.RemoteSIPEndPoint?.GetIPEndPoint()); //if (mangledTarget != null) //{ // logger.LogDebug($"SIPCallManager adjusting BYE target from {target} to {mangledTarget}."); // target = mangledTarget; //} //dialogue.Hangup(m_sipTransport, m_outboundProxy, target); dialogue.Hangup(m_sipTransport, dialogue.RemoteSIPEndPoint); OnCallHungup?.Invoke(dialogue); } m_sipCallDataLayer.Delete(dialogue.Id); }
private void UACInviteTransaction_TransactionTimedOut(SIPTransaction sipTransaction) { try { if (UACInviteTransactionTimedOut != null) { UACInviteTransactionTimedOut(sipTransaction); } if (CDR != null) { CDR.TimedOut(); } } catch (Exception excp) { logger.LogError("Exception UACInviteTransaction_TransactionTimedOut. " + excp.Message); throw; } }
public async Task <ActionResult <CDR> > PostCDR(CDR cDR) { _context.CDRs.Add(cDR); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CDRExists(cDR.ID)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetCDR", new { id = cDR.ID }, cDR)); }
private async Task <SocketError> UACInviteTransaction_TransactionInformationResponseReceived( SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { if (sipResponse.StatusCode > 100 && sipResponse.StatusCode <= 199) { if (sipResponse.Header.RSeq > 0) { // Send a PRACK for this provisional response. PRackRequest = GetPRackRequest(sipResponse); await SendRequestAsync(PRackRequest).ConfigureAwait(false); } } if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Progress(sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } if (UACInviteTransactionInformationResponseReceived != null) { return(await UACInviteTransactionInformationResponseReceived(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse).ConfigureAwait(false)); } else { return(SocketError.Success); } } catch (Exception excp) { Logger.Logger.Error( "Exception UACInviteTransaction_TransactionInformationResponseReceived. ->" + excp.Message); return(SocketError.Fault); } }
private void UACInviteTransaction_TransactionFinalResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { // BranchId for 2xx responses needs to be a new one, non-2xx final responses use same one as original request. if (sipResponse.StatusCode >= 200 && sipResponse.StatusCode < 299) { if (_sendOkAckManually == false) { Send2xxAckRequest(null, null); } } else { // ACK for non 2xx response is part of the INVITE transaction and gets routed to the same endpoint as the INVITE. var ackRequest = GetInTransactionACKRequest(sipResponse, m_transactionRequest.URI, LocalSIPEndPoint); base.SendRequest(RemoteEndPoint, ackRequest); } UACInviteTransactionFinalResponseReceived?.Invoke(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse); if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Answered(sipResponse.StatusCode, sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } } catch (Exception excp) { Logger.Logger.Error( "Exception UACInviteTransaction_TransactionFinalResponseReceived. ->" + excp.Message); } }
private void UACInviteTransaction_TransactionInformationResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { UACInviteTransactionInformationResponseReceived?.Invoke(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse); if (sipResponse.StatusCode > 100 && sipResponse.StatusCode <= 199 && sipResponse.Header.RSeq > 0) { // Send a PRACK for this provisional response. SendPRackRequest(sipResponse); } if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Progress(sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } } catch (Exception excp) { logger.LogError("Exception UACInviteTransaction_TransactionInformationResponseReceived. " + excp.Message); } }
public void Init() { _sut = new CDR(0711535724, 0711593911, date, 65); }
private void UASInviteTransaction_TransactionFailed(SIPTransaction sipTransaction, SocketError failureReason) { UASInviteTransactionFailed?.Invoke(this, failureReason); CDR?.TimedOut(); }
public new void SendFinalResponse(SIPResponse sipResponse) { CDR?.Answered(sipResponse.StatusCode, sipResponse.Status, sipResponse.ReasonPhrase, null, null); base.SendFinalResponse(sipResponse); }
public new Task <SocketError> SendProvisionalResponse(SIPResponse sipResponse) { CDR?.Progress(sipResponse.Status, sipResponse.ReasonPhrase, null, null); return(base.SendProvisionalResponse(sipResponse)); }
private void button5_Click(object sender, EventArgs e) { // my bandwagon one call // channel originate pjsip/6001 extension 6001@from-internel //OriginateAction oc1 = new OriginateAction(); //oc1.Context = @"from-internel"; //oc1.Priority = "1"; //oc1.Channel = @"pjsip/6001"; //oc1.CallerId = "97477009999"; //oc1.Exten = "6001"; //oc1.Async = true; //oc1.Timeout = ORIGINATE_TIMEOUT; //CDR call = new CDR(); //call.Anumber = "97477009999"; //call.Bnumber = "7001"; //try //{ // dcdr.Add(call.Anumber, call); // manager.SendAction(oc1, null); //} //catch (Exception ep) //{ } dcdr.Clear(); // asterisk 190 N calls long initBNumber = 500036312340000; long initANumber = 85222930000; int j = int.Parse(textBox1.Text); for (int i = 0; i < j; i++) { OriginateAction oc = new OriginateAction(); oc.Async = true; oc.Context = @"autodialer"; oc.Priority = "1"; oc.Channel = @"sip/astToTB/" + (initBNumber + i).ToString(); oc.CallerId = (initANumber + i).ToString(); oc.Exten = "100"; oc.Timeout = ORIGINATE_TIMEOUT; //oc.Context = @"from-internel"; //oc.Priority = "1"; //oc.Channel = @"pjsip/6001"; //oc.CallerId = "97477009999"; //oc.Exten = "6001"; //oc.Async = true; //oc.Timeout = ORIGINATE_TIMEOUT; CDR call = new CDR(); call.Anumber = oc.CallerId; call.Bnumber = (initBNumber + i).ToString(); try { dcdr.Add(call.Anumber, call); manager.SendAction(oc, null); } catch (Exception ep) { } } //************************************* end of my bandwagon /******** asterisk 190 * * long initBNumber = 500036312340000; * * * long initANumber = 85222930000; * * * //int j = int.Parse(textBox1.Text); * * for (int i = 0; i < 50; i++) * { * * OriginateAction oc = new OriginateAction(); * oc.Async = true; * oc.Context = @"autodialer"; * oc.Priority = "1"; * //oc.Channel = @"sip/ast2/70019779805550000"; * * oc.Channel = @"sip/astToTB/" + (initBNumber + i).ToString(); * * * //oc.CallerId = "97477009999"; * * oc.CallerId = (initANumber + i).ToString(); * oc.Exten = "100"; * oc.Timeout = ORIGINATE_TIMEOUT; * manager.SendAction(oc, null); * * * } // for * * * * ******/// ebd of asterisk 190 //int i,k=0; //int j = int.Parse(textBox1.Text); //while(true) //{ // for ( i = k; i < j; i++) // { // OriginateAction oc = new OriginateAction(); // oc.Async = true; // oc.Context = @"autodialer"; // oc.Priority = "1"; // //oc.Channel = @"sip/ast2/70019779805550000"; // oc.Channel = @"sip/astToTB/" + (initBNumber + i).ToString(); // //oc.CallerId = "97477009999"; // oc.CallerId = (initANumber + i).ToString(); // oc.Exten = "100"; // oc.Timeout = ORIGINATE_TIMEOUT; // manager.SendAction(oc, null); // if (i >= k + 50) // { // k = k + 51; // System.Threading.Thread.Sleep(30000); // break; // } // } // for // } }
public IActionResult Import() { IFormFile file = Request.Form.Files[0]; string folderName = "UploadExcel"; string webRootPath = _hostingEnvironment.WebRootPath; string newPath = Path.Combine(webRootPath, folderName); StringBuilder sb = new StringBuilder(); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string sFileExtension = Path.GetExtension(file.FileName).ToLower(); ISheet sheet; string fullPath = Path.Combine(newPath, file.FileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); stream.Position = 0; if (sFileExtension == ".xls") { HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } else { XSSFWorkbook hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } IRow headerRow = sheet.GetRow(0); //Get Header Row int cellCount = headerRow.LastCellNum; for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File { IRow row = sheet.GetRow(i); if (row == null) { continue; } if (row.Cells.All(d => d.CellType == CellType.Blank)) { continue; } var item = db.CDR.Where(s => s.MSISDN.Equals(row.GetCell(1).ToString())).Count(); if (item == 0) { CDR cdr = new CDR(); cdr.CONTRNO = row.GetCell(0).ToString(); cdr.MSISDN = row.GetCell(1).ToString(); cdr.SimCardId = db.SimCard.SingleOrDefault(s => s.SimCardNumber.Equals(row.GetCell(1).ToString())).Id; cdr.SimCard = db.SimCard.SingleOrDefault(s => s.SimCardNumber.Equals(row.GetCell(1).ToString())); cdr.PREPAID_FLAG = row.GetCell(3).ToString(); cdr.STATUS = row.GetCell(4).ToString(); cdr.REASON = row.GetCell(5).ToString(); cdr.TARIFF_PROFILE = row.GetCell(6).ToString(); cdr.USAGE_STATE = row.GetCell(7).ToString(); db.CDR.Add(cdr); db.SaveChanges(); IRow header = sheet.GetRow(0); for (int j = header.FirstCellNum + 8; j < cellCount - 1; j++) { CDR_Date date = new CDR_Date(); date.CDR_ID = cdr.Id; date.CDR = cdr; try { string[] sdate = header.GetCell(j).DateCellValue.ToShortDateString().Split("/"); date.Date = sdate[1] + "/" + sdate[0] + "/" + sdate[2]; //date.Date = header.GetCell(j).DateCellValue.ToShortDateString(); } catch (Exception) { string[] sdate = header.GetCell(j).ToString().Split("/"); date.Date = sdate[1] + "/" + sdate[0] + "/" + sdate[2]; } date.Ammount = Convert.ToDouble(row.GetCell(j).ToString()); db.CDR_Date.Add(date); db.SaveChanges(); } } else { var cdr = db.CDR.SingleOrDefault(s => s.MSISDN.Equals(row.GetCell(1).ToString())); IRow header = sheet.GetRow(0); for (int j = header.FirstCellNum + 8; j < cellCount - 1; j++) { var x = header.GetCell(j).DateCellValue.ToShortDateString(); var a = db.CDR_Date.Where(s => s.CDR_ID.Equals(cdr.Id) && s.Date.Equals(x)); if (a.Count() == 0) { CDR_Date date = new CDR_Date(); date.CDR_ID = cdr.Id; date.CDR = cdr; try { string[] sdate = header.GetCell(j).DateCellValue.ToShortDateString().Split("/"); date.Date = sdate[1] + "/" + sdate[0] + "/" + sdate[2]; //date.Date = header.GetCell(j).DateCellValue.ToShortDateString(); } catch (Exception) { string[] sdate = header.GetCell(j).ToString().Split("/"); date.Date = sdate[1] + "/" + sdate[0] + "/" + sdate[2]; } date.Ammount = Convert.ToDouble(row.GetCell(j).ToString()); db.CDR_Date.Add(date); db.SaveChanges(); } } } } } } return(View()); }
/// <summary> /// Cancels this transaction. This does NOT generate a CANCEL request. A separate /// reliable transaction needs to be created for that. /// </summary> /// <param name="cancelReason">The reason for cancelling the transaction.</param> public void CancelCall(string cancelReason = null) { UpdateTransactionState(SIPTransactionStatesEnum.Cancelled); CDR?.Cancelled(cancelReason); }
public static void CDR_SerializeDeserialize_Test01() { #region Defined CDR1 var CDR1 = new CDR(CountryCode.Parse("DE"), Party_Id.Parse("GEF"), CDR_Id.Parse("CDR0001"), DateTime.Parse("2020-04-12T18:20:19Z"), DateTime.Parse("2020-04-12T22:20:19Z"), new CDRToken( Token_Id.Parse("1234"), TokenTypes.RFID, Contract_Id.Parse("C1234") ), AuthMethods.AUTH_REQUEST, new CDRLocation( Location_Id.Parse("LOC0001"), "Biberweg 18", "Jena", "Deutschland", GeoCoordinate.Parse(10, 20), EVSE_UId.Parse("DE*GEF*E*LOC0001*1"), EVSE_Id.Parse("DE*GEF*E*LOC0001*1"), Connector_Id.Parse("1"), ConnectorTypes.IEC_62196_T2, ConnectorFormats.SOCKET, PowerTypes.AC_3_PHASE, "Name?", "07749" ), Currency.EUR, new ChargingPeriod[] { new ChargingPeriod( DateTime.Parse("2020-04-12T18:21:49Z"), new CDRDimension[] { new CDRDimension( CDRDimensions.ENERGY, 1.33M ) }, Tariff_Id.Parse("DE*GEF*T0001") ), new ChargingPeriod( DateTime.Parse("2020-04-12T18:21:50Z"), new CDRDimension[] { new CDRDimension( CDRDimensions.TIME, 5.12M ) }, Tariff_Id.Parse("DE*GEF*T0002") ) }, // Total costs new Price( 10.00, 11.60 ), // Total Energy 50.00M, // Total time TimeSpan.FromMinutes(30), Session_Id.Parse("0815"), AuthorizationReference.Parse("Auth0815"), Meter_Id.Parse("Meter0815"), // OCPI Computer Science Extentions new EnergyMeter( Meter_Id.Parse("Meter0815"), "EnergyMeter Model #1", "hw. v1.80", "fw. v1.20", "Energy Metering Services", null, null ), // OCPI Computer Science Extentions new TransparencySoftware[] { new TransparencySoftware( "Chargy Transparency Software Desktop Application", "v1.00", LegalStatus.LegallyBinding, OpenSourceLicenses.GPL3, "GraphDefined GmbH", URL.Parse("https://open.charging.cloud/logo.svg"), URL.Parse("https://open.charging.cloud/Chargy/howto"), URL.Parse("https://open.charging.cloud/Chargy"), URL.Parse("https://github.com/OpenChargingCloud/ChargyDesktopApp") ), new TransparencySoftware( "Chargy Transparency Software Mobile Application", "v1.00", LegalStatus.ForInformationOnly, OpenSourceLicenses.GPL3, "GraphDefined GmbH", URL.Parse("https://open.charging.cloud/logo.svg"), URL.Parse("https://open.charging.cloud/Chargy/howto"), URL.Parse("https://open.charging.cloud/Chargy"), URL.Parse("https://github.com/OpenChargingCloud/ChargyMobileApp") ) }, new Tariff[] { new Tariff( CountryCode.Parse("DE"), Party_Id.Parse("GEF"), Tariff_Id.Parse("TARIFF0001"), Currency.EUR, new TariffElement[] { new TariffElement( new PriceComponent[] { PriceComponent.ChargingTime( TimeSpan.FromSeconds(300), 2.00M, 0.10M ) }, new TariffRestrictions [] { new TariffRestrictions( Time.FromHourMin(08, 00), // Start time Time.FromHourMin(18, 00), // End time DateTime.Parse("2020-12-01"), // Start timestamp DateTime.Parse("2020-12-31"), // End timestamp 1.12M, // MinkWh 5.67M, // MaxkWh 1.34M, // MinCurrent 8.89M, // MaxCurrent 1.49M, // MinPower 9.91M, // MaxPower TimeSpan.FromMinutes(10), // MinDuration TimeSpan.FromMinutes(30), // MaxDuration new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday }, ReservationRestrictionTypes.RESERVATION ) } ) }, TariffTypes.PROFILE_GREEN, new DisplayText[] { new DisplayText(Languages.de, "Hallo Welt!"), new DisplayText(Languages.en, "Hello world!"), }, URL.Parse("https://open.charging.cloud"), new Price( // Min Price 1.10, 1.26 ), new Price( // Max Price 2.20, 2.52 ), DateTime.Parse("2020-12-01"), // Start timestamp DateTime.Parse("2020-12-31"), // End timestamp new EnergyMix( true, new EnergySource[] { new EnergySource( EnergySourceCategories.SOLAR, 80 ), new EnergySource( EnergySourceCategories.WIND, 20 ) }, new EnvironmentalImpact[] { new EnvironmentalImpact( EnvironmentalImpactCategories.CARBON_DIOXIDE, 0.1 ) }, "Stadtwerke Jena-Ost", "New Green Deal" ), DateTime.Parse("2020-09-22") ) }, new SignedData( EncodingMethod.GraphDefiened, new SignedValue[] { new SignedValue( SignedValueNature.START, "PlainStartValue", "SignedStartValue" ), new SignedValue( SignedValueNature.INTERMEDIATE, "PlainIntermediateValue", "SignedIntermediateValue" ), new SignedValue( SignedValueNature.END, "PlainEndValue", "SignedEndValue" ) }, 1, // Encoding method version null, // Public key "https://open.charging.cloud/pools/1/stations/1/evse/1/publicKey" ), // Total Fixed Costs new Price( 20.00, 23.10 ), // Total Energy Cost new Price( 20.00, 23.10 ), // Total Time Cost new Price( 20.00, 23.10 ), // Total Parking Time TimeSpan.FromMinutes(120), // Total Parking Cost new Price( 20.00, 23.10 ), // Total Reservation Cost new Price( 20.00, 23.10 ), "Remark!", InvoiceReference_Id.Parse("Invoice:0815"), true, // IsCredit CreditReference_Id.Parse("Credit:0815"), DateTime.Parse("2020-09-12") ); #endregion var JSON = CDR1.ToJSON(); Assert.AreEqual("DE", JSON["country_code"].Value <String>()); Assert.AreEqual("GEF", JSON["party_id"].Value <String>()); Assert.AreEqual("CDR0001", JSON["id"].Value <String>()); Assert.IsTrue(CDR.TryParse(JSON, out CDR CDR2, out String ErrorResponse)); Assert.IsNull(ErrorResponse); Assert.AreEqual(CDR1.CountryCode, CDR2.CountryCode); Assert.AreEqual(CDR1.PartyId, CDR2.PartyId); Assert.AreEqual(CDR1.Id, CDR2.Id); Assert.AreEqual(CDR1.Start.ToIso8601(), CDR2.Start.ToIso8601()); Assert.AreEqual(CDR1.End.ToIso8601(), CDR2.End.ToIso8601()); Assert.AreEqual(CDR1.CDRToken, CDR2.CDRToken); Assert.AreEqual(CDR1.AuthMethod, CDR2.AuthMethod); Assert.AreEqual(CDR1.Location, CDR2.Location); Assert.AreEqual(CDR1.Currency, CDR2.Currency); Assert.AreEqual(CDR1.ChargingPeriods, CDR2.ChargingPeriods); Assert.AreEqual(CDR1.TotalCosts, CDR2.TotalCosts); Assert.AreEqual(CDR1.TotalEnergy, CDR2.TotalEnergy); Assert.AreEqual(CDR1.TotalTime, CDR2.TotalTime); Assert.AreEqual(CDR1.SessionId, CDR2.SessionId); Assert.AreEqual(CDR1.AuthorizationReference, CDR2.AuthorizationReference); Assert.AreEqual(CDR1.MeterId, CDR2.MeterId); Assert.AreEqual(CDR1.EnergyMeter, CDR2.EnergyMeter); Assert.AreEqual(CDR1.TransparencySoftwares, CDR2.TransparencySoftwares); Assert.AreEqual(CDR1.Tariffs, CDR2.Tariffs); Assert.AreEqual(CDR1.SignedData, CDR2.SignedData); Assert.AreEqual(CDR1.TotalFixedCosts, CDR2.TotalFixedCosts); Assert.AreEqual(CDR1.TotalEnergyCost, CDR2.TotalEnergyCost); Assert.AreEqual(CDR1.TotalTimeCost, CDR2.TotalTimeCost); Assert.AreEqual(CDR1.TotalParkingTime, CDR2.TotalParkingTime); Assert.AreEqual(CDR1.TotalParkingCost, CDR2.TotalParkingCost); Assert.AreEqual(CDR1.TotalReservationCost, CDR2.TotalReservationCost); Assert.AreEqual(CDR1.Remark, CDR2.Remark); Assert.AreEqual(CDR1.InvoiceReferenceId, CDR2.InvoiceReferenceId); Assert.AreEqual(CDR1.Credit, CDR2.Credit); Assert.AreEqual(CDR1.CreditReferenceId, CDR2.CreditReferenceId); Assert.AreEqual(CDR1.LastUpdated.ToIso8601(), CDR2.LastUpdated.ToIso8601()); }
public static void CDR_DeserializeGitHub_Test01() { #region Define JSON var JSON = @"{ ""country_code"": ""BE"", ""party_id"": ""BEC"", ""id"": ""12345"", ""start_date_time"": ""2015-06-29T21:39:09Z"", ""end_date_time"": ""2015-06-29T23:37:32Z"", ""cdr_token"": { ""uid"": ""012345678"", ""type"": ""RFID"", ""contract_id"": ""DE8ACC12E46L89"" }, ""auth_method"": ""WHITELIST"", ""cdr_location"": { ""id"": ""LOC1"", ""name"": ""Gent Zuid"", ""address"": ""F.Rooseveltlaan 3A"", ""city"": ""Gent"", ""postal_code"": ""9000"", ""country"": ""BEL"", ""coordinates"": { ""latitude"": ""3.729944"", ""longitude"": ""51.047599"" }, ""evse_uid"": ""3256"", ""evse_id"": ""BE*BEC*E041503003"", ""connector_id"": ""1"", ""connector_standard"": ""IEC_62196_T2"", ""connector_format"": ""SOCKET"", ""connector_power_type"": ""AC_1_PHASE"" }, ""currency"": ""EUR"", ""tariffs"": [{ ""country_code"": ""BE"", ""party_id"": ""BEC"", ""id"": ""12"", ""currency"": ""EUR"", ""elements"": [{ ""price_components"": [{ ""type"": ""TIME"", ""price"": 2.00, ""vat"": 10.0, ""step_size"": 300 }] }], ""last_updated"": ""2015-02-02T14:15:01Z"" }], ""charging_periods"": [{ ""start_date_time"": ""2015-06-29T21:39:09Z"", ""dimensions"": [{ ""type"": ""TIME"", ""volume"": 1.973 }], ""tariff_id"": ""12"" }], ""total_cost"": { ""excl_vat"": 4.00, ""incl_vat"": 4.40 }, ""total_energy"": 15.342, ""total_time"": 1.973, ""total_time_cost"": { ""excl_vat"": 4.00, ""incl_vat"": 4.40 }, ""last_updated"": ""2015-06-29T22:01:13Z"" }"; #endregion Assert.IsTrue(CDR.TryParse(JSON, out CDR parsedCDR, out String ErrorResponse)); Assert.IsNull(ErrorResponse); Assert.AreEqual(CountryCode.Parse("BE"), parsedCDR.CountryCode); Assert.AreEqual(Party_Id.Parse("BEC"), parsedCDR.PartyId); Assert.AreEqual(CDR_Id.Parse("12345"), parsedCDR.Id); //Assert.AreEqual(true, parsedCDR.Publish); //Assert.AreEqual(CDR1.Start. ToIso8601(), parsedCDR.Start. ToIso8601()); //Assert.AreEqual(CDR1.End.Value.ToIso8601(), parsedCDR.End.Value.ToIso8601()); //Assert.AreEqual(CDR1.kWh, parsedCDR.kWh); //Assert.AreEqual(CDR1.CDRToken, parsedCDR.CDRToken); //Assert.AreEqual(CDR1.AuthMethod, parsedCDR.AuthMethod); //Assert.AreEqual(CDR1.AuthorizationReference, parsedCDR.AuthorizationReference); //Assert.AreEqual(CDR1.CDRId, parsedCDR.CDRId); //Assert.AreEqual(CDR1.EVSEUId, parsedCDR.EVSEUId); //Assert.AreEqual(CDR1.ConnectorId, parsedCDR.ConnectorId); //Assert.AreEqual(CDR1.MeterId, parsedCDR.MeterId); //Assert.AreEqual(CDR1.EnergyMeter, parsedCDR.EnergyMeter); //Assert.AreEqual(CDR1.TransparencySoftwares, parsedCDR.TransparencySoftwares); //Assert.AreEqual(CDR1.Currency, parsedCDR.Currency); //Assert.AreEqual(CDR1.ChargingPeriods, parsedCDR.ChargingPeriods); //Assert.AreEqual(CDR1.TotalCosts, parsedCDR.TotalCosts); //Assert.AreEqual(CDR1.Status, parsedCDR.Status); //Assert.AreEqual(CDR1.LastUpdated.ToIso8601(), parsedCDR.LastUpdated.ToIso8601()); }
private void UASInviteTransaction_TransactionTimedOut(SIPTransaction sipTransaction) { UASInviteTransactionTimedOut?.Invoke(this); CDR?.TimedOut(); }
/// <summary> /// Retrieve all the CDR records that have not been loaded into the phone_cdr table /// yet. This method is called by the ArenaPbxCdr Agent. /// </summary> /// <returns>A collection of CDR records that are new since the last run.</returns> public CDRCollection GetCDRRecords() { CDRCollection cdrRecords = new CDRCollection(); SqlDataReader rdr; // // Execute the stored procedure. The stored procedure merges the two tables // (the phone_cdr table in Arena and the cdr table in Asterisk) and returns // a reader with only the CDR records from Asterisk that do not exist in Arena. // rdr = new Arena.DataLayer.Organization.OrganizationData().ExecuteReader("cust_asterisk_sp_get_cdr_records"); while (rdr.Read()) { CDR cdr = new CDR(); // // If the source channel is a SIP device (we do not yet use IAX) then // we need to strip out just the device name (extension number). Asterisk // provides this in a "SIP/268-293fab239" format. // string srcChannel = rdr["channel"].ToString(); if (srcChannel.ToUpper().StartsWith("SIP/")) { cdr.Source = srcChannel.Substring(4); cdr.Source = cdr.Source.Substring(0, cdr.Source.IndexOf('-')); } else { cdr.Source = rdr["src"].ToString(); } // // If the destination channel is a SIP device (we do not yet use IAX) then // we need to strip out just the device name (extension number). Asterisk // provides this in a "SIP/268-293fab239" format. // string dstChannel = rdr["dstchannel"].ToString(); if (dstChannel.ToUpper().StartsWith("SIP/")) { cdr.Destination = dstChannel.Substring(4); cdr.Destination = cdr.Destination.Substring(0, cdr.Destination.IndexOf('-')); } else { cdr.Destination = rdr["dst"].ToString(); } // // If the destination begins is 7 or more characters and does not begin with // a 9, then prepend the 9. Some of our phone calls have the 9, some do not. // Make sure they are all the same. // Next if it is a long distance call (e.g. 917605552732) strip out the 1 since // Arena does not use it. // if (cdr.Destination.Length >= 7 && cdr.Destination[0] != '9') { cdr.Destination = "9" + cdr.Destination; // Prepend a 9 for outward calls that don't have it. } if (cdr.Destination.Length > 7 && cdr.Destination.Substring(0, 2) == "91") { cdr.Destination = "9" + cdr.Destination.Substring(2); // Strip out the 1 for long distance } // // Get the CallerID as identified by Asterisk. // cdr.CallerID = rdr["clid"].ToString(); // // Get the time the call began. // if (!rdr.IsDBNull(rdr.GetOrdinal("start"))) { cdr.CallStart = (DateTime)rdr["start"]; } // // Get the time the call was answered (our system does not use this so the // stored procedure sets this to null). // if (!rdr.IsDBNull(rdr.GetOrdinal("answer"))) { cdr.Answered = (DateTime)rdr["answer"]; } // // Get the time the call was ended. // if (!rdr.IsDBNull(rdr.GetOrdinal("end"))) { cdr.CallEnd = (DateTime)rdr["end"]; } // // Get the duration of the call. As of Asterisk 1.6 the duration and billable // seconds is now a floating point, so it might return 129.4 seconds. Convert // to a whole number. // if (!rdr.IsDBNull(rdr.GetOrdinal("duration"))) { cdr.Duration = Convert.ToInt32(rdr["duration"]); } // // Get the billable duration of the call. // if (!rdr.IsDBNull(rdr.GetOrdinal("billsec"))) { cdr.BillSeconds = Convert.ToInt32(rdr["billsec"]); } // // The disposition is the "state" of the call. // if (!rdr.IsDBNull(rdr.GetOrdinal("disposition"))) { switch (rdr["disposition"].ToString()) { case "ANSWERED": cdr.Disposition = CDR_Disposition.Answered; break; case "NO ANSWER": cdr.Disposition = CDR_Disposition.No_Answer; break; case "BUSY": cdr.Disposition = CDR_Disposition.Busy; break; case "FAILED": cdr.Disposition = CDR_Disposition.Failed; break; } } // // Save the foreign key so that our stored procedure can find the // original CDR record later. // cdr.ForeignKey = rdr["uniqueid"].ToString(); // // Add the CDR record to the collection. The agent worker will then match // the CDR record to the person records associated with the call. // cdrRecords.Add(cdr); } rdr.Close(); return(cdrRecords); }