-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- For gifv files only an image was shown. - Now the gifv file is played back.
- Loading branch information
Showing
7 changed files
with
145 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Net; | ||
using System.Threading; | ||
|
||
namespace WpfImageViewer | ||
{ | ||
internal class MediaFileServer | ||
{ | ||
private readonly HttpListener _httpListener = new HttpListener(); | ||
private readonly Func<HttpListenerRequest, byte[]> _requestHandlerMethod; | ||
private string _prefix; | ||
|
||
public string Prefix { get => _prefix; } | ||
|
||
public MediaFileServer(string prefix, Func<HttpListenerRequest, byte[]> requestHandlerMethod) | ||
{ | ||
_ = prefix ?? throw new ArgumentNullException(nameof(prefix)); | ||
_ = requestHandlerMethod ?? throw new ArgumentNullException(nameof(requestHandlerMethod)); | ||
|
||
_prefix = prefix; | ||
_requestHandlerMethod = requestHandlerMethod; | ||
_httpListener.Prefixes.Add(prefix); | ||
_httpListener.Start(); | ||
} | ||
|
||
public void Run() | ||
{ | ||
_ = ThreadPool.QueueUserWorkItem((o) => | ||
{ | ||
try | ||
{ | ||
while (_httpListener.IsListening) | ||
{ | ||
_ = ThreadPool.QueueUserWorkItem((c) => | ||
{ | ||
var ctx = c as HttpListenerContext; | ||
try | ||
{ | ||
byte[] buffer = _requestHandlerMethod(ctx.Request); | ||
ctx.Response.ContentLength64 = buffer.Length; | ||
ctx.Response.ContentType = "application/octet-stream"; | ||
ctx.Response.OutputStream.Write(buffer, 0, buffer.Length); | ||
} | ||
catch { } | ||
finally | ||
{ | ||
ctx.Response.OutputStream.Close(); | ||
} | ||
}, _httpListener.GetContext()); | ||
} | ||
} | ||
catch { } | ||
}); | ||
} | ||
|
||
public void Stop() | ||
{ | ||
_httpListener.Stop(); | ||
_httpListener.Close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters