Last active
September 12, 2025 11:15
-
-
Save rappen/4076c1031fda9cebcfde37c01e34830c to your computer and use it in GitHub Desktop.
Sample of IOrganizationService implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #region IOrganizationService implementation | |
| public Guid Create(Entity entity) | |
| { | |
| Trace($"Creating {entity.LogicalName} with {entity.Attributes.Count} attributes"); | |
| var sw = Stopwatch.StartNew(); | |
| var result = service.Create(entity); | |
| sw.Stop(); | |
| Trace($"Created in {sw.ElapsedMilliseconds} ms"); | |
| return result; | |
| } | |
| public Entity Retrieve(string entityName, Guid id, ColumnSet columnSet) | |
| { | |
| Trace($"Retrieving {entityName} {id} with {columnSet.Columns.Count} attributes"); | |
| var sw = Stopwatch.StartNew(); | |
| var result = service.Retrieve(entityName, id, columnSet); | |
| sw.Stop(); | |
| Trace($"Retrieved in {sw.ElapsedMilliseconds} ms"); | |
| return result; | |
| } | |
| public Entity Retrieve(EntityReference reference, params string[] columns) => Retrieve(reference.LogicalName, reference.Id, new ColumnSet(columns)); | |
| public void Update(Entity entity) | |
| { | |
| Trace($"Updating {entity.LogicalName} with {entity.Attributes.Count} attributes"); | |
| var sw = Stopwatch.StartNew(); | |
| service.Update(entity); | |
| sw.Stop(); | |
| Trace($"Updated in {sw.ElapsedMilliseconds} ms"); | |
| } | |
| public void Delete(string entityName, Guid id) | |
| { | |
| Trace($"Deletng {entityName} {id}"); | |
| var sw = Stopwatch.StartNew(); | |
| service.Delete(entityName, id); | |
| sw.Stop(); | |
| Trace($"Deleted in {sw.ElapsedMilliseconds} ms"); | |
| } | |
| public void Delete(EntityReference reference) => Delete(reference.LogicalName, reference.Id); | |
| public OrganizationResponse Execute(OrganizationRequest request) | |
| { | |
| Trace($"Executing {request}"); | |
| var sw = Stopwatch.StartNew(); | |
| var result = service.Execute(request); | |
| sw.Stop(); | |
| Trace($"Executed in {sw.ElapsedMilliseconds} ms"); | |
| return result; | |
| } | |
| public void Associate(string entityName, Guid entityId, Relationship relationship, EntityReferenceCollection relatedEntities) | |
| { | |
| Trace($"Associating {entityName} {entityId} over {relationship.SchemaName} with {relatedEntities.Count} {string.Join(", ", relatedEntities.Select(r => r.LogicalName))}"); | |
| var sw = Stopwatch.StartNew(); | |
| service.Associate(entityName, entityId, relationship, relatedEntities); | |
| sw.Stop(); | |
| Trace($"Associated in {sw.ElapsedMilliseconds} ms"); | |
| } | |
| public void Disassociate(string entityName, Guid entityId, Relationship relationship, EntityReferenceCollection relatedEntities) | |
| { | |
| Trace($"Disassociating {entityName} {entityId} over {relationship.SchemaName} with {relatedEntities.Count} {string.Join(", ", relatedEntities.Select(r => r.LogicalName))}"); | |
| var sw = Stopwatch.StartNew(); | |
| service.Disassociate(entityName, entityId, relationship, relatedEntities); | |
| sw.Stop(); | |
| Trace($"Disassociated in {sw.ElapsedMilliseconds} ms"); | |
| } | |
| public EntityCollection RetrieveMultiple(QueryBase query) | |
| { | |
| Trace($"Retrieving with {query}"); | |
| var sw = Stopwatch.StartNew(); | |
| var result = service.RetrieveMultiple(query); | |
| sw.Stop(); | |
| Trace($"Retrieved {result.Entities.Count} {result.EntityName} in {sw.ElapsedMilliseconds} ms"); | |
| return result; | |
| } | |
| #endregion IOrganizationService implementation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment