Skip to content
31 changes: 14 additions & 17 deletions dotnet/src/webdriver/EncodedFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,41 @@

using System;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// Represents a file transmitted over the wire as a base64-encoded string.
/// </summary>
public abstract class EncodedFile
{
private string base64Encoded = string.Empty;
private byte[] byteArray;

/// <summary>
/// Initializes a new instance of the <see cref="EncodedFile"/> class.
/// </summary>
/// <param name="base64EncodedFile">The file as a Base64-encoded string.</param>
/// <exception cref="ArgumentNullException">If <paramref name="base64EncodedFile"/> is <see langword="null"/>.</exception>
/// <exception cref="FormatException">
/// <para>The length of <paramref name="base64EncodedFile"/>, ignoring white-space characters, is not zero or a multiple of 4.</para>
/// <para>-or-</para>
/// <para>The format of <paramref name="base64EncodedFile"/> is invalid. <paramref name="base64EncodedFile"/> contains a non-base-64 character,
/// more than two padding characters, or a non-white space-character among the padding characters.</para>
/// </exception>
protected EncodedFile(string base64EncodedFile)
{
this.base64Encoded = base64EncodedFile;
this.byteArray = Convert.FromBase64String(this.base64Encoded);
this.AsBase64EncodedString = base64EncodedFile ?? throw new ArgumentNullException(nameof(base64EncodedFile));
this.AsByteArray = Convert.FromBase64String(this.AsBase64EncodedString);
}

/// <summary>
/// Gets the value of the encoded file as a Base64-encoded string.
/// </summary>
public string AsBase64EncodedString
{
get { return this.base64Encoded; }
}
public string AsBase64EncodedString { get; }

/// <summary>
/// Gets the value of the encoded file as an array of bytes.
/// </summary>
public byte[] AsByteArray
{
get { return this.byteArray; }
}
public byte[] AsByteArray { get; }

/// <summary>
/// Saves the file, overwriting it if it already exists.
Expand All @@ -65,9 +65,6 @@ public byte[] AsByteArray
/// Returns a <see cref="string">String</see> that represents the current <see cref="object">Object</see>.
/// </summary>
/// <returns>A <see cref="string">String</see> that represents the current <see cref="object">Object</see>.</returns>
public override string ToString()
{
return this.base64Encoded;
}
public override string ToString() => this.AsBase64EncodedString;
}
}
5 changes: 5 additions & 0 deletions dotnet/src/webdriver/ISupportsPrint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
// under the License.
// </copyright>

using System;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
Expand All @@ -29,6 +33,7 @@ public interface ISupportsPrint
/// </summary>
/// <param name="options">A <see cref="PrintOptions"/> object describing the options of the printed document.</param>
/// <returns>The <see cref="PrintDocument"/> object containing the PDF-formatted print representation of the page.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="options"/> is <see langword="null"/>.</exception>
PrintDocument Print(PrintOptions options);
}
}
17 changes: 17 additions & 0 deletions dotnet/src/webdriver/PrintDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using System;
using System.IO;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
Expand All @@ -31,6 +33,13 @@ public class PrintDocument : EncodedFile
/// Initializes a new instance of the <see cref="PrintDocument"/> class.
/// </summary>
/// <param name="base64EncodedDocument">The printed document as a Base64-encoded string.</param>
/// <exception cref="ArgumentNullException">If <paramref name="base64EncodedDocument"/> is <see langword="null"/>.</exception>
/// <exception cref="FormatException">
/// <para>The length of <paramref name="base64EncodedDocument"/>, ignoring white-space characters, is not zero or a multiple of 4.</para>
/// <para>-or-</para>
/// <para>The format of <paramref name="base64EncodedDocument"/> is invalid. <paramref name="base64EncodedDocument"/> contains a non-base-64 character,
/// more than two padding characters, or a non-white space-character among the padding characters.</para>
/// </exception>
public PrintDocument(string base64EncodedDocument) : base(base64EncodedDocument)
{
}
Expand All @@ -39,6 +48,14 @@ public PrintDocument(string base64EncodedDocument) : base(base64EncodedDocument)
/// Saves this <see cref="PrintDocument"/> as a PDF formatted file, overwriting the file if it already exists.
/// </summary>
/// <param name="fileName">The full path and file name to save the printed document to.</param>
/// <exception cref="ArgumentException">
/// <para>If <paramref name="fileName"/> is <see langword="null"/> or whitespace.</para>
/// <para>-or-</para>
/// <para><paramref name="fileName"/> refers to a non-file device, such as "con:", "com1:", "lpt1:", etc. in an NTFS environment.</para>
/// </exception>
/// <exception cref="NotSupportedException"><paramref name="fileName"/> refers to a non-file device, such as "con:", "com1:", "lpt1:", etc. in a non-NTFS environment.</exception>
/// <exception cref="DirectoryNotFoundException">The specified path is invalid, such as being on an unmapped drive.</exception>
/// <exception cref="PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length.</exception>
public override void SaveAsFile(string fileName)
{
if (string.IsNullOrEmpty(fileName))
Expand Down
Loading
Loading