Skip to content

Commit

Permalink
Source Imported CodeSmith.Data for now
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Aug 6, 2015
1 parent ea4102c commit bd15118
Show file tree
Hide file tree
Showing 204 changed files with 27,824 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using CodeSmith.Data.Rules;
using CodeSmith.Data.Rules.Assign;

namespace CodeSmith.Data.Attributes
{
/// <summary>
/// Assigns a new GUID to the property for the specified entity states.
/// </summary>
/// <example>
/// <para>Add rule using the Metadata class and attribute.</para>
/// <code><![CDATA[
/// private class Metadata
/// {
/// // fragment of the metadata class
///
/// [Guid(EntityState.New)]
/// public Guid UserId { get; set; }
/// }
/// ]]></code>
/// </example>
/// <seealso cref="T:CodeSmith.Data.Rules.Assign.GuidRule"/>
public class GuidAttribute : RuleAttributeBase
{
/// <summary>
/// Initializes a new instance of the <see cref="GuidAttribute"/> class.
/// </summary>
public GuidAttribute()
{}

/// <summary>
/// Initializes a new instance of the <see cref="GuidAttribute"/> class.
/// </summary>
/// <param name="state">State of the object that can be assigned.</param>
public GuidAttribute(EntityState state)
{
State = state;
}

/// <summary>
/// Creates the rule.
/// </summary>
/// <param name="property">The property name this rule applies to.</param>
/// <returns>A new instance of the rule.</returns>
public override IRule CreateRule(string property)
{
return new GuidRule(property, State);
}

/// <summary>
/// Determines whether the specified value of the object is valid.
/// </summary>
/// <param name="value">The value of the specified validation object on which the <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute"/> is declared.</param>
/// <returns>
/// true if the specified value is valid; otherwise, false.
/// </returns>
public override bool IsValid(object value)
{
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using CodeSmith.Data.Rules;
using CodeSmith.Data.Rules.Assign;

namespace CodeSmith.Data.Attributes
{
/// <summary>
/// Assigns the current user's IP address to the property for the specified entity states.
/// </summary>
/// <example>
/// <para>Add rule using the Metadata class and attribute.</para>
/// <code><![CDATA[
/// private class Metadata
/// {
/// // fragment of the metadata class
///
/// [IpAddress(EntityState.Dirty)]
/// public string IpAddress { get; set; }
/// }
/// ]]></code>
/// </example>
/// <seealso cref="T:CodeSmith.Data.Rules.Assign.IpAddressRule"/>
public class IpAddressAttribute : RuleAttributeBase
{
/// <summary>
/// Initializes a new instance of the <see cref="IpAddressAttribute"/> class.
/// </summary>
public IpAddressAttribute()
{}

/// <summary>
/// Initializes a new instance of the <see cref="IpAddressAttribute"/> class.
/// </summary>
/// <param name="state">State of the object that can be assigned.</param>
public IpAddressAttribute(EntityState state)
{
State = state;
}

/// <summary>
/// Creates the rule.
/// </summary>
/// <param name="property">The property name this rule applies to.</param>
/// <returns>A new instance of the rule.</returns>
public override IRule CreateRule(string property)
{
return new IpAddressRule(property, State);
}

/// <summary>
/// Determines whether the specified value of the object is valid.
/// </summary>
/// <param name="value">The value of the specified validation object on which the <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute"/> is declared.</param>
/// <returns>
/// true if the specified value is valid; otherwise, false.
/// </returns>
public override bool IsValid(object value)
{
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeSmith.Data.Rules;
using CodeSmith.Data.Rules.Validation;

namespace CodeSmith.Data.Attributes
{
public class NotNullAttribute : RuleAttributeBase
{
public NotNullAttribute()
: this(EntityState.Dirty)
{ }

public NotNullAttribute(EntityState state)
{
State = state;
}

public override bool IsValid(object value)
{
return value != null;
}

public override IRule CreateRule(string property)
{
return new NotNullRule(property);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using CodeSmith.Data.Rules;
using CodeSmith.Data.Rules.Assign;

namespace CodeSmith.Data.Attributes
{
/// <summary>
/// Assigns the current date / time to the property for the specified entity states.
/// </summary>
/// <example>
/// <para>Add rule using the Metadata class and attribute.</para>
/// <code><![CDATA[
/// private class Metadata
/// {
/// // fragment of the metadata class
///
/// [Now(EntityState.New)]
/// public DateTime CreatedDate { get; set; }
///
/// [Now(EntityState.Dirty)]
/// public DateTime ModifiedDate { get; set; }
/// }
/// ]]></code>
/// </example>
/// <seealso cref="T:CodeSmith.Data.Rules.Assign.NowRule"/>
public class NowAttribute : RuleAttributeBase
{
/// <summary>
/// Initializes a new instance of the <see cref="NowAttribute"/> class.
/// </summary>
public NowAttribute()
: this(EntityState.Dirty, NowTimeZone.Local)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="NowAttribute"/> class.
/// </summary>
/// <param name="state">State of the object that can be assigned.</param>
public NowAttribute(EntityState state)
: this(state, NowTimeZone.Local)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="NowAttribute"/> class.
/// </summary>
/// <param name="state">State of the object that can be assigned.</param>
/// <param name="timeZone">The time zone.</param>
public NowAttribute(EntityState state, NowTimeZone timeZone)
{
State = state;
TimeZone = timeZone;
}


public NowTimeZone TimeZone { get; set; }

/// <summary>
/// Creates the rule.
/// </summary>
/// <param name="property">The property name this rule applies to.</param>
/// <returns>A new instance of the rule.</returns>
public override IRule CreateRule(string property)
{
return new NowRule(property, State, TimeZone);
}

/// <summary>
/// Determines whether the specified value of the object is valid.
/// </summary>
/// <param name="value">The value of the specified validation object on which the <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute"/> is declared.</param>
/// <returns>
/// true if the specified value is valid; otherwise, false.
/// </returns>
public override bool IsValid(object value)
{
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.ComponentModel.DataAnnotations;
using CodeSmith.Data.Rules;

namespace CodeSmith.Data.Attributes
{
/// <summary>
/// A base class for rule attributes.
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public abstract class RuleAttributeBase : ValidationAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="RuleAttributeBase"/> class.
/// </summary>
protected RuleAttributeBase()
{
State = EntityState.Dirty;
}

/// <summary>
/// Gets or sets the state.
/// </summary>
/// <value>The state of the object that the rule can run on.</value>
public EntityState State { get; protected set; }

/// <summary>
/// Creates the rule.
/// </summary>
/// <param name="property">The property name this rule applies to.</param>
/// <returns>A new instance of the rule.</returns>
public abstract IRule CreateRule(string property);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using CodeSmith.Data.Rules;
using CodeSmith.Data.Rules.Assign;

namespace CodeSmith.Data.Attributes
{
/// <summary>
/// Assigns the current users name to the property for the specified entity states.
/// </summary>
/// <example>
/// <para>Add rule using the Metadata class and attribute.</para>
/// <code><![CDATA[
/// private class Metadata
/// {
/// // fragment of the metadata class
///
/// [UserName(EntityState.New)]
/// public string CreatedBy { get; set; }
///
/// [UserName(EntityState.Dirty)]
/// public string ModifiedBy { get; set; }
/// }
/// ]]></code>
/// </example>
/// <seealso cref="T:CodeSmith.Data.Rules.Assign.UserNameRule"/>
public class UserNameAttribute : RuleAttributeBase
{
/// <summary>
/// Initializes a new instance of the <see cref="UserNameAttribute"/> class.
/// </summary>
public UserNameAttribute()
{}

/// <summary>
/// Initializes a new instance of the <see cref="UserNameAttribute"/> class.
/// </summary>
/// <param name="state">State of the object that can be assigned.</param>
public UserNameAttribute(EntityState state)
{
State = state;
}

/// <summary>
/// Creates the rule.
/// </summary>
/// <param name="property">The property name this rule applies to.</param>
/// <returns>A new instance of the rule.</returns>
public override IRule CreateRule(string property)
{
return new UserNameRule(property, State);
}

/// <summary>
/// Determines whether the specified value of the object is valid.
/// </summary>
/// <param name="value">The value of the specified validation object on which the <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute"/> is declared.</param>
/// <returns>
/// true if the specified value is valid; otherwise, false.
/// </returns>
public override bool IsValid(object value)
{
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace CodeSmith.Data.Audit
{
/// <summary>
/// Indicates that a field in an audited class should always be included in the audit data even if it hasn't been changed.
/// </summary>
/// <seealso cref="AuditAttribute"/>
/// <seealso cref="NotAuditedAttribute"/>
/// <seealso cref="AuditManager"/>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class AlwaysAuditAttribute : Attribute
{ }
}
Loading

0 comments on commit bd15118

Please sign in to comment.