public override void Delete(string entityName, Guid id)
 {
     if (DeleteAction != null)
     {
         DeleteAction(Service, entityName, id);
     }
     else if (DeleteActions != null)
     {
         if (DeleteCache == null)
         {
             DeleteCache = Service;
             foreach (var delete in DeleteActions)
             {
                 DeleteCache = new FakeIOrganizationService(DeleteCache)
                 {
                     DeleteAction = delete
                 };
             }
         }
         DeleteCache.Delete(entityName, id);
     }
     else
     {
         if (ExecutionTracingEnabled)
         {
             Timer.Time(DeleteInternal, new Tuple <string, Guid>(entityName, id), "Delete {0}({1}): {2}", entityName, id);
         }
         else
         {
             Service.Delete(entityName, id);
         }
     }
 }
 public override void Update(Entity entity)
 {
     if (UpdateAction != null)
     {
         UpdateAction(Service, entity);
     }
     else if (UpdateActions != null)
     {
         if (UpdateCache == null)
         {
             UpdateCache = Service;
             foreach (var update in UpdateActions)
             {
                 UpdateCache = new FakeIOrganizationService(UpdateCache)
                 {
                     UpdateAction = update
                 };
             }
         }
         UpdateCache.Update(entity);
     }
     else
     {
         if (ExecutionTracingEnabled)
         {
             Timer.Time(UpdateInternal, entity, "Update Entity {0}: {1}", entity.GetNameId());
         }
         else
         {
             Service.Update(entity);
         }
     }
 }
        public override Entity Retrieve(string entityName, Guid id, ColumnSet columnSet)
        {
            Entity entity;

            if (RetrieveFunc != null)
            {
                entity = RetrieveFunc(Service, entityName, id, columnSet);
            }
            else if (RetrieveFuncs != null)
            {
                if (RetrieveCache == null)
                {
                    RetrieveCache = Service;
                    foreach (var retrieve in RetrieveFuncs)
                    {
                        RetrieveCache = new FakeIOrganizationService(RetrieveCache)
                        {
                            RetrieveFunc = retrieve
                        };
                    }
                }
                entity = RetrieveCache.Retrieve(entityName, id, columnSet);
            }
            else
            {
                entity = ExecutionTracingEnabled ? Timer.Time(RetrieveInternal, new Tuple <string, Guid, ColumnSet>(entityName, id, columnSet), "Retrieve {0}({1}): {2}", entityName, id) : Service.Retrieve(entityName, id, columnSet);
            }
            return(entity);
        }
 public override void Disassociate(string entityName, Guid entityId, Relationship relationship, EntityReferenceCollection relatedEntities)
 {
     if (DisassociateAction != null)
     {
         DisassociateAction(Service, entityName, entityId, relationship, relatedEntities);
     }
     else if (DisassociateActions != null)
     {
         if (DisassociateCache == null)
         {
             DisassociateCache = Service;
             foreach (var disassociate in DisassociateActions)
             {
                 DisassociateCache = new FakeIOrganizationService(DisassociateCache)
                 {
                     DisassociateAction = disassociate
                 };
             }
         }
         DisassociateCache.Disassociate(entityName, entityId, relationship, relatedEntities);
     }
     else
     {
         if (ExecutionTracingEnabled)
         {
             Timer.Time(DisassociateInternal, new Tuple <string, Guid, Relationship, EntityReferenceCollection>(entityName, entityId, relationship, relatedEntities),
                        "Disassociate {0}:{1} using relationship {2} to releated Entities {3}: {4}",
                        entityName, entityId, relationship, relatedEntities.Select(e => e.GetNameId()).ToCsv());
         }
         else
         {
             Service.Disassociate(entityName, entityId, relationship, relatedEntities);
         }
     }
 }
示例#5
0
        /// <summary>
        /// Executes the given action, returning a list of Query Expressions that would have been executed against the server.
        /// If the action does something with the results of the query expression, it most likely will fail. i.e. retrieves an entity,
        /// then uses that entity's id to update another entity
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public static List <QueryExpression> GetExecutedQueryExpressions(this Action <IOrganizationService> action)
        {
            var expressions = new List <QueryExpression>();
            var mock        = new FakeIOrganizationService(null)
            {
                AssociateAction    = (s, name, id, rel, entities) => { },
                CreateFunc         = (s, entity) => Guid.Empty,
                DeleteAction       = (s, name, id) => { },
                DisassociateAction = (s, name, id, rel, entities) => { },
                ExecuteFunc        = (s, r) => new OrganizationResponse(),
                RetrieveFunc       = (s, name, id, cs) =>
                {
                    expressions.Add(new QueryExpression(name).WhereEqual(EntityHelper.GetIdAttributeName(name), id));
                    return(new Entity(name));
                },
                RetrieveMultipleFunc = (s, qb) =>
                {
                    var qe = qb as QueryExpression;
                    if (qe != null)
                    {
                        expressions.Add(qe);
                    }
                    return(new EntityCollection());
                },
                UpdateAction = (s, e) => { },
            };

            action(mock);

            return(expressions);
        }
        public override Guid Create(Entity entity)
        {
            Guid id;

            if (CreateFunc != null)
            {
                id = CreateFunc(Service, entity);
            }
            else if (CreateFuncs != null)
            {
                if (CreateCache == null)
                {
                    CreateCache = Service;
                    foreach (var create in CreateFuncs)
                    {
                        CreateCache = new FakeIOrganizationService(CreateCache)
                        {
                            CreateFunc = create
                        };
                    }
                }
                id = CreateCache.Create(entity);
            }
            else
            {
                id = ExecutionTracingEnabled ? Timer.Time(CreateInternal, entity, "Create {0}: {1}", entity.GetNameId()) : Service.Create(entity);
            }
            return(id);
        }
