예제 #1
0
        /// <summary>
        /// Выложить картинки на FTP
        /// </summary>
        /// <param name="presInfo">Информация о презентации</param>
        public void UploadImages(PresentationInfo presInfo)
        {
            if (presInfo == null)
            {
                throw new ArgumentNullException("presentation info is not set");
            }

            for (int index = 0; index < presInfo.SlidersInfo.Count; index++)
            {
                SlideInfo slideInfo = presInfo.SlidersInfo[index];

                //if (!String.IsNullOrEmpty(slideInfo.ImageNameServerSmall))
                //{
                //  UploadImage(slideInfo.ImageNameClientSmall, String.Format("{0}/{1}", SmallImageServerDir, slideInfo.ImageNameServerSmall));
                //}

                CreateFtpFolder(Path.Combine(_UploadImagesBaseDir, FilesServerDir, presInfo.DbId.ToString()));

                if (!String.IsNullOrEmpty(slideInfo.ImageNameClientAverage))
                {
                    CreateFtpFolder(Path.Combine(_UploadImagesBaseDir, FilesServerDir, presInfo.DbId.ToString(), "268"));
                    UploadImage(
                        Path.Combine(SlideInfo.GetLocalImageDirectoryAbsolutePath(presInfo.DbId, "268"), slideInfo.ImageNameClientAverage),
                        String.Format("{0}/{1}/268/{2}", FilesServerDir, presInfo.DbId, slideInfo.ImageNameClientAverage));
                }

                if (!String.IsNullOrEmpty(slideInfo.ImageNameClientBig))
                {
                    CreateFtpFolder(Path.Combine(_UploadImagesBaseDir, FilesServerDir, presInfo.DbId.ToString(), "653"));
                    UploadImage(
                        Path.Combine(SlideInfo.GetLocalImageDirectoryAbsolutePath(presInfo.DbId, "653"), slideInfo.ImageNameClientBig),
                        String.Format("{0}/{1}/653/{2}", FilesServerDir, presInfo.DbId, slideInfo.ImageNameClientBig));
                }

                if (UploadImageCompleteCallback != null)
                {
                    UploadImageCompleteCallback(this, new UploadImageCompliteInfo {
                        TotalImagesCount = presInfo.SlidersInfo.Count, CurrentImageNumber = index + 1
                    });
                }
            }

            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(String.Format("ftp://{0}/{1}/{2}/{3}",
                                                                                       _FTPHost,
                                                                                       Path.Combine(_UploadImagesBaseDir, FilesServerDir),
                                                                                       presInfo.DbId,
                                                                                       presInfo.UrlNews + ".zip"));

                request.UseBinary   = true;
                request.Method      = WebRequestMethods.Ftp.UploadFile;
                request.Credentials = new NetworkCredential(_UserName, _UserPassword);

                Stream requestStream = request.GetRequestStream();

                using (FileStream sourse = new FileStream(presInfo.ZipPresentationAbsoluteLocation, FileMode.Open))
                {
                    int    count  = 0;
                    int    lenght = 0;
                    byte[] buffer = new byte[4096];
                    while ((count = sourse.Read(buffer, 0, 4096)) != 0)
                    {
                        lenght += count;

                        if (OnUploadPresentationBlockCallbak != null)
                        {
                            OnUploadPresentationBlockCallbak(this, new UploadPresentationBlockInfo {
                                PercentProgress = (int)(lenght * 100 / sourse.Length)
                            });
                        }

                        requestStream.Write(buffer, 0, count);
                    }

                    requestStream.Close();
                }

                File.Delete(presInfo.ZipPresentationAbsoluteLocation);
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Во время загрузки файла с презентацией {0} на сервер, возникла ошибка: {1}", presInfo.ServerFileName, ex.Message));
            }
        }
