Exemplo n.º 1
0
        public async Task <bool> Initialization(IGraphService graphService)
        {
            try
            {
                var categories = new List <string>();
                var providers  = new List <string>();
                var alerts     = await graphService.GetAlertsAsync(new AlertFilterModel(1000));

                foreach (var alert in alerts?.Item1)
                {
                    if (!string.IsNullOrWhiteSpace(alert.AssignedTo))
                    {
                        if (GetUserAccountDevice(alert.AssignedTo) == null)
                        {
                            UserAccountDevice userAccountDevice = await graphService.GetUserDetailsAsync(alert.AssignedTo, true, true, true);

                            SetUserAccountDevice(alert.AssignedTo, userAccountDevice);
                        }
                    }

                    if (alert.UserStates != null)
                    {
                        foreach (var userState in alert.UserStates)
                        {
                            if (!string.IsNullOrWhiteSpace(userState.UserPrincipalName) && GetUserAccountDevice(userState.UserPrincipalName) == null)
                            {
                                UserAccountDevice userAccountDevice = await graphService.GetUserDetailsAsync(userState.UserPrincipalName, populatePicture : true, populateManager : true, populateDevices : true);

                                if (!string.IsNullOrWhiteSpace(userAccountDevice.Manager.Upn))
                                {
                                    userAccountDevice.Manager = await graphService.GetUserDetailsAsync(userAccountDevice.Manager.Upn, populatePicture : false, populateManager : false, populateDevices : false);
                                }

                                if (!string.IsNullOrWhiteSpace(userState.DomainName))
                                {
                                    userAccountDevice.DomainName = userState.DomainName;
                                }

                                userAccountDevice.RiskScore = userState?.RiskScore;
                                userAccountDevice.LogonId   = userState?.LogonId;
                                userAccountDevice.EmailRole = userState?.EmailRole.ToString();

                                if (userAccountDevice?.RegisteredDevices?.Count() == 0 && userAccountDevice?.OwnedDevices?.Count() == 0)
                                {
                                    userAccountDevice.RegisteredDevices = _demoExample.GetDevices();
                                    userAccountDevice.OwnedDevices      = _demoExample.GetDevices();
                                }

                                if (userAccountDevice != null)
                                {
                                    SetUserAccountDevice(userState.UserPrincipalName, userAccountDevice);
                                }
                            }
                        }
                    }

                    if (alert.VendorInformation != null && !string.IsNullOrWhiteSpace(alert.VendorInformation.Provider))
                    {
                        providers.Add(alert.VendorInformation.Provider);
                    }

                    if (!string.IsNullOrWhiteSpace(alert.Category))
                    {
                        categories.Add(alert.Category);
                    }
                }

                if (categories.Count > 0)
                {
                    SetFilter("Categories", categories.Distinct().ToList());
                }

                if (providers.Count > 0)
                {
                    SetFilter("Providers", providers.Distinct().ToList());
                }

                return(true);
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception.Message);
                return(false);
            }
        }
Exemplo n.º 2
0
        // Microsoft.Graph.Device
        private async Task AddAdditionalInformationAboutAlert(Alert alert, AlertDetailsViewModel alertModel)
        {
            try
            {
                var startAdd = DateTime.Now;

                if (!string.IsNullOrWhiteSpace(alert.AssignedTo))
                {
                    UserAccountDevice assignedTo = _memoryCacheHelper.GetUserAccountDevice(alert.AssignedTo);

                    if (assignedTo == null)
                    {
                        assignedTo = await _graphService.GetUserDetailsAsync(alert.AssignedTo, populatePicture: true, populateManager : true, populateDevices : true);

                        alertModel.AssignedTo = assignedTo;
                        _memoryCacheHelper.SetUserAccountDevice(alert.AssignedTo, assignedTo);
                    }

                    alertModel.AssignedTo = assignedTo;
                }

                List <UserAccountDevice> userAccountDevices = new List <UserAccountDevice>();

                foreach (var userState in alert?.UserStates)
                {
                    // Get info about user
                    var principalName = userState.UserPrincipalName;
                    if (!string.IsNullOrWhiteSpace(principalName))
                    {
                        UserAccountDevice userAccountDevice = _memoryCacheHelper.GetUserAccountDevice(principalName);

                        if (userAccountDevice == null)
                        {
                            userAccountDevice = await _graphService.GetUserDetailsAsync(principalName, populatePicture : true, populateManager : true, populateDevices : true, populateRiskyUser : true);

                            if (!string.IsNullOrWhiteSpace(userAccountDevice.Manager.Upn))
                            {
                                userAccountDevice.Manager = await _graphService.GetUserDetailsAsync(userAccountDevice.Manager.Upn, populatePicture : false, populateManager : false, populateDevices : false);
                            }

                            if (!string.IsNullOrWhiteSpace(userState.DomainName))
                            {
                                userAccountDevice.DomainName = userState.DomainName;
                            }

                            userAccountDevice.RiskScore = userState?.RiskScore;
                            userAccountDevice.LogonId   = userState?.LogonId;
                            userAccountDevice.EmailRole = userState?.EmailRole.ToString();

                            if (userAccountDevice?.RegisteredDevices?.Count() == 0 && userAccountDevice?.OwnedDevices?.Count() == 0)
                            {
                                userAccountDevice.RegisteredDevices = _demoExample.GetDevices();
                                userAccountDevice.OwnedDevices      = _demoExample.GetDevices();
                            }
                            _memoryCacheHelper.SetUserAccountDevice(principalName, userAccountDevice);
                        }
                        if (userAccountDevice != null)
                        {
                            userAccountDevices.Add(userAccountDevice);
                        }
                    }
                }

                alertModel.UserAccountDevices = userAccountDevices;

                Debug.WriteLine($"Executing time AddAdditionalInformationAboutAlert: {DateTime.Now - startAdd}");
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception.Message);
            }
        }