/// <summary> /// Updates an existing CDR. /// </summary> /// <param name="cdr">The CDR to update.</param> public void Update(SIPCDR cdr) { using (var db = new SIPSorceryEntities()) { string cdrID = cdr.CDRId.ToString(); var existingCDR = (from cd in db.CDRs where cd.ID == cdrID select cd).SingleOrDefault(); if (existingCDR == null) { throw new ApplicationException("The CDR to update could not be found"); } else { // Fields that are not permitted to be updated. // ID // Inserted // Direction // Created // Destination // From // Call-ID existingCDR.Owner = cdr.Owner; existingCDR.AdminMemberID = cdr.AdminMemberId; existingCDR.BridgeID = (cdr.BridgeId != Guid.Empty) ? cdr.BridgeId.ToString() : null; existingCDR.InProgressTime = (cdr.ProgressTime != null) ? cdr.ProgressTime.Value.ToString("o") : null; existingCDR.InProgressStatus = cdr.ProgressStatus; existingCDR.InProgressReason = cdr.ProgressReasonPhrase; existingCDR.RingDuration = (cdr.ProgressTime != null && cdr.AnswerTime != null) ? Convert.ToInt32(cdr.AnswerTime.Value.Subtract(cdr.ProgressTime.Value).TotalSeconds) : 0; existingCDR.AnsweredTime = (cdr.AnswerTime != null) ? cdr.AnswerTime.Value.ToString("o") : null; existingCDR.AnsweredStatus = cdr.AnswerStatus; existingCDR.AnsweredReason = cdr.AnswerReasonPhrase; existingCDR.Duration = (cdr.AnswerTime != null && cdr.HangupTime != null) ? Convert.ToInt32(cdr.HangupTime.Value.Subtract(cdr.AnswerTime.Value).TotalSeconds) : 0;; existingCDR.HungupTime = (cdr.HangupTime != null) ? cdr.HangupTime.Value.ToString("o") : null; existingCDR.HungupReason = cdr.HangupReason; existingCDR.AnsweredAt = cdr.AnsweredAt; existingCDR.DialPlanContextID = (cdr.DialPlanContextID != Guid.Empty) ? cdr.DialPlanContextID.ToString() : null; existingCDR.RemoteSocket = (cdr.RemoteEndPoint != null) ? cdr.RemoteEndPoint.ToString() : null; existingCDR.LocalSocket = (cdr.LocalSIPEndPoint != null) ? cdr.LocalSIPEndPoint.ToString() : null; db.SaveChanges(); } } }
internal UASInviteTransaction( SIPTransport sipTransport, SIPRequest sipRequest, SIPEndPoint dstEndPoint, SIPEndPoint localSIPEndPoint, SIPEndPoint outboundProxy, IPAddress contactIPAddress, bool noCDR = false) : base(sipTransport, sipRequest, dstEndPoint, localSIPEndPoint, outboundProxy) { TransactionType = SIPTransactionTypesEnum.Invite; m_remoteTag = sipRequest.Header.From.FromTag; m_contactIPAddress = contactIPAddress; if (sipRequest.Header.To.ToTag == null) { // This UAS needs to set the To Tag. m_localTag = CallProperties.CreateNewTag(); } else { // This is a re-INVITE. m_localTag = sipRequest.Header.To.ToTag; } //logger.Debug("New UASTransaction (" + TransactionId + ") for " + TransactionRequest.URI.ToString() + " to " + RemoteEndPoint + "."); SIPEndPoint localEP = SIPEndPoint.TryParse(sipRequest.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipRequest.Header.ProxyReceivedFrom) ?? dstEndPoint; if (!noCDR) { CDR = new SIPCDR(SIPCallDirection.In, sipRequest.URI, sipRequest.Header.From, sipRequest.Header.CallId, localEP, remoteEP); } //UpdateTransactionState(SIPTransactionStatesEnum.Proceeding); TransactionRequestReceived += UASInviteTransaction_TransactionRequestReceived; TransactionInformationResponseReceived += UASInviteTransaction_TransactionResponseReceived; TransactionFinalResponseReceived += UASInviteTransaction_TransactionResponseReceived; TransactionTimedOut += UASInviteTransaction_TransactionTimedOut; TransactionRemoved += UASInviteTransaction_TransactionRemoved; }
/// <summary> /// Updates an existing CDR. /// </summary> /// <param name="cdr">The CDR to update.</param> public void Update(SIPCDR sipCDR) { using (var db = _dbContextFactory.CreateDbContext()) { var existing = (from cdr in db.CDRs where cdr.ID == sipCDR.CDRId select cdr).SingleOrDefault(); if (existing == null) { logger.LogWarning($"CDRDataLayer the CDR with ID {sipCDR.CDRId} could not be found for an Update operation."); } else { // Fields that are not permitted to be updated. // ID // Inserted // Direction // Created // Destination // From // Call-ID existing.BridgeID = (sipCDR.BridgeId != Guid.Empty) ? sipCDR.BridgeId : null; existing.InProgressAt = sipCDR.ProgressTime; existing.InProgressStatus = sipCDR.ProgressStatus; existing.InProgressReason = sipCDR.ProgressReasonPhrase; existing.RingDuration = sipCDR.GetProgressDuration(); existing.AnsweredAt = sipCDR.AnswerTime; existing.AnsweredStatus = sipCDR.AnswerStatus; existing.AnsweredReason = sipCDR.AnswerReasonPhrase; existing.Duration = sipCDR.GetAnsweredDuration(); existing.HungupAt = sipCDR.HangupTime; existing.HungupReason = sipCDR.HangupReason; existing.AnsweredAt = sipCDR.AnsweredAt; existing.RemoteSocket = sipCDR.RemoteEndPoint?.ToString(); existing.LocalSocket = sipCDR.LocalSIPEndPoint?.ToString(); db.SaveChanges(); } } }
public void WriteCDR(SIPCDR cdr) { try { SIPCDRAsset cdrAsset = new SIPCDRAsset(cdr); var existingCDR = m_sipCDRPersistor.Get(cdrAsset.Id); if (existingCDR == null) { cdrAsset.Inserted = DateTimeOffset.UtcNow; m_sipCDRPersistor.Add(cdrAsset); } else { m_sipCDRPersistor.Update(cdrAsset); } } catch (Exception excp) { logger.Error("Exception QueueCDR. " + excp.Message); } }
/// <summary> /// This method attempts to reserve a the initial amount of credit for a call. /// </summary> /// <param name="accountCode">The accountCode the credit should be reserved against.</param> /// <param name="amount">The amount of credit to reserve.</param> /// <param name="rate">The rate for the call destination and the values that will be used for subsequent credit reservations.</param> /// <param name="initialSeconds">IF the reservation is successful this parameter will hold the number of seconds that were reserved for the initial reservation.</param> /// <returns>True if there was enough credit for the reservation otherwise false.</returns> public decimal ReserveInitialCredit(string accountCode, string rateID, SIPCDR cdr, out int initialSeconds) { try { logger.Debug("ReserveInitialCredit for " + accountCode + " and rate ID " + rateID + "."); initialSeconds = 0; using (var db = new SIPSorceryEntities()) { using (var trans = new TransactionScope()) { var rate = db.Rates.Where(x => x.ID == rateID).SingleOrDefault(); if (accountCode.IsNullOrBlank() || (rate == null || rate.Rate1 <= 0)) { return(Decimal.MinusOne); } logger.Debug("ReserveInitialCredit for " + accountCode + ", rate " + rate.Rate1 + ", setup cost " + rate.SetupCost + ", increment seconds " + rate.IncrementSeconds + "."); var customerAccount = db.CustomerAccounts.Where(x => x.AccountCode == accountCode).SingleOrDefault(); if (customerAccount == null) { logger.Debug("The initial reservation for " + accountCode + " failed due to the no matching accountcode."); return(Decimal.MinusOne); } // Get the owning customer's RTCC billing increment. //int rtccIncrement = (from cust in db.Customers where cust.Name.ToLower() == customerAccount.Owner.ToLower() select cust.RTCCBillingIncrement).Single(); initialSeconds = (rate.IncrementSeconds > MINIMUM_INITIAL_RESERVATION_SECONDS) ? rate.IncrementSeconds : MINIMUM_INITIAL_RESERVATION_SECONDS; decimal reservationCost = ((decimal)initialSeconds / (decimal)60 * rate.Rate1) + rate.SetupCost; if (customerAccount.Credit < reservationCost) { logger.Debug("The initial reservation for " + accountCode + ", duration " + initialSeconds + "s and " + reservationCost.ToString("0.#####") + " failed due to lack of credit."); return(Decimal.MinusOne); } else { var rtccRecord = new RTCC() { ID = Guid.NewGuid().ToString(), CDRID = cdr.CDRId.ToString(), AccountCode = accountCode, SecondsReserved = initialSeconds, Cost = reservationCost, Rate = rate.Rate1, SetupCost = rate.SetupCost, IncrementSeconds = rate.IncrementSeconds, Inserted = DateTime.UtcNow }; db.RTCCs1.AddObject(rtccRecord); //var callCDR = (from cdr in db.CDRs where cdr.ID == cdrID select cdr).SingleOrDefault(); //if (callCDR == null) //{ // logger.Debug("The initial reservation for " + accountCode + " and " + reservationCost.ToString("0.#####") + " failed due to the no matching CDR for " + cdrID + "."); // return false; //} //else if (callCDR.HungupTime != null) //{ // logger.Debug("The initial reservation for " + accountCode + " and " + reservationCost.ToString("0.#####") + " failed due to the CDR already being hungup."); // return false; //} // The credit is available deduct it from the customer account balance and place it on the CDR. customerAccount.Credit = customerAccount.Credit - reservationCost; // Set the fields on the CDR. //callCDR.Rate = rate; //callCDR.SecondsReserved = seconds; //callCDR.AccountCode = accountCode; //callCDR.Cost = reservationCost; //db.CDRs.AddObject(cdr); db.SaveChanges(); trans.Complete(); logger.Debug("The initial reservation for " + accountCode + ", duration " + initialSeconds + "s and " + reservationCost.ToString("0.#####") + " was successful."); return(reservationCost); } } } } catch (Exception excp) { logger.Error("Exception ReserveInitialCredit. " + excp); throw; } }
public void Load(DataRow cdrRow) { m_sipCDR = new SIPCDR(); m_sipCDR.CDRId = new Guid(cdrRow["id"] as string); m_sipCDR.Owner = cdrRow["owner"] as string; m_sipCDR.AdminMemberId = cdrRow["adminmemberid"] as string; Inserted = DateTimeOffset.Parse(cdrRow["inserted"] as string); m_sipCDR.CallDirection = (cdrRow["direction"] as string == SIPCallDirection.In.ToString()) ? SIPCallDirection.In : SIPCallDirection.Out; Created = DateTimeOffset.Parse(cdrRow["created"] as string); m_sipCDR.Destination = SIPURI.ParseSIPURI(cdrRow["dsturi"] as string); m_sipCDR.From = SIPFromHeader.ParseFromHeader(cdrRow["fromheader"] as string); m_sipCDR.CallId = cdrRow["callid"] as string; m_sipCDR.LocalSIPEndPoint = (!(cdrRow["localsocket"] as string).IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(cdrRow["localsocket"] as string) : null; m_sipCDR.RemoteEndPoint = (!(cdrRow["remotesocket"] as string).IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(cdrRow["remotesocket"] as string) : null; m_sipCDR.BridgeId = (!(cdrRow["bridgeid"] as string).IsNullOrBlank()) ? new Guid(cdrRow["bridgeid"] as string) : Guid.Empty; if (cdrRow["inprogresstime"] != DBNull.Value && cdrRow["inprogresstime"] != null && !(cdrRow["inprogresstime"] as string).IsNullOrBlank()) { InProgressTime = DateTimeOffset.Parse(cdrRow["inprogresstime"] as string); } else { InProgressTime = null; } m_sipCDR.ProgressStatus = (cdrRow["inprogressstatus"] != null) ? Convert.ToInt32(cdrRow["inprogressstatus"]) : 0; m_sipCDR.ProgressReasonPhrase = cdrRow["inprogressreason"] as string; if (cdrRow["answeredtime"] != DBNull.Value && cdrRow["answeredtime"] != null && !(cdrRow["answeredtime"] as string).IsNullOrBlank()) { AnsweredTime = DateTimeOffset.Parse(cdrRow["answeredtime"] as string); } else { AnsweredTime = null; } m_sipCDR.AnswerStatus = (cdrRow["answeredstatus"] != DBNull.Value && cdrRow["answeredstatus"] != null) ? Convert.ToInt32(cdrRow["answeredstatus"]) : 0; m_sipCDR.AnswerReasonPhrase = cdrRow["answeredreason"] as string; if (cdrRow["hunguptime"] != DBNull.Value && cdrRow["hunguptime"] != null && !(cdrRow["hunguptime"] as string).IsNullOrBlank()) { HungupTime = DateTimeOffset.Parse(cdrRow["hunguptime"] as string); } else { HungupTime = null; } m_sipCDR.HangupReason = cdrRow["hungupreason"] as string; m_sipCDR.InProgress = (m_sipCDR.ProgressTime != null); m_sipCDR.IsAnswered = (m_sipCDR.AnswerTime != null); m_sipCDR.IsHungup = (m_sipCDR.HangupTime != null); }
public SIPCDRAsset(SIPCDR sipCDR) { Inserted = DateTimeOffset.UtcNow; m_sipCDR = sipCDR; }
public SIPCDRAsset() { Inserted = DateTimeOffset.UtcNow; m_sipCDR = new SIPCDR(); }
public SIPCDRAsset(SIPCDR sipCDR) { //Inserted = DateTimeOffset.UtcNow; m_sipCDR = sipCDR; }
public SIPCDRAsset() { //Inserted = DateTimeOffset.UtcNow; m_sipCDR = new SIPCDR(); }
public void Load(DataRow cdrRow) { m_sipCDR = new SIPCDR(); m_sipCDR.CDRId = new Guid(cdrRow["id"] as string); m_sipCDR.Owner = cdrRow["owner"] as string; m_sipCDR.AdminMemberId = cdrRow["adminmemberid"] as string; Inserted = DateTimeOffset.Parse(cdrRow["inserted"] as string); m_sipCDR.CallDirection = (cdrRow["direction"] as string == SIPCallDirection.In.ToString()) ? SIPCallDirection.In : SIPCallDirection.Out; Created = DateTimeOffset.Parse(cdrRow["created"] as string); m_sipCDR.Destination = SIPURI.ParseSIPURI(cdrRow["dsturi"] as string); m_sipCDR.From = SIPFromHeader.ParseFromHeader(cdrRow["fromheader"] as string); m_sipCDR.CallId = cdrRow["callid"] as string; m_sipCDR.LocalSIPEndPoint = (!(cdrRow["localsocket"] as string).IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(cdrRow["localsocket"] as string) : null; m_sipCDR.RemoteEndPoint = (!(cdrRow["remotesocket"] as string).IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(cdrRow["remotesocket"] as string) : null; m_sipCDR.BridgeId = (!(cdrRow["bridgeid"] as string).IsNullOrBlank()) ? new Guid(cdrRow["bridgeid"] as string) : Guid.Empty; if (cdrRow["inprogresstime"] != DBNull.Value && cdrRow["inprogresstime"] != null && !(cdrRow["inprogresstime"] as string).IsNullOrBlank()) { InProgressTime = DateTimeOffset.Parse(cdrRow["inprogresstime"] as string); } else { InProgressTime = null; } m_sipCDR.ProgressStatus = (cdrRow["inprogressstatus"] != null) ? Convert.ToInt32(cdrRow["inprogressstatus"]) : 0; m_sipCDR.ProgressReasonPhrase = cdrRow["inprogressreason"] as string; if (cdrRow["answeredtime"] != DBNull.Value && cdrRow["answeredtime"] != null && !(cdrRow["answeredtime"] as string).IsNullOrBlank()) { AnsweredTime = DateTimeOffset.Parse(cdrRow["answeredtime"] as string); } else { AnsweredTime = null; } m_sipCDR.AnswerStatus = (cdrRow["answeredstatus"] != DBNull.Value && cdrRow["answeredstatus"] != null) ? Convert.ToInt32(cdrRow["answeredstatus"]) : 0; m_sipCDR.AnswerReasonPhrase = cdrRow["answeredreason"] as string; if (cdrRow["hunguptime"] != DBNull.Value && cdrRow["hunguptime"] != null && !(cdrRow["hunguptime"] as string).IsNullOrBlank()) { HungupTime = DateTimeOffset.Parse(cdrRow["hunguptime"] as string); } else { HungupTime = null; } m_sipCDR.HangupReason = cdrRow["hungupreason"] as string; m_sipCDR.InProgress = (m_sipCDR.ProgressTime != null); m_sipCDR.IsAnswered = (m_sipCDR.AnswerTime != null); m_sipCDR.IsHungup = (m_sipCDR.HangupTime != null); m_sipCDR.AccountCode = cdrRow["accountcode"] as string; m_sipCDR.SecondsReserved = (cdrRow["secondsreserved"] != null) ? Convert.ToInt32(cdrRow["secondsreserved"]) : 0; m_sipCDR.Rate = (cdrRow["rate"] != null) ? Convert.ToDecimal(cdrRow["rate"]) : Decimal.Zero; m_sipCDR.Cost = (cdrRow["cost"] != null) ? Convert.ToDecimal(cdrRow["cost"]) : Decimal.Zero; if (cdrRow["answeredat"] != DBNull.Value && cdrRow["answeredat"] != null) { AnsweredAt = (DateTime)cdrRow["answeredat"]; } m_sipCDR.ReconciliationResult = cdrRow["reconciliationresult"] as string; m_sipCDR.IsHangingUp = (cdrRow.Table.Columns.Contains("ishangingup") && cdrRow["ishangingup"] != null && cdrRow["ishangingup"] != DBNull.Value) ? Convert.ToBoolean(cdrRow["ishangingup"]) : false; }
public void Load(DataRow cdrRow) { m_sipCDR = new SIPCDR(); m_sipCDR.CDRId = new Guid(cdrRow["id"] as string); m_sipCDR.Owner = cdrRow["owner"] as string; m_sipCDR.AdminMemberId = cdrRow["adminmemberid"] as string; Inserted = DateTimeOffset.Parse(cdrRow["inserted"] as string); m_sipCDR.CallDirection = (cdrRow["direction"] as string == SIPCallDirection.In.ToString()) ? SIPCallDirection.In : SIPCallDirection.Out; Created = DateTimeOffset.Parse(cdrRow["created"] as string); m_sipCDR.Destination = SIPURI.ParseSIPURI(cdrRow["dsturi"] as string); m_sipCDR.From = SIPFromHeader.ParseFromHeader(cdrRow["fromheader"] as string); m_sipCDR.CallId = cdrRow["callid"] as string; m_sipCDR.LocalSIPEndPoint = (!(cdrRow["localsocket"] as string).IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(cdrRow["localsocket"] as string) : null; m_sipCDR.RemoteEndPoint = (!(cdrRow["remotesocket"] as string).IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(cdrRow["remotesocket"] as string) : null; m_sipCDR.BridgeId = (!(cdrRow["bridgeid"] as string).IsNullOrBlank()) ? new Guid(cdrRow["bridgeid"] as string) : Guid.Empty; if (cdrRow["inprogresstime"] != DBNull.Value && cdrRow["inprogresstime"] != null && !(cdrRow["inprogresstime"] as string).IsNullOrBlank()) { InProgressTime = DateTimeOffset.Parse(cdrRow["inprogresstime"] as string); } else { InProgressTime = null; } m_sipCDR.ProgressStatus = (cdrRow["inprogressstatus"] != null && cdrRow["inprogressstatus"] != DBNull.Value) ? Convert.ToInt32(cdrRow["inprogressstatus"]) : 0; m_sipCDR.ProgressReasonPhrase = cdrRow["inprogressreason"] as string; if (cdrRow["answeredtime"] != DBNull.Value && cdrRow["answeredtime"] != null && !(cdrRow["answeredtime"] as string).IsNullOrBlank()) { AnsweredTime = DateTimeOffset.Parse(cdrRow["answeredtime"] as string); } else { AnsweredTime = null; } m_sipCDR.AnswerStatus = (cdrRow["answeredstatus"] != DBNull.Value && cdrRow["answeredstatus"] != null) ? Convert.ToInt32(cdrRow["answeredstatus"]) : 0; m_sipCDR.AnswerReasonPhrase = cdrRow["answeredreason"] as string; if (cdrRow["hunguptime"] != DBNull.Value && cdrRow["hunguptime"] != null && !(cdrRow["hunguptime"] as string).IsNullOrBlank()) { HungupTime = DateTimeOffset.Parse(cdrRow["hunguptime"] as string); } else { HungupTime = null; } m_sipCDR.HangupReason = cdrRow["hungupreason"] as string; m_sipCDR.InProgress = (m_sipCDR.ProgressTime != null); m_sipCDR.IsAnswered = (m_sipCDR.AnswerTime != null); m_sipCDR.IsHungup = (m_sipCDR.HangupTime != null); if (cdrRow["answeredat"] != DBNull.Value && cdrRow["answeredat"] != null) { AnsweredAt = (DateTime)cdrRow["answeredat"]; } m_sipCDR.DialPlanContextID = (!(cdrRow["dialplancontextid"] as string).IsNullOrBlank()) ? new Guid(cdrRow["dialplancontextid"] as string) : Guid.Empty; }