private void BckgBatch_DoWork(object sender, DoWorkEventArgs e) { int totalNumOfFiles = lstBatchHandbookFiles.Items.Count; for (int i = 1; i <= totalNumOfFiles; i++) { try { AddToLog("Start Batch Handbook conversion. File "+i.ToString()+"/"+totalNumOfFiles.ToString()); this.Invoke(new MethodInvoker(delegate { UpdateBatchLabel("("+i.ToString() + "/" + totalNumOfFiles.ToString()+") Exporting slides (this may take a while)..."); })); bckgBatch.ReportProgress(0); HandbookPPT hbPPT = new HandbookPPT(); string pptFileName = lstBatchHandbookFiles.Items[i - 1].ToString(); AddToLog("Start exporting slides from: " + pptFileName); string exportSlidesRetVal = hbPPT.ExportSlides(pptFileName, bckgBatch); bckgBatch.ReportProgress(33); this.Invoke(new MethodInvoker(delegate { UpdateBatchLabel("(" + i.ToString() + "/" + totalNumOfFiles.ToString() + ") Creating the handbook..."); })); HandbookDoc hbDOC = new HandbookDoc(); string docFileName=""; docFileName = Path.GetDirectoryName(pptFileName) + "\\" + Path.GetFileNameWithoutExtension(pptFileName) + ".docx"; bool instructorGuide = chkHandbookInstructorGuide.Checked; bool goSamePage = chkBatchHandbookGoalObjSamePage.Checked; AddToLog("Start creating handbook document: " + docFileName); hbDOC.CreateDocument(pptFileName, bckgBatch, docFileName, instructorGuide, goSamePage); bckgBatch.ReportProgress(100); AddToLog("Handbook conversion finished."); if (chkHandbookDeletePictures.Checked) { string folderName = Path.GetDirectoryName(pptFileName) + "\\" + Path.GetFileNameWithoutExtension(pptFileName); AddToLog("Deleting slide pictures folder: " + folderName); Directory.Delete(folderName, true); } } catch (Exception ex) { AddToLog("Problem in handbook conversion: " + ex.Message); MessageBox.Show("There was a problem with handbook conversion." + ex.Message); } } }
private void BckgHandbook_DoWork(object sender, DoWorkEventArgs e) { try { AddToLog("Start Handbook conversion."); this.Invoke(new MethodInvoker(delegate { UpdateHandbookLabel("Exporting slides (this may take a while)..."); })); bckgHandbook.ReportProgress(0); HandbookPPT hbPPT = new HandbookPPT(); string pptFileName = txtHandbookFile.Text; AddToLog("Start exporting slides from: " + pptFileName); string exportSlidesRetVal = hbPPT.ExportSlides(pptFileName, bckgHandbook); bckgHandbook.ReportProgress(33); this.Invoke(new MethodInvoker(delegate { UpdateHandbookLabel("Creating the handbook..."); })); HandbookDoc hbDOC = new HandbookDoc(); string docFileName = txtHandbookSaveLocation.Text; bool instructorGuide = chkHandbookInstructorGuide.Checked; bool goSamePage = chkGoalObjSamePage.Checked; AddToLog("Start creating handbook document: " + docFileName); hbDOC.CreateDocument(pptFileName, bckgHandbook, docFileName, instructorGuide, goSamePage); bckgHandbook.ReportProgress(100); AddToLog("Handbook conversion finished."); if (chkHandbookDeletePictures.Checked) { string folderName = Path.GetDirectoryName(pptFileName) + "\\" + Path.GetFileNameWithoutExtension(pptFileName); AddToLog("Deleting slide pictures folder: " + folderName); Directory.Delete(folderName, true); } } catch(Exception ex) { AddToLog("Problem in handbook conversion: " + ex.Message); MessageBox.Show("There was a problem with handbook conversion." + ex.Message); } }
public void CreateDocument(string pptName, BackgroundWorker bckgWorker, string saveName, bool InstructorGuide, bool GoalsObjectivesSamePage) { PresentationDocument presentationDocument = null; WordprocessingDocument wordprocessingDocument = null; int i = 1; try { string templateFile = Environment.CurrentDirectory + "\\Templates\\StudentHandbookTemplate.docx"; if(InstructorGuide) { templateFile = Environment.CurrentDirectory + "\\Templates\\InstructorGuideTemplate.docx"; } File.Copy(templateFile, saveName, true); string savePath = Path.GetDirectoryName(pptName) + "\\" + Path.GetFileNameWithoutExtension(pptName); presentationDocument = PresentationDocument.Open(pptName, true); wordprocessingDocument = WordprocessingDocument.Open(saveName, true); string[] fileEntries = Directory.GetFiles(savePath); HandbookPPT hbp = new HandbookPPT(); int counter = 0; foreach (string fileName in fileEntries) { counter++; float progress = (((float)counter / fileEntries.Length) / 2) * 100; bckgWorker.ReportProgress(33 + (int)progress); int a = fileName.IndexOf("Slide"); string tempString = fileName.Substring(0, a) + "Slide" + i.ToString() + ".png"; int hbSlideYesNo = GetHBSlideStatus(presentationDocument, i - 1); string slideLayoutName = GetSlideLayoutName(presentationDocument, i - 1); if (((hbp.SlideVisibile(presentationDocument, i-1) == true && hbSlideYesNo==0) || hbSlideYesNo==1) && (hbSlideYesNo!=2)) { //if (i == 2) // AddSectionBreak(true, wordprocessingDocument); bool samePage = false; bool addNotes = true; bool twoSlidesOnOnePage = false; if (GoalsObjectivesSamePage) { if (slideLayoutName == Properties.Settings.Default.LESSON_GOAL_SLIDE) { samePage = true; addNotes = false; twoSlidesOnOnePage = true; } if (slideLayoutName == Properties.Settings.Default.LESSON_OBJECTIVES_SLIDE) { addNotes = false; twoSlidesOnOnePage = true; } } InsertAPicture(wordprocessingDocument, tempString, twoSlidesOnOnePage); if (addNotes) { NotesInSlideToWord(presentationDocument, i - 1, wordprocessingDocument, InstructorGuide); } //if (i == 2) // AddSectionBreak(false, wordprocessingDocument); if (i < fileEntries.Length && !samePage) { InsertPageBreak(wordprocessingDocument); } } i++; } bckgWorker.ReportProgress(85); } catch (Exception ex) { AddToLog("Problem with creating handbook document. " + ex.Message + Environment.NewLine + "Slide: " + i.ToString()); MessageBox.Show("Problem with creating handbook document. " + ex.Message + Environment.NewLine + "Slide: " + i.ToString()); } finally { presentationDocument.Close(); wordprocessingDocument.Close(); bckgWorker.ReportProgress(95); } }