Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit d2ccf29

Browse files
committed
events
1 parent 7c91912 commit d2ccf29

223 files changed

Lines changed: 5490 additions & 23463 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Backend/Jp.Application/AutoMapper/DomainToViewModelMappingProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public DomainToViewModelMappingProfile()
2222
CreateMap<User, UserViewModel>(MemberList.Destination);//.ForMember(x => x.LockoutEnd, opt => opt.MapFrom(src => src.LockoutEnd != null ? src.LockoutEnd.Value.DateTime.ToShortDateString() : string.Empty));
2323
CreateMap<User, UserListViewModel>(MemberList.Destination);
2424

25-
CreateMap<StoredEvent, EventHistoryData>().ConstructUsing(a => new EventHistoryData() { Action = a.MessageType, Id = a.Id.ToString(), Details = a.Data, When = a.Timestamp.ToString(CultureInfo.InvariantCulture), Who = a.User });
25+
CreateMap<StoredEvent, EventHistoryData>().ConstructUsing(a => new EventHistoryData() { Action = a.Message, Id = a.Id.ToString(), Details = a.Data, When = a.Timestamp.ToString(CultureInfo.InvariantCulture), Who = a.User, Category = a.MessageType });
2626
CreateMap<Client, ClientListViewModel>(MemberList.Destination);
2727
CreateMap<IdentityServer4.EntityFramework.Entities.Secret, SecretViewModel>(MemberList.Destination);
2828
CreateMap<IdentityServer4.EntityFramework.Entities.ClientProperty, ClientPropertyViewModel>();

