private ObservableCollection <Sandbox> ReadSandboxInfo(FileInfo fileInfo) { ObservableCollection <Sandbox> sandboxes = new ObservableCollection <Sandbox>(); using (ExcelPackage excelPackage = new ExcelPackage(fileInfo)) { ExcelWorkbook book = excelPackage.Workbook; ExcelWorksheet sheet = book.Worksheets[sheetName]; for (int row = sheet.Dimension.Start.Row + 1; row <= sheet.Dimension.End.Row; row++) { var tempSandbox = new Sandbox(); for (int column = sheet.Dimension.Start.Column; column <= sheet.Dimension.End.Column; column++) { string cellValue = sheet.Cells[row, column].Text; MapCellValueToSandBox(cellValue, tempSandbox, column); } tempSandbox.ColorOfSandbox = DetermineSandBoxColor(tempSandbox.Deployable); tempSandbox.LocalPathToSandBox = SandboxPath.TryGetSandbox(int.Parse(tempSandbox.SandboxNumber))?.SandboxfilePath ?? null; sandboxes.Add(tempSandbox); } } return(sandboxes); }
/// <summary> /// Returns the names of files (including their paths) that match the specified search /// pattern in the specified directory. /// </summary> /// <param name="path">The relative or absolute path to the directory to search. This string is not /// case-sensitive.</param> /// <param name="pattern">The search string to match against the names of files in path. This parameter /// can contain a combination of valid literal path and wildcard (* and ?) characters, /// but it doesn't support regular expressions.</param> /// <returns>An XPathNavigator of the full names (including paths) for the files in the specified directory /// that match the specified search pattern, or an empty array if no files are found.</returns> public XPathNavigator ListFilesFiltered(string path, string pattern) { var cleanedPath = SandboxPath.EnsureSafePath(_sandbox, path); #if DEBUG && false Console.WriteLine($"==> Path: {path}"); Console.WriteLine($"==> Pattern: {pattern}"); Console.WriteLine($"==> Cleaned: {cleanedPath}"); #endif var files = Directory.Exists(cleanedPath) ? Directory.GetFiles(cleanedPath, pattern) : Enumerable.Empty <string>();; var xml = new XElement(_ns + "files", from f in files select new XElement(_ns + "file", new XText(f)) ); return(xml.ToXPathNavigable().CreateNavigator()); }
/// <summary> /// Returns the names of files (including their paths) that match the specified search /// pattern in the specified directory. /// </summary> /// <param name="path">The relative or absolute path to the directory to search. This string is not /// case-sensitive.</param> /// <returns>An XPathNavigator of the full names (including paths) for the files in the specified directory /// that match the specified search pattern, or an empty array if no files are found.</returns> public XPathNavigator ListFiles(string path) => new XElement(_ns + "files", from f in Directory.GetFiles(SandboxPath.EnsureSafePath(_sandbox, path)) select new XElement(_ns + "file", f) ).ToXPathNavigable().CreateNavigator();