void SetCurrentFiles() { CurrentFiles.Clear(); if (!string.IsNullOrEmpty(SelectedPath) && Directory.Exists(SelectedPath)) { FileError = false; DirectoryInfo directory = new DirectoryInfo(SelectedPath); try { foreach (FileSystemInfo f in directory.GetFileSystemInfos()) { CurrentFiles.Add(f); } } catch (UnauthorizedAccessException ex) { if (_log.IsWarnEnabled) { _log.Warn("Error Getting File System Infos. Selected Path=" + SelectedPath, ex); } FileError = true; } if (!FileError) { SetWatcher(); } } else { fsw.EnableRaisingEvents = false; } }
private void DiscoverFiles(string rootPath, string searchText) { CurrentFiles.Clear(); CurrentFilesSelected.Clear(); if (rootPath != String.Empty) { DirectoryInfo di = new DirectoryInfo(rootPath); var files = di.EnumerateFiles("*", SearchOption.AllDirectories) .Where(f => ResourceExtensions.ValidExtensions.Contains(f.Extension)) .Where(f => f.Name != PACKAGES_FILENAME); if (!string.IsNullOrWhiteSpace(searchText)) { files = files.Where(f => f.FullName.Contains(searchText)); } foreach (FileInfo f in files) { CurrentFiles.Add(f); } OnPropertyChanged("CurrentFiles"); } }
private IEnumerable <string> GetAllFilesInDirectory(string directoryPath, Delimon.Win32.IO.SearchOption searchOption) { IEnumerable <string> files = null; IEnumerable <string> subdirectories = null; try { files = Directory.EnumerateFiles(directoryPath.LongPathFormat()); subdirectories = Directory.EnumerateDirectories(directoryPath.LongPathFormat()); } catch (UnauthorizedAccessException) { if (null != Logger) { Logger.Error(string.Format("--- GetAllFilesInDirectory: No permission to access folder {0}", directoryPath)); } } catch (IOException e) { if (null != Logger) { Logger.Error(string.Format("--- GetAllFilesInDirectory: I/O error: {0}", e.Message)); } } if (files != null) { var f = _currentFiles; foreach (string file in files) { f.Add(file.LongPathFormat()); CurrentFiles = f; yield return(file); } } if (subdirectories != null && searchOption == Delimon.Win32.IO.SearchOption.AllDirectories) { foreach (string subdirectory in subdirectories) { if ((Delimon.Win32.IO.File.GetAttributes(subdirectory) & Delimon.Win32.IO.FileAttributes.ReparsePoint) != Delimon.Win32.IO.FileAttributes.ReparsePoint) { foreach (string file in GetAllFilesInDirectory(subdirectory, searchOption)) { CurrentFiles.Add(file.LongPathFormat()); yield return(file.LongPathFormat()); } } else if (null != Logger) { Logger.Warn(string.Format("{0} --- JUNCTION detected, skipped", subdirectory)); } } } }
private void OnDeleteResource(object sender, ExecutedRoutedEventArgs e) { var filesToDelete = FileList.SelectedItems.Cast <File>().ToList(); if (FileOperationAPIWrapper.Send(string.Join("\0", filesToDelete.Select(a => a.Info.FullName)))) { foreach (var file in filesToDelete) { CurrentFiles.Remove(file); } } }
private void CreateTab(string fileName) { try { var tb = new FastColoredTextBox(); tb.Font = new Font("Consolas", 11f); tb.ImeMode = ImeMode.On;//支持中文 //必须把函数绑定写在初次Text赋值之前,否则第一次赋值无法触发TB_TextChanged tb.TextChanged += new EventHandler <TextChangedEventArgs>(TB_TextChanged); tb.MouseMove += new MouseEventHandler(tb_MouseMove); tb.ChangedLineColor = changedLineColor; tb.HighlightingRangeType = HighlightingRangeType.VisibleRange; tb.ContextMenuStrip = RightClickMenu; tb.Dock = DockStyle.Fill; tb.BorderStyle = BorderStyle.Fixed3D; //tb.VirtualSpace = true; tb.LeftPadding = 12; //tb.Language = Language.CSharp;//特!么!就!是!这!句!话!找!了!一!晚!上! tb.AddStyle(sameWordsStyle);//same words style var tab = new FATabStripItem(fileName != null ? Path.GetFileName(fileName) : "[new]", tb); CurrentFiles.AddTab(tab); CurrentFiles.SelectedItem = tab; tab.Tag = fileName; tb.Text = ""; if (fileName != null) { tb.OpenFile(fileName); } tb.Tag = new TbInfo(); tb.Focus(); //create autocomplete popup menu AutocompleteMenu popupMenu = new AutocompleteMenu(tb); popupMenu.Items.ImageList = ilAutocomplete; popupMenu.Opening += new EventHandler <CancelEventArgs>(popupMenu_Opening); BuildAutocompleteMenu(popupMenu); (tb.Tag as TbInfo).popupMenu = popupMenu; } catch (Exception ex) { if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Retry) { CreateTab(fileName); } } }
override protected IEnumerable <string> GetAllFilesInDirectory(string directoryPath, Delimon.Win32.IO.SearchOption searchOption) { IEnumerable <string> files = null; IEnumerable <string> subdirectories = null; GetEntries(directoryPath, ref files, ref subdirectories); if (files != null) { var f = _currentFiles; foreach (string file in files) { ZipProviderContainer.Instance.ZipProvider.SourcArchive = file; if (!ZipProviderContainer.Instance.ZipProvider.IsArchive) { continue; } f.Add(file.LongPathFormat()); CurrentFiles = f; yield return(file); } } if (subdirectories != null && searchOption == Delimon.Win32.IO.SearchOption.AllDirectories) { foreach (string subdirectory in subdirectories) { if ((Delimon.Win32.IO.File.GetAttributes(subdirectory) & Delimon.Win32.IO.FileAttributes.ReparsePoint) != Delimon.Win32.IO.FileAttributes.ReparsePoint) { foreach (string file in GetAllFilesInDirectory(subdirectory, searchOption)) { ZipProviderContainer.Instance.ZipProvider.SourcArchive = file; if (!ZipProviderContainer.Instance.ZipProvider.IsArchive) { continue; } CurrentFiles.Add(file.LongPathFormat()); _deepLevel++; yield return(file.LongPathFormat()); } } else if (null != Logger) { Logger.Warn(string.Format("{0} --- JUNCTION detected, skipped", subdirectory)); } } } }
//窗口关闭时函数 //private void PowerfulCSharpEditor_FormClosing(object sender, FormClosingEventArgs e) //{ // List<FATabStripItem> list = new List<FATabStripItem>(); // foreach (FATabStripItem tab in CurrentFiles.Items) // list.Add(tab); // foreach (var tab in list) // { // TabStripItemClosingEventArgs args = new TabStripItemClosingEventArgs(tab); // if (args.Cancel) // { // e.Cancel = true; // return; // } // CurrentFiles.RemoveTab(tab); // } //} private void Main_FormClosing(object sender, FormClosingEventArgs e) { List <FATabStripItem> list = new List <FATabStripItem>(); foreach (FATabStripItem tab in CurrentFiles.Items) { list.Add(tab); } foreach (var tab in list) { TabStripItemClosingEventArgs args = new TabStripItemClosingEventArgs(tab); if (args.Cancel) { e.Cancel = true; return; } CurrentFiles.RemoveTab(tab); } //Application.Exit();//强制关闭所有的窗口 }
public void ShowInExplorer(string relativePath) { var dirOfResource = RootDirectory.FindDir(Path.GetDirectoryName(relativePath)); var current = dirOfResource; while (current.ParentDirectory != null) { current = current.ParentDirectory; current.IsExpanded = true; } dirOfResource.IsSelected = true; var fileOfResource = CurrentFiles.FirstOrDefault(f => f.Name == Path.GetFileName(relativePath)); if (fileOfResource != null) { fileOfResource.IsSelected = true; } }
private void OnNewResource(object sender, ExecutedRoutedEventArgs e) { var infoProvider = (IResourceInfoProvider)e.Parameter; var newFileName = Path.Combine(SelectedDirectory.DirectoryInfo.FullName, infoProvider.ResourceType.Name + infoProvider.Extensions[0]); int count = 1; while (System.IO.File.Exists(newFileName)) { newFileName = Path.Combine(SelectedDirectory.DirectoryInfo.FullName, infoProvider.ResourceType.Name + count++ + infoProvider.Extensions[0]); } infoProvider.SaveToDisk(new FileInfo(newFileName), null); OnRefreshResources(this, default(DependencyPropertyChangedEventArgs)); CurrentFiles.ForEach(f => f.IsSelected = false); var newFile = CurrentFiles.First(f => f.Info.FullName == newFileName); newFile.IsSelected = true; newFile.IsEditing = true; }
private void OnNewResource(object sender, ExecutedRoutedEventArgs e) { var infoProvider = (IResourceInfoProvider)e.Parameter; var newFileName = Path.Combine(SelectedDirectory.DirectoryInfo.FullName, infoProvider.ResourceType.Name + infoProvider.Extensions[0]); int count = 1; while (System.IO.File.Exists(newFileName)) { newFileName = Path.Combine(SelectedDirectory.DirectoryInfo.FullName, infoProvider.ResourceType.Name + count++ + infoProvider.Extensions[0]); } CurrentFiles.ForEach(f => f.IsSelected = false); var newFile = FileFor(new FileInfo(newFileName)); infoProvider.Save(Activator.CreateInstance(infoProvider.ResourceType), newFile.Info); newFile.IsSelected = true; newFile.IsEditing = true; CurrentFiles.Add(newFile); }
private void DeleteSelectedPackage() { if (SelectedPackage != null) { var toBeDeleted = Packages.Where(x => x == SelectedPackage).FirstOrDefault(); if (toBeDeleted != null) { if (ActivePackage == SelectedPackage) { ActivePackage = null; //Also, clear out any dependencies CurrentFiles.Clear(); CurrentFilesSelected.Clear(); WebResourceInfos.Clear(); WebResourceInfosSelected.Clear(); } Packages.Remove(toBeDeleted); SelectedPackage = null; } SavePackages(); } }
override protected IEnumerable <string> GetAllFilesInDirectory(string directoryPath, Delimon.Win32.IO.SearchOption searchOption) { IEnumerable <string> files = null; IEnumerable <string> subdirectories = null; GetEntries(directoryPath, ref files, ref subdirectories); if (files != null) { var f = _currentFiles; foreach (string file in files) { if (_isComplete) { break; } while (Pause) { Application.DoEvents(); } if (!f.Contains(file)) { f.Add(file.LongPathFormat()); } CurrentFiles = f; yield return(file); } } if (subdirectories != null && searchOption == Delimon.Win32.IO.SearchOption.AllDirectories) { foreach (string subdirectory in subdirectories) { if (_isComplete) { break; } var valid = false; try { valid = (Delimon.Win32.IO.File.GetAttributes(subdirectory) & Delimon.Win32.IO.FileAttributes.ReparsePoint) != Delimon.Win32.IO.FileAttributes.ReparsePoint; } catch (Exception ex) { if (null != Logger) { Logger.Error(string.Format("{0} --- Exception at GetAllFilesInDirectory, error was : {0}", ex.Message)); } } if (valid) { foreach (string file in GetAllFilesInDirectory(subdirectory, searchOption)) { if (_isComplete) { break; } while (Pause) { Application.DoEvents(); } if (!CurrentFiles.Contains(file)) { CurrentFiles.Add(file.LongPathFormat()); } yield return(file.LongPathFormat()); } } else if (null != Logger) { Logger.Warn(string.Format("{0} --- JUNCTION detected, skipped", subdirectory)); } } } }
private void LoadData(DataSet ds) { const int TBL_GENERAL = 0; const int TBL_LOCATIONS = 1; const int TBL_STATUS_HISTORY = 2; const int TBL_CURRENT_ICONS = 3; const int TBL_CURRENT_FILES = 4; const int TBL_CURRENT_ACCESS = 5; const int ROW_FIRST = 0; DataTable dtGeneral = ds.Tables[TBL_GENERAL]; if (dtGeneral.Rows.Count > 0) { DataRow dr = dtGeneral.Rows[ROW_FIRST]; // badge info Badge.BadgeID = (int)dr["BadgeID"]; Badge.BadgeNumber = (string)dr["BadgeNumber"]; Badge.BadgeColor = (string)dr["BadgeColor"]; Badge.WhenBecomesActive = (DateTime)dr["WhenBadgeBecomesActive"]; Badge.WhenExpires = (DateTime)dr["WhenBadgeExpires"]; Badge.BadgeStatus = (string)dr["BadgeStatus"]; // person info Person.NamePrefix = (string)dr["NamePrefixDescription"]; Person.FirstName = (string)dr["FirstName"]; Person.MiddleName = (string)dr["MiddleName"]; Person.LastName = (string)dr["LastName"]; Person.NameSuffix = (string)dr["NameSuffixDescription"]; // Unknown info Miscellaneous.FingerprintDate = Badge.WhenBecomesActive; Miscellaneous.PrintDate = Badge.WhenBecomesActive; Miscellaneous.PrintUser = "******"; // Company info Company.CompanyCode = (string)dr["CompanyCode"]; Company.CompanyID = (int)dr["CompanyID"]; Company.CorporationName = (string)dr["CorporationName"]; // Division info Division.DivisionID = (int)dr["DivisionID"]; Division.DivisionCode = (string)dr["DivisionCode"]; Division.DivisionName = (string)dr["DivisionName"]; if (dr.Table.Columns.Contains("DivisionTypeName")) { Division.DivisionTypeName = (string)dr["DivisionTypeName"]; } Division.JobRole = (string)dr["JobRoleDescription"]; } DataTable dtLocations = ds.Tables[TBL_LOCATIONS]; if (dtLocations.Rows.Count > 0) { foreach (DataRow row in dtLocations.Rows) { Locations.Add(new Location(row)); } SelectedLocation = Locations[0]; } DataTable dtStatusHistory = ds.Tables[TBL_STATUS_HISTORY]; StatusHistory.Clear(); if (dtStatusHistory.Rows.Count > 0) { foreach (DataRow row in dtStatusHistory.Rows) { StatusHistory.Add(new BadgeStatusPeriod(row)); } } DataTable dtCurrentIcons = ds.Tables[TBL_CURRENT_ICONS]; CurrentIcons.Clear(); if (dtCurrentIcons.Rows.Count > 0) { foreach (DataRow row in dtCurrentIcons.Rows) { CurrentIcons.Add(new BadgeIcon(row)); } } DataTable dtCurrentFiles = ds.Tables[TBL_CURRENT_FILES]; CurrentFiles.Clear(); if (dtCurrentFiles.Rows.Count > 0) { foreach (DataRow row in dtCurrentFiles.Rows) { CurrentFiles.Add(new BadgeFile(row)); } } /**** * else * { * CurrentFiles.Add(new BadgeFile("text file (54) (spoofed data)", "54", "text/plain")); * CurrentFiles.Add(new BadgeFile("pdf file (5) (spoofed data)", "5", "application/pdf")); * } */ DataTable dt = ds.Tables[TBL_CURRENT_ACCESS]; CurrentAccess.Clear(); if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { CurrentAccess.Add(new BadgeAccessCategory(row)); } } /*** * else * { * CurrentAccess.Add(new BadgeAccessCategory()); * CurrentAccess.Add(new BadgeAccessCategory()); * CurrentAccess.Add(new BadgeAccessCategory()); * CurrentAccess.Add(new BadgeAccessCategory()); * } */ }