src/Backend/Jp.Application/EventSourcedNormalizers/EventHistoryData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
public class EventHistoryData
44
{
5+
public string Category { get; set; }
56
public string Action { get; set; }
67
public string Id { get; set; }
78
public string When { get; set; }

src/Backend/Jp.Application/ViewModels/UserViewModels/RegisterUserViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Jp.Domain.Core.StringUtils;
2+
using System;
23
using System.ComponentModel.DataAnnotations;
34

45
namespace Jp.Application.ViewModels.UserViewModels
@@ -46,7 +47,7 @@ public class RegisterUserViewModel
4647

4748
public bool ContainsFederationGateway()
4849
{
49-
return !string.IsNullOrEmpty(Provider) && !string.IsNullOrEmpty(ProviderId);
50+
return Provider.IsMissing() && ProviderId.IsMissing();
5051

5152
}
5253

src/Backend/Jp.Domain.Core/Events/Event.cs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
1-
using System;
2-
using MediatR;
1+
using MediatR;
2+
using System;
33

44
namespace Jp.Domain.Core.Events
55
{
66
public abstract class Event : Message, INotification
77
{
8-
public DateTime Timestamp { get; private set; }
8+
/// <summary>
9+
/// Gets or sets the time stamp when the event was raised.
10+
/// </summary>
11+
/// <value>
12+
/// The time stamp.
13+
/// </value>
14+
public DateTime Timestamp { get; protected set; }
915

10-
protected Event()
16+
public EventTypes EventType { get; set; }
17+
/// <summary>
18+
/// Gets or sets the local ip address of the current request.
19+
/// </summary>
20+
/// <value>
21+
/// The local ip address.
22+
/// </value>
23+
public string LocalIpAddress { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the remote ip address of the current request.
27+
/// </summary>
28+
/// <value>
29+
/// The remote ip address.
30+
/// </value>
31+
public string RemoteIpAddress { get; set; }
32+
33+
/// <summary>
34+
/// Gets or sets the event message.
35+
/// </summary>
36+
/// <value>
37+
/// The message.
38+
/// </value>
39+
public string Message { get; set; }
40+
41+
protected Event() { }
42+
protected Event(EventTypes eventType)
1143
{
1244
Timestamp = DateTime.Now;
1345
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Jp.Domain.Core.Events
2+
{
3+
public enum EventTypes
4+
{
5+
Success = 1,
6+
Failure = 2,
7+
Information = 3,
8+
Error = 4,
9+
}
10+
}

src/Backend/Jp.Domain.Core/Events/Message.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using MediatR;
1+
using MediatR;
32

43
namespace Jp.Domain.Core.Events
54
{
@@ -10,6 +9,7 @@ public abstract class Message : IRequest
109

1110
protected Message()
1211
{
12+
1313
MessageType = GetType().Name;
1414
}
1515
}

src/Backend/Jp.Domain.Core/Events/StoredEvent.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,29 @@ namespace Jp.Domain.Core.Events
44
{
55
public class StoredEvent : Event
66
{
7-
public StoredEvent(Event theEvent, string data, string userId)
7+
public StoredEvent(
8+
string aggregateId,
9+
string messageType,
10+
EventTypes eventType,
11+
string customMessage,
12+
string localIpAddress,
13+
string remoteIpAddress,
14+
string data) : base(eventType)
815
{
916
Id = Guid.NewGuid();
10-
AggregateId = theEvent.AggregateId;
11-
MessageType = theEvent.MessageType;
17+
AggregateId = aggregateId;
18+
MessageType = messageType;
19+
EventType = eventType;
20+
Message = customMessage;
21+
LocalIpAddress = localIpAddress;
22+
RemoteIpAddress = remoteIpAddress;
1223
Data = data;
13-
User = userId;
24+
}
25+
26+
public StoredEvent SetUser(string user)
27+
{
28+
this.User = user;
29+
return this;
1430
}
1531

1632
// EF Constructor
@@ -21,5 +37,10 @@ protected StoredEvent() { }
2137
public string Data { get; private set; }
2238

2339
public string User { get; private set; }
40+
public StoredEvent ReplaceTimeStamp(in DateTime timeStamp)
41+
{
42+
Timestamp = timeStamp;
43+
return this;
44+
}
2445
}
2546
}

src/Backend/Jp.Domain.Core/Notifications/DomainNotification.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
2-
using Jp.Domain.Core.Events;
1+
using Jp.Domain.Core.Events;
2+
using System;
33

44
namespace Jp.Domain.Core.Notifications
55
{
@@ -11,6 +11,7 @@ public class DomainNotification : Event
1111
public int Version { get; private set; }
1212

1313
public DomainNotification(string key, string value)
14+
: base(EventTypes.Failure)
1415
{
1516
DomainNotificationId = Guid.NewGuid();
1617
Version = 1;

src/Backend/Jp.Domain.Core/StringUtils/StringExtensions.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text.RegularExpressions;
1+
using System;
2+
using System.Text.RegularExpressions;
23

34
namespace Jp.Domain.Core.StringUtils
45
{
@@ -10,5 +11,52 @@ public static bool IsEmail(this string username)
1011
return Regex.IsMatch(username, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
1112
}
1213

14+
public static bool IsMissing(this string value)
15+
{
16+
return string.IsNullOrWhiteSpace(value);
17+
}
18+
19+
public static bool IsPresent(this string value)
20+
{
21+
return !string.IsNullOrWhiteSpace(value);
22+
}
23+
24+
25+
public static string AddSpacesToSentence(this string state)
26+
{
27+
var text = state.ToCharArray();
28+
var chars = new char[text.Length + HowManyCapitalizedChars(text)];
29+
30+
chars[0] = text[0];
31+
int j = 1;
32+
for (int i = 1; i < text.Length; i++)
33+
{
34+
if (char.IsUpper(text[i]))
35+
{
36+
if (text[i - 1] != ' ' && !char.IsUpper(text[i - 1]) ||
37+
(char.IsUpper(text[i - 1]) && i < text.Length - 1 && !char.IsUpper(text[i + 1])))
38+
{
39+
chars[j++] = ' ';
40+
chars[j++] = text[i];
41+
continue;
42+
}
43+
}
44+
45+
chars[j++] = text[i];
46+
}
47+
48+
return new string(chars.AsSpan());
49+
}
50+
private static int HowManyCapitalizedChars(char[] state)
51+
{
52+
var count = 0;
53+
for (var i = 0; i < state.Length; i++)
54+
{
55+
if (char.IsUpper(state[i]))
56+
count++;
57+
}
58+
59+
return count;
60+
}
1361
}
1462
}

src/Backend/Jp.Domain/Commands/Clients/SaveClientCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Jp.Domain.Validations.Client;
44
using System;
55
using System.Collections.Generic;
6+
using Jp.Domain.Core.StringUtils;
67

78
namespace Jp.Domain.Commands.Clients
89
{
@@ -22,7 +23,7 @@ public SaveClientCommand(string clientId, string name, string clientUri, string
2223
Description = description,
2324
};
2425

25-
if (!string.IsNullOrEmpty(postLogoutUri))
26+
if (postLogoutUri.IsMissing())
2627
Client.PostLogoutRedirectUris = new List<string>() { postLogoutUri };
2728
ClientType = clientType;
2829
}

0 commit comments

Comments
 (0)