예제 #1
0
        private static void CreateEmailXMLFile(HashSet <EmailXML> emails, FetchListServiceResponse <EmailXML> response)
        {
            try
            {
                using (XmlWriter writer = XmlWriter.Create("D:/emails.xml"))
                {
                    writer.WriteStartElement("Messages");
                    foreach (EmailXML emailXml in emails)
                    {
                        writer.WriteStartElement("Message");

                        writer.WriteAttributeString("MessageId", emailXml.MessageId);
                        writer.WriteAttributeString("InReplyToId", emailXml.InReplyToId);
                        writer.WriteAttributeString("Sender", emailXml.Sender);
                        writer.WriteAttributeString("RawSender", emailXml.RawSender);
                        if (emailXml.Sent != null)
                        {
                            writer.WriteAttributeString("Sent", emailXml.Sent.Value.Date.ToString("yyyy-MM-dd HH:mm:ss"));
                        }
                        writer.WriteAttributeString("Subject", emailXml.Subject);

                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                    writer.Flush();
                }
            }
            catch (Exception e)
            {
                response.Succeeded = false;
                throw new Exception($"Creating XML file failed with an error: {e.Message}");
            }
        }
예제 #2
0
        public FetchListServiceResponse <EmailXML> DownloadEmailMessagesFromEmailAccount(EmailDownloadDto emailDownloadDto)
        {
            FetchListServiceResponse <EmailXML> response = new FetchListServiceResponse <EmailXML>();
            HashSet <EmailXML> emails = new HashSet <EmailXML>();

            if ((emailDownloadDto.ServerAddress == "pop.gmail.com" || emailDownloadDto.ServerAddress == "imap.gmail.com") &&
                emailDownloadDto.UseSSL == false)
            {
                throw new Exception("Connection to GMAIL requires SSL connection.");
            }

            try
            {
                using (Imap imap = new Imap())
                {
                    imap.Connect(emailDownloadDto.ServerAddress, emailDownloadDto.Port, emailDownloadDto.UseSSL);
                    imap.Login(emailDownloadDto.Username, emailDownloadDto.Password);

                    MailBuilder builder = new MailBuilder();

                    imap.SelectInbox();

                    HashSet <long> emailUIDs = new HashSet <long>(imap.GetAll().Take(100));

                    foreach (long uid in emailUIDs)
                    {
                        IMail emailRaw = builder.CreateFromEml(imap.GetMessageByUID(uid));

                        EmailXML emailXml = new EmailXML()
                        {
                            InReplyToId = emailRaw.InReplyTo,
                            MessageId   = emailRaw.MessageID,
                            Sender      = emailRaw.Sender.Address,
                            RawSender   = emailRaw.Sender.Name,
                            Sent        = emailRaw.Date,
                            Subject     = emailRaw.Subject
                        };

                        emails.Add(emailXml);
                    }
                    imap.Close();
                }

                response.Items     = emails;
                response.Succeeded = true;

                CreateEmailXMLFile(emails, response);
            }
            catch (Exception e)
            {
                response.Succeeded = false;
                throw new Exception($"Download failed with an error: {e.Message}");
            }

            return(response);
        }
예제 #3
0
        public ActionResult DrawEmailDomainsGraph(GraphViewModel graphViewModel)
        {
            try
            {
                DateTime fromDate = DateTime.ParseExact(graphViewModel.FromDate, "MM/dd/yyyy", null);
                DateTime toDate   = DateTime.ParseExact(graphViewModel.ToDate, "MM/dd/yyyy", null);

                string connectionString = graphViewModel.FileImported == false?GetConnectionStringBasedOnSelectedMember(graphViewModel.SelectedTeamMemberId.ToString()) : _importConnectionString;

                FetchListServiceResponse <DataPoint> mostUsedEmailDomains = _graphService.FetchMostUsedEmailDomains(connectionString, fromDate, toDate);
                if (mostUsedEmailDomains.Succeeded)
                {
                    graphViewModel.EmailDomains = mostUsedEmailDomains.Items;
                }
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(500, e.Message));
            }
            return(View("GraphPie2d_partial", graphViewModel));
        }
