|
| 1 | +// <copyright file="EncodedFile.cs" company="WebDriver Committers"> |
| 2 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 3 | +// or more contributor license agreements. See the NOTICE file |
| 4 | +// distributed with this work for additional information |
| 5 | +// regarding copyright ownership. The SFC licenses this file |
| 6 | +// to you under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// </copyright> |
| 18 | + |
| 19 | +using System; |
| 20 | + |
| 21 | +namespace OpenQA.Selenium |
| 22 | +{ |
| 23 | + /// <summary> |
| 24 | + /// Represents a file transmitted over the wire as a base64-encoded string. |
| 25 | + /// </summary> |
| 26 | + public abstract class EncodedFile |
| 27 | + { |
| 28 | + private string base64Encoded = string.Empty; |
| 29 | + private byte[] byteArray; |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Initializes a new instance of the <see cref="EncodedFile"/> class. |
| 33 | + /// </summary> |
| 34 | + /// <param name="base64EncodedFile">The file as a Base64-encoded string.</param> |
| 35 | + protected EncodedFile(string base64EncodedFile) |
| 36 | + { |
| 37 | + this.base64Encoded = base64EncodedFile; |
| 38 | + this.byteArray = Convert.FromBase64String(this.base64Encoded); |
| 39 | + } |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// Gets the value of the encoded file as a Base64-encoded string. |
| 43 | + /// </summary> |
| 44 | + public string AsBase64EncodedString |
| 45 | + { |
| 46 | + get { return this.base64Encoded; } |
| 47 | + } |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Gets the value of the encoded file as an array of bytes. |
| 51 | + /// </summary> |
| 52 | + public byte[] AsByteArray |
| 53 | + { |
| 54 | + get { return this.byteArray; } |
| 55 | + } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Saves the file, overwriting it if it already exists. |
| 59 | + /// </summary> |
| 60 | + /// <param name="fileName">The full path and file name to save the file to.</param> |
| 61 | + public abstract void SaveAsFile(string fileName); |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// Returns a <see cref="string">String</see> that represents the current <see cref="object">Object</see>. |
| 65 | + /// </summary> |
| 66 | + /// <returns>A <see cref="string">String</see> that represents the current <see cref="object">Object</see>.</returns> |
| 67 | + public override string ToString() |
| 68 | + { |
| 69 | + return this.base64Encoded; |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments