public static void Start(string lessonName, int startSlideNum, string voiceName) { Debug.WriteLine("Start lesson" + Directory.GetCurrentDirectory()); GlobalFlowControl.Lesson.ResetAll(); //UpperBodyHelper.MoveRandomlyAllMotors(); RobotActionHelper.MoveDuringLesson(); form2 = new LessonSpeechUI(); form2.ShowForm(); _lessonName = lessonName; QuestionNumber = 0; _thread = new Thread(new ThreadStart(() => { int endSlideNum = FileHelper.GetLessonSlidesNumber(lessonName); string codePath = FileHelper.BasePath + @"\" + lessonName + @"\code.pptx"; progData = PowerpointHelper.GetSlidesData(codePath); for (CurrentSlideNumber = 1; CurrentSlideNumber <= endSlideNum; CurrentSlideNumber++) { if (CurrentSlideNumber < startSlideNum) { RobotProgSlide _currentProgSlide = progData[CurrentSlideNumber - 1]; var commands = _currentProgSlide.Commands; foreach (var cmd in commands) { if (cmd.Type.ToLower() == "start" && cmd.Value.ToLower() == "quiz") { QuestionNumber++; } } } else { while (LessonHelper.PauseRequested) { Thread.Sleep(1000); // Remove busy waiting overloading } Debug.WriteLine("Current Slide -----------" + CurrentSlideNumber); LessonStatusHelper.Update(lessonName, CurrentSlideNumber, "started", null, null, null); RobotProgSlide _currentProgSlide = progData[CurrentSlideNumber - 1]; _robotCommands = new RobotCommands(_currentProgSlide.Commands); _robotCommands.OnCommandUpdate += _robotCommands_OnCommandUpdate; _robotCommands.Execute(); } } OnLessonEnded(); })); _thread.Start(); }
public static List <RobotProgSlide> GetSlidesData(string filePath) { if (string.IsNullOrEmpty(filePath)) { MessageBox.Show("Please provide a file path"); return(null); } if (!File.Exists(filePath)) { MessageBox.Show($"Could not find file: {filePath}"); return(null); } if (!filePath.Contains(".ppt")) { MessageBox.Show("Please select a valid PowerPoint file (.ppt or .pptx)"); return(null); } var robotSlides = new List <RobotProgSlide>(); var pptApplication = new PowerPoint.Application(); var pptPresentations = pptApplication.Presentations; var pptPresentation = pptPresentations.Open(filePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); var slides = pptPresentation.Slides; if (slides != null) { var slidesCount = slides.Count; if (slidesCount > 0) { for (int slideIndex = 1; slideIndex <= slidesCount; slideIndex++) { var slide = slides[slideIndex]; var robotSlide = new RobotProgSlide(); string robotCode = null; foreach (PowerPoint.Shape textShape in slide.Shapes) { if (textShape.HasTextFrame == MsoTriState.msoTrue && textShape.TextFrame.HasText == MsoTriState.msoTrue) { PowerPoint.TextRange pptTextRange = textShape.TextFrame.TextRange; if (pptTextRange != null && pptTextRange.Length > 0) { robotCode += pptTextRange.Text; Marshal.ReleaseComObject(pptTextRange); } } else if (textShape.Type == MsoShapeType.msoPicture) { string pathString = Application.StartupPath + @"\TempData"; if (!File.Exists(pathString)) { Directory.CreateDirectory(pathString); } string file = pathString + $@"\Image{slideIndex.ToString()}.png"; object[] x = new object[] { file, PowerPoint.PpShapeFormat.ppShapeFormatJPG, 0, 0, PowerPoint.PpExportMode.ppScaleXY }; textShape.GetType().InvokeMember("Export", System.Reflection.BindingFlags.InvokeMethod, null, textShape, x); robotSlide.Image = Image.FromFile(file); } Marshal.ReleaseComObject(textShape); } robotCode = robotCode.Replace("\x0B", String.Empty); robotCode = robotCode.Replace("\x11", String.Empty); robotCode = robotCode.Replace("\r", String.Empty); robotCode = robotCode.Replace("\n", String.Empty); robotSlide.Code = robotCode; robotSlides.Add(robotSlide); } } } ClosePpt(pptApplication, pptPresentation); return(robotSlides); }