示例#7
0
 public override void Associate(string entityName, Guid entityId, Relationship relationship, EntityReferenceCollection relatedEntities)
 {
     if (AssociateAction != null)
     {
         AssociateAction(Service, entityName, entityId, relationship, relatedEntities);
     }
     else if (AssociateActions != null)
     {
         if (AssociateCache == null)
         {
             AssociateCache = Service;
             foreach (var action in AssociateActions)
             {
                 AssociateCache = new FakeIOrganizationService(AssociateCache)
                 {
                     AssociateAction = action
                 };
             }
         }
         AssociateCache.Associate(entityName, entityId, relationship, relatedEntities);
     }
     else
     {
         if (ExecutionTracingEnabled)
         {
             Timer.Time(AssociateInternal, new Tuple <string, Guid, Relationship, EntityReferenceCollection>(entityName, entityId, relationship, relatedEntities),
                        "Associate {0}:{1} using relationship {2} to releated Entities {3}: {4}",
                        entityName, entityId, relationship, String.Join(", ", relatedEntities.Select(e => e.GetNameId())));
         }
         else
         {
             Service.Associate(entityName, entityId, relationship, relatedEntities);
         }
     }
 }
        public override OrganizationResponse Execute(OrganizationRequest request)
        {
            OrganizationResponse response;

            if (RedirectExecuteRequestsToOrganizationServiceRequest)
            {
                response = CallOrganizationServiceRequestForExecuteRequest(request);

                if (response != null)
                {
                    return(response);
                }
            }

            if (ExecuteFunc != null)
            {
                response = ExecuteFunc(Service, request);
            }
            else if (ExecuteFuncs != null)
            {
                if (ExecuteCache == null)
                {
                    ExecuteCache = Service;
                    foreach (var execute in ExecuteFuncs)
                    {
                        ExecuteCache = new FakeIOrganizationService(ExecuteCache)
                        {
                            ExecuteFunc = execute
                        };
                    }
                }
                response = ExecuteCache.Execute(request);
            }
            else
            {
                response = ExecutionTracingEnabled ? Timer.Time(ExecuteInternal, request, "Execute {0}: {1}", request.RequestName) : Service.Execute(request);
            }
            return(response);
        }
        public override EntityCollection RetrieveMultiple(QueryBase query)
        {
            EntityCollection entities;

            if (RetrieveMultipleFunc != null)
            {
                entities = RetrieveMultipleFunc(Service, query);
            }
            else if (RetrieveMultipleFuncs != null)
            {
                if (RetrieveMultipleCache == null)
                {
                    RetrieveMultipleCache = Service;
                    foreach (var retrievemultiple in RetrieveMultipleFuncs)
                    {
                        RetrieveMultipleCache = new FakeIOrganizationService(RetrieveMultipleCache)
                        {
                            RetrieveMultipleFunc = retrievemultiple
                        };
                    }
                }
                entities = RetrieveMultipleCache.RetrieveMultiple(query);
            }
            else
            {
                if (ExecutionTracingEnabled)
                {
                    entities = query is QueryExpression qe
                        ? Timer.Time(RetrieveMultipleInternal, query, "RetrieveMultiple: {2}{0}{1}", Environment.NewLine, qe.GetSqlStatement())
                        : Timer.Time(RetrieveMultipleInternal, query, "RetrieveMultiple {0}: {1}", query);
                }
                else
                {
                    entities = Service.RetrieveMultiple(query);
                }
            }
            return(entities);
        }
        public override EntityCollection RetrieveMultiple(QueryBase query)
        {
            EntityCollection entities;
            if (RetrieveMultipleFunc != null)
            {
                entities = RetrieveMultipleFunc(Service, query);
            }
            else if (RetrieveMultipleFuncs != null)
            {
                if (RetrieveMultipleCache == null)
                {
                    RetrieveMultipleCache = Service;
                    foreach (var retrievemultiple in RetrieveMultipleFuncs)
                    {
                        RetrieveMultipleCache = new FakeIOrganizationService(RetrieveMultipleCache) {RetrieveMultipleFunc = retrievemultiple};
                    }
                }
                entities = RetrieveMultipleCache.RetrieveMultiple(query);
            }
            else
            {
                if (ExecutionTracingEnabled)
                {
                    var qe = query as QueryExpression;

                    entities = qe == null ? Timer.Time(RetrieveMultipleInternal, query, "RetrieveMultiple {0}: {1}", query) : Timer.Time(RetrieveMultipleInternal, query, "RetrieveMultiple: {2}{0}{1}", Environment.NewLine, qe.GetSqlStatement());
                }
                else
                {
                    entities = Service.RetrieveMultiple(query);
                }
            }
            return entities;
        }
 public override Entity Retrieve(string entityName, Guid id, ColumnSet columnSet)
 {
     Entity entity;
     if (RetrieveFunc != null)
     {
         entity = RetrieveFunc(Service, entityName, id, columnSet);
     }
     else if (RetrieveFuncs != null)
     {
         if (RetrieveCache == null)
         {
             RetrieveCache = Service;
             foreach (var retrieve in RetrieveFuncs)
             {
                 RetrieveCache = new FakeIOrganizationService(RetrieveCache) {RetrieveFunc = retrieve};
             }
         }
         entity = RetrieveCache.Retrieve(entityName, id, columnSet);
     }
     else
     {
         entity = ExecutionTracingEnabled ? Timer.Time(RetrieveInternal, new Tuple<string, Guid, ColumnSet>(entityName, id, columnSet), "Retrieve {0}({1}): {2}", entityName, id) : Service.Retrieve(entityName, id, columnSet);
     }
     return entity;
 }
        public override OrganizationResponse Execute(OrganizationRequest request)
        {
            OrganizationResponse response;
            if (RedirectExecuteRequestsToOrganizationServiceRequest)
            {
                response = CallOrganizationServiceRequestForExecuteRequest(request);

                if(response != null)
                {
                    return response;
                }
            }

            if (ExecuteFunc != null)
            {
                response = ExecuteFunc(Service, request);
            }
            else if (ExecuteFuncs != null)
            {
                if (ExecuteCache == null)
                {
                    ExecuteCache = Service;
                    foreach (var execute in ExecuteFuncs)
                    {
                        ExecuteCache = new FakeIOrganizationService(ExecuteCache) {ExecuteFunc = execute};
                    }
                }
                response = ExecuteCache.Execute(request);
            }
            else
            {
                response = ExecutionTracingEnabled ? Timer.Time(ExecuteInternal, request, "Execute {0}: {1}", request.RequestName) : Service.Execute(request);
            }
            return response;
        }
 public override void Disassociate(string entityName, Guid entityId, Relationship relationship, EntityReferenceCollection relatedEntities)
 {
     if (DisassociateAction != null)
     {
         DisassociateAction(Service, entityName, entityId, relationship, relatedEntities);
     }
     else if (DisassociateActions != null)
     {
         if (DisassociateCache == null)
         {
             DisassociateCache = Service;
             foreach (var disassociate in DisassociateActions)
             {
                 DisassociateCache = new FakeIOrganizationService(DisassociateCache) {DisassociateAction = disassociate};
             }
         }
         DisassociateCache.Disassociate(entityName, entityId, relationship, relatedEntities);
     }
     else
     {
         if (ExecutionTracingEnabled)
         {
             Timer.Time(DisassociateInternal, new Tuple<string, Guid, Relationship, EntityReferenceCollection>(entityName, entityId, relationship, relatedEntities),
                 "Disassociate {0}:{1} using relationship {2} to releated Entities {3}: {4}",
                 entityName, entityId, relationship, String.Join(", ", relatedEntities.Select(e => e.GetNameId())));
         }
         else
         {
             Service.Disassociate(entityName, entityId, relationship, relatedEntities);
         }
     }
 }
 public override void Delete(string entityName, Guid id)
 {
     if (DeleteAction != null)
     {
         DeleteAction(Service, entityName, id);
     }
     else if (DeleteActions != null)
     {
         if (DeleteCache == null)
         {
             DeleteCache = Service;
             foreach (var delete in DeleteActions)
             {
                 DeleteCache = new FakeIOrganizationService(DeleteCache) {DeleteAction = delete};
             }
         }
         DeleteCache.Delete(entityName, id);
     }
     else
     {
         if (ExecutionTracingEnabled)
         {
             Timer.Time(DeleteInternal, new Tuple<string, Guid>(entityName, id), "Delete {0}({1}): {2}", entityName, id);
         }
         else
         {
             Service.Delete(entityName, id);
         }
     }
 }
 public override Guid Create(Entity entity)
 {
     Guid id;
     if (CreateFunc != null)
     {
         id = CreateFunc(Service, entity);
     }
     else if (CreateFuncs != null)
     {
         if (CreateCache == null)
         {
             CreateCache = Service;
             foreach (var create in CreateFuncs)
             {
                 CreateCache = new FakeIOrganizationService(CreateCache) {CreateFunc = create};
             }
         }
         id = CreateCache.Create(entity);
     }
     else
     {
         id = ExecutionTracingEnabled ? Timer.Time(CreateInternal, entity, "Create {0}: {1}", entity.GetNameId()) : Service.Create(entity);
     }
     return id;
 }