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); }
public void NotifyParameterValueChanged(ParameterBase parameter) { var options = new ElementToGlowOptions { DirFieldMask = GlowFieldFlags.Value }; var glowParam = ElementToGlow(parameter, options); var glow = GlowRootElementCollection.CreateRoot(); glow.Insert(glowParam); OnGlowRootReady(new GlowRootReadyArgs(glow, null)); }
GlowContainer IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(Function element, ElementToGlowOptions state) { var glow = new GlowQualifiedFunction(element.Path); var dirFieldMask = state.DirFieldMask; if (dirFieldMask.HasBits(GlowFieldFlags.Identifier)) { glow.Identifier = element.Identifier; } if (dirFieldMask.HasBits(GlowFieldFlags.Description) && String.IsNullOrEmpty(element.Description) == false) { glow.Description = element.Description; } if (dirFieldMask == GlowFieldFlags.All) { if (element.Arguments != null) { var tupleItemDescs = from tuple in element.Arguments select new GlowTupleItemDescription(tuple.Item2) { Name = tuple.Item1 }; var arguments = glow.EnsureArguments(); foreach (var tupleItemDesc in tupleItemDescs) { arguments.Insert(tupleItemDesc); } } if (element.Result != null) { var tupleItemDescs = from tuple in element.Result select new GlowTupleItemDescription(tuple.Item2) { Name = tuple.Item1 }; var result = glow.EnsureResult(); foreach (var tupleItemDesc in tupleItemDescs) { result.Insert(tupleItemDesc); } } } return(glow); }
GlowContainer IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(OneToOneMatrix element, ElementToGlowOptions state) { var glow = MatrixToGlow(element, state); if (state.DirFieldMask == GlowFieldFlags.All) { glow.MatrixType = GlowMatrixType.OneToOne; } return(glow); }
GlowContainer IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(DynamicMatrix element, ElementToGlowOptions state) { var glow = MatrixToGlow(element, state); if (state.DirFieldMask == GlowFieldFlags.All) { glow.MatrixType = GlowMatrixType.NToN; glow.ParametersLocation = new GlowParametersLocation(element.ParametersSubIdentifier); glow.GainParameterNumber = 1; } return(glow); }
GlowContainer IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(NToNMatrix element, ElementToGlowOptions state) { var glow = MatrixToGlow(element, state); if (state.DirFieldMask == GlowFieldFlags.All) { glow.AddressingMode = GlowMatrixAddressingMode.NonLinear; glow.MatrixType = GlowMatrixType.NToN; if (element.ParametersNode != null) { glow.ParametersLocation = new GlowParametersLocation(element.ParametersNode.Path); } if (state.IsCompleteMatrixEnquired) { var glowTargets = glow.EnsureTargets(); var glowSources = glow.EnsureSources(); foreach (var signal in element.Targets) { glowTargets.Insert(new GlowTarget(signal.Number)); } foreach (var signal in element.Sources) { glowSources.Insert(new GlowSource(signal.Number)); } } } return(glow); }
GlowContainer IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(OneToNMatrix element, ElementToGlowOptions state) { var glow = MatrixToGlow(element, state); if (state.DirFieldMask == GlowFieldFlags.All && state.IsCompleteMatrixEnquired) { if (element.Targets.Count() < element.TargetCount) { var glowTargets = glow.EnsureTargets(); foreach (var signal in element.Targets) { glowTargets.Insert(new GlowTarget(signal.Number)); } } if (element.Sources.Count() < element.SourceCount) { var glowSources = glow.EnsureSources(); foreach (var signal in element.Sources) { glowSources.Insert(new GlowSource(signal.Number)); } } } return(glow); }
GlowContainer IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(StringParameter element, ElementToGlowOptions state) { var glow = new GlowQualifiedParameter(element.Path); var dirFieldMask = state.DirFieldMask; if (dirFieldMask.HasBits(GlowFieldFlags.Identifier)) { glow.Identifier = element.Identifier; } if (dirFieldMask.HasBits(GlowFieldFlags.Description) && String.IsNullOrEmpty(element.Description) == false) { glow.Description = element.Description; } if (dirFieldMask.HasBits(GlowFieldFlags.Value)) { glow.Value = new GlowValue(element.Value); } if (dirFieldMask == GlowFieldFlags.All) { if (element.IsWritable) { glow.Access = GlowAccess.ReadWrite; } } if ((dirFieldMask == GlowFieldFlags.All) && String.IsNullOrEmpty(element.SchemaIdentifier) == false) { glow.SchemaIdentifiers = element.SchemaIdentifier; } return(glow); }
GlowContainer IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(Node element, ElementToGlowOptions state) { var glow = new GlowQualifiedNode(element.Path); var dirFieldMask = state.DirFieldMask; if (dirFieldMask.HasBits(GlowFieldFlags.Identifier)) { glow.Identifier = element.Identifier; } if ((dirFieldMask.HasBits(GlowFieldFlags.Description)) && String.IsNullOrEmpty(element.Description) == false) { glow.Description = element.Description; } if ((dirFieldMask == GlowFieldFlags.All) && String.IsNullOrEmpty(element.SchemaIdentifier) == false) { glow.SchemaIdentifiers = element.SchemaIdentifier; } return(glow); }
protected override void OnCommand(GlowCommand glow, int[] path) { IDynamicPathHandler dynamicPathHandler; var parent = _dispatcher.Root.ResolveChild(path, out dynamicPathHandler); if (parent != null) { if (glow.Number == GlowCommandType.GetDirectory) { var glowRoot = GlowRootElementCollection.CreateRoot(); var options = new ElementToGlowOptions { DirFieldMask = glow.DirFieldMask ?? GlowFieldFlags.All }; var visitor = new InlineElementVisitor( node => { // "dir" in node if (node.ChildrenCount == 0) { glowRoot.Insert(new GlowQualifiedNode(node.Path)); } else { var glowChildren = from element in node.Children select _dispatcher.ElementToGlow(element, options); foreach (var glowChild in glowChildren) { glowRoot.Insert(glowChild); } } }, parameter => { // "dir" in parameter glowRoot.Insert(_dispatcher.ElementToGlow(parameter, options)); }, matrix => { // "dir" in matrix options.IsCompleteMatrixEnquired = true; glowRoot.Insert(_dispatcher.ElementToGlow(matrix, options)); _source.SubscribeToMatrix(matrix, subscribe: true); }, function => { // "dir" in function glowRoot.Insert(_dispatcher.ElementToGlow(function, options)); }); parent.Accept(visitor, null); // run inline visitor against parent _source.Write(glowRoot); } else if (glow.Number == GlowCommandType.Unsubscribe) { var visitor = new InlineElementVisitor(onMatrix: matrix => _source.SubscribeToMatrix(matrix, subscribe: false)); parent.Accept(visitor, null); // run inline visitor against parent } else if (glow.Number == GlowCommandType.Invoke) { var visitor = new InlineElementVisitor( onFunction: async function => { var invocation = glow.Invocation; var invocationResult = null as GlowInvocationResult; try { invocationResult = await function.Invoke(invocation); } catch (Exception ex) { Debug.WriteLine($"Exception: Dispatcher/OnCommand/Invoke: {ex.Message}"); if (invocation != null && invocation.InvocationId != null) { invocationResult = GlowInvocationResult.CreateRoot(invocation.InvocationId.Value); invocationResult.Success = false; } } if (invocationResult != null) { _source.Write(invocationResult); } }); parent.Accept(visitor, null); // run inline visitor against parent } } else { if (dynamicPathHandler != null) { dynamicPathHandler.HandleCommand(glow, path, _source); } } }
GlowContainer ElementToGlow(Element element, ElementToGlowOptions options) { return(element.Accept(this, options)); }
GlowContainer IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(OneToNBlindSourceMatrix element, ElementToGlowOptions state) { var glow = MatrixToGlow(element, state); glow.AddressingMode = GlowMatrixAddressingMode.Linear; glow.MatrixType = GlowMatrixType.OneToN; glow.MaximumConnectsPerTarget = 1; if (state.DirFieldMask == GlowFieldFlags.All && state.IsCompleteMatrixEnquired) { if (element.Targets.Count() < element.TargetCount) { var glowTargets = glow.EnsureTargets(); foreach (var signal in element.Targets) { glowTargets.Insert(new GlowTarget(signal.Number)); } } if (element.Sources.Count() < element.SourceCount) { var glowSources = glow.EnsureSources(); foreach (var signal in element.Sources) { glowSources.Insert(new GlowSource(signal.Number)); } } } return(glow); }