internal object ValueOf(string attrLogicalName) { if (this.values.ContainsKey(attrLogicalName)) { return(EntityShadow.ValueCloning(this[attrLogicalName])); } return(null); }
internal EntityShadow(EntityShadow cloneFrom) { this.Id = cloneFrom.Id; this.LogicalName = cloneFrom.LogicalName; foreach (var key in cloneFrom.values.Keys) { this[key] = cloneFrom[key]; } }
/// <summary> /// /// </summary> /// <param name="target">The tarket entity</param> /// <param name="stage">10=validate,20=pre,40=post</param> /// <param name="message">Create,Update,Delete,??</param> /// <param name="isAsync">false or true, only apply to stage 40</param> /// <param name="finalize">Will be executed end of step, regardless of any plugin execution</param> /// <param name="onDone">the valide method provided by the test library</param> private void ExecuteStep(Microsoft.Xrm.Sdk.Entity target, int stage, string message, bool isAsync, Action finalize, Action onDone) { if (message != "Create" && stage == 10) { var key = target.LogicalName + target.Id.ToString(); this.preImage = this.entities[key].Clone(); } var methods = this.pluginMethodCache.ForPlugin(this.plugin.GetType(), stage, message, target.LogicalName, isAsync, false); if (methods.Length > 0) { var pluginExecutionContext = new Services.PluginExecutionContext(stage, 1, message, target.LogicalName, target.Id, isAsync); pluginExecutionContext.InputParameters.Add("Target", target); if (message != "Create") { var imagePre = this.ResolveImage(target.LogicalName, target.Id, 1, methods, preImage); if (imagePre != null) { var imgName = Kipon.Fake.Xrm.Reflection.PluginMethod.ImageSuffixFor(1, stage, isAsync); pluginExecutionContext.PreEntityImages.Add(imgName, imagePre); } } if (stage == 40 && message != "Delete") { var imagePost = this.ResolveImage(target.LogicalName, target.Id, 2, methods, null); if (imagePost != null) { var imgName = Kipon.Fake.Xrm.Reflection.PluginMethod.ImageSuffixFor(2, stage, isAsync); pluginExecutionContext.PostEntityImages.Add(imgName, imagePost); } } var serviceProvider = new Services.ServiceProvider(pluginExecutionContext, this, this.plugin.GetType().Assembly); this.plugin.Execute(serviceProvider); finalize?.Invoke(); onDone?.Invoke(); } else { if (onDone != null) { throw new Exceptions.UnexpectedEventListenerException(plugin.GetType(), message, stage); } else { finalize?.Invoke(); } } }
internal Microsoft.Xrm.Sdk.Entity ToEntity() { var result = new Microsoft.Xrm.Sdk.Entity { Id = this.Id, LogicalName = this.LogicalName }; foreach (var f in this.values.Keys) { result[f] = EntityShadow.ValueCloning(this[f]); } return(result); }
void IEntityShadow.Create(Microsoft.Xrm.Sdk.Entity entity) { var key = entity.LogicalName + entity.Id.ToString(); if (this.entities.ContainsKey(key)) { throw new Exceptions.EntityExistsException(entity); } transaction.Add(new TransactionElement { Operation = "Create", Entity = new EntityShadow(entity.LogicalName, entity.Id) }); var et = new EntityShadow(entity); entities.Add(et.Key, et); }
void IEntityShadow.Delete(string logicalName, Guid id) { var key = logicalName + id.ToString(); if (!entities.ContainsKey(key)) { throw new Exceptions.EntityNotFoundException(logicalName, id); } var before = new EntityShadow(entities[key]); transaction.Add(new TransactionElement { Operation = "Delete", Entity = before }); this.entities.Remove(key); }
internal object this[string logicalAttributeName] { get { if (values.ContainsKey(logicalAttributeName)) { return(values[logicalAttributeName]); } return(null); } set { values[logicalAttributeName] = EntityShadow.ValueCloning(value); } }
void IEntityShadow.Update(Microsoft.Xrm.Sdk.Entity entity) { var key = entity.LogicalName + entity.Id.ToString(); if (!entities.ContainsKey(key)) { throw new Exceptions.EntityNotFoundException(entity.LogicalName, entity.Id); } var before = new EntityShadow(entities[key]); transaction.Add(new TransactionElement { Operation = "Update", Entity = before }); entities[key].UpdateFrom(entity); }
public void AddEntity(Microsoft.Xrm.Sdk.Entity crmEntity) { var et = new EntityShadow(crmEntity); entities.Add(et.Key, et); }
private Microsoft.Xrm.Sdk.Entity ResolveImage(string logicalName, Guid id, int pre1post2, Kipon.Fake.Xrm.Reflection.PluginMethod[] methods, EntityShadow pre) { if (pre1post2 == 1 && pre == null) { throw new ArgumentException("For pre you must parse the pre entity state"); } if (pre1post2 == 2 && pre != null) { throw new ArgumentException("For post you cannot parse the pre entity state"); } var needAll = false; string[] neededProperties = null; if (pre1post2 == 1) { var need = (from m in methods where m.NeedPreimage select m).Any(); if (!need) { return(null); } needAll = (from m in methods where m.AllPreimageProperties select m).Any(); if (!needAll) { var np = new List <string>(); foreach (var m in methods) { if (m.PreimageProperties != null && m.PreimageProperties.Length > 0) { np.AddRange((from p in m.PreimageProperties select p.LogicalName).Distinct()); } } neededProperties = np.Distinct().ToArray(); } } if (pre1post2 == 2) { var need = (from m in methods where m.NeedPostimage select m).Any(); if (!need) { return(null); } needAll = (from m in methods where m.AllPostimageProperties select m).Any(); if (!needAll) { var np = new List <string>(); foreach (var m in methods) { if (m.PostimageProperties != null && m.PostimageProperties.Length > 0) { np.AddRange((from p in m.PostimageProperties select p.LogicalName).Distinct()); } } neededProperties = np.Distinct().ToArray(); } } if (needAll == false && (neededProperties == null || neededProperties.Length == 0)) { return(null); } var key = logicalName + id.ToString(); if (!this.entities.ContainsKey(key)) { throw new Exceptions.EntityNotFoundException(logicalName, id); } var data = pre; if (pre1post2 == 2) { data = entities[key]; } if (needAll) { return(data.ToEntity()); } var result = new Microsoft.Xrm.Sdk.Entity { LogicalName = logicalName, Id = id }; foreach (var prop in neededProperties) { result[prop] = data.ValueOf(prop); } return(result); }