public int AddParticipantHistory(ParticipantHistoryModel p)
        {
            if (_context.ParticipantHistory.Find(p.ParticipantId) == null)
            {
                _context.ParticipantHistory.Add(p);
                return(_context.SaveChanges());
            }

            return(0);
        }
示例#2
0
        public int GetParticipantHistory(int historyHours)
        {
            int successfulAdds = 0;
            int endTime;

            // Get all the participants
            Log.Information("*************************************************");
            Log.Information("Retrieving Participant History");
            Log.Information($"Filtering from {DateTimeOffset.UtcNow.AddHours(historyHours)} to {DateTimeOffset.UtcNow} in UTC");
            Log.Information("*************************************************");
            var participantList = _managerNode.ParticipantHistory.Get(DateTimeOffset.UtcNow.AddHours(historyHours), DateTimeOffset.UtcNow).Result;

            // Add the timestamp to the participants and add to the DB
            foreach (var p in participantList)
            {
                Log.Debug("Parsing participant {0}", p.Id);

                if (p.EndTime != null)
                {
                    endTime = (int)DateTimeOffset.Parse(p.EndTime).ToUnixTimeSeconds();
                }

                ParticipantHistoryModel participant = new ParticipantHistoryModel();
                participant.AvId             = p.AvId;
                participant.Bandwidth        = p.Bandwidth;
                participant.CallDirection    = p.CallDirection;
                participant.CallQuality      = p.CallQuality;
                participant.CallUuid         = p.CallUuid;
                participant.Conference       = p.Conference ?? "";
                participant.ConferenceName   = p.ConferenceName;
                participant.ConversationId   = p.ConversationId;
                participant.DisconnectReason = p.DisconnectReason;
                participant.DisplayName      = p.DisplayName;
                participant.Duration         = p.Duration;
                participant.Encryption       = p.Encryption;
                participant.EndTime          = (p.EndTime == null) ? -1 : (int)DateTimeOffset.Parse(p.EndTime, null, DateTimeStyles.AssumeUniversal).ToUnixTimeSeconds();
                participant.HasMedia         = p.HasMedia;
                participant.ParticipantId    = p.Id;
                participant.IsStreaming      = p.IsStreaming;
                participant.LicenseCount     = p.LicenseCount;
                participant.LicenseType      = p.LicenseType;
                participant.LocalAlias       = p.LocalAlias;
                participant.MediaNode        = p.MediaNode;
                participant.ParentId         = p.ParentId;
                participant.PresentationId   = p.PresentationId;
                participant.Protocol         = p.Protocol;
                participant.ProxyNode        = p.ProxyNode;
                participant.RemoteAddress    = p.RemoteAddress;
                participant.RemoteAlias      = p.RemoteAlias;
                participant.RemotePort       = p.RemotePort;
                participant.ResourceUri      = p.ResourceUri;
                participant.Role             = p.Role;
                participant.ServiceTag       = p.ServiceTag;
                participant.ServiceType      = p.ServiceType;
                participant.SignallingNode   = p.SignallingNode;
                participant.StartTime        = (p.StartTime == null) ? -1 : (int)DateTimeOffset.Parse(p.StartTime, null, DateTimeStyles.AssumeUniversal).ToUnixTimeSeconds();
                participant.SystemLocation   = p.SystemLocation;
                participant.Vendor           = p.Vendor;

                try
                {
                    Log.Debug("Writing participant data to DB");
                    successfulAdds += _sqliteServices.AddParticipantHistory(participant);

                    if (p.MediaStreams.Count > 0)
                    {
                        foreach (var stream in p.MediaStreams)
                        {
                            try
                            {
                                Log.Debug("Parsing and writing participant media stream {0}", stream.StreamId);
                                _sqliteServices.AddMediaStreamHistory(new MediaStreamHistoryModel
                                {
                                    ParticipantId     = p.Id,
                                    EndTime           = (stream.EndTime == null) ? -1 : (int)DateTimeOffset.Parse(stream.EndTime, null, DateTimeStyles.AssumeUniversal).ToUnixTimeSeconds(),
                                    Id                = stream.Id,
                                    Node              = stream.Node,
                                    ParticipantUri    = stream.Participant,
                                    RxBitrate         = stream.RxBitrate,
                                    RxCodec           = stream.RxCodec,
                                    RxPacketLoss      = stream.RxPacketLoss,
                                    RxPacketsLost     = stream.RxPacketsLost,
                                    RxPacketsReceived = stream.RxPacketsReceived,
                                    RxResolution      = stream.RxResolution,
                                    StartTime         = (stream.StartTime == null) ? -1 :(int)DateTimeOffset.Parse(stream.StartTime, null, DateTimeStyles.AssumeUniversal).ToUnixTimeSeconds(),
                                    StreamId          = stream.StreamId,
                                    StreamType        = stream.StreamType,
                                    TxBitrate         = stream.TxBitrate,
                                    TxCodec           = stream.TxCodec,
                                    TxPacketLoss      = stream.TxPacketLoss,
                                    TxPacketsLost     = stream.TxPacketsLost,
                                    TxPacketsSent     = stream.TxPacketsSent,
                                    TxResolution      = stream.TxResolution
                                });
                            }
                            catch (Exception e)
                            {
                                Log.Information($"Exception when writing participant media stream data to DB{e.InnerException.Message}");
                            }
                        }
                    }
                } catch (Exception e)
                {
                    Log.Information($"Exception when writing participant data to DB: {e.InnerException.Message}");
                }
            }

            return(successfulAdds);
        }