/// <summary> /// Создание файла для нового словаря /// </summary> public void CreateNewDictionary() { Console.WriteLine("Введите название нового файла"); string name = Console.ReadLine(); StreamWriter sw = new StreamWriter($@"{newFolder.FullName}\{name}.txt", true); sw.Close(); NewFile?.Invoke(); }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <returns></returns> protected virtual bool OnNew(DataFileEventArgs e) { try { NewFile?.Invoke(this, e); FileName = null; IsModified = false; FileChanged?.Invoke(this, e); return(true); } catch (Exception ex) { MessageBox.Show($"Error creating new file : {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } }
public EditorViewModel() { IncreaseText = new DelegateCommand(_ => { ++FontSize; OnPropertyChanged(); }); DecreaseText = new DelegateCommand(_ => { if (FontSize > 1) { --FontSize; OnPropertyChanged(); } }); New = new DelegateCommand(_ => { if (IsDirty) { string messageBoxText = "You have unsaved changes. Do you want to save?"; string caption = "Unsaved changes"; System.Windows.MessageBoxButton button = System.Windows.MessageBoxButton.YesNoCancel; System.Windows.MessageBoxImage icon = System.Windows.MessageBoxImage.Warning; System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); if (result == System.Windows.MessageBoxResult.Yes) { SaveFile?.Invoke(this, new FileOperationEventArgs(null, CurrentText, IsDirty)); IsDirty = false; CurrentText = ""; LineNumbers = ""; } else if (result == System.Windows.MessageBoxResult.No) { NewFile?.Invoke(this, null); } } }); Save = new DelegateCommand(_ => { if (IsDirty) { SaveFile?.Invoke(this, new FileOperationEventArgs(null, CurrentText, IsDirty)); IsDirty = false; } }); Open = new DelegateCommand(_ => { OpenFile?.Invoke(this, new FileOperationEventArgs(null, null, IsDirty)); }); }
/// <summary> /// /// </summary> /// <returns></returns> protected bool OnNewFile() { try { DocumentEventArgs args = new DocumentEventArgs { FileName = string.Empty }; NewFile?.Invoke(this, args); FileName = null; IsModified = false; FileChanged?.Invoke(this, args); return(true); } catch (Exception ex) { MessageBox.Show($"Error creating new file : {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
protected void NewClicked(object sender, EventArgs e) { Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog("Create new export settings file.", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept); fc.SetCurrentFolder(System.IO.Directory.GetCurrentDirectory()); FileFilter ff = new FileFilter(); ff.AddPattern("*.tbp"); fc.Filter = ff; if (fc.Run() == (int)ResponseType.Accept) { newFileHandler.Invoke(new Uri(fc.Filename)); fc.Destroy(); Destroy(); } else { fc.Destroy(); } }
internal void watch() { var beforeList = _files; var newList = new List <string>(Files); _files = newList; var allBefore = String.Join(",", beforeList); var allNow = String.Join(",", newList); if (allBefore != allNow) { NewFileList?.Invoke(newList); } var newFiles = newList.Where(i => beforeList.All(b => b != i)).OrderByDescending(b => new FileInfo(b).LastWriteTime); var newestFile = newFiles.FirstOrDefault(); if (newestFile != null) { NewFile?.Invoke(newestFile); } }
private void OnChanged(object source, FileSystemEventArgs e) => Task.Factory.StartNew(() => NewFile?.Invoke(e.FullPath));
private void /*List<ImageInformation>*/ GetImagesUponMyCriteria(string path, ISO iso, Date date, ExposureTime et, ExposureProgram ep, Orientation or, bool isDSC, string camName, bool isManualWhiteBalance, bool isFlash, bool isGeo, bool isEdit, CancellationToken token) { Debug.Assert(String.IsNullOrWhiteSpace(path) == false, "Передана пустая строка в GetAllImages()"); // List<ImageInformation> result = new List<ImageInformation>(); string[] dirs = null; string[] files = null; try { /* string[]*/ dirs = System.IO.Directory.GetDirectories(path); /* string[]*/ files = System.IO.Directory.GetFiles(path, "*.*").Where((s) => s.ToLower().EndsWith(".jpg") || s.ToLower().EndsWith(".jpeg")).ToArray(); } catch (IOException ioe) { Console.WriteLine(ioe.Message); Trace.WriteLine(ioe.Message); //выясним, не извлекли ли съемный диск DriveInfo drive = new DriveInfo(System.IO.Path.GetPathRoot(path)); if (!drive.IsReady) { Console.WriteLine("Диск " + drive.Name + " был извлечен, или содержит ошибки, мешаюшие поиску"); Trace.WriteLine("Диск " + drive.Name + " был извлечен, или содержит ошибки, мешаюшие поиску"); return /*result*/; } if (dirs == null || files == null) { Trace.WriteLine("Массивы со списком файлов или папок - null"); return /*result*/; } } ChangeFolder?.Invoke(new SearchChangeFolderEventArgs(path, files.Length)); foreach (var f in files) { if (token.IsCancellationRequested) { return;// result; } try { var dirsPhoto = MetadataExtractor.ImageMetadataReader.ReadMetadata(Path.GetFullPath(f)); if (isMatch(f, dirsPhoto, iso, date, et, ep, or, isDSC, camName, isManualWhiteBalance, isFlash, isGeo, isEdit)) { ImageInformation ciexif = new ImageInformation(f, dirsPhoto); // result.Add(ciexif); NewFile?.Invoke(new SearchNewFileEventArgs(ciexif)); } } catch (ImageProcessingException ipe) { Console.WriteLine(ipe.Message); Trace.WriteLine(ipe.Message); } catch (IOException ioe) { Console.WriteLine(ioe.Message); Trace.WriteLine(ioe.Message); //выясним, не извлекли ли съемный диск DriveInfo drive = new DriveInfo(System.IO.Path.GetPathRoot(f)); if (!drive.IsReady) { Console.WriteLine("Диск " + drive.Name + " был извлечен, или содержит ошибки, мешаюшие поиску"); Trace.WriteLine("Диск " + drive.Name + " был извлечен, или содержит ошибки, мешаюшие поиску"); IOFatalError?.Invoke(this, new EventArgs()); return; //result; } } catch (UnauthorizedAccessException uae) { Trace.WriteLine(uae.Message); } } foreach (var d in dirs) { if ((windirSkipFlag == false) && (systemDirectoryScan == false)) { if (d.Contains(Environment.GetFolderPath(Environment.SpecialFolder.Windows))) { Trace.WriteLine("Пропуск системного каталога..."); windirSkipFlag = true; continue; } } if (token.IsCancellationRequested) { return;// result; } try { //result.AddRange(GetImagesUponMyCriteria(d,iso,date,et,ep,or,isDSC, camName, isManualWhiteBalance,isFlash,isGeo,isEdit, token)); GetImagesUponMyCriteria(d, iso, date, et, ep, or, isDSC, camName, isManualWhiteBalance, isFlash, isGeo, isEdit, token); } catch (UnauthorizedAccessException uae) { Trace.WriteLine(uae.Message); } } // return result; }
public EnglishAppControl() { DirectoryInfo dr = new DirectoryInfo("."); //1 раз: для того, чтобы этот объект не был null newFolder = new DirectoryInfo($@"{dr.FullName}\{FolderName}"); //Попытка чтения названия папки со словарями из специального файла try { using (StreamReader sr = File.OpenText("File With FolderName")) { string line; while ((line = sr.ReadLine()) != null) { FolderName = line; } //В этот раз объект создается, если уже названная папка существует newFolder = new DirectoryInfo($@"{dr.FullName}\{FolderName}"); } } catch (Exception) { //Если такого файла нет, то переходим по ссылке к созданию папки и файла-> goto Link; } //-> Вот сюда Link: // Создание новой папки if (!newFolder.Exists) { Console.WriteLine("Введите название папки, где будут храниться словари"); FolderName = Console.ReadLine(); //3 раз: создается новая папка, если таковой не было newFolder = new DirectoryInfo($@"{dr.FullName}\{FolderName}"); newFolder.Create(); using (StreamWriter sw = File.CreateText("File With FolderName")) { sw.WriteLine(FolderName); } } englishWords = new List <string>(); russianWords = new List <string>(); Console.WriteLine("Хотите просмотреть все словари?\nТогда введите да"); string str = Console.ReadLine(); if (str == "да") { this.CheckDictionaries(); } Console.WriteLine("Введите название словаря, с которым хотите работать"); string name = Console.ReadLine(); FileName = name; try { using (StreamReader sr = new StreamReader($@"{newFolder.FullName}\{FileName}.txt")) { string line; string[] words; while ((line = sr.ReadLine()) != null) { words = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); englishWords.Add(words[0]); russianWords.Add(words[1]); } } Count = englishWords.Count; } catch (Exception) { Console.WriteLine("В словаре нет слов для загрузки в приложение!"); Console.WriteLine("Хотите создать новый словарь?"); Console.WriteLine("Введите да"); string answer = Console.ReadLine(); if (answer == "да") { StreamWriter sw = new StreamWriter($@"{newFolder.FullName}\{FileName}.txt", true); NewFile?.Invoke(); Console.WriteLine("Можете добавлять слова"); } else { Console.WriteLine("Создайте словарь вручную. Дальнейшая работа невозможна"); } } }
protected virtual void OnNewFile() { NewFile?.Invoke(this, EventArgs.Empty); }
private static void RaiseNewFile() { NewFile?.Invoke(null, new EventArgs()); }
private void OnNewFile(DownloadIndex.Entry entry) { DispatchOnMainThread(() => NewFile?.Invoke(this, entry)); }