예제 #4
0
        public FetchListServiceResponse<DataPoint> FetchMostUsedEmailDomains(string connectionString, DateTime fromDate, DateTime toDate)
        {
            FetchListServiceResponse<DataPoint> response = new FetchListServiceResponse<DataPoint>();
            try
            {
                List<DataPoint> mostUsedEmailDomains;
                using (IUnitOfWork uow = CreateUnitOfWork(connectionString))
                {
                    mostUsedEmailDomains = uow.UserRepo.GetTenMostUsedEmailDomains(fromDate, toDate);
                }

                response.Items = new HashSet<DataPoint>(mostUsedEmailDomains);
                response.Succeeded = true;
                return response;
            }
            catch (Exception e)
            {
                response.Succeeded = false;
                throw new Exception(e.Message);
            }
        }
예제 #5
0
        public FetchListServiceResponse<BrokerageDto> FetchTopTenBrokers(Graph<UserDto> graph, string connectionString)
        {
            FetchListServiceResponse<BrokerageDto> response = new FetchListServiceResponse<BrokerageDto>();
            try
            {
                List<BrokerageDto> topTenBrokers;
                using (IUnitOfWork uow = CreateUnitOfWork(connectionString))
                {
                    topTenBrokers = uow.GraphRepo.GetTopTenBrokers(graph.Nodes);
                }

                response.Items = new HashSet<BrokerageDto>(topTenBrokers);
                response.Succeeded = true;
                return response;
            }
            catch (Exception e)
            {
                response.Succeeded = false;
                throw new Exception(e.Message);
            }
        }
예제 #6
0
        public FetchListServiceResponse<DateTime> FetchStartAndEndOfConversation(string connectionString)
        {
            FetchListServiceResponse<DateTime> response = new FetchListServiceResponse<DateTime>();
            try
            {
                using (IUnitOfWork uow = CreateUnitOfWork(connectionString))
                {
                    DateTime dateOfFirstConversation = uow.ConvRepo.GetDateOfFirstConversation();
                    DateTime dateOfLastConversation = uow.ConvRepo.GetDateOfLastConversation();

                    response.Items.Add(dateOfFirstConversation);
                    response.Items.Add(dateOfLastConversation);
                    response.Succeeded = true;
                }
            }
            catch (Exception)
            {
                response.Succeeded = false;
                throw new Exception("Start and end of conversation was not found.");
            }

            return response;
        }
        public ActionResult SubmitDownload(EmailDownloadViewModel model)
        {
            try
            {
                EmailDownloadDto emailDownloadDto = new EmailDownloadDto()
                {
                    Email         = model.Email,
                    Password      = model.Password,
                    Port          = model.Port,
                    ServerAddress = model.ServerAddress,
                    Username      = model.Username,
                    UseSSL        = model.UseSSL
                };

                FetchListServiceResponse <EmailXML> downloadedEmails = _emailService.DownloadEmailMessagesFromEmailAccount(emailDownloadDto);
                this.AddToastMessage("Success", "Emails were downloaded.", ToastType.Success);
            }
            catch (Exception e)
            {
                this.AddToastMessage("Error", e.Message, ToastType.Error);
            }

            return(View("Index", model));
        }
