public override int GetHashCode() { var requiredHash = RequiredComponents?.GetHashCode() ?? 0; var excludedHash = ExcludedComponents?.GetHashCode() ?? 0; return(requiredHash ^ excludedHash); }
public void Pass(HtmlDocument doc) { var nodes = doc.DocumentNode.SelectNodes("//audio"); if (nodes != null) { var c = new Component(); c.ElementName = "amp-audio"; c.ScriptPath = "https://cdn.ampproject.org/v0/amp-audio-0.1.js"; RequiredComponents.Add(c); foreach (HtmlNode n in nodes) { n.Name = "amp-audio"; if (n.Attributes["width"] == null) { n.Attributes.Add("width", "auto"); } n.Attributes["width"].Value = "auto"; } } }
/// <summary> /// Initialize a set of <see cref="IComponent"/> types that all entities associated with this system must have. /// </summary> /// <param name="components">The types of <see cref="IComponent"/> this system will require before associating with an entity.</param> public void Require(params Type[] components) { RequiredComponents.Clear(); for (int i = 0; i < components.Length; i++) { RequiredComponents.Add(components[i]); } }
/// <summary> /// Determine if a required <see cref="Type"/> component is stored in <see cref="BuildConfiguration"/>. /// The component <see cref="Type"/> must exist in the <see cref="RequiredComponents"/> list. /// </summary> /// <param name="context">The <see cref="BuildContext"/> used by the execution of this <see cref="BuildStep"/>.</param> /// <param name="type">Type of the required component.</param> /// <returns><see langword="true"/> if the required component type is found, <see langword="false"/> otherwise.</returns> public bool HasRequiredComponent(BuildContext context, Type type) { CheckTypeAndThrowIfInvalid <IBuildComponent>(type); if (RequiredComponents == null || !RequiredComponents.Contains(type)) { throw new InvalidOperationException($"Component type '{type.FullName}' is not in the {nameof(RequiredComponents)} list."); } return(context.BuildConfiguration.HasComponent(type)); }
/// <summary> /// Get the value of a required <see cref="Type"/> component from <see cref="BuildSettings"/>. /// The component <see cref="Type"/> must exist in the <see cref="RequiredComponents"/> list. /// </summary> /// <param name="context">The <see cref="BuildContext"/> used by the execution of this <see cref="BuildStep"/>.</param> /// <param name="type">Type of the required component.</param> /// <returns>The value of the required component.</returns> public IBuildSettingsComponent GetRequiredComponent(BuildContext context, Type type) { CheckTypeAndThrowIfInvalid(type); if (RequiredComponents == null || !RequiredComponents.Contains(type)) { throw new InvalidOperationException($"Component type '{type.FullName}' is not in the {nameof(RequiredComponents)} list."); } return(context.BuildSettings.GetComponent(type)); }
private void RefreshRequired() { string text = rtbComponents.Text; try { rtbComponents.Text = string.Empty; int obtainedCount = 0; string[] requiredComponents = RequiredComponents.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < requiredComponents.Length; i++) { string item = requiredComponents[i]; rtbComponents.SelectionStart = rtbComponents.TextLength; if (NLicense.IsComponentActivated(item)) { rtbComponents.SelectionColor = Color.Green; rtbComponents.AppendText(item); obtainedCount++; } else { rtbComponents.SelectionColor = Color.Red; rtbComponents.AppendText(item); } if (i != requiredComponents.Length - 1) { rtbComponents.SelectionColor = Color.Black; rtbComponents.AppendText(", "); } } if (obtainedCount == requiredComponents.Length) { lblStatus.Text = Resources.Licenses_obtained; lblStatus.ForeColor = Color.Green; } else { lblStatus.Text = Resources.Not_all_required_licenses_obtained; lblStatus.ForeColor = Color.Red; } } catch { rtbComponents.SelectionColor = Color.Black; rtbComponents.Text = text; throw; } }
/// <summary> /// Get all required components from <see cref="BuildConfiguration"/>, that matches <see cref="Type"/>. /// </summary> /// <param name="context">The <see cref="BuildContext"/> used by the execution of this <see cref="BuildStep"/>.</param> /// <param name="type">Type of the components.</param> /// <returns>List of required components.</returns> public IEnumerable <IBuildComponent> GetRequiredComponents(BuildContext context, Type type) { CheckTypeAndThrowIfInvalid <IBuildComponent>(type); if (RequiredComponents == null || !RequiredComponents.Contains(type)) { throw new InvalidOperationException($"Component type '{type.FullName}' is not in the {nameof(RequiredComponents)} list."); } var lookup = new Dictionary <Type, IBuildComponent>(); foreach (var requiredComponent in RequiredComponents) { if (!type.IsAssignableFrom(requiredComponent)) { continue; } lookup[requiredComponent] = context.BuildConfiguration.GetComponent(requiredComponent); } return(lookup.Values); }
public void Pass(HtmlDocument doc) { var nodes = doc.DocumentNode.SelectNodes("//iframe[not(ancestor::noscript)]"); if (nodes != null) { var c = new Component(); c.ElementName = "amp-youtube"; c.ScriptPath = "https://cdn.ampproject.org/v0/amp-youtube-0.1.js"; RequiredComponents.Add(c); foreach (HtmlNode n in nodes) { if (!IsYouTubeIframe(n)) { continue; } var ytCode = GetYouTubeCode(n); if (string.IsNullOrWhiteSpace(ytCode)) { continue; } HtmlNode ampYouTube = HtmlNode.CreateNode(string.Format("<amp-youtube data-videoid=\"{0}\" layout=\"responsive\"></amp-youtube>", ytCode)); EnsureHeightAndWidthAttributes(n); ScrubAttributes(n, null, true); foreach (HtmlAttribute attr in n.Attributes) { ampYouTube.Attributes.Add(attr.Name, attr.Value); } n.ParentNode.ReplaceChild(ampYouTube, n); } } }