public addressListViewModel(AddressList a) : base(a)
        {
            _showOnlyGroupsFilter = false;

            var query = from AddressEntry e in _entity.AddressEntries
                        select e;

            entries = new ObservableCollection <AddressEntry>(query);

            _view        = CollectionViewSource.GetDefaultView(entries);
            _view.Filter = delegate(object obj)
            {
                AddressEntry e       = (AddressEntry)obj;
                bool         isShown = String.IsNullOrEmpty(_nameFilter) ? true : e.Name.Contains(_nameFilter);
                isShown &= (_showOnlyGroupsFilter == OutlookProvider.isGroup(e));
                return(isShown);
            };

            _view.CurrentChanged += delegate
            {
                RaisePropertyChanged("selectedPersonCollection");
                RaisePropertyChanged("selectedTeacher");
                RaisePropertyChanged("selectedSeat");
                RaisePropertyChanged("selectedSeatGroup");
            };
        }
Пример #2
0
        //opens DeadlineQuestionsWindow and hooks up events
        public SeatResponseWorker(MailItem mi, SchoolContext paramDb)
        {
            SchoolContext _db = paramDb;

            if (mi != null)
            {
                PDF _pdfAssignment = OutlookProvider.getAssignmentsFromMailItem(mi).FirstOrDefault();
                if (_pdfAssignment != null)
                {
                    Course             course              = _db.getCourse(_pdfAssignment, true);
                    Assignment         _assignment         = _db.getAssignment(_pdfAssignment, course, false);
                    List <OutlookSeat> senderAndRecipients = new List <OutlookSeat>();
                    senderAndRecipients.AddRange(OutlookSeat.getEmailNames(mi.Recipients));
                    if (mi.Sender != null)
                    {
                        senderAndRecipients.AddRange(OutlookSeat.getEmailNames(mi.Sender));
                    }

                    if (_assignment != null)
                    {
                        foreach (OutlookSeat en in senderAndRecipients)
                        {
                            Seat _Seat = _db.getSeat(en, null, false, true);
                            if (_Seat != null)
                            {
                                _deadline = _db.DeadlinesOfSeatAssignment(_Seat, _assignment).LastOrDefault();
                                if (_deadline != null)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            DeadlineQuestionsWindow dqw = new DeadlineQuestionsWindow(_db);

            if (_deadline != null)
            {
                TopViewModel top = dqw.DataContext as TopViewModel;
                top.TCSs.selectedEntity = _deadline.TCS;
                top.TCSs.selectedViewModel.deadlines.selectedEntity = _deadline;
            }

            dqw.Closed += dqw_Closed;
            dqw.Show();
        }
Пример #3
0
        //after Seat emails are sent, this deals with the master email.
        //It cannot be moved while sending.
        //masterEmail.Move(OutlookProvider.AssignedWorkSubfolder());
        //masterEmail.Close(OlInspectorClose.olDiscard);
        //Timer delayedCloseTimer;
        //bool sending = false;
        //void setDelayedCloseTimer(MailItem mi, MAPIFolder moveToFolder)
        //{
        //    if (delayedCloseTimer == null)
        //        delayedCloseTimer = new Timer();
        //    delayedCloseTimer.Interval = 100; // 0.1 second
        //    delayedCloseTimer.Tick += (sender, e) =>
        //        {
        //            if (!sending && mi != null)
        //            {
        //                //rename the attachments
        //                //List<string> tempAttachments = new List<string>();
        //                //for (int a = 1; a < mi.Attachments.Count + 1; a++)
        //                //{
        //                //    tempAttachments.Add(OutlookProvider.renameAttachment(mi.Attachments[1], mi.Subject));
        //                //    mi.Attachments.Remove(1);
        //                //}
        //                //foreach (string a in tempAttachments)
        //                //    mi.Attachments.Add(a);

        //                //label the subject
        //                //mi.Subject = "***TEACHER COPY*** " + mi.Subject;

        //                //copy to new folder
        //                //if (moveToFolder != null)
        //                //    mi.Save();
        //                    //mi.Move(moveToFolder); //CRASHES

        //                //mi.Close(OlInspectorClose.olDiscard);


        //                delayedCloseTimer.Stop();
        //                mi = null;
        //                delayedCloseTimer = null;
        //            }
        //        };
        //    delayedCloseTimer.Start();
        //}

        //assign on item send
        void Application_ItemSend(object Item, ref bool Cancel)
        {
            //sending = true;
            MailItem mail = Item as MailItem;

            if (!Settings.Default.ItemSendEventEnabled ||
                mail == null ||
                OutlookProvider.getMarkedWorkProperty(mail))
            {
                return;
            }

            //GET PDF
            byte[] bytes = OutlookProvider.getAllPDFAttachments(mail).FirstOrDefault();

            if (bytes == null)
            {
                return; //just a normal email message!
            }
            //System.Windows.MessageBox.Show("no attachments", "", MessageBoxButton.OK, MessageBoxImage.Error);

            AuthoredWork work = new PDF(bytes).getWork <AuthoredWork>();

            if (work == null)
            {
                Cancel = false;
                //System.Windows.MessageBox.Show("unable to read attached PDF ", "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var e    = mail.Recipients.GetEnumerator();
            var list = new List <Recipient>();

            while (e.MoveNext())
            {
                list.Add((Recipient)e.Current);
            }

            if (list.Count > 1)
            {
                Cancel = System.Windows.MessageBox.Show("you can only assign work to a single recipient. Would you like to send this email anyway? Any returned pdfs will NOT be markable.", "!", MessageBoxButton.YesNo) == MessageBoxResult.No;
                return;
            }
            if (!OutlookProvider.isGroup(list[0].AddressEntry))
            {
                Cancel = System.Windows.MessageBox.Show("you can only assign work to a distribution list. Would you like to send this email anyway? Any returned pdfs will NOT be markable.", "!", MessageBoxButton.YesNo) == MessageBoxResult.No;
                return;
            }
            IEnumerable <OutlookSeat> recipients = OutlookProvider.getSeats(mail.Recipients);


            string             groupName = mail.To.Split(new[] { ';' })[0];
            Group              group     = activeDb.getOrCreateGroup(groupName);
            IEnumerable <Seat> seats     = activeDb.getOrCreateOutlookSeats(recipients, group);

            if (group == null)
            {
                Cancel = System.Windows.MessageBox.Show("Error creating class. Would you like to send this email anyway? Any returned pdfs will NOT be markable.", "", MessageBoxButton.YesNo) == MessageBoxResult.No;
                return;
            }
            if (!work.assignmentHTML.QuestionAssignmentHTMLs.Any())
            {
                Cancel = System.Windows.MessageBox.Show("This assignment does not contain any questions and will not be saved in the markbook. Would you like to send this email anyway? Any returned pdfs will NOT be markable.", "", MessageBoxButton.YesNo) == MessageBoxResult.No;
                return;
            }

            MAPIFolder assignedWorkFolder = OutlookProvider.AssignedWorkSubfolder(groupName);

            var tasks = new List <Task>();

            //EMAILS PARALLEL!
            foreach (Grouping <Attempt, Seat> attemptGroup in activeDb.getNewAttemptsFromAuthoredWork(
                         group,
                         mail.Subject,
                         Properties.Settings.Default.shuffleQuestionsEnabled,
                         Properties.Settings.Default.markLimitValue,
                         seats,
                         work._repeatedRows))
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    AssignedWork assignedWork = new AssignedWork(
                        attemptGroup.Key.GroupID,
                        attemptGroup.Key.AssignmentNum,
                        attemptGroup.Key.ShuffleSeed,
                        OutlookProvider.currentUserEmailAddress
                        );

                    AttemptHTML html    = new AttemptHTML(attemptGroup.Key);
                    string fileToAttach = html.AttemptPDFTempFile(SimplerAES.asEncryptedString(assignedWork), false);

                    MailItem emailForSeat;
                    emailForSeat = (MailItem)this.Application.CreateItem(OlItemType.olMailItem);
                    emailForSeat.SaveSentMessageFolder = assignedWorkFolder;

                    if (!string.IsNullOrEmpty(fileToAttach))
                    {
                        emailForSeat.Attachments.Add(fileToAttach);
                    }

                    emailForSeat.To       = string.Empty;
                    emailForSeat.BCC      = string.Join(";", attemptGroup.Select(s => s.Email));
                    emailForSeat.Subject  = mail.Subject;
                    emailForSeat.HTMLBody = mail.HTMLBody + Settings.Default.AssignEmailFooter;
                    emailForSeat.Send();
                }));
            } //end foreach

            Task.WaitAll(tasks.ToArray());

            Cancel = true;
            //sending = false;
            activeDb.SaveChanges();
            System.Windows.MessageBox.Show("Emails have been sent to students. You can close this window.", "", MessageBoxButton.OK);
        }
Пример #4
0
        public static void mark(IEnumerable <MailItem> mailItems)
        {
            foreach (MailItem mail in mailItems)
            {
#if DEBUG
                InputBox box = new InputBox("enter sender email address");
                box.ShowDialog();
                string senderEmail = box.text;
#else
                string senderEmail = OutlookProvider.getSeats(mail.Sender).FirstOrDefault().Email;
#endif
                Func <IEnumerable <Seat>, Seat> studentPickerMethod = (IEnumerable <Seat> paramSeats) =>
                {
                    //student picker method

                    SeatGivenAssignmentPickerViewModel svm  = new SeatGivenAssignmentPickerViewModel(paramSeats, senderEmail);
                    SeatGivenAssignmentPickerWindow    svmw = new SeatGivenAssignmentPickerWindow(svm);
                    svmw.ShowDialog();

                    if (!svm.cancelmarking)
                    {
                        if (svm.addToAlternateEmail)
                        {
                            svm.selectedSeatVM._entity.AlternateEmail = senderEmail;
                        }
                        return(svm.selectedSeatVM._entity);
                    }
                    return(null);
                };


                List <byte[]> bytes = OutlookProvider.getAllPDFAttachments(mail);

                IEnumerable <PDF> PDFs = bytes.Select(b => new PDF(b)).Where(c => c.reader != null);

                List <CompletedWork> works = new List <CompletedWork>();
                foreach (PDF pdf in PDFs)
                {
                    if (pdf.isFlattened)
                    {
                        if (MessageBox.Show("This PDF has been flattened and cannot be marked. Would you like to send an automated email explaining this to the student?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                            MailItem replyEmail = mail.Reply();
                            replyEmail.HTMLBody = "<p>The PDF you just sent could not be marked because you chose the 'send flattened' option when saving it. Please choose 'send original' next time and then I should be able to  mark it. Thanks.</p><br>";
                            replyEmail.Send();
                        }
                        continue;
                    }

                    AssignedWork aw = pdf.getWork <AssignedWork>();
                    if (aw != null)
                    {
                        works.Add(new CompletedWork(aw,
                                                    pdf.fields,
                                                    Globals.ThisAddIn.activeDb,
                                                    OutlookProvider.currentUserEmailAddress,
                                                    studentPickerMethod,
                                                    senderEmail,
                                                    mail.ReceivedTime));
                    }

                    AuthoredWork auth = pdf.getWork <AuthoredWork>();
                    if (auth != null)
                    {
                        MessageBox.Show("This pdf was sent without creating a record in the database. Maybe when AME was turned off.");
                    }
                }

                //if not a single pdf attachment could actually be marked then...
                if (!works.Any())
                {
                    System.Windows.MessageBox.Show("Could not find a filled PDF within the email attachments", "?", MessageBoxButton.OK);
                }

                foreach (CompletedWork work in works)
                {
                    if (!string.IsNullOrEmpty(work.errorMessage))
                    {
                        System.Windows.MessageBox.Show(work.errorMessage);
                        continue;
                    }
                    if (work.earMarkTest == CompletedWork.EarMarkResult.fraud &&
                        System.Windows.MessageBox.Show(string.Format(@"{0} {1} has not sent back the original pdf, but one forwarded from another student. Would you like to continue marking",
                                                                     work.sender.FirstName,
                                                                     work.sender.LastName), "!", MessageBoxButton.YesNo) == MessageBoxResult.No)
                    {
                        continue;
                    }
                    //end marking, send email back saying not his work


                    if (!Globals.Ribbons.Ribbon1.automatedMarkSend)
                    {
                        CompletedWorkViewModel vm = new CompletedWorkViewModel(work,
                                                                               () =>
                        {
                            Globals.ThisAddIn.activeDb.SaveChanges();

                            //UPDATE GRIDS
                            Globals.ThisAddIn.fireResponsesMarked(work.changedResponses);

                            //FEEDBACK EMAIL
                            MailItem replyEmail = (MailItem)Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem);    //mail.Reply;
                            replyEmail.Subject  = "feedback for " + work.assignment.Name;
                            replyEmail.HTMLBody = work.attemptHTML.feedbackEmailBody;
                            replyEmail.To       = work.sender.Email;

                            string PDFFile = work.PDFTempFile();
                            if (!string.IsNullOrEmpty(PDFFile))
                            {
                                replyEmail.Attachments.Add(PDFFile);
                            }
                            replyEmail.DeleteAfterSubmit = true;

                            OutlookProvider.setMarkedWorkProperty(replyEmail);

                            replyEmail.Display();

                            if (Properties.Settings.Default.deleteMarkedEmails)
                            {
                                mail.Delete();
                            }
                        }

                                                                               );
                        MarkAssignmentWindow maw = new MarkAssignmentWindow(vm);
                        maw.Show();
                    }
                    else //auto mark
                    {
                        Globals.ThisAddIn.activeDb.SaveChanges();
                        //UPDATE GRIDS
                        Globals.ThisAddIn.fireResponsesMarked(work.changedResponses);

                        MailItem replyEmail = (MailItem)Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem);//mail.Reply;
                        replyEmail.Subject  = "feedback on " + work.assignment.Name;
                        replyEmail.HTMLBody = work.attemptHTML.feedbackEmailBody;
                        replyEmail.To       = work.sender.Email;

                        string PDFFile = work.PDFTempFile();
                        if (!string.IsNullOrEmpty(PDFFile))
                        {
                            replyEmail.Attachments.Add(PDFFile);
                        }
                        replyEmail.DeleteAfterSubmit = true;

                        OutlookProvider.setMarkedWorkProperty(replyEmail);

#if DEBUG
                        replyEmail.Display();
#else
                        replyEmail.Send();
#endif

                        if (Properties.Settings.Default.deleteMarkedEmails)
                        {
                            mail.Delete();
                        }
                    }
                }
            }
        }