async Task InitializeExtensionChain() { // Create an initial empty extension chain. This avoid crashes in case a call to SupportsObject ends // calling methods from the extension var tempExtensions = new List <DocumentControllerExtension> { new DefaultControllerExtension() }; extensionChain = ExtensionChain.Create(tempExtensions.ToArray()); foreach (var e in tempExtensions) { await e.Init(this, null); } // Collect extensions that support this object var documentControllerService = await Runtime.GetService <DocumentControllerService> (); var extensions = new List <DocumentControllerExtension> (); foreach (var node in documentControllerService.GetModelExtensions(extensionContext)) { if (node.Data.CanHandle(this)) { var ext = node.CreateInstance(); if (!(ext is DocumentControllerExtension controllerExtension)) { throw new InvalidOperationException("Invalid document controller extension type: " + ext.GetType()); } if (await controllerExtension.SupportsController(this)) { controllerExtension.SourceExtensionNode = node; extensions.Add(controllerExtension); } else { controllerExtension.Dispose(); } } } extensionChain.Dispose(); // Now create the final extension chain extensions.Reverse(); var defaultExts = new List <DocumentControllerExtension> { new DefaultControllerExtension() }; defaultExts.Reverse(); extensions.AddRange(defaultExts); extensionChain = ExtensionChain.Create(extensions.ToArray()); extensionChain.SetDefaultInsertionPosition(defaultExts.FirstOrDefault()); foreach (var e in extensions) { await e.Init(this, GetExtensionStatus (e)); } itemExtension = extensionChain.GetExtension <DocumentControllerExtension> (); foreach (var e in extensions) { e.OnExtensionChainCreated(); } OnExtensionChainCreated(); if (extensions.Count - defaultExts.Count > 0) { NotifyContentChanged(); } }
Properties GetExtensionStatus(DocumentControllerExtension ext) { return(lastKnownStatus?.Get <Properties> (ExtensionPropertyPrefix + ext.Id)); }
void StoreExtensionStatus(DocumentControllerExtension ext) { var s = ext.GetDocumentStatus(); lastKnownStatus.Set(ExtensionPropertyPrefix + ext.Id, s); }
protected override void InitializeChain(ChainedExtension next) { base.InitializeChain(next); this.next = FindNextImplementation <DocumentControllerExtension> (next); }