/// <summary> /// Processes the specified request. /// </summary> /// <param name="url">The requested plug-in <see cref="PlugInUrl">URL</see>.</param> /// <param name="request">The <see cref="HttpRequestMessage">HTTP request</see> to process.</param> /// <param name="cancellationToken">The <see cref="CancellationToken">token</see> that can be used to cancel the operation.</param> /// <returns>The <see cref="Task{TResult}"/> containing the <see cref="HttpResponseMessage">HTTP response</see>.</returns> protected override async Task <HttpResponseMessage> Process(PlugInUrl url, HttpRequestMessage request, CancellationToken cancellationToken) { // simulate long-running operation await Task.Delay(1000).ConfigureAwait(false); return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent($"{{\"message\":\"Hello world from '{this.Name}'\"}}", Encoding.UTF8, "application/json"), }); }
/// <summary> /// Override for the Process method that specifies the actions that the plugin will execute. /// </summary> /// <param name="url">The requested plug-in <see cref="PlugInUrl">URL</see>.</param> /// <param name="request">The <see cref="HttpRequestMessage">HTTP request</see> to process.</param> /// <param name="cancellationToken">The <see cref="CancellationToken">token</see> that can be used to cancel the operation.</param> /// <returns>The <see cref="Task{TResult}"/> containing the <see cref="HttpResponseMessage">HTTP response</see>.</returns> protected override async Task <HttpResponseMessage> Process(PlugInUrl url, HttpRequestMessage request, CancellationToken cancellationToken) { await Task.Yield(); var message = new StringBuilder($"Hello world from '{this.Name}' (running as {this.User.Identity.Name}"); if (!StringComparer.OrdinalIgnoreCase.Equals(this.User.Identity.Name, this.NetworkIdentity.Name)) { message.Append($", managing as {this.NetworkIdentity.Name}"); } message.Append(')'); return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(message.ToString(), Encoding.UTF8, "text/plain"), }); }
/// <summary> /// Override for the Process method that specifies the actions that the plugin will execute. /// </summary> /// <param name="url">The requested plug-in <see cref="PlugInUrl">URL</see>.</param> /// <param name="request">The <see cref="HttpRequestMessage">HTTP request</see> to process.</param> /// <param name="cancellationToken">The <see cref="CancellationToken">token</see> that can be used to cancel the operation.</param> /// <returns>The <see cref="Task{TResult}"/> containing the <see cref="HttpResponseMessage">HTTP response</see>.</returns> protected override async Task <HttpResponseMessage> Process(PlugInUrl url, HttpRequestMessage request, CancellationToken cancellationToken) { await Task.Yield(); var credentials = this.GetWindowsCredential(url.TargetNode); var message = new StringBuilder($"Hello world from '{this.Name}' (running as { credentials.UserName }"); // You can get access to the "manage as" credentials like this: var tempPassword = credentials.Password; message.Append(')'); return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(message.ToString(), Encoding.UTF8, "text/plain"), }); throw new NotImplementedException(); }