public void DetectManifestsUsingProtobuf()
    {
        var checkoutLocation = Path.Combine(Path.GetTempPath(), "repositories");

        var checkoutDirectory = new DirectoryInfo(checkoutLocation);

        if (checkoutDirectory.Exists)
        {
            checkoutDirectory.Delete(true);
        }
        checkoutDirectory.Create();

        // clone https://github.com/protocolbuffers/protobuf to a temp location
        Invoke.Command("git", "clone https://github.com/protocolbuffers/protobuf", checkoutLocation);

        var repositoryLocation = Path.Combine(checkoutLocation, "protobuf");

        var reader = new AgentReader("freshli-agent-java");

        var actualManifests = reader.DetectManifests(repositoryLocation);

        var expectedManifests = new List <string>()
        {
            "java/pom.xml",
            "java/protoc/pom.xml",
            "protoc-artifacts/pom.xml",
            "ruby/pom.xml"
        };

        Assert.Equal(expectedManifests, actualManifests);

        // delete cloned files
        checkoutDirectory.Delete(true);
    }
        public static List <HeatMapItem> GetHeatMap(string supervisorId)
        {
            List <HeatMapItem> items = new List <HeatMapItem>();

            List <KPIInfo>      kpis      = KPIReader.GetKPI();
            List <AgentKPIInfo> agentKpis = KPIReader.GetAgentKPI();
            List <AgentInfo>    agents    = AgentReader.GetAgentsForSupervisor(supervisorId);

            var result = from k in kpis
                         join ak in agentKpis on k.KpiId equals ak.KpiId
                         join a in agents on ak.AgentId equals a.AgentId
                         orderby a.AgentName, k.KpiName
                select new { a.AgentId, a.AgentName, k.KpiId, k.KpiName, ak.KpiValue };

            foreach (var row in result)
            {
                items.Add(new HeatMapItem()
                {
                    AgentId   = row.AgentId,
                    AgentName = row.AgentName,
                    KpiId     = row.KpiId,
                    KpiName   = row.KpiName,
                    KpiScore  = row.KpiValue
                });
            }

            return(items);
        }
        public static List <LeaderBoardItem> GetLeaderBoard(string centerId)
        {
            List <LeaderBoardItem> leaderBoard = new List <LeaderBoardItem>();
            List <AgentInfo>       agents      = AgentReader.GetAgentItems(centerId);

            int rank = 0;

            foreach (AgentInfo agent in agents.OrderByDescending(a => a.Points))
            {
                leaderBoard.Add(new LeaderBoardItem()
                {
                    Name          = agent.AgentName,
                    TotalPoints   = agent.Points,
                    PhotoFileName = agent.PhotoFileName,
                    Rank          = ++rank
                });

                if (rank >= 10)
                {
                    break;
                }
            }

            return(leaderBoard);
        }
