public void UpdateSizeInfo()
		{
			using (var powerPointProcesor = new PowerPointHidden())
			{
				if (!powerPointProcesor.Connect(true)) return;
				UpdateSizeInfo(powerPointProcesor);
			}
		}
		private void barButtonItemPrintLink_ItemClick(object sender, ItemClickEventArgs e)
		{
			using (var powerPointProcessor = new PowerPointHidden())
			{
				if (!powerPointProcessor.Connect(true)) return;
				powerPointProcessor.PrintPresentation(
					_viewedFile.FullName,
					comboBoxEditSlides.SelectedIndex + 1,
					printAction => MainController.Instance.ProcessManager.Run(
						"Printing...",
						cancellationToken => printAction()));

			}
		}
		public void Print()
		{
			using (var powerPointProcessor = new PowerPointHidden())
			{
				if (!powerPointProcessor.Connect(true)) return;
				powerPointProcessor.PrintPresentation(
					_tempCopy.FullName,
					SelectedThumbnail.Index,
					printAction => MainController.Instance.ProcessManager.Run(
						"Printing...",
						cancellationToken => printAction()));
			}
		}
		private void buttonXRefreshPreview_Click(object sender, EventArgs e)
		{
			if (MainController.Instance.PopupMessages.ShowWarningQuestion(String.Format("Are you sure you want to refresh the server files for:{1}{0}?", _data.NameWithExtension, Environment.NewLine)) != DialogResult.Yes) return;

			MainController.Instance.ProcessManager.Run("Updating Preview files...", cancelationToken =>
			{
				((PowerPointLinkSettings)_data.Settings).ClearQuickViewContent();
				using (var powerPointProcessor = new PowerPointHidden())
				{
					if (!powerPointProcessor.Connect(true)) return;
					((PowerPointLinkSettings)_data.Settings).UpdateQuickViewContent(powerPointProcessor);
					((PowerPointLinkSettings)_data.Settings).UpdatePresentationInfo(powerPointProcessor);
				}

				_data.ClearPreviewContainer();
				var previewContainer = _data.GetPreviewContainer();
				var previewGenerator = previewContainer.GetPreviewGenerator();
				previewContainer.UpdateContent(previewGenerator, cancelationToken);
			});
			MainController.Instance.PopupMessages.ShowInfo(String.Format("{0}{1}Is now updated for the server!", _data.NameWithExtension, Environment.NewLine));
		}
Ejemplo n.º 5
0
		private static void UpdateQuickViewContent(Library library, CancellationToken cancellationToken)
		{
			if (!MainController.Instance.Settings.EnableLocalSync)
			{
				try
				{
					Utils.DeleteFolder(Path.Combine(library.Path, Constants.RegularPreviewContainersRootFolderName));
				}
				catch { }
				return;
			}

			var powerPointFiles = library.Pages.SelectMany(p => p.AllLinks).OfType<PowerPointLink>().ToList();
			if (!powerPointFiles.Any()) return;
			using (var powerPointProcessor = new PowerPointHidden())
			{
				if (!powerPointProcessor.Connect(true)) return;
				foreach (var powerPointLink in powerPointFiles)
				{
					if (cancellationToken.IsCancellationRequested) break;
					((PowerPointLinkSettings)powerPointLink.Settings).UpdateQuickViewContent(powerPointProcessor);
				}
			}
		}
