Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Clean and use vfs helper

- Add simple helpers to RemoteVfsManager
- Use a separate RemoteVfsManager instance for wwwroot files
- Use it to create default.htm in 'reuse' mode
  • Loading branch information...
commit 96a87c3e5883d85c5872628fb8a30df9984bcb9a 1 parent 2f9bd16
@davidebbo davidebbo authored
View
64 Kudu.Client/Editor/RemoteVfsManager.cs
@@ -1,5 +1,7 @@
-using System.Net;
+using System;
+using System.Net;
using System.Net.Http;
+using System.Net.Http.Headers;
using Kudu.Client.Infrastructure;
namespace Kudu.Client.Editor
@@ -10,5 +12,65 @@ public RemoteVfsManager(string serviceUrl, ICredentials credentials = null, Http
: base(serviceUrl, credentials, handler)
{
}
+
+ public string ReadAllText(string path)
+ {
+ HttpResponseMessage response = Client.GetAsync(path).Result;
+ if (response.StatusCode == HttpStatusCode.NotFound)
+ {
+ return null;
+ }
+
+ return response
+ .EnsureSuccessful()
+ .Content
+ .ReadAsStringAsync()
+ .Result;
+ }
+
+ public void WriteAllText(string path, string content)
+ {
+ // First make a HEAD response to get the ETag (if the file exists)
+ HttpResponseMessage response = GetHeadResponse(path);
+
+ using (var request = new HttpRequestMessage())
+ {
+ request.Method = HttpMethod.Put;
+ request.RequestUri = new Uri(path, UriKind.Relative);
+ if (response.StatusCode == HttpStatusCode.OK)
+ {
+ request.Headers.IfMatch.Add(response.Headers.ETag);
+ }
+ request.Content = new StringContent(content);
+ Client.SendAsync(request).Result.EnsureSuccessful();
+ }
+ }
+
+ public void Delete(string path)
+ {
+ // First make a HEAD response to get the ETag (if the file exists)
+ HttpResponseMessage response = GetHeadResponse(path);
+
+ // Nothing to delete if it doesn't exist
+ if (response.StatusCode == HttpStatusCode.NotFound) return;
+
+ using (var request = new HttpRequestMessage())
+ {
+ request.Method = HttpMethod.Delete;
+ request.RequestUri = new Uri(path, UriKind.Relative);
+ request.Headers.IfMatch.Add(response.Headers.ETag);
+ Client.SendAsync(request).Result.EnsureSuccessful();
+ }
+ }
+
+ private HttpResponseMessage GetHeadResponse(string path)
+ {
+ using (var headRequest = new HttpRequestMessage())
+ {
+ headRequest.Method = HttpMethod.Head;
+ headRequest.RequestUri = new Uri(path, UriKind.Relative);
+ return Client.SendAsync(headRequest).Result;
+ }
+ }
}
}
View
10 Kudu.TestHarness/ApplicationManager.cs
@@ -80,6 +80,12 @@ public RemoteVfsManager VfsManager
private set;
}
+ public RemoteVfsManager VfsWebRootManager
+ {
+ get;
+ private set;
+ }
+
public RemoteVfsManager LiveScmVfsManager
{
get;
@@ -117,6 +123,9 @@ public static void Run(string applicationName, Action<ApplicationManager> action
{
// In site reuse mode, clean out the existing site so we start clean
appManager.RepositoryManager.Delete().Wait();
+
+ // Make sure we start with the correct default file as some tests expect it
+ appManager.VfsWebRootManager.WriteAllText("index.html", "<h1>The web site is under construction</h1>");
}
var dumpPath = Path.Combine(PathHelper.TestResultsPath, applicationName, applicationName + ".zip");
@@ -195,6 +204,7 @@ public static ApplicationManager CreateApplication(string applicationName)
LogStreamManager = new RemoteLogStreamManager(site.ServiceUrl + "logstream"),
SSHKeyManager = new RemoteSSHKeyManager(site.ServiceUrl + "sshkey"),
VfsManager = new RemoteVfsManager(site.ServiceUrl + "vfs"),
+ VfsWebRootManager = new RemoteVfsManager(site.ServiceUrl + "vfs/site/wwwroot/"),
LiveScmVfsManager = new RemoteVfsManager(site.ServiceUrl + "scmvfs"),
RepositoryManager = repositoryManager,
};
Please sign in to comment.
Something went wrong with that request. Please try again.