Esempio n. 1
0
        public bool ServerLogin(string folder = null)
        {
            try
            {
                if (Server != null && Server.LoggedOn)
                {
                    return(true);
                }

                IMAPConfig config = new IMAPConfig(HostIMAP, PortIMAP, Email, Password, EnableSslIMAP, false, folder);
                IMAPClient client = new IMAPClient(config, null, 1);
                client.Logon();
                Server = client;

                return(true);
            }
            catch (Exception ex)
            {
                ex.ToOutput();
                return(false);
            }
        }
Esempio n. 2
0
        public async void Update(List <string> groupIDs)
        {
            try
            {
                IMAPClient client = new IMAPClient(imapConfig, null, 5);
                client.Logon();
                IMAPFolder folder = client.Folders[folderName];
                for (int i = 0; i < subFolderNames.Count; i++)
                {
                    folder = folder.SubFolders[i];
                    if (folder.FolderName == "Build_System")
                    {
                        break;
                    }
                }

                List <IMAPMessage> messages     = folder.Messages.OrderByDescending(msg => msg.Date).ToList();
                DateTime           lastPostDate = ReadLastPostedDateTime(cConfigurationFolderPath + cLastPostedBuildDateTimeFilePath);
                List <IMAPMessage> newMessages  = messages.TakeWhile((msg) => msg.Date > lastPostDate).ToList();

                if (newMessages.Count > 0)
                {
                    DateTime newestMessageDate = newMessages.Max((msg) => msg.Date);
                    bool     buildPosted       = await PostBuilds(newMessages, groupIDs);

                    if (buildPosted)
                    {
                        WriteLastPostedDateTime(cConfigurationFolderPath + cLastPostedBuildDateTimeFilePath, newestMessageDate);
                    }
                }
                client.Logoff();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception in BSLogic.Update(): " + ex.Message);
            }
        }
        public async void Update(Dictionary <string, HashSet <string> > channelIDsForRepositories)
        {
            try
            {
                IMAPClient client = new IMAPClient(imapConfig, null, 5);
                client.Logon();
                IMAPFolder folder = client.Folders[folderName];
                for (int i = 0; i < folder.SubFolders.Count; i++)
                {
                    folder = folder.SubFolders[i];
                    if (folder.FolderName == "Commit_Notifications")
                    {
                        break;
                    }
                }

                List <IMAPMessage> messages        = folder.Messages.OrderByDescending(msg => msg.Date).ToList();
                DateTime           lastPostDate    = ReadLastPostedDateTime(cConfigurationFolderPath + cLastPostedCommitDateTimeFilePath);
                List <IMAPMessage> newImapMessages = messages.TakeWhile((msg) => msg.Date > lastPostDate).ToList();

                if (newImapMessages.Count > 0)
                {
                    newImapMessages.OrderBy(msg => msg.Date).Reverse();
                    HashSet <string> channelIDs = new HashSet <string>(channelIDsForRepositories.Values.SelectMany(c => c).ToList());
                    Dictionary <string, HashSet <string> > commitUidsPostedInChannel = new Dictionary <string, HashSet <string> >();
                    foreach (string channelID in channelIDs)
                    {
                        HashSet <string> commitUids = await getCommitUidsForChannel(channelID);

                        commitUidsPostedInChannel.Add(channelID, commitUids);
                    }

                    foreach (IMAPMessage imapMsg in newImapMessages)
                    {
                        string[] parts          = imapMsg.Subject.Split(':');
                        string   commitToPrefix = "Commit to ";
                        string   repositoryName = "";
                        if (parts[0].Length > commitToPrefix.Length)
                        {
                            repositoryName = parts[0].Substring(commitToPrefix.Length, parts[0].Length - commitToPrefix.Length);
                        }

                        bool             repositoryFound         = false;
                        HashSet <string> channelIDsForRepository = channelIDsForRepositories.TryGetValue(repositoryName, out repositoryFound);
                        if (repositoryFound)
                        {
                            bool postResult = await PostCommitToChannels(imapMsg, channelIDsForRepository, commitUidsPostedInChannel);

                            if (!postResult)
                            {
                                return;
                            }
                        }
                    }
                    DateTime newestMessageDate = newImapMessages.Max((msg) => msg.Date);
                    WriteLastPostedDateTime(cConfigurationFolderPath + cLastPostedCommitDateTimeFilePath, newestMessageDate);
                }
                client.Logoff();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception in CommitLogic.Update(): " + ex.Message);
            }
        }