Exemple #1
0
        /// <summary>
        /// Gets a single document (or create a new one) for caching and that should not be updated.
        /// </summary>
        public Task <(bool, ContentDefinitionRecord)> GetContentDefinitionAsync()
        {
            var scopedCache = ShellScope.Services.GetRequiredService <FileContentDefinitionScopedCache>();

            if (scopedCache.ContentDefinitionRecord != null)
            {
                // Return the already loaded document but indicating that it should not be cached.
                return(Task.FromResult((false, scopedCache.ContentDefinitionRecord)));
            }

            ContentDefinitionRecord result;

            if (!File.Exists(Filename))
            {
                result = new ContentDefinitionRecord();
            }
            else
            {
                lock (this)
                {
                    using (var file = File.OpenText(Filename))
                    {
                        var serializer = new JsonSerializer();
                        result = (ContentDefinitionRecord)serializer.Deserialize(file, typeof(ContentDefinitionRecord));
                    }
                }
            }

            return(Task.FromResult((true, result)));
        }
Exemple #2
0
        private ContentDefinitionRecord GetContentDefinitionRecord()
        {
            if (_contentDefinitionRecord != null)
            {
                return(_contentDefinitionRecord);
            }

            return(_contentDefinitionRecord = _contentDefinitionStore.LoadContentDefinitionAsync().GetAwaiter().GetResult());
        }
Exemple #3
0
        public Task SaveContentDefinitionAsync(ContentDefinitionRecord contentDefinitionRecord)
        {
            using (var file = File.CreateText(Filename))
            {
                var serializer = new JsonSerializer();
                serializer.Formatting = Formatting.Indented;
                serializer.Serialize(file, contentDefinitionRecord);
            }

            return(Task.CompletedTask);
        }
        public async Task <ContentDefinitionRecord> LoadContentDefinitionAsync()
        {
            var contentDefinitionRecord = await _session
                                          .Query <ContentDefinitionRecord>()
                                          .FirstOrDefaultAsync();

            if (contentDefinitionRecord == null)
            {
                contentDefinitionRecord = new ContentDefinitionRecord();
                await SaveContentDefinitionAsync(contentDefinitionRecord);
            }

            return(contentDefinitionRecord);
        }
        /// <summary>
        /// Checks the document identifier and then clears the cached built definitions if it has changed.
        /// </summary>
        private void CheckDocumentIdentifier(ContentDefinitionRecord document)
        {
            if (!_memoryCache.TryGetValue <Document>(CacheKey, out var cacheEntry) || cacheEntry.Identifier != document.Identifier)
            {
                cacheEntry = new Document()
                {
                    Identifier = document.Identifier,
                };

                _cachedTypeDefinitions.Clear();
                _cachedPartDefinitions.Clear();

                _memoryCache.Set(CacheKey, cacheEntry);
            }
        }
Exemple #6
0
        public Task <ContentDefinitionRecord> LoadContentDefinitionAsync()
        {
            ContentDefinitionRecord result;

            if (!File.Exists(Filename))
            {
                result = new ContentDefinitionRecord();
            }
            else
            {
                using (var file = File.OpenText(Filename))
                {
                    var serializer = new JsonSerializer();
                    result = (ContentDefinitionRecord)serializer.Deserialize(file, typeof(ContentDefinitionRecord));
                }
            }

            return(Task.FromResult(result));
        }
Exemple #7
0
        public Task SaveContentDefinitionAsync(ContentDefinitionRecord contentDefinitionRecord)
        {
            lock (this)
            {
                var directoryPath = Path.GetDirectoryName(Filename);
                if (!String.IsNullOrEmpty(directoryPath) && !Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                using (var file = File.CreateText(Filename))
                {
                    var serializer = new JsonSerializer();
                    serializer.Formatting = Formatting.Indented;
                    serializer.Serialize(file, contentDefinitionRecord);
                }
            }

            return(Task.CompletedTask);
        }
Exemple #8
0
        private ContentDefinitionRecord GetContentDefinitionRecord()
        {
            // cache in the current work context
            if (_contentDefinitionRecord != null)
            {
                return(_contentDefinitionRecord);
            }

            _contentDefinitionRecord = _session
                                       .QueryAsync <ContentDefinitionRecord>()
                                       .FirstOrDefault()
                                       .Result;

            if (_contentDefinitionRecord == null)
            {
                _contentDefinitionRecord = new ContentDefinitionRecord();
                UpdateContentDefinitionRecord();
            }

            return(_contentDefinitionRecord);
        }
 /// <inheritdoc />
 public Task SaveContentDefinitionAsync(ContentDefinitionRecord contentDefinitionRecord) => _documentManager.UpdateAsync(contentDefinitionRecord);
        public Task SaveContentDefinitionAsync(ContentDefinitionRecord contentDefinitionRecord)
        {
            _session.Save(contentDefinitionRecord);

            return(Task.CompletedTask);
        }