本文整理汇总了C#中IEntity.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# IEntity.Clone方法的具体用法?C# IEntity.Clone怎么用?C# IEntity.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntity
的用法示例。
在下文中一共展示了IEntity.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
/// <summary>
/// Saves the provided entity into the provided data store.
/// </summary>
/// <param name="entity">The entity to save to the data store.</param>
/// <param name="handleReferences">A value indicating whether to delete old references and save new references.</param>
public override void Save(IEntity entity, bool handleReferences)
{
using (LogGroup logGroup = LogGroup.StartDebug("Saving entity of type '" + entity.ShortTypeName + "'."))
{
if (entity == null)
throw new ArgumentNullException("entity");
if (entity.ID == Guid.Empty)
throw new ArgumentException("entity.ID must be set.");
// Clone the entity so that it doesn't get bound to the store
IEntity clonedEntity = entity.Clone();
Db4oDataStore store = (Db4oDataStore)GetDataStore(clonedEntity);
if (store.ObjectContainer == null)
throw new InvalidOperationException("The ObjectContainer has not been initialized on the '" + store.Name + "' data store.");
using (Batch batch = BatchState.StartBatch())
{
if (EntitiesUtilities.IsReference(clonedEntity.GetType()) && DataAccess.Data.IsStored(clonedEntity))
{
LogWriter.Debug("Existing reference found. Skipping save.");
// Just skip the saving altogether, if the reference already exists
}
else
{
if (clonedEntity == null)
throw new ArgumentNullException("entity");
LogWriter.Debug("Entity type: " + clonedEntity.GetType().ToString());
LogWriter.Debug("Entity ID: " + clonedEntity.ID.ToString());
PreSave(clonedEntity, handleReferences);
if (clonedEntity != null)
{
DataUtilities.StripReferences(clonedEntity);
// Save the entity
store.ObjectContainer.Store(clonedEntity);
// Post save the original entity NOT the cloned entity
PostSave(entity);
store.Commit();
LogWriter.Debug("Entity stored in '" + store.Name + "' store.");
}
else
{
LogWriter.Debug("Cloned entity == null. Not stored.");
}
}
}
}
}
示例2: TriggerWorkflows
private bool TriggerWorkflows( IEntity entity, WorkflowTriggerType triggerType, PersonAlias personAlias )
{
Dictionary<string, PropertyInfo> properties = null;
var rockContext = new RockContext();
var workflowTypeService = new WorkflowTypeService( rockContext );
var workflowService = new WorkflowService( rockContext );
foreach ( var trigger in TriggerCache.Triggers( entity.TypeName, triggerType ).Where( t => t.IsActive == true ) )
{
bool match = true;
if ( !string.IsNullOrWhiteSpace( trigger.EntityTypeQualifierColumn ) )
{
if ( properties == null )
{
properties = new Dictionary<string, PropertyInfo>();
foreach ( PropertyInfo propertyInfo in entity.GetType().GetProperties() )
{
properties.Add( propertyInfo.Name.ToLower(), propertyInfo );
}
}
match = ( properties.ContainsKey( trigger.EntityTypeQualifierColumn.ToLower() ) &&
properties[trigger.EntityTypeQualifierColumn.ToLower()].GetValue( entity, null ).ToString()
== trigger.EntityTypeQualifierValue );
}
if ( match )
{
if ( triggerType == WorkflowTriggerType.PreSave || triggerType == WorkflowTriggerType.PreDelete )
{
var workflowType = workflowTypeService.Get( trigger.WorkflowTypeId );
if ( workflowType != null )
{
var workflow = Rock.Model.Workflow.Activate( workflowType, trigger.WorkflowName );
List<string> workflowErrors;
if ( !workflow.Process( rockContext, entity, out workflowErrors ) )
{
SaveErrorMessages.AddRange( workflowErrors );
return false;
}
else
{
if ( workflow.IsPersisted || workflowType.IsPersisted )
{
workflowService.Add( workflow );
rockContext.SaveChanges();
}
}
}
}
else
{
var transaction = new Rock.Transactions.WorkflowTriggerTransaction();
transaction.Trigger = trigger;
transaction.Entity = entity.Clone();
transaction.PersonAlias = personAlias;
Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
}
}
}
return true;
}