예제 #2
0
        /// <summary>
        /// Получить текст презентации
        /// </summary>
        /// <returns>Текст</returns>
        public PresentationInfo ParsePreesentation()
        {
            for (int i = 0; i < _Presentation.Slides.Count; i++)
            {
                SlideInfo slideInfo = new SlideInfo(_PresentationInfo)
                {
                    SlideNumber = i + 1
                };
                _PresentationInfo.SlidersInfo.Add(slideInfo);

                foreach (var shape in _Presentation.Slides[i + 1].Shapes.Cast <Microsoft.Office.Interop.PowerPoint.Shape>())
                {
                    if (shape.HasTextFrame == MsoTriState.msoTrue && shape.TextFrame.HasText == MsoTriState.msoTrue)
                    {
                        slideInfo.Text += shape.TextFrame.TextRange.Text + "<br/>";
                    }

                    if (shape.HasTable == MsoTriState.msoTrue)
                    {
                        for (int rowNum = 1; rowNum <= shape.Table.Rows.Count; rowNum++)
                        {
                            bool isNeedBrBetweenRows = false;

                            for (int cellNum = 1; cellNum <= shape.Table.Columns.Count; cellNum++)
                            {
                                var cell = shape.Table.Cell(rowNum, cellNum);

                                if (cell.Shape.HasTextFrame == MsoTriState.msoTrue && cell.Shape.TextFrame.HasText == MsoTriState.msoTrue)
                                {
                                    slideInfo.Text     += cell.Shape.TextFrame.TextRange.Text + " ";
                                    isNeedBrBetweenRows = true;
                                }
                            }

                            if (isNeedBrBetweenRows)
                            {
                                slideInfo.Text += "<br/>";
                            }
                        }
                    }
                }

                if (i == 0)
                {
                    string slideImageNameSmall = Guid.NewGuid().ToString() + "_195x146" + ".jpg";
                    // Уже не нужно
                    //_Presentation.Slides[i + 1].Export(Path.Combine(slidePath, slideImageNameSmall), "JPG", 195, 146);
                    slideInfo.ImageNameClientSmall = slideImageNameSmall;
                }

                {
                    string slideImageNameAverage = (i + 1).ToString() + ".jpg";
                    string slidePath             = SlideInfo.GetLocalImageDirectoryAbsolutePath(_PresentationInfo.DbId, "268");

                    if (!Directory.Exists(slidePath))
                    {
                        Directory.CreateDirectory(slidePath);
                    }

                    _Presentation.Slides[i + 1].Export(Path.Combine(slidePath, slideImageNameAverage), "JPG", 268, 200);
                    slideInfo.ImageNameClientAverage = slideImageNameAverage;
                }

                {
                    string slideImageNameBig = (i + 1).ToString() + ".jpg";
                    string slidePath         = SlideInfo.GetLocalImageDirectoryAbsolutePath(_PresentationInfo.DbId, "653");

                    if (!Directory.Exists(slidePath))
                    {
                        Directory.CreateDirectory(slidePath);
                    }

                    _Presentation.Slides[i + 1].Export(Path.Combine(slidePath, slideImageNameBig), "JPG", 653, 490);
                    slideInfo.ImageNameClientBig = slideImageNameBig;
                }

                ParseSlideComplite(this, new SlideCompleteParsingInfo {
                    SlideCurrentNumber = slideInfo.SlideNumber, SlideTotalNumber = _Presentation.Slides.Count
                });
            }

            return(_PresentationInfo);
        }
    /// <summary>
    /// Получить текст презентации
    /// </summary>
    /// <returns>Текст</returns>
    public PresentationInfo ParsePreesentation()
    {
      for (int i = 0; i < _Presentation.Slides.Count; i++)
      {
        SlideInfo slideInfo = new SlideInfo(_PresentationInfo) { SlideNumber = i + 1 };
        _PresentationInfo.SlidersInfo.Add(slideInfo);

        foreach (var shape in _Presentation.Slides[i + 1].Shapes.Cast<Microsoft.Office.Interop.PowerPoint.Shape>())
        {
          if (shape.HasTextFrame == MsoTriState.msoTrue && shape.TextFrame.HasText == MsoTriState.msoTrue)
            slideInfo.Text += shape.TextFrame.TextRange.Text + "<br/>";

          if (shape.HasTable == MsoTriState.msoTrue)
          {
            for (int rowNum = 1; rowNum <= shape.Table.Rows.Count; rowNum++)
            {
              bool isNeedBrBetweenRows = false;

              for (int cellNum = 1; cellNum <= shape.Table.Columns.Count; cellNum++)
              {
                var cell = shape.Table.Cell(rowNum, cellNum);

                if (cell.Shape.HasTextFrame == MsoTriState.msoTrue && cell.Shape.TextFrame.HasText == MsoTriState.msoTrue)
                {
                  slideInfo.Text += cell.Shape.TextFrame.TextRange.Text + " ";
                  isNeedBrBetweenRows = true;
                }
              }

              if (isNeedBrBetweenRows)
                slideInfo.Text += "<br/>";
            }
          }
        }

        if (i == 0)
        {
          string slideImageNameSmall = Guid.NewGuid().ToString() + "_195x146" + ".jpg";
          // Уже не нужно
          //_Presentation.Slides[i + 1].Export(Path.Combine(slidePath, slideImageNameSmall), "JPG", 195, 146);
          slideInfo.ImageNameClientSmall = slideImageNameSmall;
        }

        {
          string slideImageNameAverage = (i + 1).ToString() + ".jpg";
          string slidePath = SlideInfo.GetLocalImageDirectoryAbsolutePath(_PresentationInfo.DbId, "268");

          if (!Directory.Exists(slidePath))
            Directory.CreateDirectory(slidePath);

          _Presentation.Slides[i + 1].Export(Path.Combine(slidePath, slideImageNameAverage), "JPG", 268, 200);
          slideInfo.ImageNameClientAverage = slideImageNameAverage;
        }

        {
          string slideImageNameBig = (i + 1).ToString() + ".jpg";
          string slidePath = SlideInfo.GetLocalImageDirectoryAbsolutePath(_PresentationInfo.DbId, "653");

          if (!Directory.Exists(slidePath))
            Directory.CreateDirectory(slidePath);

          _Presentation.Slides[i + 1].Export(Path.Combine(slidePath, slideImageNameBig), "JPG", 653, 490);
          slideInfo.ImageNameClientBig = slideImageNameBig;
        }

        ParseSlideComplite(this, new SlideCompleteParsingInfo { SlideCurrentNumber = slideInfo.SlideNumber, SlideTotalNumber = _Presentation.Slides.Count });
      }

      return _PresentationInfo;
    }