public List<Entities.Content> GetPageContent(Entities.Page page) { var store = new ContentStore(Context.FileSystem); //store.Add(new Content() { Name = "Test", PageId = page.Id, Type = "string", Data = "test" }); return store.GetAll(page).MakeTree().ToList(); }
/// <inheritdoc /> public void PostInitializationCompleted(Context context, BoolResult result) { ContentStore.PostInitializationCompleted(context, result); }
/// <inheritdoc /> public Task <DeleteResult> DeleteAsync(Context context, ContentHash contentHash, DeleteContentOptions deleteOptions = null) { return(ContentStore.DeleteAsync(context, contentHash, deleteOptions)); }
public void PostInitializationCompleted(Context context, BoolResult result) { Contract.Requires(ContentStore != null, "ContentStore must be initialized here."); ContentStore.PostInitializationCompleted(context, result); }
private void SaveContent(Entities.Content content) { var store = new ContentStore(Context.FileSystem); store.Add(content); }
public void AddContent(Entities.Page page, Entities.Content contentTree) { var store = new ContentStore(Context.FileSystem); SaveContent(page, contentTree); }
public override void Initialize() { this._title = ContentStore.Get <Texture2D>("Sprites/title"); }
public void DeleteContent(Entities.Page page) { var store = new ContentStore(Context.FileSystem); store.Delete(x => x.PageId == page.Id); }
private bool LoadEntitiesFromLocalDbLocked(bool onStartup, BPlusTree <int, ContentNodeKit> localDb, ContentStore store, string entityType) { var kits = localDb.Select(x => x.Value) .OrderBy(x => x.Node.Level) .ThenBy(x => x.Node.ParentContentId) .ThenBy(x => x.Node.SortOrder) // IMPORTANT sort by level + parentId + sortOrder .ToList(); if (kits.Count == 0) { // If there's nothing in the local cache file, we should return false? YES even though the site legitately might be empty. // Is it possible that the cache file is empty but the database is not? YES... (well, it used to be possible) // * A new file is created when one doesn't exist, this will only be done when MainDom is acquired // * The new file will be populated as soon as LoadCachesOnStartup is called // * If the appdomain is going down the moment after MainDom was acquired and we've created an empty cache file, // then the MainDom release callback is triggered from on a different thread, which will close the file and // set the cache file reference to null. At this moment, it is possible that the file is closed and the // reference is set to null BEFORE LoadCachesOnStartup which would mean that the current appdomain would load // in the in-mem cache via DB calls, BUT this now means that there is an empty cache file which will be // loaded by the next appdomain and it won't check if it's empty, it just assumes that since the cache // file is there, that is correct. // Update: We will still return false here even though the above mentioned race condition has been fixed since we now // lock the entire operation of creating/populating the cache file with the same lock as releasing/closing the cache file _logger.LogInformation("Tried to load {entityType} from the local cache file but it was empty.", entityType); return(false); } return(onStartup ? store.SetAllFastSortedLocked(kits, false) : store.SetAllLocked(kits)); }
/// <summary>takes our copy of the stream, and puts it into the request stream</summary> protected void CopyRequestData() { if (_requestCopy != null) { // Since we don't use write buffering on the WebRequest object, // we need to ensure the Content-Length field is correctly set // to the length we want to set. EnsureWebRequest(); Request.ContentLength = _requestCopy.Length; // stream it into the real request stream Stream req = base.GetRequestStream(); try { const int size = 4096; byte[] bytes = new byte[size]; int numBytes; double oneLoop = 100; if (_requestCopy.Length > size) { oneLoop = (100 / ((double)_requestCopy.Length / size)); } // 3 lines of debug code // this.requestCopy.Seek(0, SeekOrigin.Begin); // StreamReader reader = new StreamReader( this.requestCopy ); // string text = reader.ReadToEnd(); _requestCopy.Seek(0, SeekOrigin.Begin); long bytesWritten = 0; double current = 0; while ((numBytes = _requestCopy.Read(bytes, 0, size)) > 0) { req.Write(bytes, 0, numBytes); bytesWritten += numBytes; if (_asyncData != null && _asyncData.Delegate != null && _asyncData.DataHandler != null) { AsyncOperationProgressEventArgs args; args = new AsyncOperationProgressEventArgs( _requestCopy.Length, bytesWritten, (int)current, Request.RequestUri, Request.Method, _asyncData.UserData); current += oneLoop; if (!_asyncData.DataHandler.SendProgressData(_asyncData, args)) { break; } } } } finally { req.Close(); } } else { if (IsBatch) { EnsureWebRequest(); ContentStore.SaveToXml(GetRequestStream()); CopyRequestData(); } } }
/// <summary> /// Lazily populates the stores only when they are first requested /// </summary> internal void EnsureCaches() => LazyInitializer.EnsureInitialized( ref _isReady, ref _isReadSet, ref _isReadyLock, () => { // lock this entire call, we only want a single thread to be accessing the stores at once and within // the call below to mainDom.Register, a callback may occur on a threadpool thread to MainDomRelease // at the same time as we are trying to write to the stores. MainDomRelease also locks on _storesLock so // it will not be able to close the stores until we are done populating (if the store is empty) lock (_storesLock) { if (!_options.IgnoreLocalDb) { _mainDom.Register(MainDomRegister, MainDomRelease); // stores are created with a db so they can write to it, but they do not read from it, // stores need to be populated, happens in OnResolutionFrozen which uses _localDbExists to // figure out whether it can read the databases or it should populate them from sql _logger.LogInformation("Creating the content store, localContentDbExists? {LocalContentDbExists}", _localContentDbExists); _contentStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory, _localContentDb); _logger.LogInformation("Creating the media store, localMediaDbExists? {LocalMediaDbExists}", _localMediaDbExists); _mediaStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory, _localMediaDb); } else { _logger.LogInformation("Creating the content store (local db ignored)"); _contentStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory); _logger.LogInformation("Creating the media store (local db ignored)"); _mediaStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory); } _domainStore = new SnapDictionary <int, Domain>(); var okContent = false; var okMedia = false; SyncBootState bootState = _syncBootStateAccessor.GetSyncBootState(); try { if (bootState != SyncBootState.ColdBoot && _localContentDbExists) { okContent = LockAndLoadContent(() => LoadContentFromLocalDbLocked(true)); if (!okContent) { _logger.LogWarning("Loading content from local db raised warnings, will reload from database."); } } if (bootState != SyncBootState.ColdBoot && _localMediaDbExists) { okMedia = LockAndLoadMedia(() => LoadMediaFromLocalDbLocked(true)); if (!okMedia) { _logger.LogWarning("Loading media from local db raised warnings, will reload from database."); } } if (!okContent) { LockAndLoadContent(() => LoadContentFromDatabaseLocked(true)); } if (!okMedia) { LockAndLoadMedia(() => LoadMediaFromDatabaseLocked(true)); } LockAndLoadDomains(); } catch (Exception ex) { _logger.LogCritical(ex, "Panic, exception while loading cache data."); throw; } return(true); } });
private Guid GetUid(ContentStore store, int id) => store.LiveSnapshot.Get(id)?.Uid ?? Guid.Empty;
private int GetId(ContentStore store, Guid uid) => store.LiveSnapshot.Get(uid)?.Id ?? 0;
/// <inheritdoc /> protected override void DisposeCore() { MemoizationStore?.Dispose(); ContentStore?.Dispose(); }
public List<Entities.Content> GetSiteContent(Entities.Site site) { var store = new ContentStore(Context.FileSystem); return store.GetSiteContent(site).MakeTree().ToList(); }
public List <Entities.Content> GetSiteContent(Entities.Site site) { var store = new ContentStore(Context.FileSystem); return(store.GetSiteContent(site).MakeTree().ToList()); }
public ClonedContentProvider(IContentLoader contentLoader, ContentStore contentStore, IPageCriteriaQueryService pageCriteriaQueryService) { _contentLoader = contentLoader; _contentStore = contentStore; _pageQueryService = pageCriteriaQueryService; }