/// <summary> /// Exports form validation rules for the parameter. /// </summary> /// <param name="Output">Output</param> /// <param name="Node">Node reference, if available.</param> public override Task ExportValidationRules(XmlWriter Output, IThingReference Node) { Output.WriteStartElement("xdv", "validate", null); Output.WriteAttributeString("datatype", "xs:int"); if (this.min.HasValue || this.max.HasValue) { Output.WriteStartElement("xdv", "range", null); if (this.min.HasValue) { Output.WriteAttributeString("min", this.min.Value.ToString()); } if (this.max.HasValue) { Output.WriteAttributeString("max", this.max.Value.ToString()); } Output.WriteEndElement(); } Output.WriteEndElement(); return(Task.CompletedTask); }
private string[] AddReference(string[] Groups, string Prefix, IThingReference NodeReference) { List<string> Result = new List<string>() { Prefix }; if (!string.IsNullOrEmpty(NodeReference.NodeId)) Result.Add(Prefix + ".nid:" + NodeReference.NodeId); if (!string.IsNullOrEmpty(NodeReference.SourceId)) Result.Add(Prefix + ".sid:" + NodeReference.SourceId); if (!string.IsNullOrEmpty(NodeReference.Partition)) Result.Add(Prefix + ".prt:" + NodeReference.Partition); if (Groups != null) { foreach (string Group in Groups) { if (!Group.StartsWith(Prefix)) Result.Add(Group); } } return Result.ToArray(); }
/// <summary> /// Sets the value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <param name="StringValue">String representation of value to set.</param> /// <returns>If the parameter could be set (true), or if the value could not be parsed or its value was invalid (false).</returns> public override async Task <bool> SetStringValue(IThingReference Node, string StringValue) { Enum Value; try { Value = (Enum)Enum.Parse(this.enumType, StringValue); } catch (Exception) { return(false); } try { await this.setHandler(Node, Value); } catch (Exception ex) { Log.Critical(ex); return(false); } return(true); }
internal static async Task <MeteringNode> GetNode(IThingReference NodeRef) { if (NodeRef.SourceId != MeteringTopology.SourceID || !string.IsNullOrEmpty(NodeRef.Partition)) { return(null); } lock (nodes) { if (nodes.TryGetValue(NodeRef.NodeId, out MeteringNode Node)) { return(Node); } } foreach (MeteringNode Node2 in await Database.Find <MeteringNode>(new FilterFieldEqualTo("NodeId", NodeRef.NodeId))) { lock (nodes) { if (nodes.TryGetValue(NodeRef.NodeId, out MeteringNode Node)) { return(Node); } else { nodes[NodeRef.NodeId] = Node2; return(Node2); } } } return(null); }
/// <summary> /// If there are subscriptions registered for a given node. /// </summary> /// <param name="Reference">Node reference.</param> /// <returns>If there are subscriptions for the current node.</returns> public bool HasSubscriptions(IThingReference Reference) { lock (this.subscriptionsByThing) { return(this.subscriptionsByThing.ContainsKey(Reference)); } }
public bool RemoveAll(IThingReference thing, EqualityLogicalOperatorToken comparator, FloatNumericPrimitiveToken value) { bool result = false; PlayerThingReference playerReference = thing as PlayerThingReference; if (playerReference != null) { // Think opposite here as we remove all that don't match. if (comparator is EqualsEqualityLogicalOperatorToken) { playerReference.Players.RemoveAll(player => player.Kills != value.ToFloat()); } else if (comparator is GreaterThanEqualToEqualityLogicalOperatorToken) { playerReference.Players.RemoveAll(player => player.Kills < value.ToFloat()); } else if (comparator is GreaterThanEqualityLogicalOperatorToken) { playerReference.Players.RemoveAll(player => player.Kills <= value.ToFloat()); } else if (comparator is LessThanEqualToEqualityLogicalOperatorToken) { playerReference.Players.RemoveAll(player => player.Kills > value.ToFloat()); } else if (comparator is LessThanEqualityLogicalOperatorToken) { playerReference.Players.RemoveAll(player => player.Kills >= value.ToFloat()); } result = playerReference.Players.Count > 0; } return result; }
/// <summary> /// Exports form validation rules for the parameter. /// </summary> /// <param name="Output">Output</param> /// <param name="Node">Node reference, if available.</param> public override Task ExportValidationRules(XmlWriter Output, IThingReference Node) { Output.WriteStartElement("xdv", "validate", null); Output.WriteAttributeString("datatype", "xs:date"); Output.WriteEndElement(); return(Task.CompletedTask); }
/// <summary> /// Determines whether the specified object is equal to the current object. /// </summary> /// <param name="obj">The object to compare with the current object.</param> /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns> public override bool Equals(object obj) { IThingReference Ref = obj as IThingReference; if (Ref == null) return false; else return this.nodeId == Ref.NodeId && this.SourceId == Ref.SourceId && this.Partition == Ref.Partition; }
/// <summary> /// Gets the string value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <returns>String representation of the value.</returns> public override async Task <string> GetStringValue(IThingReference Node) { Duration Value = await this.Get(Node); if (!(Value is null)) { return(Value.ToString()); }
public IThingReference Union(IThingReference other) { LocationThingReference locationThingReference = other as LocationThingReference; if (locationThingReference != null) { this.Locations.AddRange(locationThingReference.Locations.Where(location => this.Locations.Contains(location) == false)); } return this; }
public IThingReference Union(IThingReference other) { MapThingReference mapThingReference = other as MapThingReference; if (mapThingReference != null) { this.Maps.AddRange(mapThingReference.Maps.Where(map => this.Maps.Contains(map) == false)); } return this; }
public IThingReference Complement(IThingReference other) { MapThingReference mapThingReference = other as MapThingReference; if (mapThingReference != null) { this.Maps.RemoveAll(map => mapThingReference.Maps.Contains(map)); } return this; }
public IThingReference Complement(IThingReference other) { ItemThingReference itemThingReference = other as ItemThingReference; if (itemThingReference != null) { this.Items.RemoveAll(item => itemThingReference.Items.Contains(item)); } return this; }
public IThingReference Union(IThingReference other) { ItemThingReference itemThingReference = other as ItemThingReference; if (itemThingReference != null) { this.Items.AddRange(itemThingReference.Items.Where(item => this.Items.Contains(item) == false)); } return this; }
public IThingReference Complement(IThingReference other) { LocationThingReference locationThingReference = other as LocationThingReference; if (locationThingReference != null) { this.Locations.RemoveAll(location => locationThingReference.Locations.Contains(location)); } return this; }
/// <summary> /// Sets the value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <param name="StringValue">String representation of value to set.</param> /// <returns>If the parameter could be set (true), or if the value could not be parsed or its value was invalid (false).</returns> public override bool SetStringValue(IThingReference Node, string StringValue) { if (!CommonTypes.TryParse(StringValue, out bool Value)) { return(false); } this.Set(Node, Value); return(true); }
/// <summary> /// Sets the value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <param name="StringValue">String representation of value to set.</param> /// <returns>If the parameter could be set (true), or if the value could not be parsed or its value was invalid (false).</returns> public override bool SetStringValue(IThingReference Node, string StringValue) { if (!long.TryParse(StringValue, out long Value) || (this.min.HasValue && Value < this.min.Value) || (this.max.HasValue && Value > this.max.Value)) { return(false); } this.Set(Node, Value); return(true); }
/// <summary> /// Sets the value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <param name="StringValue">String representation of value to set.</param> /// <returns>If the parameter could be set (true), or if the value could not be parsed or its value was invalid (false).</returns> public override bool SetStringValue(IThingReference Node, string StringValue) { if (!XML.TryParse(StringValue, out DateTime Value)) { return(false); } this.Set(Node, Value); return(true); }
/// <summary> /// Sets the value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <param name="StringValue">String representation of value to set.</param> /// <returns>If the parameter could be set (true), or if the value could not be parsed or its value was invalid (false).</returns> public override async Task <bool> SetStringValue(IThingReference Node, string StringValue) { if (!Duration.TryParse(StringValue, out Duration Value)) { return(false); } await this.Set(Node, Value); return(true); }
/// <summary> /// Sets the value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <param name="StringValue">String representation of value to set.</param> /// <returns>If the parameter could be set (true), or if the value could not be parsed or its value was invalid (false).</returns> public override async Task <bool> SetStringValue(IThingReference Node, string StringValue) { if (!int.TryParse(StringValue, out int Value) || (this.min.HasValue && Value < this.min.Value) || (this.max.HasValue && Value > this.max.Value)) { return(false); } await this.Set(Node, Value); return(true); }
/// <summary> /// Exports form validation rules for the parameter. /// </summary> /// <param name="Output">Output</param> /// <param name="Node">Node reference, if available.</param> public override async Task ExportValidationRules(XmlWriter Output, IThingReference Node) { ColorReference Value = await this.Get(Node); Output.WriteStartElement("xdv", "validate", null); Output.WriteAttributeString("xmlns", "xdc", null, "urn:xmpp:xdata:color"); if (Value is null || !Value.HasAlpha) { Output.WriteAttributeString("datatype", "xdc:color"); Output.WriteElementString("xdv", "regex", null, "^[0-9a-fA-F]{6}$"); }
/// <summary> /// Exports form validation rules for the parameter. /// </summary> /// <param name="Output">Output</param> /// <param name="Node">Node reference, if available.</param> public override void ExportValidationRules(XmlWriter Output, IThingReference Node) { Output.WriteStartElement("xdv", "validate", null); Output.WriteAttributeString("datatype", "xs:string"); if (!string.IsNullOrEmpty(this.regexString)) { Output.WriteElementString("xdv", "regex", null, this.regexString); } Output.WriteEndElement(); }
/// <summary> /// Gets the value of the control parameter. /// </summary> /// <returns>Current value, or null if not available.</returns> public string Get(IThingReference Node) { try { return(this.getHandler(Node)); } catch (Exception ex) { Log.Critical(ex); return(null); } }
/// <summary> /// Gets the value of the control parameter. /// </summary> /// <returns>Current value, or null if not available.</returns> public async Task <Duration> Get(IThingReference Node) { try { return(await this.getHandler(Node)); } catch (Exception ex) { Log.Critical(ex); return(null); } }
/// <summary> /// Determines whether the specified object is equal to the current object. /// </summary> /// <param name="obj">The object to compare with the current object.</param> /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns> public override bool Equals(object obj) { IThingReference Ref = obj as IThingReference; if (Ref is null) { return(false); } else { return(this.SameThing(Ref)); } }
/// <summary> /// Gets the string value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <returns>String representation of the value.</returns> public override async Task <string> GetStringValue(IThingReference Node) { int?Value = await this.Get(Node); if (Value.HasValue) { return(Value.Value.ToString()); } else { return(string.Empty); } }
/// <summary> /// Gets the string value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <returns>String representation of the value.</returns> public override string GetStringValue(IThingReference Node) { Duration Value = this.Get(Node); if (Value != null) { return(Value.ToString()); } else { return(string.Empty); } }
/// <summary> /// Gets the string value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <returns>String representation of the value.</returns> public override string GetStringValue(IThingReference Node) { long?Value = this.Get(Node); if (Value.HasValue) { return(Value.Value.ToString()); } else { return(string.Empty); } }
/// <summary> /// Sets the value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <param name="Value">Value to set.</param> /// <returns>If the parameter could be set (true), or if the value was invalid (false).</returns> public bool Set(IThingReference Node, bool Value) { try { this.setHandler(Node, Value); return(true); } catch (Exception ex) { Log.Critical(ex); return(false); } }
/// <summary> /// Gets the string value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <returns>String representation of the value.</returns> public override async Task <string> GetStringValue(IThingReference Node) { bool?Value = await this.Get(Node); if (Value.HasValue) { return(CommonTypes.Encode(Value.Value)); } else { return(string.Empty); } }
/// <summary> /// Determines whether the specified object is equal to the current object. /// </summary> /// <param name="obj">The object to compare with the current object.</param> /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns> public override bool Equals(object obj) { IThingReference Ref = obj as IThingReference; if (Ref == null) { return(false); } else { return(this.nodeId == Ref.NodeId && this.SourceId == Ref.SourceId && this.Partition == Ref.Partition); } }
/// <summary> /// Gets the string value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <returns>String representation of the value.</returns> public override async Task <string> GetStringValue(IThingReference Node) { DateTime?Value = await this.Get(Node); if (Value.HasValue) { return(XML.Encode(Value.Value, true)); } else { return(string.Empty); } }
/// <summary> /// Gets the string value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <returns>String representation of the value.</returns> public override async Task <string> GetStringValue(IThingReference Node) { ColorReference Value = await this.Get(Node); if (Value != null) { return(Value.ToString()); } else { return(string.Empty); } }
/// <summary> /// Gets the string value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <returns>String representation of the value.</returns> public override string GetStringValue(IThingReference Node) { DateTime?Value = this.Get(Node); if (Value.HasValue) { return(XML.Encode(Value.Value, false)); } else { return(string.Empty); } }
/// <summary> /// Gets the string value of the control parameter. /// </summary> /// <param name="Node">Node reference, if available.</param> /// <returns>String representation of the value.</returns> public override string GetStringValue(IThingReference Node) { double?Value = this.Get(Node); if (Value.HasValue) { return(CommonTypes.Encode(Value.Value)); } else { return(string.Empty); } }
/// <summary> /// Gets an array of control parameters for a node. /// </summary> /// <param name="Node">Optional null reference. If not behind a concentrator, use null.</param> /// <returns>Control parameters.</returns> public Task <ControlParameter[]> GetControlParameters(IThingReference Node) { GetControlParametersEventHandler h = this.OnGetControlParameters; if (h is null) { return(Task.FromResult <ControlParameter[]>(this.controlParameters)); } else { return(h(Node)); } }
private void SetValue(IThingReference Node, bool Value) { if (this.pin is null) { if (!this.Controller.TryOpenPin(this.PinNr, GpioSharingMode.Exclusive, out this.pin, out GpioOpenStatus Status)) { throw new Exception(this.GetStatusMessage(Status)); } this.SetDriveMode(this.mode); } this.pin.Write(Value ? GpioPinValue.High : GpioPinValue.Low); }
public IThingReference Union(IThingReference other) { PlayerThingReference playerThingReference = other as PlayerThingReference; LocationThingReference locationThingReference = other as LocationThingReference; ItemThingReference itemThingReference = other as ItemThingReference; if (playerThingReference != null) { // Players and Players this.Players.AddRange(playerThingReference.Players.Where(player => this.Players.Contains(player) == false)); } else if (locationThingReference != null) { // All players from australia this.Players.RemoveAll(player => locationThingReference.Locations.Any(location => location.CountryName != player.Location.CountryName)); } else if (itemThingReference != null) { // All players using sniper rifle this.Players.RemoveAll(player => itemThingReference.Items.Any(item => player.Inventory.Now.Items.Any(playerItem => item.Name == playerItem.Name)) == false); } return this; }
public IThingReference Complement(IThingReference other) { PlayerThingReference playerThingReference = other as PlayerThingReference; LocationThingReference locationThingReference = other as LocationThingReference; ItemThingReference itemThingReference = other as ItemThingReference; if (playerThingReference != null) { // Players excluding Players this.Players.RemoveAll(player => playerThingReference.Players.Contains(player)); } else if (locationThingReference != null) { // All players not from australia this.Players.RemoveAll(player => locationThingReference.Locations.Any(location => location.CountryName == player.Location.CountryName)); } else if (itemThingReference != null) { // All players not using sniper rifle this.Players.RemoveAll(player => itemThingReference.Items.Any(item => player.Inventory.Now.Items.Any(playerItem => item.Name == playerItem.Name))); } return this; }
/// <summary> /// Initializes with the default player thing reference /// </summary> public KillsPropertyReference() { this.ThingReference = new PlayerThingReference(); }
/// <summary> /// Initializes with the default player thing reference /// </summary> public ScorePropertyReference() { this.ThingReference = new PlayerThingReference(); }
public bool CompatibleWith(IThingReference other) { return other is MapThingReference; }
/// <summary> /// Initializes with the default player thing reference /// </summary> public DeathsPropertyReference() { this.ThingReference = new PlayerThingReference(); }
public bool CompatibleWith(IThingReference other) { return other is LocationThingReference || other is PlayerThingReference; }