예제 #8
0
        public ActionResult DrawBrokerageGraph(GraphViewModel graphViewModel)
        {
            try
            {
                FetchListServiceResponse <BrokerageDto> topTenBrokersResponse = _graphService.FetchTopTenBrokers(graphViewModel.Graph, GetConnectionStringBasedOnSelectedMember(graphViewModel.SelectedTeamMemberId.ToString()));

                if (topTenBrokersResponse.Succeeded)
                {
                    graphViewModel.BrokerageDto      = topTenBrokersResponse.Items;
                    graphViewModel.BrokerageDetected = true;
                }
                HashSet <BrokerageDto> topTenBrokers = topTenBrokersResponse.Items;

                graphViewModel.DataPointDto = new DataPointDto
                {
                    DataPointsCoordinator    = new List <DataPoint>(),
                    DataPointsGatepeeker     = new List <DataPoint>(),
                    DataPointsItinerant      = new List <DataPoint>(),
                    DataPointsLiaison        = new List <DataPoint>(),
                    DataPointsRepresentative = new List <DataPoint>(),
                    DataPointsTotal          = new List <DataPoint>()
                };

                foreach (BrokerageDto broker in topTenBrokers)
                {
                    graphViewModel.DataPointDto.DataPointsCoordinator.Add(new DataPoint()
                    {
                        label = broker.Name,
                        y     = broker.Coordinator
                    });
                    graphViewModel.DataPointDto.DataPointsGatepeeker.Add(new DataPoint()
                    {
                        label = broker.Name,
                        y     = broker.Gatepeeker
                    });
                    graphViewModel.DataPointDto.DataPointsItinerant.Add(new DataPoint()
                    {
                        label = broker.Name,
                        y     = broker.Itinerant
                    });
                    graphViewModel.DataPointDto.DataPointsLiaison.Add(new DataPoint()
                    {
                        label = broker.Name,
                        y     = broker.Liaison
                    });
                    graphViewModel.DataPointDto.DataPointsRepresentative.Add(new DataPoint()
                    {
                        label = broker.Name,
                        y     = broker.Representative
                    });
                    graphViewModel.DataPointDto.DataPointsTotal.Add(new DataPoint()
                    {
                        label = broker.Name,
                        y     = broker.TotalBrokerageScore
                    });
                }
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(500, e.Message));
            }
            return(View("Graph2d_partial", graphViewModel));
        }
예제 #9
0
        public ActionResult FindBrokerage(GraphViewModel graphViewModel)
        {
            try
            {
                if (graphViewModel.Graph.Edges.Count != 0 && graphViewModel.Graph.GraphSet.Count == 0)
                {
                    foreach (Edge <UserDto> edge in graphViewModel.Graph.Edges)
                    {
                        graphViewModel.Graph.CreateGraphSet(edge);
                    }
                }

                FetchItemServiceResponse <Graph <UserDto> > response = _graphService.DetectBrokerageInGraph(graphViewModel.Graph);

                if (response.Succeeded)
                {
                    graphViewModel.Graph = response.Item;
                    FetchListServiceResponse <BrokerageDto> topTenBrokersResponse = _graphService.FetchTopTenBrokers(graphViewModel.Graph, GetConnectionStringBasedOnSelectedMember(graphViewModel.SelectedTeamMemberId.ToString()));

                    if (topTenBrokersResponse.Succeeded)
                    {
                        graphViewModel.BrokerageDto      = topTenBrokersResponse.Items;
                        graphViewModel.BrokerageDetected = true;
                    }

                    List <NodeDto> nodes = graphViewModel.Graph.Nodes.Select(x => new NodeDto()
                    {
                        id    = x.Id,
                        label = x.NodeElement.Name,
                        title = $"Node degree: {x.Degree}",
                        size  = 20,
                        group = (graphViewModel.GraphDto.nodes.First(y => y.id == x.Id).group)
                    }).ToList();
                    List <EdgeDto> edges = graphViewModel.Graph.Edges.Select(x => new EdgeDto()
                    {
                        from = x.Node1.Id, to = x.Node2.Id
                    }).ToList();

                    HashSet <BrokerageDto> topTenBrokers = topTenBrokersResponse.Items;
                    foreach (NodeDto node in (nodes.Where(x => topTenBrokers.Select(y => y.UserId).Contains(x.id))))
                    {
                        node.shape = "diamond";
                    }

                    GraphDto graphDto = new GraphDto
                    {
                        nodes = nodes,
                        edges = edges
                    };
                    graphViewModel.Graph.SetCommunityNodes();
                    graphViewModel.RolesDetected = false;
                    graphViewModel.GraphDto      = graphDto;
                }
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(500, e.Message));
            }

            return(View("GraphView_partial", graphViewModel));
        }