private string FindMachineInstall(FindMachineInstallRequest req, IAaaUser aaaUser, ILogger logger) { IDictionary<string, FindUserEntity> userDetailDic = new Dictionary<string, FindUserEntity>(); req.Product = "est"; var findUserReq = new FindUserRequest { Filter = FindUserFilter.All, SearchString = req.SearchString, }; // For external user, the auto suggest will only show the users under the user's location scope var canOnlySeeYourOwnAccount = false; if (!Permission.IsUserInternal(aaaUser)) { var scope = Permission.GetTopLocationScope(aaaUser); if (!scope.Equals(default(KeyValuePair<FindLocationFilter, string>))) { findUserReq.LocationScope = scope; } else if (aaaUser.UserId.Contains(req.SearchString) || aaaUser.EmailAddress.Contains(req.SearchString) || aaaUser.UUID.Contains(req.SearchString) || aaaUser.FullName.Contains(req.SearchString)) { canOnlySeeYourOwnAccount = true; } else { logger.LogWarn("STOpsConsole - FindMachineInstall - external user {0} has no eligible scope.", aaaUser.UserId); return "{ \"items\":[]}"; } } using (var userInfoServiceclient = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply)) { var svcResp = userInfoServiceclient.FindUser(findUserReq); if (svcResp == null || svcResp.Users.Count == 0) { return "{ \"items\":[]}"; } var machInstReq = new MachInstInfoRequest { uuids = new List<string>(), filter = req.Filter, product = req.Product }; //If user can see only his own account due to the scope. Will filter out the list of find user. if (canOnlySeeYourOwnAccount) { var user = svcResp.Users.SingleOrDefault(x => x.Uuid == aaaUser.UUID); if (user != null) { userDetailDic[user.Uuid] = user; machInstReq.uuids.Add(user.Uuid); } else { return "{ \"items\":[]}"; } } else { foreach (FindUserEntity user in svcResp.Users) { userDetailDic[user.Uuid] = user; machInstReq.uuids.Add(user.Uuid); } } FindMachInstResponse findMachInstResponse = new FindMachInstResponse() { Items = new List<FindMachInstInfoItem>() }; using (var opsConsoleServiceClient = new OpsConsoleServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply)) { MachInstInfoResponse machInstResp = opsConsoleServiceClient.GetMachineInstallInfo(machInstReq); foreach (MachInstInfoItem machInsInfo in machInstResp.Items) { FindMachInstInfoItem findMachInstInfoItem = new FindMachInstInfoItem { UUID = machInsInfo.uuid, FirstName = userDetailDic[machInsInfo.uuid].FirstName, LastName = userDetailDic[machInsInfo.uuid].LastName, EmailAddress = userDetailDic[machInsInfo.uuid].Email //MachInstInfoList = machInsInfo.machInstInfoList }; findMachInstResponse.Items.Add(findMachInstInfoItem); findMachInstResponse.Product = machInstResp.product; } } return JsonConvert.SerializeObject(findMachInstResponse) ?? "{}"; } }
public string GetStats(string query, string body, IAppServerServices services) { var req = JObject.Parse(body); string uuid = null, mid = null, iid = null, prod = null; int testid = 0; try { uuid = (string) req["uuid"]; prod = (string) req["product"]; mid = (string) req["machineGuid"]; iid = (string) req["installGuid"]; testid = (int) req["testid"]; } catch (Exception ex) { services.Logger.LogInfo("STOpsConsole - GetStats - by UUID extract query parameter exception {0}", ex.Message); } if (testid > 0 && (string.IsNullOrEmpty(uuid) || string.IsNullOrEmpty(mid) || string.IsNullOrEmpty(iid))) { services.Logger.LogInfo("STOpsConsole - GetStats - by test id {0}", testid); } else if (string.IsNullOrEmpty(mid) && string.IsNullOrEmpty(iid)) // If request has only uuid specify, try to get the stat of the latest machine id and installation id. { services.Logger.LogInfo("STOpsConsole - GetStats - by UUID"); using (var opsConsoleSvc = new OpsConsoleServiceClient(RouterBindings.Local,RouterAddresses.Local.RequestReply)) { try { var machInstReq = new MachInstInfoRequest() { uuids = new List<string> {uuid}, product = prod, filter = true }; var response = opsConsoleSvc.GetMachineInstallInfo(machInstReq); var latest = response.Items.FirstOrDefault() .machInstInfoList.OrderByDescending(y => DateTime.Parse(y.dateLastSeen)) .First(); req.Add(new JProperty("installGuid", latest.instGUID)); req.Add(new JProperty("machineGuid", latest.machGUID)); body = JsonConvert.SerializeObject(req); } catch (Exception ex) { services.Logger.LogError("STOpsConsole - GetStats:GetMachineInstallInfo - Caught exception: " + ex.Message); } } } else if (string.IsNullOrEmpty(mid) || string.IsNullOrEmpty(iid)) { services.Logger.LogWarn(string.IsNullOrEmpty(mid) ? "STOpsConsole - GetStats:GetMachineInstallInfo - machine id is null or empty" : "STOpsConsole - GetStats:GetMachineInstallInfo - installation id is null or empty"); return "{}"; } var getStatsRequest = JsonConvert.DeserializeObject<GetStatsRequest>(body); getStatsRequest.product = "est"; var product = new List<string> { "est" }; if (Permission.IsAllowToGetStats(services.UserContext, product) && Permission.IsUserInScope(services.UserContext, getStatsRequest.uuid)){ using (var opsConsoleSvc = new OpsConsoleServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply)) { try { var response = opsConsoleSvc.GetStats(getStatsRequest); if (response == null || String.IsNullOrEmpty(response.uuid)) { return "{}"; } response.firstName = services.UserSearch.GetUserByUuid(response.uuid).FirstName; response.lastName = services.UserSearch.GetUserByUuid(response.uuid).LastName; response.email = services.UserSearch.GetUserByUuid(response.uuid).EmailAddress; return JsonConvert.SerializeObject(response); } catch (Exception ex) { services.Logger.LogError("Error while invoking GetStats: {0}", ex.Message); return "{}"; } } } else { return "{}"; } }
public string GetMachineInstallInfo(string query, string body, IAppServerServices services) { var logger = services.Logger; using (var client = new OpsConsoleServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply)) { try { var machInstReq = JsonConvert.DeserializeObject<MachInstInfoRequest>(body); machInstReq.product = "est"; var response = client.GetMachineInstallInfo(machInstReq); return response == null ? "{ \"items\":[]}" : JsonConvert.SerializeObject(response); } catch (Exception ex) { logger.LogError("STOpsConsole - GetMachineInstallInfo - Caught exception: " + ex.Message); return "{}"; } } }