Ejemplo n.º 6
0
		private static void UpdatePowerPointInfo(Library library, CancellationToken cancellationToken)
		{
			var powerPointFiles = library.Pages.SelectMany(p => p.AllLinks).OfType<PowerPointLink>().ToList();
			if (!powerPointFiles.Any()) return;
			using (var powerPointProcessor = new PowerPointHidden())
			{
				if (!powerPointProcessor.Connect(true)) return;
				foreach (var powerPointLink in powerPointFiles)
				{
					if (cancellationToken.IsCancellationRequested) break;
					((PowerPointLinkSettings)powerPointLink.Settings).UpdatePresentationInfo(powerPointProcessor);
				}
			}
		}
		public void Generate(BasePreviewContainer previewContainer, CancellationToken cancellationToken)
		{
			var powerPointContainer = (PowerPointPreviewContainer)previewContainer;

			var updated = false;
			var tryCount = 0;
			do
			{
				var pdfDestination = Path.Combine(powerPointContainer.ContainerPath, PreviewFormats.Pdf);
				var updatePdf = !(Directory.Exists(pdfDestination) && Directory.GetFiles(pdfDestination).Any());
				if (updatePdf && !Directory.Exists(pdfDestination))
					Directory.CreateDirectory(pdfDestination);

				var pngDestination = Path.Combine(powerPointContainer.ContainerPath, PreviewFormats.Png);
				var updatePng = !(Directory.Exists(pngDestination) && Directory.GetFiles(pngDestination).Any()) &&
					powerPointContainer.GenerateImages;
				if (updatePng && !Directory.Exists(pngDestination))
					Directory.CreateDirectory(pngDestination);

				var pngPhoneDestination = Path.Combine(powerPointContainer.ContainerPath, PreviewFormats.PngForMobile);
				var updatePngPhone = !(Directory.Exists(pngPhoneDestination) && Directory.GetFiles(pngPhoneDestination).Any()) &&
					powerPointContainer.GenerateImages;
				if (updatePngPhone && !Directory.Exists(pngPhoneDestination))
					Directory.CreateDirectory(pngPhoneDestination);

				var thumbDestination = Path.Combine(powerPointContainer.ContainerPath, PreviewFormats.Thumbnails);
				var updateThumbs = !(Directory.Exists(thumbDestination) && Directory.GetFiles(thumbDestination).Any()) &&
					powerPointContainer.GenerateImages;
				if (updateThumbs && !Directory.Exists(thumbDestination))
					Directory.CreateDirectory(thumbDestination);

				var thumbsPhoneDestination = Path.Combine(powerPointContainer.ContainerPath, PreviewFormats.ThumbnailsForMobile);
				var updateThumbsPhone = !(Directory.Exists(thumbsPhoneDestination) && Directory.GetFiles(thumbsPhoneDestination, "*.png").Length > 0) &&
					powerPointContainer.GenerateImages;
				if (updateThumbsPhone && !Directory.Exists(thumbsPhoneDestination))
					Directory.CreateDirectory(thumbsPhoneDestination);

				var pptxDestination = Path.Combine(powerPointContainer.ContainerPath, PreviewFormats.PowerPoint);
				var updatePptx = !(Directory.Exists(pptxDestination) && Directory.GetFiles(pptxDestination).Any());
				if (updatePptx && !Directory.Exists(pptxDestination))
					Directory.CreateDirectory(pptxDestination);

				var txtDestination = Path.Combine(powerPointContainer.ContainerPath, PreviewFormats.Text);
				var updateTxt = !(Directory.Exists(txtDestination) && Directory.GetFiles(txtDestination).Any()) &&
					powerPointContainer.GenerateText;
				if (updateTxt && !Directory.Exists(txtDestination))
					Directory.CreateDirectory(txtDestination);

				var needToUpdate = updatePdf ||
					updatePng ||
					updateThumbs ||
					updatePptx ||
					updateTxt ||
					updatePngPhone ||
					updateThumbsPhone;

				if (!needToUpdate)
					break;

				using (var powerPointProcessor = new PowerPointHidden())
				{
					try
					{
						var processInteropped = false;
						if (!powerPointProcessor.Connect(true)) continue;
						MessageFilter.Register();

						Presentation presentation = null;
						processInteropped = powerPointProcessor.DoTimeLimitedAction(() =>
						{
							presentation = powerPointProcessor.PowerPointObject.Presentations.Open(previewContainer.SourcePath, WithWindow: MsoTriState.msoFalse);
							presentation.Final = false;
						});
						if (processInteropped || presentation == null) continue;

						var content = new StringBuilder();
						if (!cancellationToken.IsCancellationRequested && (updatePng || updateThumbs || updatePptx || updateTxt || updatePngPhone || updateThumbsPhone))
						{
							var i = 1;
							var thumbHeight = (int)presentation.PageSetup.SlideHeight / 10;
							var thumbWidth = (int)presentation.PageSetup.SlideWidth / 10;
							var phoneHeight = (int)(presentation.PageSetup.SlideHeight / 1.5);
							var phoneWidth = (int)(presentation.PageSetup.SlideWidth / 1.5);
							var thumbPhoneHeight = (int)presentation.PageSetup.SlideHeight / 4;
							var thumbPhoneWidth = (int)presentation.PageSetup.SlideWidth / 4;
							foreach (Slide slide in presentation.Slides)
							{
								if (cancellationToken.IsCancellationRequested) break;
								if (updatePng)
								{
									processInteropped = powerPointProcessor.DoTimeLimitedAction(() =>
									{
										slide.Export(Path.Combine(pngDestination, String.Format("Slide{0}.{1}", i, "png")), "PNG");
									});
									if (processInteropped)
										break;
								}
								if (updatePngPhone)
								{
									processInteropped = powerPointProcessor.DoTimeLimitedAction(() =>
									{
										slide.Export(Path.Combine(pngPhoneDestination, String.Format("Slide{0}.{1}", i, "png")), "PNG", phoneWidth, phoneHeight);
									});
									if (processInteropped)
										break;
								}
								if (updateThumbs)
								{
									processInteropped = powerPointProcessor.DoTimeLimitedAction(() =>
									{
										slide.Export(Path.Combine(thumbDestination, String.Format("Slide{0}.{1}", i, "png")), "PNG", thumbWidth, thumbHeight);
									});
									if (processInteropped)
										break;
								}
								if (updateThumbsPhone)
								{
									processInteropped = powerPointProcessor.DoTimeLimitedAction(() =>
									{
										slide.Export(Path.Combine(thumbsPhoneDestination, String.Format("Slide{0}.{1}", i, "png")), "PNG", thumbPhoneWidth, thumbPhoneHeight);
									});
									if (processInteropped)
										break;
								}
								if (updatePptx)
								{
									processInteropped = powerPointProcessor.DoTimeLimitedAction(() =>
									{
										var singleSlidePresentation = powerPointProcessor.PowerPointObject.Presentations.Open(previewContainer.SourcePath, WithWindow: MsoTriState.msoFalse);
										var totalSlides = singleSlidePresentation.Slides.Count;
										for (int j = totalSlides; j >= 1; j--)
											if (j != i)
												singleSlidePresentation.Slides[j].Delete();
										singleSlidePresentation.SaveCopyAs(Path.Combine(pptxDestination, String.Format("Slide{0}.{1}", i, "pptx")));
										singleSlidePresentation.Close();
										Utils.ReleaseComObject(singleSlidePresentation);
									});
									if (processInteropped)
										break;
								}
								if (updateTxt)
								{
									processInteropped = powerPointProcessor.DoTimeLimitedAction(() =>
									{
										foreach (var shape in slide.Shapes.OfType<Shape>().Where(shape => shape.HasTextFrame == MsoTriState.msoTrue))
											content.AppendLine(shape.TextFrame.TextRange.Text.Trim());
									});
									if (processInteropped)
										break;
								}
								i++;
							}
							if (processInteropped)
								continue;
						}
						if (!cancellationToken.IsCancellationRequested && updateTxt)
							using (var sw = new StreamWriter(Path.Combine(txtDestination, Path.ChangeExtension(Path.GetFileName(powerPointContainer.SourcePath), "txt")), false))
							{
								sw.Write(content.ToString());
								sw.Flush();
							}

						if (!cancellationToken.IsCancellationRequested && updatePdf)
						{
							processInteropped = powerPointProcessor.DoTimeLimitedAction(() =>
								presentation.ExportAsFixedFormat(
									Path.Combine(pdfDestination,
										Path.ChangeExtension(Path.GetFileName(powerPointContainer.SourcePath), "pdf")),
									PpFixedFormatType.ppFixedFormatTypePDF));
							if (processInteropped)
								continue;
						}

						presentation.Close();
						Utils.ReleaseComObject(presentation);

						if (needToUpdate)
						{
							PngHelper.ConvertFiles(powerPointContainer.ContainerPath);
							previewContainer.MarkAsModified();
						}

						updated = true;
					}
					catch { }
					finally
					{
						tryCount++;
						MessageFilter.Revoke();
					}
				}
			} while (!updated && tryCount < 10);
		}
		private void RefreshPreviewFiles()
		{
			var sourceLink = SelectedLinkRow?.Source as PreviewableLink;
			if (sourceLink == null) return;
			if (MainController.Instance.PopupMessages.ShowWarningQuestion(String.Format("Are you sure you want to refresh the server files for:{1}{0}?", sourceLink.NameWithExtension, Environment.NewLine)) != DialogResult.Yes) return;
			MainController.Instance.ProcessManager.Run("Updating Preview files...", cancelationToken =>
			{
				if (sourceLink.Type == FileTypes.PowerPoint)
				{
					((PowerPointLinkSettings)sourceLink.Settings).ClearQuickViewContent();
					using (var powerPointProcessor = new PowerPointHidden())
					{
						if (!powerPointProcessor.Connect(true)) return;
						((PowerPointLinkSettings)sourceLink.Settings).UpdateQuickViewContent(powerPointProcessor);
						((PowerPointLinkSettings)sourceLink.Settings).UpdatePresentationInfo(powerPointProcessor);
					}
				}
				sourceLink.ClearPreviewContainer();
				var previewContainer = sourceLink.GetPreviewContainer();
				var previewGenerator = previewContainer.GetPreviewGenerator();
				previewContainer.UpdateContent(previewGenerator, cancelationToken);
			});
			MainController.Instance.PopupMessages.ShowInfo(String.Format("{0}{1}Is now updated for the server!", sourceLink.NameWithExtension, Environment.NewLine));
		}
		private void barButtonItemPrintLink_ItemClick(object sender, ItemClickEventArgs e)
		{
			using (var powerPointProcessor = new PowerPointHidden())
			{
				if (!powerPointProcessor.Connect(true)) return;
				powerPointProcessor.PrintPresentation(
					_tempFileCopy.FullName,
					SelectedThumbnail.Index,
					printAction => MainController.Instance.ProcessManager.Run(
						"Printing...",
						cancellationToken => printAction()));
			}
		}