private static X509Certificate2 LoadCertificate() { var socialSampleAssembly = typeof(Startup).GetTypeInfo().Assembly; var embeddedFileProvider = new EmbeddedFileProvider(socialSampleAssembly, "SocialSample"); var certificateFileInfo = embeddedFileProvider.GetFileInfo("compiler/resources/cert.pfx"); using (var certificateStream = certificateFileInfo.CreateReadStream()) { byte[] certificatePayload; using (var memoryStream = new MemoryStream()) { certificateStream.CopyTo(memoryStream); certificatePayload = memoryStream.ToArray(); } return new X509Certificate2(certificatePayload, "testPassword"); } }
public void When_GetFileInfo_and_resource_does_not_exist_then_should_not_get_file_info() { var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace); var fileInfo = provider.GetFileInfo("DoesNotExist.Txt"); Assert.NotNull(fileInfo); Assert.False(fileInfo.Exists); }
public void GetFileInfo_ReturnsNotFoundFileInfo_IfFileDoesNotExistUnderSpecifiedNamespace() { // Arrange var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace + ".SubNamespace"); // Act var fileInfo = provider.GetFileInfo("File.txt"); // Assert Assert.NotNull(fileInfo); Assert.False(fileInfo.Exists); }
public void GetFileInfo_ReturnsFilesAtRoot(string filePath) { // Arrange var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace); var expectedFileLength = 8; // Act var fileInfo = provider.GetFileInfo(filePath); // Assert Assert.NotNull(fileInfo); Assert.True(fileInfo.Exists); Assert.NotEqual(default(DateTimeOffset), fileInfo.LastModified); Assert.Equal(expectedFileLength, fileInfo.Length); Assert.False(fileInfo.IsDirectory); Assert.Null(fileInfo.PhysicalPath); Assert.Equal("File.txt", fileInfo.Name); }
public void GetFileInfo_LocatesFilesUnderSubDirectories(string path) { // Arrange var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace); // Act var fileInfo = provider.GetFileInfo(path); // Assert Assert.NotNull(fileInfo); Assert.True(fileInfo.Exists); Assert.NotEqual(default(DateTimeOffset), fileInfo.LastModified); Assert.True(fileInfo.Length > 0); Assert.False(fileInfo.IsDirectory); Assert.Null(fileInfo.PhysicalPath); Assert.Equal("File.txt", fileInfo.Name); }
private static Scripts CopyEmbeddedScriptFilesToDisk() { var embeddedFileNames = new[] { "RemotePSSessionHelper.ps1", "StartServer.ps1", "StopServer.ps1" }; // Copy the scripts from this assembly's embedded resources to the temp path on the machine where these // tests are being run var embeddedFileProvider = new EmbeddedFileProvider( typeof(RemoteWindowsDeployer).GetTypeInfo().Assembly, "Microsoft.AspNetCore.Server.Testing.Deployers.RemoteWindowsDeployer"); var filesOnDisk = new string[embeddedFileNames.Length]; for (var i = 0; i < embeddedFileNames.Length; i++) { var embeddedFileName = embeddedFileNames[i]; var physicalFilePath = Path.Combine(Path.GetTempPath(), embeddedFileName); var sourceStream = embeddedFileProvider .GetFileInfo(embeddedFileName) .CreateReadStream(); using (sourceStream) { var destinationStream = File.Create(physicalFilePath); using (destinationStream) { sourceStream.CopyTo(destinationStream); } } filesOnDisk[i] = physicalFilePath; } var scripts = new Scripts(filesOnDisk[0], filesOnDisk[1], filesOnDisk[2]); return scripts; }
public void When_GetFileInfo_and_resource_exists_in_root_then_should_get_file_info() { var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace); var expectedFileLength = new FileInfo("File.txt").Length; var fileInfo = provider.GetFileInfo("File.txt"); Assert.NotNull(fileInfo); Assert.True(fileInfo.Exists); Assert.NotEqual(default(DateTimeOffset), fileInfo.LastModified); Assert.Equal(expectedFileLength, fileInfo.Length); Assert.False(fileInfo.IsDirectory); Assert.Null(fileInfo.PhysicalPath); Assert.Equal("File.txt", fileInfo.Name); //Passing in a leading slash fileInfo = provider.GetFileInfo("/File.txt"); Assert.NotNull(fileInfo); Assert.True(fileInfo.Exists); Assert.NotEqual(default(DateTimeOffset), fileInfo.LastModified); Assert.Equal(expectedFileLength, fileInfo.Length); Assert.False(fileInfo.IsDirectory); Assert.Null(fileInfo.PhysicalPath); Assert.Equal("File.txt", fileInfo.Name); }
public Stream GetResourceStream(string uri) { return(_embeddedFileProvider.GetFileInfo(uri).CreateReadStream()); }
public IFileInfo GetEmbeddedFile(string fileName) { return(fileProvider.GetFileInfo(fileName)); }
protected override void CompileSheet(ExcelWorksheet worksheet, DataTable table) { if (ActualRow) { _rowsCount = StartRow(worksheet); } if (IsReferenceSheet) { var mergeTitleCell = worksheet.Cells[_rowsCount, 1, _rowsCount, 3]; mergeTitleCell.Value = table.TableName; mergeTitleCell.Merge = true; mergeTitleCell.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; mergeTitleCell.Style.Fill.BackgroundColor.SetColor(Color.LightGreen); _rowsCount++; } if (ShouldAddHeaderRow && !IsHidden) { worksheet.DefaultColWidth = 13; var headerRow = worksheet.Row(1); headerRow.Height = 45.60; #region Logo and Tab name var logoAndTabTitleCells = worksheet.Cells[1, 1, 1, 6]; logoAndTabTitleCells.Merge = true; //Picture var embeddedProvider = new EmbeddedFileProvider(Assembly.Load("SQAD.MTNext.Resources")); var sqadLogo = Image.FromStream(embeddedProvider.GetFileInfo("Resources/SQADLogo.png").CreateReadStream()); var picture = worksheet.Drawings.AddPicture("SQADLogo", sqadLogo); picture.SetPosition(0, 2, 0, 5); //Tab name text var tabName = logoAndTabTitleCells.RichText.Add($"{CurrentTable.TableName.ToUpper()} "); var staticNameTabText = logoAndTabTitleCells.RichText.Add("DATA FIELDS"); tabName.Size = staticNameTabText.Size = 40; tabName.Color = staticNameTabText.Color = Color.FromArgb(0, 159, 220); tabName.FontName = staticNameTabText.FontName = "Calibri"; tabName.Bold = true; logoAndTabTitleCells.Style.Indent = 7; #endregion Logo and Tab name #region Notice text var noticeTextCells = worksheet.Cells[1, 7, 1, 8]; noticeTextCells.Merge = true; var noticeImportantText = noticeTextCells.RichText.Add("IMPORTANT: "); noticeImportantText.Bold = true; noticeImportantText.Size = 11; noticeImportantText.FontName = "Calibri"; noticeImportantText.Color = Color.White; var noticeWarningText = noticeTextCells .RichText .Add("Text instructions for how to complete this section of the page. (the first two lines of this sheet will be omitted from the import)."); noticeWarningText.Size = 11; noticeWarningText.FontName = "Calibri"; noticeWarningText.Bold = false; noticeWarningText.Color = Color.White; noticeTextCells.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; noticeTextCells.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(132, 151, 176)); noticeTextCells.Style.WrapText = true; noticeTextCells.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Top; #endregion Notice text var fullLogoCells = worksheet.Cells[1, 9, 1, 12]; fullLogoCells.Merge = true; var logoX = Image.FromStream(embeddedProvider.GetFileInfo("Resources/logox.png").CreateReadStream()); var fullLogo = worksheet.Drawings.AddPicture("SQADLogoFull", logoX); fullLogo.SetPosition(0, 2, 9, 0); } //if (IsHidden == false) //{ foreach (DataColumn col in table.Columns) { if (worksheet.Name.Equals("Reference") && !ActualRow) { break; } var colName = worksheet.Cells[_rowsCount, col.Ordinal + 1].RichText.Add(col.ColumnName); colName.Bold = true; colName.Size = 13; worksheet.Cells[_rowsCount, col.Ordinal + 1].Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; worksheet.Cells[_rowsCount, col.Ordinal + 1].Style.Border.Right.Color .SetColor(Color.Black); if (worksheet.Name.Equals("Properties")) { continue; } if ((col.Ordinal + 1) % 2 == 0) { int maxRows = _rowsCount + table.Rows.Count; worksheet.Cells[_rowsCount, col.Ordinal + 1, maxRows, col.Ordinal + 1].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; worksheet.Cells[_rowsCount, col.Ordinal + 1, maxRows, col.Ordinal + 1].Style.Fill.BackgroundColor .SetColor(Color.FromArgb(242, 242, 242)); worksheet.Cells[_rowsCount, col.Ordinal + 1, maxRows, col.Ordinal + 1].Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; worksheet.Cells[_rowsCount, col.Ordinal + 1, maxRows, col.Ordinal + 1].Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; worksheet.Cells[_rowsCount, col.Ordinal + 1, maxRows, col.Ordinal + 1].Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; worksheet.Cells[_rowsCount, col.Ordinal + 1, maxRows, col.Ordinal + 1].Style.Border.Right.Color .SetColor(Color.Black); worksheet.Cells[_rowsCount, col.Ordinal + 1, maxRows, col.Ordinal + 1].Style.Border.Left.Color .SetColor(Color.Black); worksheet.Cells[_rowsCount, col.Ordinal + 1, maxRows, col.Ordinal + 1].Style.Border.Bottom.Color .SetColor(Color.LightGray); } if (col.ColumnMapping == MappingType.Hidden) { worksheet.Column(col.Ordinal + 1).Hidden = true; } //add range names if (ActualRow && ColNames.ContainsKey(col.ColumnName)) { ExcelRange range = worksheet.Cells[_rowsCount, col.Ordinal + 1]; //ExcelRange range = worksheet.Cells[1, 1, col.Ordinal + 1, table.Columns.Count + 1]; worksheet.Names.Add(ColNames[col.ColumnName].Item1.Replace(" ", string.Empty), range); } } //} Dictionary <int, List <int> > rowColumnPair = new Dictionary <int, List <int> >(); foreach (DataRow row in table.Rows) { _rowsCount++; foreach (DataColumn col in table.Columns) { var colObject = row[col]; //adjustment for excel column count index (start from 1. nondevelopment count, duh!) var excelColumnIndex = col.Ordinal + 1; if (!(colObject is ExcelCell)) { worksheet.Cells[_rowsCount, excelColumnIndex].Value = colObject; } else { var cell = colObject as ExcelCell; if (ActualRow && ColNames.ContainsKey(col.ColumnName) && ColNames[col.ColumnName].Item2) { worksheet.Cells[_rowsCount, excelColumnIndex].Style.Numberformat.Format = "#,##0.00"; } if (cell.IsLocked) { worksheet.Cells[_rowsCount, excelColumnIndex].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; worksheet.Cells[_rowsCount, excelColumnIndex].Style.Fill.BackgroundColor.SetColor(Color.Gray); var lockedCell = worksheet.Cells[_rowsCount, excelColumnIndex].RichText.Add(cell.CellValue.ToString()); //.te.Fill.BackgroundColor.SetColor(System.Drawing.Color.Gray); lockedCell.Color = Color.Gray; var lockedDataValication = worksheet.Cells[_rowsCount, excelColumnIndex].DataValidation.AddTextLengthDataValidation(); lockedDataValication.Operator = OfficeOpenXml.DataValidation.ExcelDataValidationOperator.equal; lockedDataValication.Formula.Value = 0; lockedDataValication.AllowBlank = true; lockedDataValication.ShowErrorMessage = true; lockedDataValication.ShowInputMessage = true; lockedDataValication.Error = "This option is not available for input"; lockedDataValication.ErrorStyle = OfficeOpenXml.DataValidation.ExcelDataValidationWarningStyle.stop; lockedDataValication.ErrorTitle = "Input not allowed"; lockedDataValication.PromptTitle = $"No data input is allowed"; lockedDataValication.Prompt = "Editing this cell is not allowed"; continue; } worksheet.Cells[_rowsCount, excelColumnIndex].Value = cell.CellValue; if (!IsHidden && !IsReferenceSheet) { if (!string.IsNullOrEmpty(cell.DataValidationSheet)) { var dataValidation = worksheet.DataValidations.AddListValidation(worksheet .Cells[_rowsCount, excelColumnIndex] .Address); dataValidation.ShowErrorMessage = true; string validationAddress = $"'Reference'!{worksheet.Cells[cell.DataValidationBeginRow, cell.DataValidationNameCellIndex, cell.DataValidationBeginRow + cell.DataValidationRowsCount - 1, cell.DataValidationNameCellIndex]}"; dataValidation.Formula.ExcelFormula = validationAddress; string code = string.Empty; code += $"If Target.Column = {excelColumnIndex} Then \n"; code += $" matchVal = Application.Match(Target.Value, Worksheets(\"Reference\").Range(\"{worksheet.Cells[cell.DataValidationBeginRow, cell.DataValidationNameCellIndex, cell.DataValidationBeginRow + cell.DataValidationRowsCount - 1, cell.DataValidationNameCellIndex].Address}\"), 0) \n"; code += $" selectedNum = Application.Index(Worksheets(\"Reference\").Range(\"{worksheet.Cells[cell.DataValidationBeginRow, cell.DataValidationValueCellIndex, cell.DataValidationBeginRow + cell.DataValidationRowsCount - 1, cell.DataValidationValueCellIndex].Address}\"), matchVal, 1) \n"; code += " If Not IsError(selectedNum) Then \n"; code += " Target.Value = selectedNum \n"; code += " End If \n"; code += "End If \n"; _sheetCodeColumnStatements.Add(code); } else if (cell.CellValue != null && bool.TryParse(cell.CellValue.ToString(), out var result)) { string address = worksheet.Cells[_rowsCount, excelColumnIndex].Address; if (worksheet.DataValidations[address] == null) { var dataValidation = worksheet.DataValidations.AddListValidation(address); dataValidation.ShowErrorMessage = true; dataValidation.Formula.Values.Add("True"); dataValidation.Formula.Values.Add("False"); } } } } } } _rowsCount += __ROWS_BETWEEN_REFERENCE_SHEETS__; if (ActualRow) { worksheet.Cells.AutoFitColumns(); if (!worksheet.Name.Equals("Properties")) { worksheet.Cells[worksheet.Dimension.Address].AutoFilter = true; InsertFirstRow(worksheet); } } }
private void LoadIcon() { var embeddedProvider = new EmbeddedFileProvider(Assembly.GetExecutingAssembly()); this.Icon = new WindowIcon(embeddedProvider.GetFileInfo("Icons\\ansicon.png").CreateReadStream()); }
public void GetFileInfo_ReturnsNotFoundIfPathStartsWithBackSlash() { // Arrange var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace); // Act var fileInfo = provider.GetFileInfo("\\File.txt"); // Assert Assert.NotNull(fileInfo); Assert.False(fileInfo.Exists); }
public void When_GetFileInfo_and_resources_in_path_then_should_get_file_infos() { var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace); var fileInfo = provider.GetFileInfo("Resources/File.txt"); Assert.NotNull(fileInfo); Assert.True(fileInfo.Exists); Assert.NotEqual(default(DateTimeOffset), fileInfo.LastModified); Assert.True(fileInfo.Length > 0); Assert.False(fileInfo.IsDirectory); Assert.Null(fileInfo.PhysicalPath); Assert.Equal("File.txt", fileInfo.Name); }