Beispiel #4
0
        public static CenterViewResponse GetCenterView(string centerId)
        {
            List <KPIItem>      centerView = new List <KPIItem>();
            List <AgentKPIInfo> allKPIs    = KPIReader.GetAgentKPI();
            List <KPIInfo>      kpiNames   = KPIReader.GetAllKPIInfo();

            List <SupervisorInfo> supervisors = AgentReader.GetSupervisorsForCenter(centerId);

            foreach (var supervisor in supervisors)
            {
                List <KPIItem> supervisorKPI = GetSupervisorView(supervisor.SupervisorId).SupervisorView;

                if (supervisorKPI.Count > 0)
                {
                    List <AgentInfo> agents = AgentReader.GetAgentsForSupervisor(supervisor.SupervisorId);
                    var agentKPIs           = from allK in allKPIs
                                              join a in agents on allK.AgentId equals a.AgentId
                                              group allK by allK.KpiId into g
                                              select new { KpiId = g.First().KpiId, KpiTotal = g.Average(a => a.KpiValue) };

                    string topKpiString    = string.Empty;
                    string bottomKpiString = string.Empty;

                    var topKPI = agentKPIs.OrderByDescending(a => a.KpiTotal).Take(2);
                    foreach (var row in topKPI)
                    {
                        string kpiName = kpiNames.Where(k => k.KpiId.Equals(row.KpiId)).FirstOrDefault().KpiName;
                        topKpiString += string.Format("{0}: {1};", kpiName, row.KpiTotal);
                    }

                    var bottomKPI = agentKPIs.OrderBy(a => a.KpiTotal).Take(2);
                    foreach (var row in bottomKPI)
                    {
                        string kpiName = kpiNames.Where(k => k.KpiId.Equals(row.KpiId)).FirstOrDefault().KpiName;
                        bottomKpiString += string.Format("{0}: {1};", kpiName, row.KpiTotal);
                    }

                    double avgScore = supervisorKPI.Average(a => a.Score);

                    centerView.Add(new KPIItem()
                    {
                        AgentId   = supervisor.SupervisorId,
                        AgentName = supervisor.SupervisorName,
                        Score     = Convert.ToInt32(avgScore),
                        TopKPI    = topKpiString,
                        BottomKPI = bottomKpiString
                    });
                }
            }

            return(new CenterViewResponse()
            {
                CenterName = AgentReader.GetCenterName(centerId),
                CenterView = centerView
            });
        }
        public object From(AgentReader reader)
        {
            _ = reader.ReadUInt32(); // msglen
            var answer = (AgentMessageType)reader.ReadByte();

            if (answer != AgentMessageType.SSH2_AGENT_IDENTITIES_ANSWER)
            {
                throw new Exception($"Wrong Answer {answer}");
            }

            var keys    = new List <PrivateKeyAgent>();
            var numKeys = reader.ReadUInt32();
            var i       = 0;

            while (i < numKeys)
            {
                var keyData = reader.ReadStringAsBytes();
                using var keyStream = new MemoryStream(keyData);
                using var keyReader = new AgentReader(keyStream);

                var keyType = keyReader.ReadString();
                Key key;
                switch (keyType)
                {
                case "ssh-rsa":
                    var exponent = keyReader.ReadBignum();
                    var modulus  = keyReader.ReadBignum();
                    key = new RsaAgentKey(modulus, exponent, _agent, keyData);
                    break;

                case "ecdsa-sha2-nistp256":
                // Fallthrough
                case "ecdsa-sha2-nistp384":
                // Fallthrough
                case "ecdsa-sha2-nistp521":
                    var curve = keyReader.ReadString();
                    var q     = keyReader.ReadBignum2();
                    key = new EcdsaAgentKey(curve, q, _agent, keyData);
                    break;

                case "ssh-ed25519":
                    var pK = keyReader.ReadBignum2();
                    key = new ED25519AgentKey(pK, _agent, keyData);
                    break;

                default:
                    throw new Exception($"Unsupported KeyType {keyType}");
                }
                key.Comment = reader.ReadString();
                keys.Add(new PrivateKeyAgent(key));
                i++;
            }

            return(keys.ToArray());
        }
Beispiel #6
0
        public object?From(AgentReader reader)
        {
            _ = reader.ReadUInt32(); // msglen
            var answer = (AgentMessageType)reader.ReadByte();

            if (answer != AgentMessageType.SSH_AGENT_SUCCESS)
            {
                throw new Exception($"Wrong Answer {answer}");
            }
            return(null);
        }
Beispiel #7
0
        public static SupervisorViewResponse GetSupervisorView(string supervisorId)
        {
            List <KPIItem> supervisorView = new List <KPIItem>();

            List <KPIInfo>      kpis      = KPIReader.GetKPIInfo();
            List <AgentKPIInfo> agentKpis = KPIReader.GetAgentKPI();
            List <AgentInfo>    agents    = AgentReader.GetAgentsForSupervisor(supervisorId);

            var result = from k in kpis
                         join ak in agentKpis on k.KpiId equals ak.KpiId
                         join a in agents on ak.AgentId equals a.AgentId
                         orderby a.AgentName, ak.KpiValue ascending
                select new { a.AgentName, k.KpiName, ak.KpiValue };

            var agentGroups = result.GroupBy(a => a.AgentName).Select(g => g.FirstOrDefault());

            foreach (var agentGroup in agentGroups)
            {
                var    agentRows       = result.Where(a => a.AgentName.Equals(agentGroup.AgentName));
                double avgKpi          = agentRows.Average(a => a.KpiValue);
                string topKpiString    = string.Empty;
                string bottomKpiString = string.Empty;

                var topKPI = agentRows.OrderByDescending(a => a.KpiValue).Take(2);
                foreach (var row in topKPI)
                {
                    topKpiString += string.Format("{0}: {1};", row.KpiName, row.KpiValue);
                }

                var bottomKPI = agentRows.OrderBy(a => a.KpiValue).Take(2);
                foreach (var row in bottomKPI)
                {
                    bottomKpiString += string.Format("{0}: {1};", row.KpiName, row.KpiValue);
                }

                supervisorView.Add(new KPIItem()
                {
                    AgentName = agentGroup.AgentName,
                    Score     = Convert.ToInt32(avgKpi),
                    TopKPI    = topKpiString,
                    BottomKPI = bottomKpiString
                });
            }

            return(new SupervisorViewResponse()
            {
                SupervisorName = AgentReader.GetSupervisorName(supervisorId),
                SupervisorView = supervisorView.OrderByDescending(i => i.Score).ToList()
            });
        }
