-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathTracing.cs
70 lines (59 loc) · 2.04 KB
/
Tracing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
using System;
using System.Linq;
using System.Runtime.Serialization;
namespace Moryx.AbstractionLayer
{
/// <summary>
/// Activity trace information
/// </summary>
[DataContract]
public class Tracing
{
/// <summary>
/// The time when this activity was started.
/// </summary>
public DateTime? Started { get; set; }
/// <summary>
/// The time when this activity was finished.
/// </summary>
public DateTime? Completed { get; set; }
/// <summary>
/// Optional tracing text for errors or information
/// </summary>
public string Text { get; set; }
/// <summary>
/// Contains the error code that is associated with the error that caused e.g. an activity failure
/// </summary>
public int ErrorCode { get; set; }
/// <summary>
/// Generic progress information
/// </summary>
public int Progress { get; set; }
/// <summary>
/// Resource that executed the activity
/// </summary>
public long ResourceId { get; set; }
///
// ReSharper disable once InconsistentNaming <-- too cool to rename :P
public Sparta Transform<Sparta>() where Sparta
: Tracing, new()
{
if (this is Sparta)
return this as Sparta;
var replacement = new Sparta();
var replacementType = typeof(Sparta);
var sharedProperties = GetType().GetProperties()
// ReSharper disable once PossibleNullReferenceException
.Where(p => p.DeclaringType.IsAssignableFrom(replacementType));
foreach (var property in sharedProperties)
{
var value = property.GetValue(this);
if (property.CanWrite)
property.SetValue(replacement, value);
}
return replacement;
}
}
}