本文整理汇总了C#中Rock.Model.Attribute类的典型用法代码示例。如果您正苦于以下问题:C# Attribute类的具体用法?C# Attribute怎么用?C# Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attribute类属于Rock.Model命名空间,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapActivityMinistry
/// <summary>
/// Maps the activity ministry.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
private void MapActivityMinistry( IQueryable<Row> tableData )
{
int groupEntityTypeId = EntityTypeCache.Read( "Rock.Model.Group" ).Id;
var attributeService = new AttributeService();
// Add an Attribute for the unique F1 Ministry Id
var ministryAttributeId = attributeService.Queryable().Where( a => a.EntityTypeId == groupEntityTypeId
&& a.Key == "F1MinistryId" ).Select( a => a.Id ).FirstOrDefault();
if ( ministryAttributeId == 0 )
{
var newMinistryAttribute = new Rock.Model.Attribute();
newMinistryAttribute.Key = "F1MinistryId";
newMinistryAttribute.Name = "F1 Ministry Id";
newMinistryAttribute.FieldTypeId = IntegerFieldTypeId;
newMinistryAttribute.EntityTypeId = groupEntityTypeId;
newMinistryAttribute.EntityTypeQualifierValue = string.Empty;
newMinistryAttribute.EntityTypeQualifierColumn = string.Empty;
newMinistryAttribute.Description = "The FellowshipOne identifier for the ministry that was imported";
newMinistryAttribute.DefaultValue = string.Empty;
newMinistryAttribute.IsMultiValue = false;
newMinistryAttribute.IsRequired = false;
newMinistryAttribute.Order = 0;
attributeService.Add( newMinistryAttribute, ImportPersonAlias );
attributeService.Save( newMinistryAttribute, ImportPersonAlias );
ministryAttributeId = newMinistryAttribute.Id;
}
// Get previously imported Ministries
var importedMinistries = new AttributeValueService().GetByAttributeId( ministryAttributeId )
.Select( av => new { RLCId = av.Value.AsType<int?>(), LocationId = av.EntityId } )
.ToDictionary( t => t.RLCId, t => t.LocationId );
foreach ( var row in tableData )
{
int? ministryId = row["Ministry_ID"] as int?;
if ( ministryId != null && !importedMinistries.ContainsKey( ministryId ) )
{
// Activity_ID
// Ministry_Name
// Activity_Name
// Ministry_Active
// Activity_Active
}
}
}
示例2: EmailStatus
private string EmailStatus( WorkflowAction action )
{
// Use the current action type' guid as the key for a 'Email Status' attribute
string AttrKey = action.ActionType.Guid.ToString() + "_EmailStatus";
// Check to see if the action's activity does not yet have the the 'Email Status' attribute.
// The first time this action runs on any workflow instance using this action instance, the
// attribute will not exist and need to be created
if ( !action.Activity.Attributes.ContainsKey( AttrKey ) )
{
var attribute = new Rock.Model.Attribute();
attribute.EntityTypeId = action.Activity.TypeId;
attribute.EntityTypeQualifierColumn = "ActivityTypeId";
attribute.EntityTypeQualifierValue = action.Activity.ActivityTypeId.ToString();
attribute.Name = "Email Status";
attribute.Key = AttrKey;
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT.AsGuid() ).Id;
// Need to save the attribute now (using different context) so that an attribute id is returned.
using ( var newRockContext = new RockContext() )
{
new AttributeService( newRockContext ).Add( attribute );
newRockContext.SaveChanges();
}
action.Activity.Attributes.Add( AttrKey, AttributeCache.Read( attribute ) );
var attributeValue = new AttributeValueCache();
attributeValue.AttributeId = attribute.Id;
attributeValue.Value = string.Empty;
action.Activity.AttributeValues.Add( AttrKey, attributeValue );
}
else
{
return action.Activity.GetAttributeValue( AttrKey );
}
return string.Empty;
}
示例3: gAttributes_ShowEdit
/// <summary>
/// Gs the group attributes_ show edit.
/// </summary>
/// <param name="attributeGuid">The attribute GUID.</param>
protected void gAttributes_ShowEdit( Guid attributeGuid )
{
Attribute attribute;
if ( attributeGuid.Equals( Guid.Empty ) )
{
attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
edtAttributes.ActionTitle = ActionTitle.Add( "attribute for workflows of workflow type " + tbName.Text );
}
else
{
attribute = AttributesState.First( a => a.Guid.Equals( attributeGuid ) );
edtAttributes.ActionTitle = ActionTitle.Edit( "attribute for workflows of workflow type " + tbName.Text );
}
edtAttributes.ReservedKeyNames = AttributesState.Where( a => !a.Guid.Equals( attributeGuid ) ).Select( a => a.Key ).ToList();
edtAttributes.SetAttributeProperties( attribute, typeof( Group ) );
ShowDialog( "Attributes" );
}
示例4: gBinaryFileAttributes_ShowEdit
/// <summary>
/// Gs the binary file attributes_ show edit.
/// </summary>
/// <param name="attributeGuid">The attribute GUID.</param>
protected void gBinaryFileAttributes_ShowEdit( Guid attributeGuid )
{
pnlDetails.Visible = false;
pnlBinaryFileAttribute.Visible = true;
Attribute attribute;
if ( attributeGuid.Equals( Guid.Empty ) )
{
attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
edtBinaryFileAttributes.ActionTitle = ActionTitle.Add( "attribute for binary files of type " + tbName.Text );
}
else
{
attribute = BinaryFileAttributesState.First( a => a.Guid.Equals( attributeGuid ) );
edtBinaryFileAttributes.ActionTitle = ActionTitle.Edit( "attribute for binary files of type " + tbName.Text );
}
edtBinaryFileAttributes.ReservedKeyNames = BinaryFileAttributesState.Where( a => !a.Guid.Equals( attributeGuid ) ).Select( a => a.Key ).ToList();
edtBinaryFileAttributes.SetAttributeProperties( attribute, typeof( BinaryFile ) );
}
示例5: gGroupMemberAttributes_ShowEdit
/// <summary>
/// Gs the group attributes_ show edit.
/// </summary>
/// <param name="attributeGuid">The attribute GUID.</param>
protected void gGroupMemberAttributes_ShowEdit( Guid attributeGuid )
{
Attribute attribute;
if ( attributeGuid.Equals( Guid.Empty ) )
{
attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
edtGroupMemberAttributes.ActionTitle = ActionTitle.Add( "attribute for members in groups of group type " + tbName.Text );
}
else
{
attribute = GroupMemberAttributesState.First( a => a.Guid.Equals( attributeGuid ) );
edtGroupMemberAttributes.ActionTitle = ActionTitle.Edit( "attribute for members in groups of group type " + tbName.Text );
}
var reservedKeyNames = new List<string>();
GroupMemberAttributesInheritedState.Select( a => a.Key ).ToList().ForEach( a => reservedKeyNames.Add( a ) );
GroupMemberAttributesState.Where( a => !a.Guid.Equals( attributeGuid ) ).Select( a => a.Key ).ToList().ForEach( a => reservedKeyNames.Add( a ) );
edtGroupMemberAttributes.ReservedKeyNames = reservedKeyNames.ToList();
edtGroupMemberAttributes.SetAttributeProperties( attribute, typeof( GroupMember ) );
ShowDialog( "GroupMemberAttributes" );
}
示例6: ShowActivityAttributeEdit
/// <summary>
/// Shows the attribute edit.
/// </summary>
/// <param name="attributeGuid">The attribute unique identifier.</param>
private void ShowActivityAttributeEdit( Guid activityTypeGuid, Guid attributeGuid )
{
if ( ActivityAttributesState.ContainsKey( activityTypeGuid ) )
{
var attributeList = ActivityAttributesState[activityTypeGuid];
Attribute attribute;
if ( attributeGuid.Equals( Guid.Empty ) )
{
attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
edtActivityAttributes.ActionTitle = ActionTitle.Add( "Add Activity Attribute" );
}
else
{
attribute = attributeList.First( a => a.Guid.Equals( attributeGuid ) );
edtActivityAttributes.ActionTitle = ActionTitle.Edit( "Edit Activity Attribute" );
}
edtActivityAttributes.ReservedKeyNames = attributeList.Where( a => !a.Guid.Equals( attributeGuid ) ).Select( a => a.Key ).ToList();
edtActivityAttributes.SetAttributeProperties( attribute, typeof( WorkflowActivity ) );
hfActivityTypeGuid.Value = activityTypeGuid.ToString();
ShowDialog( "ActivityAttributes" );
}
BuildControls( true );
}
示例7: gMarketingCampaignAdAttributeType_ShowEdit
/// <summary>
/// Gs the marketing campaign ad attribute type_ show edit.
/// </summary>
/// <param name="attributeId">The attribute id.</param>
protected void gMarketingCampaignAdAttributeType_ShowEdit( Guid attributeGuid )
{
pnlDetails.Visible = false;
pnlAdTypeAttribute.Visible = true;
Attribute attribute;
if ( attributeGuid.Equals( Guid.Empty ) )
{
attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
edtAdTypeAttributes.ActionTitle = ActionTitle.Add( "attribute for ad type " + tbName.Text );
}
else
{
attribute = AttributesState.First( a => a.Guid.Equals( attributeGuid ) );
edtAdTypeAttributes.ActionTitle = ActionTitle.Edit( "attribute for ad type " + tbName.Text );
}
edtAdTypeAttributes.ReservedKeyNames = AttributesState.Where( a => !a.Guid.Equals( attributeGuid ) ).Select( a => a.Key ).ToList();
edtAdTypeAttributes.SetAttributeProperties( attribute, typeof( MarketingCampaignAd ) );
}
示例8: Execute
/// <summary>
/// Executes the action.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="action">The action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
public override bool Execute( RockContext rockContext, WorkflowAction action, object entity, out List<string> errorMessages )
{
errorMessages = new List<string>();
// Get the number of minutes to delay
int? minutes = GetAttributeValue( action, "MinutesToDelay" ).AsIntegerOrNull();
if ( !minutes.HasValue || minutes.Value <= 0 )
{
return true;
}
// Use the current action type' guid as the key for a 'Delay Activated' attribute
string AttrKey = action.ActionType.Guid.ToString();
// Check to see if the action's activity does not yet have the the 'Delay Activated' attribute.
// The first time this action runs on any workflow instance using this action instance, the
// attribute will not exist and need to be created
if ( !action.Activity.Attributes.ContainsKey( AttrKey ) )
{
var attribute = new Rock.Model.Attribute();
attribute.EntityTypeId = action.Activity.TypeId;
attribute.EntityTypeQualifierColumn = "ActivityTypeId";
attribute.EntityTypeQualifierValue = action.Activity.ActivityTypeId.ToString();
attribute.Name = "Delay Activated";
attribute.Key = AttrKey;
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT.AsGuid() ).Id;
// Need to save the attribute now (using different context) so that an attribute id is returned.
var newRockContext = new RockContext();
new AttributeService( newRockContext ).Add( attribute );
newRockContext.SaveChanges();
action.Activity.Attributes.Add( AttrKey, AttributeCache.Read( attribute ) );
var attributeValue = new Rock.Model.AttributeValue();
attributeValue.AttributeId = attribute.Id;
attributeValue.Value = RockDateTime.Now.ToString( "o" );
action.Activity.AttributeValues.Add( AttrKey, attributeValue );
action.AddLogEntry( string.Format( "{0:N0} Minute Delay Activated.", minutes.Value ), true );
}
else
{
// Check to see if this action instance has a value for the 'Delay Activated' attrbute
DateTime? activated = action.Activity.GetAttributeValue( AttrKey ).AsDateTime();
if ( !activated.HasValue )
{
// If no value exists, set the value to the current time
action.Activity.SetAttributeValue( AttrKey, RockDateTime.Now.ToString( "o" ) );
action.AddLogEntry( string.Format( "{0:N0} Minute Delay Activated.", minutes.Value ), true );
}
else
{
// If a value does exist, check to see if the number of minutes to delay has passed
// since the value was saved
if ( activated.Value.AddMinutes( minutes.Value ).CompareTo( RockDateTime.Now ) < 0 )
{
// If delay has elapsed, return True ( so that processing of activity will continue )
action.AddLogEntry( string.Format( "{0:N0} Minute Delay Completed.", minutes.Value ), true );
return true;
}
}
}
// If delay has not elapsed, return false so that processing of activity stops
return false;
}
示例9: gGroupMemberAttributes_ShowEdit
/// <summary>
/// Gs the group member attributes_ show edit.
/// </summary>
/// <param name="attributeGuid">The attribute GUID.</param>
protected void gGroupMemberAttributes_ShowEdit( Guid attributeGuid )
{
Attribute attribute;
if ( attributeGuid.Equals( Guid.Empty ) )
{
attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
edtGroupMemberAttributes.ActionTitle = ActionTitle.Add( "attribute for group members of " + tbName.Text );
}
else
{
attribute = GroupMemberAttributesState.First( a => a.Guid.Equals( attributeGuid ) );
edtGroupMemberAttributes.ActionTitle = ActionTitle.Edit( "attribute for group members of " + tbName.Text );
}
edtGroupMemberAttributes.SetAttributeProperties( attribute, typeof( GroupMember ) );
ShowDialog( "GroupMemberAttributes", true );
}
示例10: gDefinedTypeAttributes_ShowEdit
/// <summary>
/// Gs the defined type attributes_ show edit.
/// </summary>
/// <param name="attributeGuid">The attribute GUID.</param>
protected void gDefinedTypeAttributes_ShowEdit( Guid attributeGuid )
{
pnlDetails.Visible = false;
vsDetails.Enabled = false;
pnlDefinedTypeAttributes.Visible = true;
Attribute attribute;
if ( attributeGuid.Equals( Guid.Empty ) )
{
attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
edtDefinedTypeAttributes.ActionTitle = ActionTitle.Add( "attribute for defined type " + tbTypeName.Text );
}
else
{
AttributeService attributeService = new AttributeService();
attribute = attributeService.Get( attributeGuid );
edtDefinedTypeAttributes.ActionTitle = ActionTitle.Edit( "attribute for defined type " + tbTypeName.Text );
}
edtDefinedTypeAttributes.SetAttributeProperties( attribute, typeof( DefinedValue ) );
this.HideSecondaryBlocks( true );
}
示例11: SetValue
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <param name="saveValue">if set to <c>true</c> [save value].</param>
/// <param name="rockContext">The rock context.</param>
public void SetValue( string key, string value, bool saveValue, RockContext rockContext )
{
AttributeCache attributeCache = null;
if ( saveValue )
{
// Save new value
rockContext = rockContext ?? new RockContext();
var attributeValueService = new AttributeValueService( rockContext );
var attributeValue = attributeValueService.GetGlobalAttributeValue( key );
if ( attributeValue == null )
{
var attributeService = new AttributeService( rockContext );
var attribute = attributeService.GetGlobalAttribute( key );
if ( attribute == null )
{
attribute = new Rock.Model.Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( new Guid( SystemGuid.FieldType.TEXT ) ).Id;
attribute.EntityTypeQualifierColumn = string.Empty;
attribute.EntityTypeQualifierValue = string.Empty;
attribute.Key = key;
attribute.Name = key.SplitCase();
attributeService.Add( attribute );
rockContext.SaveChanges();
}
attributeValue = new AttributeValue();
attributeValue.IsSystem = false;
attributeValue.AttributeId = attribute.Id;
attributeValueService.Add( attributeValue );
}
attributeValue.Value = value;
rockContext.SaveChanges();
}
lock(_obj)
{
attributeIds = null;
}
AttributeValues.AddOrUpdate( key, value, ( k, v ) => value );
attributeCache = Attributes.FirstOrDefault( a => a.Key.Equals( key, StringComparison.OrdinalIgnoreCase ) );
if ( attributeCache != null )
{
value = attributeCache.FieldType.Field.FormatValue( null, value, attributeCache.QualifierValues, false );
}
AttributeValuesFormatted.AddOrUpdate( key, value, (k, v) => value);
}
示例12: gAttributes_ShowEdit
/// <summary>
/// Shows the edit attribute dialog.
/// </summary>
/// <param name="attributeGuid">The attribute unique identifier.</param>
protected void gAttributes_ShowEdit( Guid attributeGuid )
{
Attribute attribute;
if ( attributeGuid.Equals( Guid.Empty ) )
{
attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
}
else
{
attribute = AttributesState.First( a => a.Guid.Equals( attributeGuid ) );
}
edtAttributes.ActionTitle = ActionTitle.Edit( "attribute for Opportunities of Connection type " + tbName.Text );
var reservedKeyNames = new List<string>();
AttributesState.Where( a => !a.Guid.Equals( attributeGuid ) ).Select( a => a.Key ).ToList().ForEach( a => reservedKeyNames.Add( a ) );
edtAttributes.AllowSearchVisible = true;
edtAttributes.ReservedKeyNames = reservedKeyNames.ToList();
edtAttributes.SetAttributeProperties( attribute, typeof( ConnectionType ) );
ShowDialog( "Attributes" );
}
示例13: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
using ( new UnitOfWorkScope() )
{
var attributeService = new AttributeService();
var attributeQualifierService = new AttributeQualifierService();
Rock.Model.Attribute attribute;
int attributeId = 0;
if ( hfId.Value != string.Empty && !int.TryParse( hfId.Value, out attributeId ) )
{
attributeId = 0;
}
if ( attributeId == 0 )
{
attribute = new Rock.Model.Attribute();
attribute.IsSystem = false;
attribute.EntityTypeId = _entityTypeId;
attribute.EntityTypeQualifierColumn = _entityQualifierColumn;
attribute.EntityTypeQualifierValue = _entityQualifierValue;
attributeService.Add( attribute, CurrentPersonId );
}
else
{
AttributeCache.Flush( attributeId );
attribute = attributeService.Get( attributeId );
}
attribute.Key = tbKey.Text;
attribute.Name = tbName.Text;
attribute.Category = tbCategory.Text;
attribute.Description = tbDescription.Text;
attribute.FieldTypeId = int.Parse( ddlFieldType.SelectedValue );
var fieldType = FieldTypeCache.Read( attribute.FieldTypeId );
foreach ( var oldQualifier in attribute.AttributeQualifiers.ToList() )
{
attributeQualifierService.Delete( oldQualifier, CurrentPersonId );
}
attribute.AttributeQualifiers.Clear();
List<Control> configControls = new List<Control>();
foreach ( var key in fieldType.Field.ConfigurationKeys() )
{
configControls.Add( phFieldTypeQualifiers.FindControl( "configControl_" + key ) );
}
foreach ( var configValue in fieldType.Field.ConfigurationValues( configControls ) )
{
AttributeQualifier qualifier = new AttributeQualifier();
qualifier.IsSystem = false;
qualifier.Key = configValue.Key;
qualifier.Value = configValue.Value.Value ?? string.Empty;
attribute.AttributeQualifiers.Add( qualifier );
}
attribute.DefaultValue = tbDefaultValue.Text;
attribute.IsMultiValue = cbMultiValue.Checked;
attribute.IsRequired = cbRequired.Checked;
attributeService.Save( attribute, CurrentPersonId );
}
BindGrid();
pnlDetails.Visible = false;
pnlList.Visible = true;
}
示例14: SetValue
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public static void SetValue( string key, string value )
{
var rockContext = new Rock.Data.RockContext();
var attributeService = new AttributeService( rockContext );
var attribute = attributeService.GetSystemSetting( key );
if ( attribute == null )
{
attribute = new Rock.Model.Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( new Guid( SystemGuid.FieldType.TEXT ) ).Id;
attribute.EntityTypeQualifierColumn = Rock.Model.Attribute.SYSTEM_SETTING_QUALIFIER;
attribute.EntityTypeQualifierValue = string.Empty;
attribute.Key = key;
attribute.Name = key.SplitCase();
attribute.DefaultValue = value;
attributeService.Add( attribute );
}
else
{
attribute.DefaultValue = value;
}
rockContext.SaveChanges();
AttributeCache.Flush( attribute.Id );
var settings = SystemSettings.Read();
var attributeCache = settings.Attributes.FirstOrDefault( a => a.Key.Equals( key, StringComparison.OrdinalIgnoreCase ) );
if ( attributeCache != null )
{
attributeCache.DefaultValue = value;
}
else
{
settings.Attributes.Add( AttributeCache.Read( attribute.Id ) );
}
}
示例15: HoursElapsed
private double HoursElapsed( WorkflowAction action )
{
// Use the current action type' guid as the key for a 'DateTime Sent' attribute
string AttrKey = action.ActionType.Guid.ToString() + "_DateTimeSent";
// Check to see if the action's activity does not yet have the the 'DateTime Sent' attribute.
// The first time this action runs on any workflow instance using this action instance, the
// attribute will not exist and need to be created
if ( !action.Activity.Attributes.ContainsKey( AttrKey ) )
{
var attribute = new Rock.Model.Attribute();
attribute.EntityTypeId = action.Activity.TypeId;
attribute.EntityTypeQualifierColumn = "ActivityTypeId";
attribute.EntityTypeQualifierValue = action.Activity.ActivityTypeId.ToString();
attribute.Name = "DateTime Sent";
attribute.Key = AttrKey;
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT.AsGuid() ).Id;
// Need to save the attribute now (using different context) so that an attribute id is returned.
using ( var newRockContext = new RockContext() )
{
new AttributeService( newRockContext ).Add( attribute );
newRockContext.SaveChanges();
}
action.Activity.Attributes.Add( AttrKey, AttributeCache.Read( attribute ) );
var attributeValue = new AttributeValueCache();
attributeValue.AttributeId = attribute.Id;
attributeValue.Value = RockDateTime.Now.ToString( "o" );
action.Activity.AttributeValues.Add( AttrKey, attributeValue );
}
else
{
// Check to see if this action instance has a value for the 'Delay Activated' attrbute
DateTime? dateSent = action.Activity.GetAttributeValue( AttrKey ).AsDateTime();
if ( dateSent.HasValue )
{
// If a value does exist, check to see if the number of minutes to delay has passed
// since the value was saved
return RockDateTime.Now.Subtract( dateSent.Value ).TotalHours;
}
else
{
// If no value exists, set the value to the current time
action.Activity.SetAttributeValue( AttrKey, RockDateTime.Now.ToString( "o" ) );
}
}
return 0.0D;
}