GlowMatrixBase MatrixToGlow(Matrix matrix, ElementToGlowOptions options) { var dirFieldMask = options.DirFieldMask; var glow = new GlowQualifiedMatrix(matrix.Path) { Identifier = matrix.Identifier, TargetCount = matrix.TargetCount, SourceCount = matrix.SourceCount, }; if (dirFieldMask.HasBits(GlowFieldFlags.Description) && String.IsNullOrEmpty(matrix.Description) == false) { glow.Description = matrix.Description; } if (matrix.LabelsNode != null && dirFieldMask == GlowFieldFlags.All) { var labels = new EmberSequence(GlowTags.MatrixContents.Labels); labels.Insert(new GlowLabel { BasePath = matrix.LabelsNode.Path, Description = "Primary" }); glow.Labels = labels; } if (dirFieldMask.HasBits(GlowFieldFlags.Connections) && options.IsCompleteMatrixEnquired) { var glowConnections = glow.EnsureConnections(); foreach (var signal in matrix.Targets) { var glowConnection = new GlowConnection(signal.Number); if (signal.ConnectedSources.Any()) { glowConnection.Sources = signal.ConnectedSources.Select(source => source.Number).ToArray(); } glowConnections.Insert(glowConnection); } } if ((dirFieldMask == GlowFieldFlags.All) && String.IsNullOrEmpty(matrix.SchemaIdentifier) == false) { glow.SchemaIdentifiers = matrix.SchemaIdentifier; } return(glow); }
/// <summary> /// EmBER+ tree matrix event changes /// </summary> private void ReceivedMatrixConnectionEvent(string identifierPath, GlowConnection connection, int[] path) { log.Debug($"Received Matrix Connection {identifierPath} , Operation: {(ConnectOperation)connection.Operation}, Target: {connection.Target}, First source: {connection.Sources.FirstOrDefault()}"); // Send out the target state var signal = new ClientMatrixSignalViewModel() { Index = connection.Target, ConnectedSources = connection.Sources }; _websocketHub.Clients.All.ChangesInEmberTreeMatrix(identifierPath, signal); }
public void NotifyMatrixConnection(Matrix matrix, Signal target, object state) { var glow = GlowRootElementCollection.CreateRoot(); var glowMatrix = new GlowQualifiedMatrix(matrix.Path); var glowConnection = new GlowConnection(target.Number) { Sources = target.ConnectedSources.Select(signal => signal.Number).ToArray(), Disposition = GlowConnectionDisposition.Modified, }; glowMatrix.EnsureConnections().Insert(glowConnection); glow.Insert(glowMatrix); OnGlowRootReady(new GlowRootReadyArgs(glow, null) { Matrix = matrix }); }
void FillMatrix(GlowMatrixBase glow, XElement xml) { var contentsXml = xml.Element("contents"); if(contentsXml != null) { contentsXml.Element("identifier").Do(value => glow.Identifier = value); contentsXml.Element("description").Do(value => glow.Description = value); contentsXml.Element("type").Do(value => glow.MatrixType = XmlConvert.ToInt32(value)); contentsXml.Element("addressingMode").Do(value => glow.AddressingMode = XmlConvert.ToInt32(value)); contentsXml.Element("targetCount").Do(value => glow.TargetCount = XmlConvert.ToInt32(value)); contentsXml.Element("sourceCount").Do(value => glow.SourceCount = XmlConvert.ToInt32(value)); contentsXml.Element("maximumTotalConnects").Do(value => glow.MaximumTotalConnects = XmlConvert.ToInt32(value)); contentsXml.Element("maximumConnectsPerTarget").Do(value => glow.MaximumConnectsPerTarget = XmlConvert.ToInt32(value)); var parametersLocationXml = contentsXml.Element("parametersLocation"); if(parametersLocationXml != null) { var attrib = parametersLocationXml.Attribute("type"); if(attrib.Value == "RELATIVE-OID") { glow.ParametersLocation = new GlowParametersLocation(ConvertPath(parametersLocationXml.Value)); } else if(attrib.Value == "INTEGER") { glow.ParametersLocation = new GlowParametersLocation(XmlConvert.ToInt32(parametersLocationXml.Value)); } } contentsXml.Element("gainParameterNumber").Do(value => glow.GainParameterNumber = XmlConvert.ToInt32(value)); var labelsXml = contentsXml.Element("labels"); if(labelsXml != null) { var glowLabels = from xmlChild in labelsXml.Elements("Label") select new GlowLabel { BasePath = ConvertPath(xmlChild.Attribute("basePath").Value), Description = xmlChild.Attribute("description").Value, }; var glowLabelsCollection = new EmberSequence(GlowTags.MatrixContents.Labels); foreach(var glowLabel in glowLabels) glowLabelsCollection.Insert(glowLabel); glow.Labels = glowLabelsCollection; } } var childrenXml = xml.Element("children"); if(childrenXml != null) FillElementCollection(glow.EnsureChildren(), childrenXml); var targetsXml = xml.Element("targets"); if(targetsXml != null) { var glowTargets = from xmlChild in targetsXml.Elements("Target") select new GlowTarget(XmlConvert.ToInt32(xmlChild.Attribute("number").Value)); var collection = glow.EnsureTargets(); foreach(var glowTarget in glowTargets) collection.Insert(glowTarget); } var sourcesXml = xml.Element("sources"); if(sourcesXml != null) { var glowSources = from xmlChild in sourcesXml.Elements("Source") select new GlowSource(XmlConvert.ToInt32(xmlChild.Attribute("number").Value)); var collection = glow.EnsureSources(); foreach(var glowSource in glowSources) collection.Insert(glowSource); } var connectionsXml = xml.Element("connections"); if(connectionsXml != null) { var collection = glow.EnsureConnections(); foreach(var xmlChild in connectionsXml.Elements("Connection")) { var glowConnection = new GlowConnection(XmlConvert.ToInt32(xmlChild.Attribute("target").Value)); xmlChild.Element("sources").Do(value => glowConnection.Sources = ConvertPath(value)); xmlChild.Element("operation").Do(value => glowConnection.Operation = XmlConvert.ToInt32(value)); xmlChild.Element("disposition").Do(value => glowConnection.Disposition = XmlConvert.ToInt32(value)); collection.Insert(glowConnection); } } }
void FillMatrix(GlowMatrixBase glow, XElement xml) { var contentsXml = xml.Element("contents"); if (contentsXml != null) { contentsXml.Element("identifier").Do(value => glow.Identifier = value); contentsXml.Element("description").Do(value => glow.Description = value); contentsXml.Element("type").Do(value => glow.MatrixType = XmlConvert.ToInt32(value)); contentsXml.Element("addressingMode").Do(value => glow.AddressingMode = XmlConvert.ToInt32(value)); contentsXml.Element("targetCount").Do(value => glow.TargetCount = XmlConvert.ToInt32(value)); contentsXml.Element("sourceCount").Do(value => glow.SourceCount = XmlConvert.ToInt32(value)); contentsXml.Element("maximumTotalConnects").Do(value => glow.MaximumTotalConnects = XmlConvert.ToInt32(value)); contentsXml.Element("maximumConnectsPerTarget").Do(value => glow.MaximumConnectsPerTarget = XmlConvert.ToInt32(value)); var parametersLocationXml = contentsXml.Element("parametersLocation"); if (parametersLocationXml != null) { var attrib = parametersLocationXml.Attribute("type"); if (attrib.Value == "RELATIVE-OID") { glow.ParametersLocation = new GlowParametersLocation(ConvertPath(parametersLocationXml.Value)); } else if (attrib.Value == "INTEGER") { glow.ParametersLocation = new GlowParametersLocation(XmlConvert.ToInt32(parametersLocationXml.Value)); } } contentsXml.Element("gainParameterNumber").Do(value => glow.GainParameterNumber = XmlConvert.ToInt32(value)); var labelsXml = contentsXml.Element("labels"); if (labelsXml != null) { var glowLabels = from xmlChild in labelsXml.Elements("Label") select new GlowLabel { BasePath = ConvertPath(xmlChild.Attribute("basePath").Value), Description = xmlChild.Attribute("description").Value, }; var glowLabelsCollection = new EmberSequence(GlowTags.MatrixContents.Labels); foreach (var glowLabel in glowLabels) { glowLabelsCollection.Insert(glowLabel); } glow.Labels = glowLabelsCollection; } } var childrenXml = xml.Element("children"); if (childrenXml != null) { FillElementCollection(glow.EnsureChildren(), childrenXml); } var targetsXml = xml.Element("targets"); if (targetsXml != null) { var glowTargets = from xmlChild in targetsXml.Elements("Target") select new GlowTarget(XmlConvert.ToInt32(xmlChild.Attribute("number").Value)); var collection = glow.EnsureTargets(); foreach (var glowTarget in glowTargets) { collection.Insert(glowTarget); } } var sourcesXml = xml.Element("sources"); if (sourcesXml != null) { var glowSources = from xmlChild in sourcesXml.Elements("Source") select new GlowSource(XmlConvert.ToInt32(xmlChild.Attribute("number").Value)); var collection = glow.EnsureSources(); foreach (var glowSource in glowSources) { collection.Insert(glowSource); } } var connectionsXml = xml.Element("connections"); if (connectionsXml != null) { var collection = glow.EnsureConnections(); foreach (var xmlChild in connectionsXml.Elements("Connection")) { var glowConnection = new GlowConnection(XmlConvert.ToInt32(xmlChild.Attribute("target").Value)); xmlChild.Element("sources").Do(value => glowConnection.Sources = ConvertPath(value)); xmlChild.Element("operation").Do(value => glowConnection.Operation = XmlConvert.ToInt32(value)); xmlChild.Element("disposition").Do(value => glowConnection.Disposition = XmlConvert.ToInt32(value)); collection.Insert(glowConnection); } } }