private void Workgroups_ConfigurationObjectsChanged(object sender, ConfigurationObjectChangesEventArgs <WorkgroupConfiguration, WorkgroupConfiguration.Property> e)
        {
            try
            {
                //_logging.LogNote("Workgroups_ConfigurationObjectsChanged");
                foreach (var changedObject in e.ObjectsChanged)
                {
                    var updated = false;
                    var workgroupConfiguration = changedObject.Key;

                    using (var repository = Repository)
                    {
                        var wg = repository.Workgroups.FirstOrDefault(w => w.ConfigId == workgroupConfiguration.ConfigurationId.Id);
                        if (wg != null)
                        {
                            //_logging.LogNote("Workgroup: " + wg.DisplayName);
                            if (changedObject.Value.Contains(WorkgroupConfiguration.Property.Utilizations))
                            {
                                //_logging.LogNote("Utilizations Changed");

                                var utilList = wg.Utilizations.ToList();
                                wg.Utilizations.Clear();
                                foreach (var utilization in utilList)
                                {
                                    repository.Utilizations.Remove(utilization);
                                }

                                var utilizations = workgroupConfiguration.Utilizations;
                                var utils        = utilizations.Value;
                                var u            = utils.Select(utilizationSettings => new Utilization
                                {
                                    MediaType          = GetMediaType(utilizationSettings.MediaType),
                                    MaxAssignable      = utilizationSettings.MaxAssignable,
                                    UtilizationPercent = utilizationSettings.Utilization
                                }).ToList();
                                repository.Utilizations.AddRange(u);
                                wg.Utilizations = u;
                                updated         = true;
                                var utilizationString = String.Join(",", u.Select(i => i.MediaType));
                                //_logging.LogNote(String.Format("Utilizations: {0}", utilizationString));
                            }
                            if (updated)
                            {
                                repository.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                _logging.LogException(exception);
                _logging.TraceException(exception, "WorkgroupConfigurations Error");
            }
        }
Ejemplo n.º 2
0
        private void Users_ConfigurationObjectsChanged(object sender, ConfigurationObjectChangesEventArgs <UserConfiguration, UserConfiguration.Property> e)
        {
            try
            {
                //_logging.LogNote("Users_ConfigurationObjectsChanged");
                foreach (var changedObject in e.ObjectsChanged)
                {
                    var updated           = false;
                    var userConfiguration = changedObject.Key;

                    using (var repository = Repository)
                    {
                        var agent = repository.Agents.FirstOrDefault(a => a.ConfigId == userConfiguration.ConfigurationId.Id);
                        if (agent != null)
                        {
                            //_logging.LogNote("Agent: " + agent.DisplayName);
                            if (changedObject.Value.Contains(UserConfiguration.Property.Skills))
                            {
                                //_logging.LogNote("Skills Changed");
                                foreach (var skill in agent.Skills.ToList())
                                {
                                    agent.Skills.Remove(skill);
                                }
                                var skills          = userConfiguration.Skills.Value.Select(s => s.Id.Id);
                                var inheritedSkills = userConfiguration.Skills.InheritedValue.Select(s => s.Id.Id);

                                //in addition to value, i also need inherited value
                                var skls =
                                    skills.Select(skill => repository.Skills.FirstOrDefault(s => s.ConfigId == skill))
                                    .Where(sk => sk != null)
                                    .ToList();
                                if (inheritedSkills.Any())
                                {
                                    skls.AddRange(inheritedSkills.Select(skill => repository.Skills.FirstOrDefault(s => s.ConfigId == skill))
                                                  .Where(sk => sk != null)
                                                  .ToList());
                                }

                                agent.Skills = skls;
                                updated      = true;
                                //var skillString = String.Join(",", skls.Select(i => i.DisplayName));
                                //_logging.LogNote(String.Format("Skills: {0}", skillString));
                            }
                            if (changedObject.Value.Contains(UserConfiguration.Property.Utilizations))
                            {
                                //_logging.LogNote("Utilizations Changed");

                                var utilList = agent.Utilizations.ToList();
                                agent.Utilizations.Clear();
                                foreach (var utilization in utilList)
                                {
                                    repository.Utilizations.Remove(utilization);
                                }

                                var utilizations = userConfiguration.Utilizations;
                                var utils        = utilizations.Value;
                                var u            = utils.Select(utilizationSettings => new Utilization
                                {
                                    MediaType          = GetMediaType(utilizationSettings.MediaType),
                                    MaxAssignable      = utilizationSettings.MaxAssignable,
                                    UtilizationPercent = utilizationSettings.Utilization
                                }).ToList();
                                repository.Utilizations.AddRange(u);
                                agent.Utilizations = u;
                                updated            = true;
                                //var utilizationString = String.Join(",", u.Select(i => i.MediaType));
                                //_logging.LogNote(String.Format("Utilizations: {0}", utilizationString));
                            }
                            if (changedObject.Value.Contains(UserConfiguration.Property.Workgroups))
                            {
                                try
                                {
                                    var workgroups = userConfiguration.Workgroups;
                                    var wgs        = workgroups.Value;
                                    foreach (var wg in wgs.Select(i => i.Id))
                                    {
                                        if (agent.ActiveInWorkgroups.Select(i => i.ConfigId).Any(i => i == wg))
                                        {
                                            WorkgroupPeople.RefreshWatch       = true;
                                            WorkgroupInteractions.RefreshWatch = true;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    _logging.LogException(ex);
                                    _logging.TraceException(ex, "AgentConfigurations Error - Workgroups Changed");
                                }
                            }
                            if (updated)
                            {
                                repository.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                _logging.LogException(exception);
                _logging.TraceException(exception, "AgentConfigurations Error");
            }
        }