当前位置: 首页>>代码示例>>C#>>正文


C# IEntity.Clone方法代码示例

本文整理汇总了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.");

                        }
                    }
                }
            }
        }
开发者ID:jeremysimmons,项目名称:sitestarter,代码行数:63,代码来源:Db4oDataSaver.cs

示例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;
        }
开发者ID:Ganon11,项目名称:Rock,代码行数:66,代码来源:DbContext.cs


注:本文中的IEntity.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。