Ejemplo n.º 1
0
        public static async Task Monitor()
        {
            System.Timers.Timer t = new System.Timers.Timer();
            t.AutoReset = false;
            t.Interval  = 10 * 1000;

            try
            {
                if (members == null)
                {
                    members = await MessagesController.GetConverationMembers();
                }

                Console.WriteLine("-------------\n STARTED: INGESTING USER MESSAGES \n-------------");

                foreach (var member in members)
                {
                    List <Message> userMessages = await APIService.GetInitialMessageDeltasForUser(member.ObjectId);

                    Storage.userMessages.Add(member.ObjectId, userMessages);
                    await IngestMessagesForUser(member.ObjectId);
                }

                Console.WriteLine("-------------\n DONE: INGESTING USER MESSAGES \n-------------");

                t.Elapsed += async delegate
                {
                    try
                    {
                        await PollForUserMessages();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"ERROR IN TIMER THREAD: {e.Message}");
                        Console.WriteLine($"ERROR IN TIMER THREAD: {e.StackTrace}");
                    }
                    finally
                    {
                        t.Start();
                    }
                };
                t.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine($"ERROR IN BACKGROUND THREAD-0: {e.Message}");
                Console.WriteLine($"ERROR IN BACKGROUND THREAD-0: {e.StackTrace}");
            }
        }
Ejemplo n.º 2
0
        public async static Task <bool> IngestMessagesForUser(string userId)
        {
            var tasks = new List <Task>();

            foreach (Message entry in Storage.userMessages[userId])
            {
                //if (entry.BodyPreview.Contains(Resources.ResourceManager.GetString("DLPPhrase")))
                if (SimpleDLP.containsRestrictedPhrases(entry.BodyPreview))
                {
                    if (members == null)
                    {
                        members = await MessagesController.GetConverationMembers();
                    }
                    foreach (var member in members)
                    {
                        if (member.ObjectId == userId && entry.Sender.EmailAddress.Name != "Clarence")
                        {
                            Console.WriteLine("-------------\nFOUND ISSUE\n-------------");
                            string recipientsEmails = string.Empty;
                            foreach (var rep in entry.ToRecipients)
                            {
                                recipientsEmails += $"{rep.EmailAddress.Address},";
                            }
                            tasks.Add(SendComplianceMsgAsync(member, entry.BodyPreview, entry.Sender.EmailAddress.Address, recipientsEmails));
                            break;
                        }
                    }
                }

                ///message user once
                if (tasks.Count > 0)
                {
                    break;
                }
            }
            await Task.WhenAll(tasks);

            return(true);
        }