Skip to content

Commit 3e4eb7f

Browse files
committed
[dotnet] use brackets in Selenium Manager for automatic disposal
1 parent f75c119 commit 3e4eb7f

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,25 @@ private static string Binary
7979
try
8080
{
8181
string name = "selenium-manager-" + folder;
82-
Stream fileStream = ResourceUtilities.GetResourceStream(name, name);
83-
BinaryReader binReader = new BinaryReader(fileStream, Encoding.ASCII);
84-
byte[] fileBytes = binReader.ReadBytes((int)fileStream.Length);
85-
binReader.Close();
86-
fileStream.Close();
87-
88-
string directoryName = string.Format(CultureInfo.InvariantCulture, "webdriver.{0}",
89-
Guid.NewGuid().ToString("N"));
90-
var path = Path.Combine(Path.GetTempPath(), directoryName + "/" + folder);
91-
Directory.CreateDirectory(path);
92-
var filePath = Path.Combine(path, "selenium-manager" + extension);
93-
94-
using (BinaryWriter binWriter = new BinaryWriter(File.Open(filePath, FileMode.Create)))
82+
using (Stream fileStream = ResourceUtilities.GetResourceStream(name, name))
9583
{
96-
binWriter.Flush();
97-
binWriter.Write(fileBytes);
98-
binWriter.Close();
84+
using (BinaryReader binReader = new BinaryReader(fileStream, Encoding.ASCII))
85+
{
86+
byte[] fileBytes = binReader.ReadBytes((int)fileStream.Length);
87+
string directoryName = string.Format(CultureInfo.InvariantCulture, "webdriver.{0}",
88+
Guid.NewGuid().ToString("N"));
89+
var path = Path.Combine(Path.GetTempPath(), directoryName + "/" + folder);
90+
Directory.CreateDirectory(path);
91+
var filePath = Path.Combine(path, "selenium-manager" + extension);
92+
93+
using (BinaryWriter binWriter = new BinaryWriter(File.Open(filePath, FileMode.Create)))
94+
{
95+
binWriter.Flush();
96+
binWriter.Write(fileBytes);
97+
}
98+
binary = filePath;
99+
}
99100
}
100-
101-
binary = filePath;
102101
}
103102
catch (Exception ex)
104103
{

0 commit comments

Comments
 (0)