Skip to content

Commit bd15118

Browse files
committed
Source Imported CodeSmith.Data for now
https://github.com/codesmithtools/CodeSmith.Data
1 parent ea4102c commit bd15118

File tree

204 files changed

+27824
-0
lines changed

Some content is hidden

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

204 files changed

+27824
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using CodeSmith.Data.Rules;
2+
using CodeSmith.Data.Rules.Assign;
3+
4+
namespace CodeSmith.Data.Attributes
5+
{
6+
/// <summary>
7+
/// Assigns a new GUID to the property for the specified entity states.
8+
/// </summary>
9+
/// <example>
10+
/// <para>Add rule using the Metadata class and attribute.</para>
11+
/// <code><![CDATA[
12+
/// private class Metadata
13+
/// {
14+
/// // fragment of the metadata class
15+
///
16+
/// [Guid(EntityState.New)]
17+
/// public Guid UserId { get; set; }
18+
/// }
19+
/// ]]></code>
20+
/// </example>
21+
/// <seealso cref="T:CodeSmith.Data.Rules.Assign.GuidRule"/>
22+
public class GuidAttribute : RuleAttributeBase
23+
{
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="GuidAttribute"/> class.
26+
/// </summary>
27+
public GuidAttribute()
28+
{}
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="GuidAttribute"/> class.
32+
/// </summary>
33+
/// <param name="state">State of the object that can be assigned.</param>
34+
public GuidAttribute(EntityState state)
35+
{
36+
State = state;
37+
}
38+
39+
/// <summary>
40+
/// Creates the rule.
41+
/// </summary>
42+
/// <param name="property">The property name this rule applies to.</param>
43+
/// <returns>A new instance of the rule.</returns>
44+
public override IRule CreateRule(string property)
45+
{
46+
return new GuidRule(property, State);
47+
}
48+
49+
/// <summary>
50+
/// Determines whether the specified value of the object is valid.
51+
/// </summary>
52+
/// <param name="value">The value of the specified validation object on which the <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute"/> is declared.</param>
53+
/// <returns>
54+
/// true if the specified value is valid; otherwise, false.
55+
/// </returns>
56+
public override bool IsValid(object value)
57+
{
58+
return true;
59+
}
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using CodeSmith.Data.Rules;
2+
using CodeSmith.Data.Rules.Assign;
3+
4+
namespace CodeSmith.Data.Attributes
5+
{
6+
/// <summary>
7+
/// Assigns the current user's IP address to the property for the specified entity states.
8+
/// </summary>
9+
/// <example>
10+
/// <para>Add rule using the Metadata class and attribute.</para>
11+
/// <code><![CDATA[
12+
/// private class Metadata
13+
/// {
14+
/// // fragment of the metadata class
15+
///
16+
/// [IpAddress(EntityState.Dirty)]
17+
/// public string IpAddress { get; set; }
18+
/// }
19+
/// ]]></code>
20+
/// </example>
21+
/// <seealso cref="T:CodeSmith.Data.Rules.Assign.IpAddressRule"/>
22+
public class IpAddressAttribute : RuleAttributeBase
23+
{
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="IpAddressAttribute"/> class.
26+
/// </summary>
27+
public IpAddressAttribute()
28+
{}
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="IpAddressAttribute"/> class.
32+
/// </summary>
33+
/// <param name="state">State of the object that can be assigned.</param>
34+
public IpAddressAttribute(EntityState state)
35+
{
36+
State = state;
37+
}
38+
39+
/// <summary>
40+
/// Creates the rule.
41+
/// </summary>
42+
/// <param name="property">The property name this rule applies to.</param>
43+
/// <returns>A new instance of the rule.</returns>
44+
public override IRule CreateRule(string property)
45+
{
46+
return new IpAddressRule(property, State);
47+
}
48+
49+
/// <summary>
50+
/// Determines whether the specified value of the object is valid.
51+
/// </summary>
52+
/// <param name="value">The value of the specified validation object on which the <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute"/> is declared.</param>
53+
/// <returns>
54+
/// true if the specified value is valid; otherwise, false.
55+
/// </returns>
56+
public override bool IsValid(object value)
57+
{
58+
return true;
59+
}
60+
}
61+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using CodeSmith.Data.Rules;
6+
using CodeSmith.Data.Rules.Validation;
7+
8+
namespace CodeSmith.Data.Attributes
9+
{
10+
public class NotNullAttribute : RuleAttributeBase
11+
{
12+
public NotNullAttribute()
13+
: this(EntityState.Dirty)
14+
{ }
15+
16+
public NotNullAttribute(EntityState state)
17+
{
18+
State = state;
19+
}
20+
21+
public override bool IsValid(object value)
22+
{
23+
return value != null;
24+
}
25+
26+
public override IRule CreateRule(string property)
27+
{
28+
return new NotNullRule(property);
29+
}
30+
}
31+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using CodeSmith.Data.Rules;
2+
using CodeSmith.Data.Rules.Assign;
3+
4+
namespace CodeSmith.Data.Attributes
5+
{
6+
/// <summary>
7+
/// Assigns the current date / time to the property for the specified entity states.
8+
/// </summary>
9+
/// <example>
10+
/// <para>Add rule using the Metadata class and attribute.</para>
11+
/// <code><![CDATA[
12+
/// private class Metadata
13+
/// {
14+
/// // fragment of the metadata class
15+
///
16+
/// [Now(EntityState.New)]
17+
/// public DateTime CreatedDate { get; set; }
18+
///
19+
/// [Now(EntityState.Dirty)]
20+
/// public DateTime ModifiedDate { get; set; }
21+
/// }
22+
/// ]]></code>
23+
/// </example>
24+
/// <seealso cref="T:CodeSmith.Data.Rules.Assign.NowRule"/>
25+
public class NowAttribute : RuleAttributeBase
26+
{
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="NowAttribute"/> class.
29+
/// </summary>
30+
public NowAttribute()
31+
: this(EntityState.Dirty, NowTimeZone.Local)
32+
{ }
33+
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="NowAttribute"/> class.
36+
/// </summary>
37+
/// <param name="state">State of the object that can be assigned.</param>
38+
public NowAttribute(EntityState state)
39+
: this(state, NowTimeZone.Local)
40+
{ }
41+
42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="NowAttribute"/> class.
44+
/// </summary>
45+
/// <param name="state">State of the object that can be assigned.</param>
46+
/// <param name="timeZone">The time zone.</param>
47+
public NowAttribute(EntityState state, NowTimeZone timeZone)
48+
{
49+
State = state;
50+
TimeZone = timeZone;
51+
}
52+
53+
54+
public NowTimeZone TimeZone { get; set; }
55+
56+
/// <summary>
57+
/// Creates the rule.
58+
/// </summary>
59+
/// <param name="property">The property name this rule applies to.</param>
60+
/// <returns>A new instance of the rule.</returns>
61+
public override IRule CreateRule(string property)
62+
{
63+
return new NowRule(property, State, TimeZone);
64+
}
65+
66+
/// <summary>
67+
/// Determines whether the specified value of the object is valid.
68+
/// </summary>
69+
/// <param name="value">The value of the specified validation object on which the <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute"/> is declared.</param>
70+
/// <returns>
71+
/// true if the specified value is valid; otherwise, false.
72+
/// </returns>
73+
public override bool IsValid(object value)
74+
{
75+
return true;
76+
}
77+
}
78+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
using CodeSmith.Data.Rules;
4+
5+
namespace CodeSmith.Data.Attributes
6+
{
7+
/// <summary>
8+
/// A base class for rule attributes.
9+
/// </summary>
10+
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
11+
public abstract class RuleAttributeBase : ValidationAttribute
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="RuleAttributeBase"/> class.
15+
/// </summary>
16+
protected RuleAttributeBase()
17+
{
18+
State = EntityState.Dirty;
19+
}
20+
21+
/// <summary>
22+
/// Gets or sets the state.
23+
/// </summary>
24+
/// <value>The state of the object that the rule can run on.</value>
25+
public EntityState State { get; protected set; }
26+
27+
/// <summary>
28+
/// Creates the rule.
29+
/// </summary>
30+
/// <param name="property">The property name this rule applies to.</param>
31+
/// <returns>A new instance of the rule.</returns>
32+
public abstract IRule CreateRule(string property);
33+
}
34+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using CodeSmith.Data.Rules;
2+
using CodeSmith.Data.Rules.Assign;
3+
4+
namespace CodeSmith.Data.Attributes
5+
{
6+
/// <summary>
7+
/// Assigns the current users name to the property for the specified entity states.
8+
/// </summary>
9+
/// <example>
10+
/// <para>Add rule using the Metadata class and attribute.</para>
11+
/// <code><![CDATA[
12+
/// private class Metadata
13+
/// {
14+
/// // fragment of the metadata class
15+
///
16+
/// [UserName(EntityState.New)]
17+
/// public string CreatedBy { get; set; }
18+
///
19+
/// [UserName(EntityState.Dirty)]
20+
/// public string ModifiedBy { get; set; }
21+
/// }
22+
/// ]]></code>
23+
/// </example>
24+
/// <seealso cref="T:CodeSmith.Data.Rules.Assign.UserNameRule"/>
25+
public class UserNameAttribute : RuleAttributeBase
26+
{
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="UserNameAttribute"/> class.
29+
/// </summary>
30+
public UserNameAttribute()
31+
{}
32+
33+
/// <summary>
34+
/// Initializes a new instance of the <see cref="UserNameAttribute"/> class.
35+
/// </summary>
36+
/// <param name="state">State of the object that can be assigned.</param>
37+
public UserNameAttribute(EntityState state)
38+
{
39+
State = state;
40+
}
41+
42+
/// <summary>
43+
/// Creates the rule.
44+
/// </summary>
45+
/// <param name="property">The property name this rule applies to.</param>
46+
/// <returns>A new instance of the rule.</returns>
47+
public override IRule CreateRule(string property)
48+
{
49+
return new UserNameRule(property, State);
50+
}
51+
52+
/// <summary>
53+
/// Determines whether the specified value of the object is valid.
54+
/// </summary>
55+
/// <param name="value">The value of the specified validation object on which the <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute"/> is declared.</param>
56+
/// <returns>
57+
/// true if the specified value is valid; otherwise, false.
58+
/// </returns>
59+
public override bool IsValid(object value)
60+
{
61+
return true;
62+
}
63+
}
64+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace CodeSmith.Data.Audit
4+
{
5+
/// <summary>
6+
/// Indicates that a field in an audited class should always be included in the audit data even if it hasn't been changed.
7+
/// </summary>
8+
/// <seealso cref="AuditAttribute"/>
9+
/// <seealso cref="NotAuditedAttribute"/>
10+
/// <seealso cref="AuditManager"/>
11+
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
12+
public class AlwaysAuditAttribute : Attribute
13+
{ }
14+
}

0 commit comments

Comments
 (0)