Commit ead81899 authored by Honfika's avatar Honfika

some property setter visibility changed, wpf demo project simplified

parent b6829121
......@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
set { SetValue(ServerConnectionCountProperty, value); }
}
private readonly Dictionary<SessionEventArgs, SessionListItem> sessionDictionary = new Dictionary<SessionEventArgs, SessionListItem>();
private readonly Dictionary<HttpWebClient, SessionListItem> sessionDictionary = new Dictionary<HttpWebClient, SessionListItem>();
private SessionListItem selectedSession;
public MainWindow()
......@@ -105,7 +105,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
await Dispatcher.InvokeAsync(() =>
{
SessionListItem item;
if (sessionDictionary.TryGetValue(e, out item))
if (sessionDictionary.TryGetValue(e.WebSession, out item))
{
item.Update();
}
......@@ -133,7 +133,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
await Dispatcher.InvokeAsync(() =>
{
SessionListItem item2;
if (sessionDictionary.TryGetValue(e, out item2))
if (sessionDictionary.TryGetValue(e.WebSession, out item2))
{
item2.Update();
item = item2;
......@@ -154,27 +154,28 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{
var item = CreateSessionListItem(e);
Sessions.Add(item);
sessionDictionary.Add(e, item);
sessionDictionary.Add(e.WebSession, item);
return item;
}
private SessionListItem CreateSessionListItem(SessionEventArgs e)
{
lastSessionNumber++;
bool isTunnelConnect = e is TunnelConnectSessionEventArgs;
var item = new SessionListItem
{
Number = lastSessionNumber,
SessionArgs = e,
WebSession = e.WebSession,
IsTunnelConnect = isTunnelConnect,
};
if (e is TunnelConnectSessionEventArgs || e.WebSession.Request.UpgradeToWebSocket)
if (isTunnelConnect || e.WebSession.Request.UpgradeToWebSocket)
{
e.DataReceived += (sender, args) =>
{
var session = (SessionEventArgs)sender;
SessionListItem li;
if (sessionDictionary.TryGetValue(session, out li))
if (sessionDictionary.TryGetValue(session.WebSession, out li))
{
li.ReceivedDataCount += args.Count;
}
......@@ -184,7 +185,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{
var session = (SessionEventArgs)sender;
SessionListItem li;
if (sessionDictionary.TryGetValue(session, out li))
if (sessionDictionary.TryGetValue(session.WebSession, out li))
{
li.SentDataCount += args.Count;
}
......@@ -203,7 +204,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
foreach (var item in selectedItems.Cast<SessionListItem>().ToArray())
{
Sessions.Remove(item);
sessionDictionary.Remove(item.SessionArgs);
sessionDictionary.Remove(item.WebSession);
}
}
}
......
......@@ -20,7 +20,9 @@ namespace Titanium.Web.Proxy.Examples.Wpf
public int Number { get; set; }
public SessionEventArgs SessionArgs { get; set; }
public HttpWebClient WebSession { get; set; }
public bool IsTunnelConnect { get; set; }
public string StatusCode
{
......@@ -70,8 +72,6 @@ namespace Titanium.Web.Proxy.Examples.Wpf
set { SetField(ref sentDataCount, value); }
}
public HttpWebClient WebSession { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void SetField<T>(ref T field, T value,[CallerMemberName] string propertyName = null)
......@@ -88,13 +88,13 @@ namespace Titanium.Web.Proxy.Examples.Wpf
public void Update()
{
var request = SessionArgs.WebSession.Request;
var response = SessionArgs.WebSession.Response;
var request = WebSession.Request;
var response = WebSession.Response;
int statusCode = response?.ResponseStatusCode ?? 0;
StatusCode = statusCode == 0 ? "-" : statusCode.ToString();
Protocol = request.RequestUri.Scheme;
if (SessionArgs is TunnelConnectSessionEventArgs)
if (IsTunnelConnect)
{
Host = "Tunnel to";
Url = request.RequestUri.Host + ":" + request.RequestUri.Port;
......@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
}
BodySize = response?.ContentLength ?? -1;
Process = GetProcessDescription(SessionArgs.WebSession.ProcessId.Value);
Process = GetProcessDescription(WebSession.ProcessId.Value);
}
private string GetProcessDescription(int processId)
......
......@@ -79,17 +79,17 @@ namespace Titanium.Web.Proxy.EventArguments
/// A web session corresponding to a single request/response sequence
/// within a proxy connection
/// </summary>
public HttpWebClient WebSession { get; set; }
public HttpWebClient WebSession { get; }
/// <summary>
/// Are we using a custom upstream HTTP proxy?
/// </summary>
public ExternalProxy CustomUpStreamHttpProxyUsed { get; set; }
public ExternalProxy CustomUpStreamHttpProxyUsed { get; internal set; }
/// <summary>
/// Are we using a custom upstream HTTPS proxy?
/// </summary>
public ExternalProxy CustomUpStreamHttpsProxyUsed { get; set; }
public ExternalProxy CustomUpStreamHttpsProxyUsed { get; internal set; }
public event EventHandler<DataEventArgs> DataSent;
......
using System.Net;
using Titanium.Web.Proxy.Http;
using Titanium.Web.Proxy.Models;
namespace Titanium.Web.Proxy.EventArguments
......@@ -7,10 +8,10 @@ namespace Titanium.Web.Proxy.EventArguments
{
public bool IsHttpsConnect { get; set; }
public TunnelConnectSessionEventArgs(int bufferSize, ProxyEndPoint endPoint)
internal TunnelConnectSessionEventArgs(int bufferSize, ProxyEndPoint endPoint, ConnectRequest connectRequest)
: base(bufferSize, endPoint, null)
{
WebSession.Request = connectRequest;
}
}
}
......@@ -33,17 +33,17 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// Headers passed with Connect.
/// </summary>
public ConnectRequest ConnectRequest { get; set; }
public ConnectRequest ConnectRequest { get; internal set; }
/// <summary>
/// Web Request.
/// </summary>
public Request Request { get; set; }
public Request Request { get; internal set; }
/// <summary>
/// Web Response.
/// </summary>
public Response Response { get; set; }
public Response Response { get; internal set; }
/// <summary>
/// PID of the process that is created the current session when client is running in this machine
......@@ -74,8 +74,7 @@ namespace Titanium.Web.Proxy.Http
connection.LastAccess = DateTime.Now;
ServerConnection = connection;
}
/// <summary>
/// Prepare and send the http(s) request
/// </summary>
......
......@@ -88,8 +88,7 @@ namespace Titanium.Web.Proxy
await HeaderParser.ReadHeaders(clientStreamReader, connectRequest.RequestHeaders);
var connectArgs = new TunnelConnectSessionEventArgs(BufferSize, endPoint);
connectArgs.WebSession.Request = connectRequest;
var connectArgs = new TunnelConnectSessionEventArgs(BufferSize, endPoint, connectRequest);
connectArgs.ProxyClient.TcpClient = tcpClient;
connectArgs.ProxyClient.ClientStream = clientStream;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment