Ejemplo n.º 1
0
        private void UpdateCache()
        {
            if (CrmVersionManager.IsSupported(CrmVersion.CRM2011_UR12))
            {
                ParameterCollection result = GetEntityUsingMetadataQuery();
                foreach (var item in (EntityMetadataCollection)result["EntityMetadata"])
                {
                    _entities.Add(item.LogicalName, item);
                }
                var deleted = (DeletedMetadataCollection)result["DeletedMetadata"];
                if (deleted != null && deleted.Keys.Contains(DeletedMetadataFilters.Entity))
                {
                    foreach (var item in deleted[DeletedMetadataFilters.Entity])
                    {
                        _entities.Remove(_entities.Single(e => e.MetadataId == item).LogicalName);
                    }
                }

                _timestamp = (string)result["ServerVersionStamp"];
            }
            else
            {
                IEnumerable <EntityMetadata> result = (EntityMetadata[])GetEntitiesUsingRequestAll()["EntityMetadata"];
                _entities = new Cache <EntityMetadata>();
                foreach (var item in result)
                {
                    _entities.Add(item.LogicalName, item);
                }

                _lastUpdated = DateTime.UtcNow;
            }
        }
Ejemplo n.º 2
0
        private bool IsCacheValid()
        {
            if (CrmVersionManager.IsSupported(CrmVersion.CRM2011_UR12))
            {
                if (_timestamp == null)
                {
                    return(false);
                }

                OrganizationRequest  request  = new OrganizationRequest("RetrieveTimestamp");
                OrganizationResponse response = CrmContext.OrganizationProxy.Execute(request);
                string result = (string)response.Results["Timestamp"];

                return(string.Equals(_timestamp, result, StringComparison.InvariantCultureIgnoreCase));
            }
            else
            {
                if (_lastUpdated == null)
                {
                    return(false);
                }

                return((DateTime.UtcNow - _lastUpdated).Value.TotalMinutes < 10.0);
            }
        }