public void Save(EfMappingViews views)
        {
            var sw = Stopwatch.StartNew();

            JsonUtility.SerializeToFile(views, _cacheFilePath);
            _performanceLogger.Write(sw, () => $"Serialized and saved views to '{_cacheFilePath}'.");
        }
Пример #2
0
        private void GenerateAndSaveViews()
        {
            var sw = Stopwatch.StartNew();

            var mappingCollection = (StorageMappingItemCollection)_metadataWorkspaceFileProvider.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
            var hash = mappingCollection.ComputeMappingHashValue();

            _performanceLogger.Write(sw, () => $"Calculated hash for current model.");
            string additionalHash = _efMappingViewsHash.GetAdditionalHash();

            _performanceLogger.Write(sw, () => $"Calculated additional hash.");

            var currentViewCache = _efMappingViewsFileStore.Load();

            if (!string.IsNullOrEmpty(currentViewCache?.Hash) &&
                currentViewCache.Hash == hash &&
                currentViewCache.AdditionalHash == additionalHash)
            {
                _logger.Trace(() => $"Hash not changed. View cache is valid. Skipping generation.");
                return;
            }

            sw.Restart();
            var errors   = new List <EdmSchemaError>();
            var newViews = mappingCollection.GenerateViews(errors)
                           .ToDictionary(a => EfMappingViewCache.GetExtentKey(a.Key), a => a.Value.EntitySql);

            foreach (var edmSchemaError in errors)
            {
                _logger.Warning(() => $"{edmSchemaError}");
            }

            var newViewCache = new EfMappingViews {
                Hash = hash, Views = newViews, AdditionalHash = additionalHash
            };

            _performanceLogger.Write(sw, () => $"Generated new views. Old hash != new hash ('{currentViewCache?.Hash}' != '{hash}').");

            _efMappingViewsFileStore.Save(newViewCache);
        }
Пример #3
0
 public EfMappingViewCache(EfMappingViews mappingViews)
 {
     _mappingViews = mappingViews;
 }