private static PowerPoint.Shape AddSlideAsShape(PowerPointSlide slideToAdd, PowerPointSlide targetSlide) { try { // Export the slide as .png to a temporary location, then add it to shapes. // This yields a higher quality image compared to copy-pasting slide as image. string tempFilePath = FileDir.GetTemporaryPngFilePath(); GraphicsUtil.ExportSlide(slideToAdd, tempFilePath); PowerPoint.Shape slideAsShape = targetSlide.Shapes.AddPicture2(tempFilePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0); try { FileDir.DeleteFile(tempFilePath); } catch (Exception) { return(slideAsShape); } return(slideAsShape); } catch (Exception) { // It is possible that there could permissions-related issues that cause user to be unable to create/delete files. // In that case, we proceed with copy-pasting the slide as image. slideToAdd.Copy(); PowerPoint.Shape slideAsShape = targetSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; return(slideAsShape); } }
private static void ExtractMediaFiles(string zipFullPath, string tempPath) { try { ZipStorer zip = ZipStorer.Open(zipFullPath, FileAccess.Read); List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir(); Regex regex = new Regex(SlideXmlSearchPattern); foreach (ZipStorer.ZipFileEntry entry in dir) { string name = Path.GetFileName(entry.FilenameInZip); if (name?.Contains(".wav") ?? false || regex.IsMatch(name)) { zip.ExtractFile(entry, tempPath + name); } } zip.Close(); FileDir.DeleteFile(zipFullPath); } catch (Exception e) { ErrorDialogBox.ShowDialog(CommonText.ErrorExtract, "Archived files cannot be retrieved.", e); } }
public override int GetHashCode() { int hash = 1; if (FileDir.Length != 0) { hash ^= FileDir.GetHashCode(); } if (TempFileDir.Length != 0) { hash ^= TempFileDir.GetHashCode(); } if (MpvPath.Length != 0) { hash ^= MpvPath.GetHashCode(); } if (SvpPath.Length != 0) { hash ^= SvpPath.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
static public int SaveFile(string ep, List <TransFilesInfo> listFiles, string dir) { if (0 == listFiles.Count) { return(-1); } ProtoSendFiles info = new ProtoSendFiles(); foreach (var dirs in listFiles) { FileDir obj = new FileDir(); obj.FileName.value_ = dirs.Path; info.FileList.Add(obj); } info.ToDir.value_ = dir; byte[] b_data = null; int len = 0; b_data = new byte[info.length()]; if (!info.serialize(b_data, ref len)) { return(-1); } unsafe { fixed(byte *data_stream = b_data) { return(NetInterface.NetPushFilesToRemote(ep, data_stream, len)); } } }
public DirectoryItem FileDirToDirectoryItem(FileDir pf) { DirectoryItem rez = new DirectoryItem(); rez.Name = pf.Name; rez.isDir = pf.isDir; rez.FullPath = currentPath + pf.Name; return(rez); }
private void CheckPath(string fullPath) { string path = Path.GetDirectoryName(fullPath); if (!FileDir.ExistsDir(path)) { throw new Exception(string.Format("Не удалось создать каталог {0}", path)); } }
static public int PushFiles(List <string> listEP, List <TransFilesInfo> listDir, string toDir) { if (0 == listDir.Count) { return(-1); } ProtoSendFiles info = new ProtoSendFiles(); String BaseDir = null; Tool.Setting.ConfigRead.ReadLocalDir(ref BaseDir); if (BaseDir == null) { return(-1); } foreach (var dirs in listDir) { FileDir obj = new FileDir(); obj.FileName.value_ = BaseDir + dirs.Path.Substring(1, dirs.Path.Length - 1); info.FileList.Add(obj); } info.ToDir.value_ = toDir; byte[] b_data = null; int len = 0; b_data = new byte[info.length()]; if (!info.serialize(b_data, ref len)) { return(-1); } string epList = null; foreach (string ep in listEP) { if (ep == null) { continue; } epList += ep + "|"; } unsafe { fixed(byte *data_stream = b_data) { return(NetInterface.NetPushFilesToRemote(epList, data_stream, len)); } } }
private static void OverwriteFileUsing(string presFullName, string zipFullPath) { try { FileDir.DeleteFile(zipFullPath); FileDir.CopyFile(presFullName, zipFullPath); } catch (Exception e) { ErrorDialogBox.ShowDialog(CommonText.ErrorAccessTempFolder, string.Empty, e); } }
public AbstractFile GetNew(FileDir type) { AbstractFile Result = null; switch (type) { case FileDir.File: Result = new ConcreteFile(); break; case FileDir.Folder: Result = new ConcreteFolder(); break; } return(Result); }
//Stores slide-size crop of the current slide as a global variable private void AddZoomSlideCroppedPicture(float magnifyRatio = 1.0f) { PowerPointSlide zoomSlideCopy = this.Duplicate(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(zoomSlideCopy.Index); PowerPoint.Shape cropShape = zoomSlideCopy.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRectangle, 0, 0, PowerPointPresentation.Current.SlideWidth - 0.01f, PowerPointPresentation.Current.SlideHeight - 0.01f); cropShape.Select(); PowerPoint.Selection sel = Globals.ThisAddIn.Application.ActiveWindow.Selection; PowerPoint.Shape croppedShape = CropToShape.Crop(zoomSlideCopy, sel, magnifyRatio: magnifyRatio); try { string tempFilePath = FileDir.GetTemporaryPngFilePath(); Utils.GraphicsUtil.ExportShape(croppedShape, tempFilePath); zoomSlideCroppedShapes = _slide.Shapes.AddPicture2(tempFilePath, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue, 0, 0); croppedShape.Delete(); try { FileDir.DeleteFile(tempFilePath); } catch (Exception) { // If the file cannot be deleted, we continue without deletion. } } catch (Exception) { // Revert to normal copy and pasting if unable to create file. croppedShape.Cut(); zoomSlideCroppedShapes = _slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; } zoomSlideCroppedShapes.Name = "PPTLabsMagnifyAreaGroup" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); Utils.ShapeUtil.FitShapeToSlide(ref zoomSlideCroppedShapes); zoomSlideCopy.Delete(); }
public List <FileDir> GetDirectoryFiles(string dirPath) { DirectoryInfo d = new DirectoryInfo(dirPath); if (d.Exists) { FileInfo[] fInf = d.GetFiles(); List <FileDir> rez = new List <FileDir>(fInf.Length); foreach (FileInfo f in fInf) { FileDir fd = new FileDir(); fd.Name = f.Name; fd.Length = f.Length; rez.Add(fd); } return(rez); } return(new List <FileDir>());; }
/// <summary> /// Формирование дерева запросов на основании папки QBE /// </summary> public void LoadTree() { LogFile.WriteLog("Загрузка списка скриптов..."); if (!FileDir.ExistsDir(FileDir.basePath + "\\Scripts")) { LogFile.WriteLog("Каталог Scripts не существует"); MessageBox.Show("Каталог Scripts не существует!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { treeQBE.Items.Clear(); DirectoryInfo root = new DirectoryInfo(FileDir.basePath + "\\Scripts\\"); Nodes.Add(FileDir.CreateDirectoryNode(root)); treeQBE.ItemsSource = Nodes; LogFile.WriteLog("Загрузка списка скриптов успешно завершена"); } catch (Exception e) { LogFile.WriteLog("Ошибка загрузки списка скриптов! " + e.Message + ": " + e.StackTrace); MessageBox.Show("Ошибка загрузки списка скриптов! " + e.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void SavePathBrowserButton_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog folderDialog = new FolderBrowserDialog { ShowNewFolderButton = true, SelectedPath = savePathInput.Text, Description = ShapesLabText.FolderDialogDescription }; // loop until user chooses an empty folder, or click "Cancel" button while (true) { // this launcher will scroll the view to selected path DialogResult folderDialogResult = FolderDialogLauncher.ShowFolderBrowser(folderDialog); if (folderDialogResult == Forms.DialogResult.OK) { string newPath = folderDialog.SelectedPath; if (!FileDir.IsDirectoryEmpty(newPath)) { System.Windows.MessageBox.Show(ShapesLabText.ErrorFolderNonEmpty); } else { savePathInput.Text = newPath; break; } } else { // if user cancels the dialog, break the loop break; } } }
public List <FileDir> GetDirectorySubDirs(string dirPath) { DirectoryInfo d = new DirectoryInfo(dirPath); if (d.Exists) { DirectoryInfo[] dirInf = d.GetDirectories(); List <FileDir> rez = new List <FileDir>(dirInf.Length); foreach (DirectoryInfo di in dirInf) { FileDir fd = new FileDir(); fd.Name = di.Name; fd.isDir = true; rez.Add(fd); } return(rez); } if (dirPath == systemRootAlias) { String[] drives = Environment.GetLogicalDrives(); List <FileDir> rez = new List <FileDir>(drives.Length); foreach (string di in drives) { FileDir fd = new FileDir(); fd.Name = di; fd.isDir = true; rez.Add(fd); } return(rez); } return(new List <FileDir>()); }
/// <summary> /// Общий запуск процесса выполнения скрпта /// </summary> public void Run() { // ждем Wait(); // если отмену нажали раньше, чем дошла очередь скрипта if (ProcessItem.cancel) { Cancel(processItem); return; } // запуск процесса processItem.Run(); SetText("Запуск", StatusType.Process, string.Format("[{0}][{1}] Запуск...", processItem.CodeIfns, processItem.ScriptName)); // преобразование к скрипту try { if (ProcessItem.cancel) { Cancel(processItem); return; } SetText("Подготовка скрипта", StatusType.Process, string.Format("[{0}][{1}] Подготовка скрипта...", processItem.CodeIfns, processItem.ScriptName)); this.RunConvertFileScript(); SetText("Подготовка скрипта завершена", StatusType.Process, string.Format("[{0}][{1}] Подготовка скрипта завершена", processItem.CodeIfns, processItem.ScriptName)); } catch (Exception exception) { SetText("", StatusType.Error, string.Format("[{0}][{1}]", processItem.CodeIfns, processItem.ScriptName), exception, "Ошибка конвертации скрипта"); processItem.End(); return; } // подстановки try { if (ProcessItem.cancel) { Cancel(processItem); return; } SetText("Подстановки", StatusType.Process, string.Format("[{0}][{1}] Подстановки...", processItem.CodeIfns, processItem.ScriptName)); this.RunReplaces(); SetText("Подстановки завершены", StatusType.Process, string.Format("[{0}][{1}] Подстановки завершены", processItem.CodeIfns, processItem.ScriptName)); } catch (Exception exception) { SetText("", StatusType.Error, string.Format("[{0}][{1}]", processItem.CodeIfns, processItem.ScriptName), exception, "Ошибка подстановки"); processItem.End(); return; } // SQL try { int timeSleep = 60 * 1000 * int.Parse(Settings.RepeatTimeout); SQL sql = null; // выполняем в соответствии с количеством попыток (в случае возникновения ошибок SQL) for (int i = 1; i <= int.Parse(Settings.RepeatCount); i++) { try { if (ProcessItem.cancel) { Cancel(processItem); return; } SetText("Выполнение скрипта...", StatusType.Process, string.Format("[{0}][{1}] Выполнение скрипта...", processItem.CodeIfns, processItem.ScriptName)); sql = new SQL(this.connectionString, this.indexDb); sql.ColumnsHeader = this.headers; sql.RunQuery(this.queryText); if (ProcessItem.cancel) { Cancel(processItem); return; } SetText("Выполнение скрипта завершено", StatusType.Process, string.Format("[{0}][{1}] Выполнение скрипта завершено", processItem.CodeIfns, processItem.ScriptName)); break; } catch (SqlException sqlException) { SetText("", StatusType.Error, string.Format("[{0}][{1}]", processItem.CodeIfns, processItem.ScriptName), sqlException, "Ошибка SQL (SqlException) "); } catch (Exception exception) { SetText("", StatusType.Error, string.Format("[{0}][{1}]", processItem.CodeIfns, processItem.ScriptName), exception, "Ошибка SQL (Exception) "); } if (ProcessItem.cancel) { Cancel(processItem); return; } this.processItem.Status = StatusType.Replace; Thread.Sleep(timeSleep); if (i == int.Parse(Settings.RepeatCount)) { processItem.End(); SetText("Не удалось выполнить скрипт", StatusType.Stop, string.Format("[{0}][{1}] Не удалось выполнить скрипт после {2} попыток", processItem.CodeIfns, processItem.ScriptName, Settings.RepeatCount)); return; } } // сохранение результата try { if (sql == null) { throw new Exception("Не определена переменная sql!"); } if (ProcessItem.cancel) { Cancel(processItem); return; } SetText("Сохранение результата", StatusType.Process, string.Format("[{0}][{1}] Сохранение результата...", processItem.CodeIfns, processItem.ScriptName)); result.Cahrset = this.scriptEncoding; result.Headers = sql.ColumnsHeader; foreach (List <string> line in sql.Data) { result.SaveRow(line); } string fileResult = FileDir.basePath + "\\Result\\" + FileDir.DirNameDate() + "\\" + this.ScriptNameWithoutExtension + "\\" + this.codeIfns + ".csv"; result.SaveToFile(fileResult); SetText("Результат сохранен", StatusType.Process, string.Format("[{0}][{1}] Результат сохранен в '{2}'", processItem.CodeIfns, processItem.ScriptName, fileResult)); } catch (Exception exception) { SetText("", StatusType.Error, string.Format("[{0}][{1}]", processItem.CodeIfns, processItem.ScriptName), exception, "Ошибка сохранения результата"); processItem.End(); return; } } catch (Exception exception) { SetText("", StatusType.Error, string.Format("[{0}][{1}]", processItem.CodeIfns, processItem.ScriptName), exception, "Общая ошибка"); processItem.End(); return; } // Если все успешно завершено if (!ProcessItem.cancel && !this.processItem.IsError) { this.processItem.StatusText = "Завершено"; this.processItem.Status = StatusType.Success; } processItem.End(); }