コード例 #1
0
ファイル: iSpringConverter.cs プロジェクト: pczy/Pub.Class
        public void StartConversion() {
            // if ((m_pptConverter != null) && (m_pptConverter.PresentationOpened))
            //{
                try {
                    LogLine("Initializing");
                    m_pptConverter = new PresentationConverter();

                    // open presentation
                    LogLine("Opening presentation " + m_pptFileName);
                    m_pptConverter.OpenPresentation(m_pptFileName);
                    LogLine("Presentation " + m_pptFileName + " opened successfully");

                    // set up event handlers to display conversion progress
                    m_pptConverter.OnStartProcessingData += new _iSpringEvents_OnStartProcessingDataEventHandler(pptConverter_OnStartProcessingData);
                    m_pptConverter.OnFinishProcessingData += new _iSpringEvents_OnFinishProcessingDataEventHandler(pptConverter_OnFinishProcessingData);
                    m_pptConverter.OnSlideProgressChanged += new _iSpringEvents_OnSlideProgressChangedEventHandler(pptConverter_OnSlideProgressChanged);


                    System.Threading.Thread.Sleep(10);

                    // convert presentation
                    LogLine("Generating SWF file " + m_swfFileName);
                    m_pptConverter.GenerateSolidPresentation(m_swfFileName, null, null);
                    LogLine("SWF File " + m_swfFileName + " generated successfully");
                } catch (Exception e) {
                    Console.WriteLine("Error: " + e.Message);
                }

            //}
        }
コード例 #2
0
        public void StartConversion()
        {
            // if ((m_pptConverter != null) && (m_pptConverter.PresentationOpened))
            //{
            try {
                LogLine("Initializing");
                m_pptConverter = new PresentationConverter();

                // open presentation
                LogLine("Opening presentation " + m_pptFileName);
                m_pptConverter.OpenPresentation(m_pptFileName);
                LogLine("Presentation " + m_pptFileName + " opened successfully");

                // set up event handlers to display conversion progress
                m_pptConverter.OnStartProcessingData  += new _iSpringEvents_OnStartProcessingDataEventHandler(pptConverter_OnStartProcessingData);
                m_pptConverter.OnFinishProcessingData += new _iSpringEvents_OnFinishProcessingDataEventHandler(pptConverter_OnFinishProcessingData);
                m_pptConverter.OnSlideProgressChanged += new _iSpringEvents_OnSlideProgressChangedEventHandler(pptConverter_OnSlideProgressChanged);


                System.Threading.Thread.Sleep(10);

                // convert presentation
                LogLine("Generating SWF file " + m_swfFileName);
                m_pptConverter.GenerateSolidPresentation(m_swfFileName, null, null);
                LogLine("SWF File " + m_swfFileName + " generated successfully");
            } catch (Exception e) {
                Console.WriteLine("Error: " + e.Message);
            }

            //}
        }
コード例 #3
0
        public void UploadPowerPoint(string userId, string companyId, string name, string description, string webPath, string physicalPath, string fileName, byte[] pptFile)
        {
            try
            {
                var company  = unitOfWork.CompanyRepository.GetById(companyId);
                var scormNum = GetNumberOfScorm(companyId) + 1;

                if (company.IsTrial && scormNum > 2)
                {
                    throw new ScormException("You can upload only one scorm file under the trial version");
                }

                //Create powerpoint to html5 converter object.
                PresentationConverter presentationConverter = new PresentationConverter();
                //Initialize library using userName and productKey in case of redistributable license.
                //presentationConverter.InitLibrary("userName", "productKey");


                //Update conversion settings
                presentationConverter.Settings.CreateDirectoryForOutput = false;

                //Output settings
                presentationConverter.Settings.Output.AdvanceOnMouseClick = true;
                presentationConverter.Settings.Output.BackgroundColor     = -16777216;//ARGB of black.
                presentationConverter.Settings.Output.EmbedFonts          = true;
                presentationConverter.Settings.Output.FitToWindow         = true;
                presentationConverter.Settings.Output.IncludeHiddenSlides = true;
                presentationConverter.Settings.Output.WindowScale         = 100;
                presentationConverter.Settings.CreateDirectoryForOutput   = false;

                //For LMS output
                presentationConverter.Settings.Lms             = new LmsSettings();
                presentationConverter.Settings.Lms.LmsType     = LmsType.Scorm2NdEdition2004;
                presentationConverter.Settings.Lms.CourseTitle = name;
                presentationConverter.Settings.Lms.Description = description;

                //For thumbnail generation
                //presentationConverter.Settings.Thumbnail = new ThumbnailSettings();
                //presentationConverter.Settings.Thumbnail.Format = ThumbnailImageFormat.Jpg;
                //presentationConverter.Settings.Thumbnail.Scale = 10;

                //To add company logo
                //presentationConverter.Settings.Logo = new LogoSettings();
                //presentationConverter.Settings.Logo.Left = 10;
                //presentationConverter.Settings.Logo.Top = 10;
                //presentationConverter.Settings.Logo.Width = 200;
                //presentationConverter.Settings.Logo.Height = 100;
                //presentationConverter.Settings.Logo.Hyperlink = "http://www.digitalofficepro.com";
                //presentationConverter.Settings.Logo.ImagePath = @"C:\Users\user\Documents\Logo.png";

                //For custom player
                //presentationConverter.Settings.Player = new PlayerSettings();
                //presentationConverter.Settings.Player.Path =@"C:\Program Files (x86)\DigitalOfficePro\HTML5PointSDK\Players\classic";


                //Save ppt file on temparay directory
                string tempPath   = GetTemporaryDirectory();
                string tempFile   = Path.Combine(tempPath, fileName);
                string randomPath = Path.GetRandomFileName();

                File.WriteAllBytes(tempFile, pptFile);


                //Open persenattion
                presentationConverter.OpenPresentation(tempFile);
                logger.Info("PowerPoint presentation '{0}' is opened.", tempFile);
                string outputHtmlFile = Path.Combine(tempPath, randomPath);
                logger.Debug("SCORM file path: " + outputHtmlFile);
                logger.Debug("SCORM zip file: " + outputHtmlFile + ".zip");

                //HTML5 conversion
                presentationConverter.Convert(outputHtmlFile);

                logger.Info("Converted presentation '{0}' to '{1}'.", tempFile, outputHtmlFile);
                presentationConverter.ClosePresentation();
                logger.Debug("Presentation closed");

                //output file is PowerPoint2Scorm.zip

                // real path to save
                physicalPath = Path.Combine(physicalPath, randomPath);
                webPath      = webPath + "/" + randomPath;
                Directory.CreateDirectory(physicalPath);

                // UNZIP
                using (ZipFile zip = ZipFile.Read(outputHtmlFile + ".zip"))
                {
                    zip.ExtractAll(physicalPath);
                }

                // DELETE
                Directory.Delete(tempPath, true);

                string manifestXml = File.ReadAllText(Path.Combine(physicalPath, "imsmanifest.xml"));

                unitOfWork.ScormRepository.Insert(new Scorm
                {
                    CompanyId    = companyId,
                    Description  = description,
                    Name         = name,
                    PhysicalPath = physicalPath,
                    UpdatedBy    = userId,
                    UpdatedTs    = DateTime.UtcNow,
                    WebPath      = webPath,
                    ManifestXml  = manifestXml
                });

                unitOfWork.SaveChanges();
            }
            catch (Exception ex)
            {
                try
                {
                    Directory.Delete(physicalPath, true);
                }
                catch (Exception)
                {
                }

                logger.Error(ex.ToString());
                throw ex;
            }
        }