123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using Vinno.IUS.Common.Log;
- using Vinno.IUS.Common.Network;
- using Vinno.IUS.Common.Network.Leaf;
- using Vinno.IUS.Common.Network.Transfer;
- using Vinno.vCloud.Protocol.Infrastructures;
- using Vinno.vCloud.Protocol.Messages.Client.RemoteDiagnosis;
- using Vinno.vCloud.Protocol.Messages.Live;
- namespace Vinno.vCloud.Common.FIS.Consultation
- {
- internal class ConsultationRecipient : ConsultationClient
- {
- private readonly ManualResetEvent _timingManualResetEvent = new ManualResetEvent(false);
- private readonly string _terminalId;
- private readonly string _uniqueId;
- private string _initiatorId;
- private bool _isEmergencyRequesting;
- private string _cameraId;
- private string _micId;
- private string _speakerId;
- /// <summary>
- /// Raised when receive a Consultation request from server.
- /// </summary>
- public event EventHandler<ConsultationInfo> ConsultationRequestArrived;
- public ConsultationRecipient(ConsultationLiveVideoProvider videoProvider, string terminalId, string uniqueId) : base(videoProvider)
- {
- _terminalId = terminalId;
- _uniqueId = uniqueId;
- }
- /// <summary>
- /// Send a join Rtc Consultation Live request
- /// </summary>
- /// <returns></returns>
- public LiveStates AcceptConsultation(string cameraHardwareId, string micHardwareId, string speakerHardwareId)
- {
- var liveState = LiveStates.UnknowException;
- try
- {
- if (CurrentLiveStatus == LiveStates.RecipientAcceptting || CurrentLiveStatus == LiveStates.RecipientAcceptted)
- {
- Logger.WriteLineInfo($"Consultation Live-- {FLYINSONOUser.Name} accept Consultation failed due to CurrentLiveStatus is {CurrentLiveStatus}");
- return LiveStates.TalkIsBusy;
- }
- CurrentLiveStatus = LiveStates.RecipientAcceptting;
- Logger.WriteLineInfo($"Consultation Live-- {FLYINSONOUser.Name} accept Consultation request begin");
- using (var request = new AcceptMeetingRequest())
- {
- request.RoomId = ConsultationInfo.RoomId;
- request.InitiatorId = _initiatorId;
- request.RecipientId = FLYINSONOUser.AccountId;
- request.FeatureSource = FeatureSource.RemoteDiagnosis;
- request.Source = FLYINSONOUser.LoginSource;
- request.PushLiveState = ConsultationInfo.State;
- request.ClientLanguage = GetCurrentLanguage();
- var result = ClientLeaf.Send(request);
- Logger.WriteLineInfo($"Send AcceptMeetingRequest To Server");
- if (result != null)
- {
- var resultMessage = AcceptMeetingResult.Convert(result);
- if (resultMessage != null)
- {
- liveState = resultMessage.State;
- if (resultMessage != null && resultMessage.State == LiveStates.OK)
- {
- lock (ConsultationInfoLocker)
- {
- ConsultationInfo.State = resultMessage.State;
- }
- StartConsultation(cameraHardwareId, micHardwareId, speakerHardwareId);
- CurrentLiveStatus = LiveStates.RecipientAcceptted;
- return CurrentLiveStatus;
- }
- Logger.WriteLineInfo($"Consultation Live-- {FLYINSONOUser.Name} accept meeConsultationting request end");
- }
- }
- }
- }
- catch (ConnectionTimeoutException ex)
- {
- Logger.WriteLineError($"ConnectionTimeoutException happened when accept Consultation{ex}");
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Exception happened when accept Consultation{ex}");
- }
- var recipientId = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(x => x.RoleType == ConsultationRoleType.Recipient)?.Id;
- if (recipientId == FLYINSONOUser.AccountId)
- {
- Hangup(true);
- }
- else
- {
- Hangup(false);
- }
- return liveState;
- }
- /// <summary>
- /// Send a Rtc Consultation Live rejectation request
- /// </summary>
- /// <returns></returns>
- public LiveStates RejectConsultation()
- {
- Logger.WriteLineInfo($"Consultation Live-- {FLYINSONOUser.Name} reject meet request begin");
- CurrentLiveStatus = LiveStates.RecipientRejected;
- StopConsultation();
- var roomId = ConsultationInfo.RoomId;
- var initiatorId = ConsultationInfo.ConsultationMemberInfos.FirstOrDefault(x => x.RoleType == ConsultationRoleType.Initiator)?.Id;
- lock (ConsultationInfoLocker)
- {
- ConsultationInfo = null;
- }
- Logger.WriteLineInfo($"Consultation Live-- {FLYINSONOUser.Name} reject Consultation request end");
- using (var request = new RejectMeetingRequest())
- {
- request.RoomId = roomId;
- request.RecipientId = FLYINSONOUser.AccountId;
- request.InitiatorId = initiatorId;
- request.LoginSource = FLYINSONOUser.LoginSource;
- request.ClientLanguage = GetCurrentLanguage();
- var result = ClientLeaf.Send(request);
- Logger.WriteLineInfo($"Send RejectMeetingRequest To Server");
- if (result != null)
- {
- var resultMessage = MeetingResult.Convert(result); //拒绝会诊result
- if (resultMessage != null)
- {
- return resultMessage.State;
- }
- }
- }
- return LiveStates.UnknowException;
- }
- protected override void HandleConsultationMemberNotificationArrived(MeetingMemberNotification meetingMemberNotification)
- {
- if (ConsultationInfo != null)
- {
- var mem = meetingMemberNotification.Members.FirstOrDefault(f => f.RoleType == MeetingRoleType.Recipient && f.OperationType == ClientMessageOperationType.Delete);
- if (mem != null)
- {
- OnDisconnected(ConsultationDisconnectedType.HangupByOther);
- }
- else
- {
- ConsultationMemberChange(meetingMemberNotification);
- foreach (var member in meetingMemberNotification.Members)
- {
- var memberInfo = ConsultationInfo?.ConsultationMemberInfos.FirstOrDefault(f => f.Id == member.Id);
- if (member.OperationType == ClientMessageOperationType.Add)
- {
- ConsultationRoleType roleType = ConsultationRoleType.Initiator;
- switch (member.RoleType)
- {
- case MeetingRoleType.Initiator:
- roleType = ConsultationRoleType.Initiator;
- break;
- case MeetingRoleType.Recipient:
- roleType = ConsultationRoleType.Recipient;
- break;
- case MeetingRoleType.Expert:
- roleType = ConsultationRoleType.Expert;
- break;
- case MeetingRoleType.Administrator:
- roleType = ConsultationRoleType.Administrator;
- break;
- }
- var meetingMemberInfo = new ConsultationMemberInfo
- {
- OperationType = member.OperationType,
- RoleType = roleType,
- RoomId = member.RoomId,
- LoginSource = member.LoginSource,
- State = member.State,
- Id = member.Id,
- Name = member.Name,
- DisplayName = member.DisplayName,
- Avatar = member.Avatar,
- UserSign = member.UserSign,
- PushUrl = member.PushUrl,
- PullRtmpUrl = member.PullRtmpUrl,
- PullFlvUrl = member.PullFlvUrl,
- PullHlsUrl = member.PullHlsUrl,
- PushLiveState = member.PushLiveState,
- };
- if (memberInfo == null)
- {
- ConsultationInfo.ConsultationMemberInfos.Add(meetingMemberInfo);
- }
- else
- {
- memberInfo = meetingMemberInfo;
- }
- }
- else if (member.OperationType == ClientMessageOperationType.Delete)
- {
- if (memberInfo != null)
- {
- ConsultationInfo?.ConsultationMemberInfos.Remove(memberInfo);
- }
- }
- }
- base.HandleConsultationMemberNotificationArrived(meetingMemberNotification);
- }
- }
- }
- protected override void OnMessageArrived(object sender, Message e)
- {
- try
- {
- base.OnMessageArrived(sender, e);
- var startMeetingNotification = StartMeetingNotification.Convert(e); //接收者收到被邀请通知
- if (startMeetingNotification != null)
- {
- HandleStartMeetingNotification(startMeetingNotification);
- }
- var cancelStartMeetingNotification = CancelStartMeetingNotification.Convert(e); //取消会诊通知
- if (cancelStartMeetingNotification != null)
- {
- HandleCancelStartMeetingNotification();
- }
- var rejectEmergencyConsultationNotification = RejectEmergencyConsultationNotification.Convert(e); //专家拒绝紧急会诊通知
- if (rejectEmergencyConsultationNotification != null)
- {
- HandleRejectEmergencyConsultationNotification(rejectEmergencyConsultationNotification);
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Consultation Recipient OnMessageArrived Error:{ex}");
- }
- }
- private void HandleRejectEmergencyConsultationNotification(RejectEmergencyConsultationNotification rejectEmergencyConsultationNotification)
- {
- Logger.WriteLineInfo($"MeetingRecipient OnRejectEmergencyConsultationNotificationArrived,reason:{rejectEmergencyConsultationNotification.Reason}");
- if (EmergencyConsultationInfo != null && EmergencyConsultationInfo.SortExperts != null && EmergencyConsultationInfo.ConsultationId == rejectEmergencyConsultationNotification.ConsultationId)
- {
- _timingManualResetEvent.Set();
- var prevSortExpert = EmergencyConsultationInfo.SortExperts.FirstOrDefault(f => f.UserId == rejectEmergencyConsultationNotification.ExpertId);
- if (prevSortExpert != null)
- {
- var nextSortExpert = EmergencyConsultationInfo.SortExperts.FirstOrDefault(f => f.Sort == prevSortExpert.Sort + 1);
- if (nextSortExpert != null)
- {
- if (!CreateAndStartEmergencyConsultation(nextSortExpert))
- {
- _timingManualResetEvent.Set();
- _isEmergencyRequesting = false;
- CurrentLiveStatus = LiveStates.RecipientRejected;
- OnRejectConsultationNotifyArrived(new ConsultationSubscriberInfo
- {
- RoomId = null,
- Id = rejectEmergencyConsultationNotification.ExpertId
- });
- lock (EmergencyConsultationLocker)
- {
- EmergencyConsultationInfo = null;
- }
- }
- }
- else
- {
- _isEmergencyRequesting = false;
- CurrentLiveStatus = LiveStates.RecipientRejected;
- OnRejectConsultationNotifyArrived(new ConsultationSubscriberInfo
- {
- RoomId = null,
- Id = rejectEmergencyConsultationNotification.ExpertId
- });
- lock (EmergencyConsultationLocker)
- {
- EmergencyConsultationInfo = null;
- }
- }
- }
- }
- }
- private void HandleCancelStartMeetingNotification()
- {
- if (ConsultationInfo != null)
- {
- OnDisconnected(ConsultationDisconnectedType.CancelledByInitiator);
- Logger.WriteLineInfo($"CancelStartMeetingNotification handled");
- }
- }
- private void HandleStartMeetingNotification(StartMeetingNotification startMeetingNotification)
- {
- Logger.WriteLineInfo("LiveMeeting StartMeetingNotification Arrived");
- CurrentLiveStatus = LiveStates.ChatRequestArrived;
- var mode = startMeetingNotification.Mode;
- var roomId = startMeetingNotification.RoomId;
- var protocol = startMeetingNotification.LiveProtocol;
- List<ConsultationMemberInfo> meetingMemberInfos = new List<ConsultationMemberInfo>();
- foreach (var member in startMeetingNotification.Members)
- {
- ConsultationRoleType roleType = ConsultationRoleType.Initiator;
- switch (member.RoleType)
- {
- case MeetingRoleType.Initiator:
- roleType = ConsultationRoleType.Initiator;
- break;
- case MeetingRoleType.Recipient:
- roleType = ConsultationRoleType.Recipient;
- break;
- case MeetingRoleType.Expert:
- roleType = ConsultationRoleType.Expert;
- break;
- case MeetingRoleType.Administrator:
- roleType = ConsultationRoleType.Administrator;
- break;
- }
- var meetingMemberInfo = new ConsultationMemberInfo
- {
- OperationType = member.OperationType,
- RoleType = roleType,
- RoomId = member.RoomId,
- LoginSource = member.LoginSource,
- State = member.State,
- Id = member.Id,
- Name = member.Name,
- DisplayName = member.DisplayName,
- Avatar = member.Avatar,
- UserSign = member.UserSign,
- PushUrl = member.PushUrl,
- PullRtmpUrl = member.PullRtmpUrl,
- PullFlvUrl = member.PullFlvUrl,
- PullHlsUrl = member.PullHlsUrl,
- PushLiveState = member.PushLiveState,
- };
- meetingMemberInfos.Add(meetingMemberInfo);
- }
- var terminalInfo = new TerminalInfo();
- var liveTerminal = startMeetingNotification.LiveTerminals.FirstOrDefault();
- var channels = new List<PullChannnelUrl>();
- if (liveTerminal.Channels != null)
- {
- foreach (var channelInfo in liveTerminal.Channels)
- {
- var channel = new PullChannnelUrl
- {
- Enable = channelInfo.Enable,
- FlvUrl = channelInfo.FlvUrl,
- Height = channelInfo.Height,
- HlsUrl = channelInfo.HlsUrl,
- Name = channelInfo.Name,
- RtmpUrl = channelInfo.RtmpUrl,
- UserId = channelInfo.UserId,
- Width = channelInfo.Width,
- };
- channels.Add(channel);
- }
- }
- if (liveTerminal.IsMultiChannels)//Windows魔盒
- {
- var mainTerminalInfo = liveTerminal.Channels.Select(f => f.Name).Contains("Main") ? liveTerminal.Channels.FirstOrDefault(f => f.Name == "Main") : liveTerminal.Channels.FirstOrDefault();
- var cameraInfo = liveTerminal.Channels.Count > 1 ? liveTerminal.Channels.FirstOrDefault(x => x.Name != "Main") : null;
- terminalInfo = new TerminalInfo()
- {
- OperationType = liveTerminal.OperationType,
- TerminalLiveEnabled = mainTerminalInfo.Enable,
- CameraLiveEnabled = cameraInfo?.Enable ?? false,
- IsMergeChannel = liveTerminal.IsMergeChannel,
- TerminalWidth = mainTerminalInfo.Width,
- TerminalHeight = mainTerminalInfo.Height,
- TerminalUrl = mainTerminalInfo.RtmpUrl,
- CameraWidth = cameraInfo?.Width ?? 0,
- CameraHeight = cameraInfo?.Height ?? 0,
- CameraUrl = cameraInfo?.RtmpUrl,
- TerminalLiveProtocol = liveTerminal.LiveProtocol,
- IntegerRoomId = liveTerminal.IntegerRoomId,
- TerminalIntegerRoomId = liveTerminal.TerminalIntegerRoomId,
- State = liveTerminal.State,
- Id = string.IsNullOrEmpty(mainTerminalInfo.UserId) ? liveTerminal.Id : mainTerminalInfo.UserId,
- CameraId = cameraInfo?.UserId,
- IsMultiChannels = liveTerminal.IsMultiChannels,
- PullDataMode = liveTerminal.PullDataMode,
- TerminalRoomId = liveTerminal.RoomId,
- Channels = channels,
- };
- }
- else
- {
- terminalInfo = new TerminalInfo()
- {
- OperationType = liveTerminal.OperationType,
- TerminalLiveEnabled = liveTerminal.TerminalLiveEnabled,
- CameraLiveEnabled = liveTerminal.CameraLiveEnabled,
- IsMergeChannel = liveTerminal.IsMergeChannel,
- TerminalWidth = liveTerminal.TerminalWidth,
- TerminalHeight = liveTerminal.TerminalHeight,
- TerminalUrl = liveTerminal.TerminalUrl,
- CameraWidth = liveTerminal.CameraWidth,
- CameraHeight = liveTerminal.CameraHeight,
- CameraUrl = liveTerminal.CameraUrl,
- TerminalLiveProtocol = liveTerminal.LiveProtocol,
- IntegerRoomId = liveTerminal.IntegerRoomId,
- TerminalIntegerRoomId = liveTerminal.TerminalIntegerRoomId,
- State = liveTerminal.State,
- Id = liveTerminal.Id,
- IsMultiChannels = liveTerminal.IsMultiChannels,
- PullDataMode = liveTerminal.PullDataMode,
- TerminalRoomId = liveTerminal.RoomId,
- Channels = channels,
- };
- }
- lock (ConsultationInfoLocker)
- {
- var info = new ConsultationInfo(ChatRole.Recipient);
- info.AppId = startMeetingNotification.AppId;
- info.RoomId = startMeetingNotification.RoomId;
- info.LiveTalkingMode = mode;
- info.IntegerRoomId = startMeetingNotification.IntegerRoomId;
- info.LiveProtocol = startMeetingNotification.LiveProtocol;
- info.ConsultationMemberInfos = meetingMemberInfos;
- info.TerminalInfo = terminalInfo;
- info.IsCurrentTerminal = info.TerminalInfo?.Id == _terminalId;
- ConsultationInfo = info;
- _initiatorId = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(x => x.RoleType == ConsultationRoleType.Initiator)?.Id;
- }
- var userName = GetAccoutNameByAccountId(startMeetingNotification.InitiatorId);
- Logger.WriteLineInfo($"StartMeetingNotification handled RoomId:{ConsultationInfo.RoomId}");
- if (!_isEmergencyRequesting)
- {
- ConsultationRequestArrived?.Invoke(this, ConsultationInfo);
- }
- else
- {
- _timingManualResetEvent.Set();
- _isEmergencyRequesting = false;
- AcceptConsultation(_cameraId, _micId, _speakerId);
- if (CurrentLiveStatus == LiveStates.RecipientAcceptted)
- {
- OnJoinConsultationNotifyArrived();
- }
- }
- }
- public EnumEmergencyConsultationResult RequestEmergencyConsultation(string cameraId, string micId, string speakerId)
- {
- var liveState = EnumEmergencyConsultationResult.UnknowException;
- try
- {
- if (CurrentLiveStatus == LiveStates.RecipientAcceptting || CurrentLiveStatus == LiveStates.RecipientAcceptted)
- {
- Logger.WriteLineInfo($"Consultation Live-- {FLYINSONOUser.Name} Request Emergency Consultation failed due to CurrentLiveStatus is {CurrentLiveStatus}");
- return EnumEmergencyConsultationResult.IsBusy;
- }
- if (_isEmergencyRequesting)
- {
- Logger.WriteLineInfo($"Consultation Live-- {FLYINSONOUser.Name} Request Emergency Consultation failed due to is Requesting Emergency Consultation");
- return EnumEmergencyConsultationResult.IsBusy;
- }
- _cameraId = cameraId;
- _micId = micId;
- _speakerId = speakerId;
- var emergencyConsultationInfo = GetEmergencyConsultationExpertsInfo();
- lock (EmergencyConsultationLocker)
- {
- EmergencyConsultationInfo = emergencyConsultationInfo;
- }
- switch (EmergencyConsultationInfo.NoExpertCause)
- {
- case NoExpertCause.ExpertsOfflineAll:
- return EnumEmergencyConsultationResult.ExpertsOfflineAll;
- case NoExpertCause.ExpertsDeficiencyOfTimeAll:
- return EnumEmergencyConsultationResult.ExpertsDeficiencyOfTimeAll;
- case NoExpertCause.ExpertsOfflineOrDeficiencyOfTime:
- return EnumEmergencyConsultationResult.ExpertsOfflineOrDeficiencyOfTime;
- }
- if (EmergencyConsultationInfo.SortExperts == null || EmergencyConsultationInfo.SortExperts.Count == 0)
- {
- return EnumEmergencyConsultationResult.ExpertsIsNotExist;
- }
- CurrentLiveStatus = LiveStates.InitiatorRequestingChat;
- Logger.WriteLineInfo($"Consultation Live-- {FLYINSONOUser.Name} request Emergency Consultation request begin");
- if (CreateAndStartEmergencyConsultation(EmergencyConsultationInfo.SortExperts.FirstOrDefault()))
- {
- _isEmergencyRequesting = true;
- return EnumEmergencyConsultationResult.OK;
- }
- else
- {
- _isEmergencyRequesting = false;
- _timingManualResetEvent.Set();
- return EnumEmergencyConsultationResult.Failed;
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Exception happened when RequestEmergencyConsultation Consultation{ex}");
- }
- _isEmergencyRequesting = false;
- return liveState;
- }
- private void StartTimingTask()
- {
- _timingManualResetEvent.Reset();
- Task.Run(() =>
- {
- try
- {
- var currentSort = EmergencyConsultationInfo.CurrentSort;
- var currentExpert = EmergencyConsultationInfo.SortExperts.FirstOrDefault(f => f.Sort == currentSort);
- Logger.WriteLineInfo($"Consultation Recipient Timing Task Start,Current Sort is {currentSort},ExpertName:{currentExpert?.UserName},ExpertId:{currentExpert?.UserId}");
- if (!_timingManualResetEvent.WaitOne(20000))
- {
- Logger.WriteLineError($"Consultation Emergency Consultation Call Time out,Will Cancel and Request Next Automatic");
- if (EmergencyConsultationInfo != null)
- {
- CancelEmergencyConsultation();
- var emergencyConsultationInfo = GetEmergencyConsultationExpertsInfo();
- lock (EmergencyConsultationLocker)
- {
- EmergencyConsultationInfo = emergencyConsultationInfo;
- }
- var nextSortExpert = EmergencyConsultationInfo.SortExperts.FirstOrDefault(f => f.Sort == currentSort + 1);
- if (nextSortExpert != null)
- {
- if (CreateAndStartEmergencyConsultation(nextSortExpert))
- {
- _isEmergencyRequesting = true;
- }
- else
- {
- _timingManualResetEvent.Set();
- _isEmergencyRequesting = false;
- CurrentLiveStatus = LiveStates.RecipientRejected;
- OnRejectConsultationNotifyArrived(new ConsultationSubscriberInfo
- {
- RoomId = null,
- Id = currentExpert?.UserId,
- });
- lock (EmergencyConsultationLocker)
- {
- EmergencyConsultationInfo = null;
- }
- }
- }
- else
- {
- _timingManualResetEvent.Set();
- _isEmergencyRequesting = false;
- CurrentLiveStatus = LiveStates.RecipientRejected;
- OnRejectConsultationNotifyArrived(new ConsultationSubscriberInfo
- {
- RoomId = null,
- Id = currentExpert?.UserId,
- });
- lock (EmergencyConsultationLocker)
- {
- EmergencyConsultationInfo = null;
- }
- }
- }
- }
- else
- {
- Logger.WriteLineInfo($"Consultation Recipient Timing Task Ended");
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"ConsultationRecipient Timing Task Error:{ex}");
- }
- });
- }
- /// <summary>
- /// 发起紧急会诊接口
- /// </summary>
- private bool CreateAndStartEmergencyConsultation(EmergencyConsultationExpertInfo expertDoctor)
- {
- try
- {
- if (expertDoctor == null)
- {
- Logger.WriteLineError($"Consultation Recipient CreateAndStartEmergencyConsultation Failed,ExpertDoctor is null");
- return false;
- }
- EmergencyConsultationInfo.CurrentSort = expertDoctor.Sort;
- StartTimingTask();
- using (var request = new CreateAndStartEmergencyConsultationRequest())
- {
- request.EquCode = _uniqueId;
- request.ApplyDoctor = FLYINSONOUser.Name;
- request.ExpertDoctor = expertDoctor.UserName;
- var result = ClientLeaf?.Send(request);
- if (result != null)
- {
- var resultMessage = CreateAndStartEmergencyConsultationResult.Convert(result);
- if (resultMessage != null)
- {
- EmergencyConsultationInfo.ConsultationId = resultMessage.Id;
- return resultMessage.IsSuccess;
- }
- }
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"CreateAndStartEmergencyConsultation Error:{ex}");
- }
- return false;
- }
- public LiveStates CancelEmergencyConsultation()
- {
- var livestates = LiveStates.Failed;
- try
- {
- Logger.WriteLineInfo($"Consultation Recipient-- {FLYINSONOUser.Name} CancelEmergencyConsultation begin");
- using (var request = new CancelEmergencyConsultationRequest())
- {
- request.ConsultationId = EmergencyConsultationInfo.ConsultationId;
- request.ExpertId = EmergencyConsultationInfo.SortExperts.FirstOrDefault(x => x.Sort == EmergencyConsultationInfo.CurrentSort)?.UserId;
- var result = ClientLeaf.Send(request);
- if (result != null)
- {
- var resultMessage = CancelEmergencyConsultationResult.Convert(request);
- if (resultMessage != null)
- {
- if (resultMessage.IsSuccess)
- {
- CurrentLiveStatus = LiveStates.Cancelled;
- }
- }
- }
- }
- lock (EmergencyConsultationLocker)
- {
- EmergencyConsultationInfo = null;
- }
- _timingManualResetEvent.Set();
- _isEmergencyRequesting = false;
- Logger.WriteLineInfo($"Consultation Recipient-- {FLYINSONOUser.Name} CancelEmergencyConsultation end");
- return livestates;
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Consultation Recipient-- {FLYINSONOUser.Name} CancelEmergencyConsultation error:{ex}");
- return LiveStates.UnknowException;
- }
- }
- public override void Dispose()
- {
- Logger.WriteLineInfo("Consultation Recipient is dispose begin");
- _timingManualResetEvent?.Set();
- _isEmergencyRequesting = false;
- base.Dispose();
- Logger.WriteLineInfo("Consultation Recipient is dispose end");
- }
- }
- }
|