Skip to content

Commit 05bd76d

Browse files
committed
Removed unnecessary code to make demo simpler
1 parent 5fc50fa commit 05bd76d

File tree

3 files changed

+22
-40
lines changed

3 files changed

+22
-40
lines changed

.vs/config/applicationhost.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
</site>
164164
<site name="eCommerce.WebService" id="2">
165165
<application path="/" applicationPool="Clr4IntegratedAppPool">
166-
<virtualDirectory path="/" physicalPath="C:\Users\Zan Kavtaskin\Source\Repos\Domain-Driven-Design-Example\eCommerce.WebService" />
166+
<virtualDirectory path="/" physicalPath="\\vmware-host\Shared Folders\Documents\GitHub\Domain-Driven-Design-Example\eCommerce.WebService" />
167167
</application>
168168
<bindings>
169169
<binding protocol="http" bindingInformation="*:50300:localhost" />
Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using eCommerce.Helpers.Logging;
22
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Net;
6-
using System.Net.Http;
73
using System.Security.Cryptography;
84
using System.Text;
95
using System.Web;
@@ -16,42 +12,29 @@ public class WebRequestCorrelationIdentifier : IRequestCorrelationIdentifier
1612

1713
public WebRequestCorrelationIdentifier()
1814
{
19-
string ipAddress = getIPAddress();
20-
string userName = HttpContext.Current.Request.Params["LOGON_USER"];
21-
string userAgent = HttpContext.Current.Request.UserAgent.ToString();
22-
string time = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
23-
24-
string rawId = time + "|" + ipAddress + "|" + userName + "|" + userAgent;
25-
26-
this.CorrelationID = md5Hash(rawId);
27-
}
28-
29-
private static string getIPAddress()
30-
{
31-
string ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
32-
33-
if (string.IsNullOrEmpty(ip))
34-
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
35-
else
36-
ip = ip.Split(',')[0];
37-
38-
return ip;
39-
}
40-
41-
private static string md5Hash(string input)
42-
{
43-
MD5 md5 = System.Security.Cryptography.MD5.Create();
44-
45-
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
46-
byte[] hash = md5.ComputeHash(inputBytes);
47-
48-
StringBuilder sb = new StringBuilder();
49-
for (int i = 0; i < hash.Length; i++)
15+
/* #Customise your correlation ID here
16+
* More request identification varibles you add easier
17+
* it's going to be to find the relevant W3C request when you hash it
18+
*
19+
* Below is just an example of varibles and hash algorithm that you can use:
20+
*/
21+
string rawCorrelationID = string.Join("_",
22+
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"],
23+
HttpContext.Current.Request.Params["LOGON_USER"],
24+
HttpContext.Current.Request.UserAgent.ToString(),
25+
HttpContext.Current.Request.Path,
26+
DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")
27+
);
28+
29+
StringBuilder hashBuilder = new StringBuilder();
30+
using (MD5 md5 = MD5.Create())
5031
{
51-
sb.Append(hash[i].ToString("X2"));
32+
byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(rawCorrelationID));
33+
for (int i = 0; i < hash.Length; i++)
34+
hashBuilder.Append(hash[i].ToString("X2"));
5235
}
5336

54-
return sb.ToString();
37+
this.CorrelationID = hashBuilder.ToString();
5538
}
5639
}
5740
}

eCommerce/Helpers/Domain/DomainEventRecord.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ namespace eCommerce.Helpers.Domain
88
public class DomainEventRecord
99
{
1010
public string Type { get; set; }
11-
public DateTime Created { get; set; }
1211
public List<KeyValuePair<string, string>> Args { get; set; }
13-
1412
public string CorrelationID { get; set; }
13+
public DateTime Created { get; set; }
1514
}
1615
}

0 commit comments

Comments
 (0)