/// <summary> /// Imports a <see cref="ClientSideComponent"/> to use it as base for configuring the client side web part instance /// </summary> /// <param name="component"><see cref="ClientSideComponent"/> to import</param> /// <param name="clientSideWebPartPropertiesUpdater">Function callback that allows you to manipulate the client side web part properties after import</param> public void Import(ClientSideComponent component, Func <String, String> clientSideWebPartPropertiesUpdater = null) { this.component = component; // Sometimes the id guid is encoded with curly brackets, so let's drop those this.webPartId = new Guid(component.Id).ToString("D"); // Parse the manifest json blob as we need some data from it JObject wpJObject = JObject.Parse(component.Manifest); this.title = wpJObject["preconfiguredEntries"][0]["title"]["default"].Value <string>(); this.description = wpJObject["preconfiguredEntries"][0]["title"]["default"].Value <string>(); if (wpJObject["supportsFullBleed"] != null) { this.supportsFullBleed = wpJObject["supportsFullBleed"].Value <bool>(); } else { this.supportsFullBleed = false; } this.SetPropertiesJson(wpJObject["preconfiguredEntries"][0]["properties"].ToString(Formatting.None)); if (clientSideWebPartPropertiesUpdater != null) { this.propertiesJson = clientSideWebPartPropertiesUpdater(this.propertiesJson); } }
/// <summary> /// Instantiates a client side web part based on the information that was obtain from calling the AvailableClientSideComponents methods on the <see cref="ClientSidePage"/> object. /// </summary> /// <param name="component">Component to create a ClientSideWebPart instance for</param> public ClientSideWebPart(ClientSideComponent component) : this() { if (component == null) { throw new ArgumentNullException("Passed in component cannot be null"); } this.Import(component); }