public async Task <string> SendMessage(SendMessageQuery sendMessageQuery) { _logger.LogInformation($"Make api call get send message to user {sendMessageQuery.userPrincipalName}"); string token = Request.Headers["Authorization"]; return(await _userSessionService.SendMessage(token, sendMessageQuery).ConfigureAwait(false)); }
public async Task <string> SendMessage(string accessToken, SendMessageQuery sendMessageQuery) { _logger.LogInformation($"Enter into service call to send message to {sendMessageQuery.userPrincipalName}"); var key = sendMessageQuery; var result = await _cache.GetOrCreateAsync(key, async entry => { var url = ""; var Content = new StringContent(JsonConvert.SerializeObject(sendMessageQuery), Encoding.UTF8, "application/json"); url = $"{_brokerUrl}RdsManagement/V1/TenantGroups/{sendMessageQuery.tenantGroupName}/Tenants/{sendMessageQuery.tenantName}/HostPools/{sendMessageQuery.hostPoolName}/SessionHosts/{sendMessageQuery.sessionHostName}/Sessions/{sendMessageQuery.sessionId}/actions/send-message-user?MessageTitle={sendMessageQuery.messageTitle.ToString()}&MessageBody={sendMessageQuery.messageBody.ToString()}"; var reply = await PostRequest(url, JsonConvert.SerializeObject(sendMessageQuery), accessToken).ConfigureAwait(false); // Set cache expiration entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2); return(reply); }).ConfigureAwait(false); return(result); }
public async Task <IActionResult> SendMessage(DiagnoseDetailPageViewModel data) { if (ModelState.IsValid) { var viewData = new SendMessageQuery(); var messageStatus = new List <MessageStatus>(); tenantGroupName = HttpContext.Session.Get <string>("SelectedTenantGroupName"); tenant = HttpContext.Session.Get <string>("SelectedTenantName"); var refreshtoken = await HttpContext.GetTokenAsync("refresh_token").ConfigureAwait(false); accessToken = _commonService.GetAccessTokenWVD(refreshtoken); //await HttpContext.GetTokenAsync("access_token"); if (string.IsNullOrEmpty(data.Message) && string.IsNullOrEmpty(data.Title)) { ViewBag.TitleErrorMsg = "Subject is required"; ViewBag.MessageErrorMsg = "Message is required"; } else if (string.IsNullOrEmpty(data.Title)) { ViewBag.TitleErrorMsg = "Title is required"; } else if (string.IsNullOrEmpty(data.Message)) { ViewBag.MessageErrorMsg = "Message is required"; } else { if (data.UserSessions.Where(x => x.IsSelected == true).ToList().Count > 0) { foreach (var item in data.UserSessions.Where(x => x.IsSelected == true).ToList()) { var sendMessageQuery = new SendMessageQuery() { tenantGroupName = item.tenantGroupName, tenantName = item.tenantName, hostPoolName = item.hostPoolName, sessionHostName = item.sessionHostName, sessionId = item.sessionId, messageTitle = data.Title, messageBody = data.Message, userPrincipalName = item.userPrincipalName, adUserName = item.adUserName }; var Content = new StringContent(JsonConvert.SerializeObject(sendMessageQuery), Encoding.UTF8, "application/json"); _logger.LogInformation($"Call service to send message to {item.userPrincipalName}"); var response = await _userSessionService.SendMessage(accessToken, sendMessageQuery).ConfigureAwait(false); if (response == HttpStatusCode.OK.ToString()) { messageStatus.Add(new MessageStatus() { Message = $"Message sent successfully to {item.adUserName}", Status = "Success" }); } else if (response == HttpStatusCode.Forbidden.ToString() || response == HttpStatusCode.Unauthorized.ToString()) { messageStatus.Add(new MessageStatus() { Message = $"Failed to send message to {item.adUserName} . You don't have permissions to send message.", Status = "Error" }); } else { messageStatus.Add(new MessageStatus() { Message = $"Failed to send message to {item.adUserName}", Status = "Error" }); } } ViewBag.ErrorMsg = ""; } else { ViewBag.ErrorMsg = "Please select at least one user"; } } return(View("ActivityHostDetails", new DiagnoseDetailPageViewModel() { UserSessions = data.UserSessions.Where(usr => usr.IsSelected = true) .Select(usr => { usr.IsSelected = false; return usr; }) .ToList(), Title = data.Title, Message = data.Message, SendMsgStatuses = messageStatus, ConnectionActivity = data.ConnectionActivity, ShowConnectedUser = true, ShowMessageForm = true, selectedUsername = data.UserSessions.Where(x => x.IsSelected == true).ToList(), VMPerformance = await GetVMPerformance(data.ConnectionActivity.SessionHostName).ConfigureAwait(false) })); } else { return(View("ActivityHostDetails", new DiagnoseDetailPageViewModel() { UserSessions = data.UserSessions.Where(usr => usr.IsSelected = true) .Select(usr => { usr.IsSelected = false; return usr; }) .ToList(), ConnectionActivity = data.ConnectionActivity, ShowConnectedUser = true, ShowMessageForm = true, Title = data.Title, Message = data.Message, selectedUsername = data.UserSessions.Where(x => x.IsSelected == true).ToList(), VMPerformance = await GetVMPerformance(data.ConnectionActivity.SessionHostName).ConfigureAwait(false) })); } }
public void SendMessage([FromBody] SendMessageQuery query) { MessageServiceVk vkService = new MessageServiceVk(); vkService.SendByUrl(query.Url, $"elementcustom{query.Guid}"); }