92 lines
3.4 KiB
Plaintext
92 lines
3.4 KiB
Plaintext
====================================================================================================================
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="storageContainer"></param>
|
|
/// <param name="path"></param>
|
|
/// <returns></returns>
|
|
//======================================================================================================================
|
|
public StorageObject GetStorageObject(string path)
|
|
{
|
|
try
|
|
{
|
|
path = path.Replace(@"\", "/");
|
|
RequestHeaders headers = StorageRequestSigner.CreateSignedHeaders(HttpMethod.GET, path);
|
|
string resourcePath = ["StorageManagementURI"] + "/" + path;
|
|
HttpClient client = new HttpClient();
|
|
client.DefaultHeaders = headers;
|
|
|
|
Uri uri = new Uri(resourcePath);
|
|
HttpResponseMessage msg = client.Get(uri);
|
|
|
|
if (msg.StatusCode == System.Net.HttpStatusCode.OK)
|
|
{
|
|
msg.Content.LoadIntoBufferAsync();
|
|
StorageObject storageObject = new StorageObject();
|
|
storageObject.Key = path;
|
|
storageObject.Load(msg.Content.ReadAsStream());
|
|
this.CopyCommonRequestHeaders(ref storageObject, msg.Headers);
|
|
return storageObject;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex);
|
|
}
|
|
return null;
|
|
}
|
|
//======================================================================================================================
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
/// <returns></returns>
|
|
//======================================================================================================================
|
|
public bool IsValidPath(string storageContainer, string path)
|
|
{
|
|
HttpClient client = new HttpClient();
|
|
Uri uri = new Uri(["StorageManagementURI"] + cDelimiter + storageContainer + cDelimiter + path + cDelimiter + "folder.txt");
|
|
string rootCheck = null;
|
|
|
|
if (path == cDelimiter) {
|
|
rootCheck = String.Empty;
|
|
}
|
|
else {
|
|
rootCheck = cFolderMarker;
|
|
}
|
|
|
|
|
|
if (this.GetStorageObject(storageContainer + cDelimiter + path + cDelimiter + rootCheck) != null)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
//======================================================================================================================
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
//======================================================================================================================
|
|
public StorageObjects GetStorageObjects (string storageContainer, string path)
|
|
{
|
|
HttpQueryString queryString = new HttpQueryString();
|
|
|
|
if (path == "")
|
|
{
|
|
queryString.Add("prefix", "" );
|
|
queryString.Add("delimiter", "/");
|
|
}
|
|
else
|
|
{
|
|
path = path.Replace(@"\", "/");
|
|
queryString.Add("prefix", path);
|
|
queryString.Add("delimiter", "/");
|
|
} |