Refactor Citrix virtual session data collection
This commit is contained in:
@@ -3825,77 +3825,42 @@ namespace C4IT.DataHistoryProvider
|
||||
|
||||
try
|
||||
{
|
||||
var Age2 = Age;
|
||||
if (Ids.Count == 1)
|
||||
Age2 = 365;
|
||||
var AgentLimit = DateTime.UtcNow + TimeSpan.FromDays(-Age2);
|
||||
|
||||
var idInput = Ids.Select(v => new cF4sdIdentityEntry() { Id = v, Class = infoClass }).ToList();
|
||||
var listIds = await getConnectorIdList(idInput, Token, requestInfo, LogDeep + 1);
|
||||
|
||||
if (listIds == null || listIds.Count == 0)
|
||||
var _relationService = GetStagedRelationService();
|
||||
if (_relationService == null)
|
||||
return null;
|
||||
|
||||
var lstAgentIds = new Dictionary<int, cDataHistoryUsageIdInfo>(Ids.Count);
|
||||
var lstTicketIds = new List<cF4sdConnectorIds>(Ids.Count);
|
||||
|
||||
foreach (var Entry in listIds)
|
||||
var _relatedTo = new List<cFasdApiSearchResultEntry>();
|
||||
foreach (var _idEntry in Ids)
|
||||
{
|
||||
if (M42WpmCollector != null && infoClass == enumFasdInformationClass.User)
|
||||
var _rel = new cFasdApiSearchResultEntry()
|
||||
{
|
||||
if (Entry.sid != null)
|
||||
lstTicketIds.Add(Entry);
|
||||
}
|
||||
if (Entry.lastSeenByAgent != null && Entry.lastSeenByAgent >= AgentLimit)
|
||||
{
|
||||
if (Entry.agentId2 != null)
|
||||
lstAgentIds[(int)Entry.agentId2] = new cDataHistoryUsageIdInfo() { Id = Entry.Id, AccountType = enumAccountType.Azure };
|
||||
if (Entry.agentId != null)
|
||||
lstAgentIds[(int)Entry.agentId] = new cDataHistoryUsageIdInfo() { Id = Entry.Id, AccountType = enumAccountType.AD };
|
||||
}
|
||||
if (Entry.localAgentIds != null)
|
||||
{
|
||||
foreach (var entryLocal in Entry.localAgentIds)
|
||||
{
|
||||
if (entryLocal.lastSeenByAgent >= AgentLimit)
|
||||
lstAgentIds[entryLocal.agentId] = new cDataHistoryUsageIdInfo() { Id = Entry.Id, AccountType = enumAccountType.Local, account = entryLocal.account, domain = "" };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (DefaultLogger.IsDebug)
|
||||
{
|
||||
var _msgDebug = new List<string>()
|
||||
{
|
||||
$"{lstAgentIds?.Count} agent ids found by usage determination:"
|
||||
Type = cFasdApiSearchResultEntry.getSearchClass(infoClass),
|
||||
id = _idEntry
|
||||
};
|
||||
foreach (var dbgEntry in lstAgentIds)
|
||||
_msgDebug.Add($"{dbgEntry.Key}: accountType={dbgEntry.Value.AccountType}, account={dbgEntry.Value.account}, domain={dbgEntry.Value.domain}, id={dbgEntry.Value.Id}");
|
||||
DefaultLogger.LogList(LogLevels.Debug, _msgDebug);
|
||||
_relatedTo.Add(_rel);
|
||||
}
|
||||
|
||||
var taskList = new List<Task<List<cF4sdApiSearchResultRelation>>>(2);
|
||||
if (lstAgentIds.Count > 0)
|
||||
taskList.Add(Task.Run<List<cF4sdApiSearchResultRelation>>(async () => { return await GetUsedInfoFromAgentData(infoClass, lstAgentIds, Age, Token, requestInfo, LogDeep + 1); }));
|
||||
if (lstTicketIds.Count > 0)
|
||||
taskList.Add(Task.Run<List<cF4sdApiSearchResultRelation>>(async () => { return await getTicketUsage(infoClass, lstTicketIds, Age, Token, requestInfo, LogDeep + 1); }));
|
||||
|
||||
if (taskList.Count == 0)
|
||||
var taskId = await _relationService.StartGatheringRelatedObjects(_relatedTo, Age);
|
||||
if (Token.IsCancellationRequested)
|
||||
return null;
|
||||
|
||||
var arrTask = taskList.ToArray();
|
||||
var RetVal = await Task.WhenAll<List<cF4sdApiSearchResultRelation>>(arrTask);
|
||||
|
||||
var RetVal2 = new List<cF4sdApiSearchResultRelation>();
|
||||
foreach (var Entry in RetVal)
|
||||
var _retVal = new List<cF4sdApiSearchResultRelation>();
|
||||
do
|
||||
{
|
||||
if (Entry != null)
|
||||
RetVal2.AddRange(Entry);
|
||||
}
|
||||
var _rels = await _relationService.GetRelatedObjectsAsync(taskId.Id, Token);
|
||||
if (Token.IsCancellationRequested)
|
||||
return null;
|
||||
if (_rels == null)
|
||||
return null;
|
||||
|
||||
_retVal.AddRange(_rels.Relations);
|
||||
|
||||
if (_rels.IsComplete)
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
return _retVal ;
|
||||
|
||||
if (RetVal2.Count > 0)
|
||||
return RetVal2;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
@@ -5589,7 +5554,7 @@ namespace C4IT.DataHistoryProvider
|
||||
if (infoClass == enumFasdInformationClass.Ticket)
|
||||
return new cF4sdConnectorIds() { Id = Identity.Id, infoClass = enumFasdInformationClass.Ticket };
|
||||
if (infoClass == enumFasdInformationClass.VirtualSession)
|
||||
return new cF4sdConnectorIds() { Id = Identity.Id, infoClass = enumFasdInformationClass.VirtualSession };
|
||||
return new cF4sdConnectorIds() { Id = Identity.Id, Instance = Identity.Instance, infoClass = enumFasdInformationClass.VirtualSession };
|
||||
if (infoClass == enumFasdInformationClass.MobileDevice)
|
||||
return new cF4sdConnectorIds() { Id = Identity.Id, infoClass = enumFasdInformationClass.MobileDevice };
|
||||
|
||||
@@ -6911,6 +6876,8 @@ namespace C4IT.DataHistoryProvider
|
||||
|
||||
public enumFasdInformationClass infoClass { get; set; } = enumFasdInformationClass.Unknown;
|
||||
public Guid Id { get; set; }
|
||||
public Guid Instance { get; set; } = Guid.Empty;
|
||||
|
||||
public int? agentId { get; set; } = null;
|
||||
public int? agentId2 { get; set; } = null;
|
||||
public List<localIdEntry> localAgentIds { get; set; } = null;
|
||||
|
||||
Reference in New Issue
Block a user