Beispiel #8
0
        public static AgentViewResponse GetAgentView(string agentId)
        {
            List <AgentKPIScore> agentView = new List <AgentKPIScore>();

            List <KPIInfo>      kpis      = KPIReader.GetKPIInfo();
            List <AgentKPIInfo> agentKpis = KPIReader.GetAgentKPI();
            AgentInfo           agentInfo = AgentReader.GetAgentInfo(agentId);

            var result = from k in kpis
                         join ak in agentKpis on k.KpiId equals ak.KpiId
                         where ak.AgentId == agentId
                         orderby k.KpiName
                         select new { k.KpiId, k.KpiName, ak.Date, ak.KpiValue, ak.HadTraining, ak.IsAwarded, ak.Description };

            var kpiGroups = result.GroupBy(k => k.KpiName).Select(g => g.FirstOrDefault());

            foreach (var kpiGroup in kpiGroups)
            {
                var kpiRows = result.Where(k => k.KpiName.Equals(kpiGroup.KpiName));

                List <KPIScoreInfo> scoreList = new List <KPIScoreInfo>();
                foreach (var row in kpiRows)
                {
                    var    dateRows      = kpiRows.Where(k => Convert.ToDateTime(k.Date) <= row.Date);
                    double centerAverage = dateRows.Average(k => k.KpiValue);

                    scoreList.Add(new KPIScoreInfo()
                    {
                        Date          = row.Date,
                        Score         = row.KpiValue.ToString(),
                        CenterAverage = centerAverage.ToString("F"),
                        HadTraining   = row.HadTraining,
                        IsAwarded     = row.IsAwarded,
                        Description   = row.Description
                    });
                }

                agentView.Add(new AgentKPIScore()
                {
                    KPIName      = kpiGroup.KpiName,
                    ScoreDetails = scoreList
                });
            }

            return(new AgentViewResponse()
            {
                AgentName = AgentReader.GetAgentInfo(agentId).AgentName,
                AgentView = agentView
            });
        }
Beispiel #9
0
        public object From(AgentReader reader)
        {
            _ = reader.ReadUInt32(); // msglen
            var answer = (AgentMessageType)reader.ReadByte();

            if (answer != AgentMessageType.SSH2_AGENT_SIGN_RESPONSE)
            {
                throw new Exception($"Wrong Answer {answer}");
            }

            var signatureData = reader.ReadStringAsBytes();

            using var signatureStream = new MemoryStream(signatureData);
            using var signatureReader = new AgentReader(signatureStream);

            // identifier
            _ = signatureReader.ReadString();
            return(signatureReader.ReadStringAsBytes());
        }
        public static List <AgentKPIScore> GetAgentDashboard(string agentId)
        {
            List <AgentKPIScore> items = new List <AgentKPIScore>();

            List <KPIInfo>      kpis      = KPIReader.GetKPI();
            List <AgentKPIInfo> agentKpis = KPIReader.GetAgentKPI();
            AgentInfo           agentInfo = AgentReader.GetAgentInfo(agentId);

            var result = from k in kpis
                         join ak in agentKpis on k.KpiId equals ak.KpiId
                         where ak.AgentId == agentId
                         orderby k.KpiName
                         select new { k.KpiId, k.KpiName, ak.Date, ak.KpiValue, ak.HadTraining, ak.IsAwarded, ak.Description };

            var kpiGroups = result.GroupBy(k => k.KpiName).Select(g => g.FirstOrDefault());

            foreach (var kpiGroup in kpiGroups)
            {
                var kpiRows = result.Where(k => k.KpiName.Equals(kpiGroup.KpiName));

                List <KPIScoreInfo> scoreList = new List <KPIScoreInfo>();
                foreach (var row in kpiRows)
                {
                    scoreList.Add(new KPIScoreInfo()
                    {
                        Date        = row.Date,
                        Score       = row.KpiValue.ToString(),
                        HadTraining = row.HadTraining,
                        IsAwarded   = row.IsAwarded,
                        Description = row.Description
                    });
                }

                items.Add(new AgentKPIScore()
                {
                    KPIName      = kpiGroup.KpiName,
                    ScoreDetails = scoreList
                });
            }

            return(items);
        }
        public static EngagementResult GetEngagement(EngagementRequest request)
        {
            EngagementResult result = new EngagementResult();

            string agentId   = request.AgentId;
            var    agentItem = AgentReader.GetAgentItems().First(i => i.AgentId.Equals(agentId, StringComparison.OrdinalIgnoreCase));

            string[] queues  = agentItem.QueueList;
            string   queueId = queues[0];

            QueueItem queueItem = QueueReader.GetQueueItems().First(q => q.QueueId.Equals(queueId, StringComparison.OrdinalIgnoreCase));

            AgentEngagementManager engagementManager = new AgentEngagementManager();
            int freeMinutes = engagementManager.CalculateFreeMinutes(agentId, queueItem);

            result.FreeMinutes = freeMinutes;
            result.Items       = EngagementReader.GetEngagementItems(freeMinutes);

            return(result);
        }
Beispiel #12
0
        public static HeatMapViewResponse GetHeatMapView(string supervisorId)
        {
            var heatMapItems = new List <Dictionary <string, string> >();

            List <KPIInfo>      kpis      = KPIReader.GetAllKPIInfo();
            List <AgentKPIInfo> agentKpis = KPIReader.GetAgentKPI();
            List <AgentInfo>    agents    = AgentReader.GetAgentsForSupervisor(supervisorId);

            string           centerId     = AgentReader.GetCenterIdForSupervisor(supervisorId);
            List <AgentInfo> centerAgents = AgentReader.GetAgentsForCenter(centerId);

            var result = from k in kpis
                         join ak in agentKpis on k.KpiId equals ak.KpiId
                         join a in agents on ak.AgentId equals a.AgentId
                         orderby k.Category, k.KpiId, a.AgentName
                select new { a.AgentId, a.AgentName, a.Date, k.KpiId, k.KpiName, ak.KpiValue, k.Category };

            var kpiGroups = result.GroupBy(a => a.KpiName).Select(g => g.FirstOrDefault());

            foreach (var kpiGroup in kpiGroups)
            {
                var kpiRows = from a in result
                              where a.KpiName.Equals(kpiGroup.KpiName)
                              group a by a.AgentName into g
                              select g.OrderByDescending(i => i.Date).FirstOrDefault();

                var item = new Dictionary <string, string>();
                item.Add("..Category", kpiGroup.Category);
                item.Add(".Behavior Attribute", kpiGroup.KpiName);

                var centerResult = from ak in agentKpis
                                   join ca in centerAgents on ak.AgentId equals ca.AgentId
                                   where ak.KpiId == kpiGroup.KpiId
                                   group ak by ak.KpiId into g
                                   select new { CenterAverage = g.Average(a => a.KpiValue) };

                var sdResult = from ak in agentKpis
                               join ca in centerAgents on ak.AgentId equals ca.AgentId
                               where ak.KpiId == kpiGroup.KpiId
                               select new { ak.KpiValue };
                List <double> sdList = new List <double>();
                foreach (var row in sdResult)
                {
                    sdList.Add(row.KpiValue);
                }

                double centerAverage = Convert.ToInt32(centerResult.First().CenterAverage);
                item.Add(".Center Average", centerAverage.ToString("F"));

                double standardDeviation = StatisticsHelper.GetStandardDeviation(sdList);
                item.Add(".Standard Deviation", standardDeviation.ToString("F"));

                foreach (var row in kpiRows)
                {
                    item.Add(row.AgentName, row.KpiValue.ToString("F"));
                }

                heatMapItems.Add(item);
            }

            return(new HeatMapViewResponse()
            {
                SupervisorName = AgentReader.GetSupervisorName(supervisorId),
                HeatMapView = heatMapItems
            });
        }