Beispiel #1
0
        public async Task <ActionResult> ShowEndpointData(int id)
        {
            List <EndpointEntities> endpointEntities = await new nuDirectApiController().GetAllEndpoints();
            EndpointEntities        endpoint         = endpointEntities.FirstOrDefault(x => x.EndpointId == id);

            ViewBag.PingResponseTime = "-";
            ViewBag.PingStatus       = "-";
            ViewBag.PingReplyAddress = "-";

            ViewBag.SimilarEndpoints = endpointEntities.Where(x => x.KnownIP == endpoint.KnownIP && x.EndpointId != endpoint.EndpointId);

            if (!string.IsNullOrEmpty(endpoint.KnownIP))
            {
                try
                {
                    Ping      myPing = new Ping();
                    PingReply reply  = myPing.Send(endpoint.KnownIP, 1000);
                    if (reply != null)
                    {
                        Console.WriteLine("Status :  " + reply.Status + " \n Time : " + reply.RoundtripTime.ToString() + " \n Address : " + reply.Address);
                        //Console.WriteLine(reply.ToString());

                        ViewBag.PingResponseTime = reply.RoundtripTime.ToString();
                        ViewBag.PingStatus       = reply.Status;
                        ViewBag.PingReplyAddress = reply.Address;
                    }
                }
                catch
                {
                    Console.WriteLine("ERROR: You have Some TIMEOUT issue");
                }
            }

            return(View(endpoint));
        }
        public async Task <ActionResult> TransfersByEntity(string StartDate, string EndDate, string EntityType)
        {
            if (string.IsNullOrEmpty(EntityType))
            {
                return(View(new List <EntityTransferCountModel>()));
            }

            List <EntityTransferCountModel> transferCounts = new List <EntityTransferCountModel>();

            List <TransferEntities> transfers = (await new nuDirectApiController().GetAllTransfers()).Where(x => x.Started > DateTime.Parse(StartDate) && x.Started < DateTime.Parse(EndDate).AddDays(1)).ToList();

            if (EntityType == "Customer")
            {
                List <CustomerEntities> customers = await new nuDirectApiController().GetAllCustomers();
                List <EndpointEntities> endpoints = await new nuDirectApiController().GetAllEndpoints();

                int[] sourceEndpoints = transfers.Select(x => x.SourceEpId).Distinct().ToArray();

                foreach (int i in sourceEndpoints)
                {
                    EndpointEntities currentEndpoint = endpoints.FirstOrDefault(z => z.EndpointId == i);
                    int endpointCount = transfers.Where(x => x.SourceEpId == i).Count();

                    if (transferCounts.Where(x => x.EntityName == currentEndpoint.customer.Company).Count() == 0)
                    {
                        transferCounts.Add(new EntityTransferCountModel()
                        {
                            EntityName = currentEndpoint.customer.Company, EntityCount = endpointCount
                        });
                    }
                    else
                    {
                        transferCounts.FirstOrDefault(x => x.EntityName == currentEndpoint.customer.Company).EntityCount += endpointCount;
                    }
                }
            }
            else if (EntityType == "CostCenter")
            {
                List <FolderEntities> folders = await new nuDirectApiController().GetAllFolders();

                int[] sourceFolders = transfers.Select(x => x.SourceFolderId).Distinct().ToArray();

                foreach (int i in sourceFolders)
                {
                    FolderEntities currentFolder = folders.FirstOrDefault(z => z.FolderId == i);
                    int            FolderCount   = transfers.Where(x => x.SourceFolderId == i).Count();

                    if (transferCounts.Where(x => x.EntityName == currentFolder.CostCentreCode).Count() == 0)
                    {
                        transferCounts.Add(new EntityTransferCountModel()
                        {
                            EntityName = currentFolder.CostCentreCode, EntityCount = FolderCount
                        });
                    }
                    else
                    {
                        transferCounts.FirstOrDefault(x => x.EntityName == currentFolder.CostCentreCode).EntityCount += FolderCount;
                    }
                }
            }
            else
            {
                List <CustomerEntities> customers = await new nuDirectApiController().GetAllCustomers();
                List <EndpointEntities> endpoints = await new nuDirectApiController().GetAllEndpoints();

                int[] sourceEndpoints = transfers.Select(x => x.SourceEpId).Distinct().ToArray();

                foreach (int i in sourceEndpoints)
                {
                    EndpointEntities currentEndpoint = endpoints.FirstOrDefault(z => z.EndpointId == i);
                    int endpointCount = transfers.Where(x => x.SourceEpId == i).Count();

                    if (transferCounts.Where(x => x.EntityName == currentEndpoint.customer.BusinessUnit).Count() == 0)
                    {
                        transferCounts.Add(new EntityTransferCountModel()
                        {
                            EntityName = currentEndpoint.customer.BusinessUnit, EntityCount = endpointCount
                        });
                    }
                    else
                    {
                        transferCounts.FirstOrDefault(x => x.EntityName == currentEndpoint.customer.BusinessUnit).EntityCount += endpointCount;
                    }
                }
            }

            return(View(transferCounts));
        }