serverRoom/amt-sdk-20-0-0-1/WebStorageModule/Src/IWebStorageConnection.cs

292 lines
9.6 KiB
C#

using System;
using System.Text;
using System.Security;
namespace Intel.WebStorage
{
/// <summary>
/// Provides basic access to the AMT's Web Storage
/// </summary>
public interface IWebStorageConnection : IDisposable
{
#region Properties
/// <summary>
/// The host name\IP of the machine to connect.
/// </summary>
string Host { get; set; }
/// <summary>
/// Gets or sets the user name.
/// </summary>
string UserName { get; set; }
/// <summary>
/// Gets or sets the password.
/// </summary>
SecureString Password { get; set; }
/// <summary>
/// Indicates whether to use secure connection (HTTP\HTTPS).
/// </summary>
bool Secure { get; set; }
/// <summary>
/// Indicates which authentication scheme to use with the AMT.
/// </summary>
AuthenticationScheme Authentication { get; set; }
/// <summary>
/// Connection options.
/// </summary>
IWebStorageConnectionOptions Options { get; }
#endregion //Properties
#region Methods
/// <summary>
/// Put a file in the root directory of AMT web storage.
/// Only index.htm and logon.htm can be saved in this location.
/// </summary>
void Put(string filePath);
/// <summary>
/// Put a file in the root directory of AMT web storage with specific HTTP headers fields for a file to be uploaded to the AMT.
/// Only index.htm and logon.htm can be saved in this location.
/// </summary>
void Put(string filePath, Headers headers);
/// <summary>
/// Put a file in the AMT's web storage.
/// </summary>
/// <param name="directory">.</param>
/// <param name="subdirectory">.</param>
/// <param name="fileName">.</param>
/// <param name="webUILinkName">.</param>
void Put(string filePath, string directory, string subdirectory, string webUILinkName);
/// <summary>
/// Put a file in the AMT's web storage with specific HTTP headers fields for a file to be uploaded to the AMT.
/// </summary>
/// <param name="directory">.</param>
/// <param name="subdirectory">.</param>
/// <param name="fileName">.</param>
/// <param name="headers">.</param>
void Put(string filePath, string directory, string subdirectory, Headers headers);
/// <summary>
/// Get a file from the AMT's web storage.
/// </summary>
/// <param name="directory">.</param>
/// <param name="subdirectory">.</param>
/// <param name="fileName">.</param>
/// <param name="webUILinkName">.</param>
byte[] Get(string directory, string subdirectory, string fileName);
/// <summary>
/// Get file content from the AMT's web storage.
/// </summary>
/// <param name="directory"></param>
/// <param name="subdirectory"></param>
/// <param name="fileName"></param>
/// <returns>File contnet</returns>
string GetFileContent(string directory, string subdirectory, string fileName);
/// <summary>
/// Get the contents of a specific web storage directory.
/// </summary>
/// <param name="directory">.</param>
/// <param name="subdirectory">.</param>
/// <param name="fileName">.</param>
/// <param name="webUILinkName">.</param>
string GetContent(string directory, string subdirectory);
/// <summary>
/// Delete a file from the AMT's web storage.
/// </summary>
/// <param name="directory">.</param>
/// <param name="subdirectory">.</param>
/// <param name="fileName">.</param>
/// <param name="webUILinkName">.</param>
void Delete(string directory, string subdirectory, string fileName);
#endregion //Methods
}
#region Structs
/// <summary>
/// A struct that defines supported HTTP header fields for a file to be uploaded to the AMT.
/// This header fields will be included in the HTTP GET response header of the file.
/// </summary>
public struct Headers
{
private const int MAX_HEADER_FIELD_LENGTH = 256;
private string _contentType;
private string _contentEncoding;
private string _contentDisposition;
private string _cacheControl;
private string _xFrameOptions;
private string _webUIlink;
/// <summary>
/// The Content-Type of the file.
/// If this property is null or empty string the Content-Type field value in any HTTP GET response header will be: text/plain.
/// </summary>
public string ContentType
{
get { return _contentType;}
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("Content-Type header field can contain up to 256 characters.");
_contentType = value;
}
}
/// <summary>
/// The Content-Encoding of the file.
/// The Content-Encoding field will not be included in the response header of any HTTP GET command if this property is null or empty string.
/// </summary>
public string ContentEncoding
{
get { return _contentEncoding; }
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("Content-Encoding header field can contain up to 256 characters.");
_contentEncoding = value;
}
}
/// <summary>
/// The Content-Disposition of the file.
/// The Content-Disposition field will not be included in the response header of any HTTP GET command if this property is null or empty string.
/// </summary>
public string ContentDisposition
{
get { return _contentDisposition; }
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("Content-Disposition header field can contain up to 256 characters.");
_contentDisposition = value;
}
}
/// <summary>
/// The Cache-Control of the file.
/// The Cache-Control field will not be included in the response header of any HTTP GET command if this property is null or empty string.
/// </summary>
public string CacheControl
{
get { return _cacheControl; }
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("Cache-Control header field can contain up to 256 characters.");
_cacheControl = value;
}
}
/// <summary>
/// The X-Frame-Options header field value of the file.
/// The X-Frame-Options field will not be included in the response header of any HTTP GET command if this property is null or empty string.
/// </summary>
public string XFrameOptions
{
get { return _xFrameOptions; }
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("X-Frame-Options header field can contain up to 256 characters.");
_xFrameOptions = value;
}
}
/// <summary>
/// The link name of the file that will be shown in the WebUI.
/// If empty or null - no new link name will be added to the file.
/// This parameter will not be passed in the HTTP response header.
/// </summary>
public string Link
{
get { return _webUIlink; }
set { _webUIlink = value; }
}
public override string ToString()
{
StringBuilder str = new StringBuilder();
str.Append("<metadata>");
//Headers
str.Append("<headers>");
if (!String.IsNullOrEmpty(ContentType))
str.Append("<h>Content-Type:" + ContentType + "</h>");
if (!String.IsNullOrEmpty(ContentEncoding))
str.Append("<h>Content-Encoding:" + ContentEncoding + "</h>");
if (!String.IsNullOrEmpty(ContentDisposition))
str.Append("<h>Content-Disposition:" + ContentDisposition + "</h>");
if (!String.IsNullOrEmpty(CacheControl))
str.Append("<h>Cache-Control:" + CacheControl + "</h>");
if (!String.IsNullOrEmpty(XFrameOptions))
str.Append("<h>X-Frame-Options:" + XFrameOptions + "</h>");
str.Append("</headers>");
//WebUI Link
if (!String.IsNullOrEmpty(Link))
{
str.Append("<link>" + Link + "</link>");
}
str.Append("</metadata>");
return str.ToString();
}
public byte[] GetBytes()
{
string headerStr = ToString();
return Encoding.UTF8.GetBytes(headerStr);
}
}
#endregion //Structs
#region Enums
/// <summary>
/// HTTP request method.
/// </summary>
public enum HttpRequestMethod
{
PUT = 0,
GET,
DELETE
}
/// <summary>
/// Authentication scheme.
/// </summary>
public enum AuthenticationScheme
{
Digest = 0,
Kerberos
}
#endregion //Enums
}