示例#1
0
文件: Model.cs 项目: scy/ember-plus
        bool IGlowVisitor <object, bool> .Visit(GlowQualifiedParameter glow, object state)
        {
            Element parent;
            var     local = GetElementAt(glow.Path, out parent);
            var     xml   = BuildXml(glow);

            if (parent != null)
            {
                if (local == null)
                {
                    local = new Element(parent, glow.Path.Last(), glow.Identifier, ElementType.Parameter, xml);

                    parent._children.Add(local);
                }
                else
                {
                    local.Update(glow.Identifier, ElementType.Parameter, xml);
                }

                var value = glow.Value;

                if (value != null)
                {
                    local.ParameterType = value.Type;
                }
            }

            return(true);
        }
        protected void OnEmberTreeChanged(object sender, Dispatcher.GlowRootReadyArgs e)
        {
            // Triggered on EmBER+ tree change
            Console.WriteLine("OnEmberTreeChanged");
            try
            {
                GlowQualifiedParameter glowParameter    = e.Root.FirstOrDefault() as GlowQualifiedParameter;
                ParameterBase          changedParameter = GetElement <ParameterBase>(glowParameter?.Path);

                if (glowParameter != null)
                {
                    Console.WriteLine($"EmberTree node {glowParameter.Value.ToString()} //IdentifierPath changed. {changedParameter?.IdentifierPath}");
                    Debug.WriteLine($"INFO {glowParameter.GetType().ToString()}");
                    Task.Run(async() =>
                    {
                        Console.WriteLine($"EmberTree node {glowParameter.Value.ToString()} //IdentifierPath changed. {changedParameter?.IdentifierPath}");
                        await OnHandleValuesChanged(changedParameter);

                        // TODO: Add event for saving tree
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR parsing tree");
                Console.Write(ex);
            }
        }
        GlowQualifiedParameter ConvertQualifiedParameter(XElement xml)
        {
            var glow = new GlowQualifiedParameter(ConvertPath(xml.Attribute("path").Value));

            FillParameter(glow, xml);
            return(glow);
        }
        object IGlowVisitor <XmlWriter, object> .Visit(GlowQualifiedParameter glow, XmlWriter state)
        {
            state.WriteStartElement("QualifiedParameter");
            state.WriteAttributeString("path", ConvertPath(glow.Path));

            ConvertParameter(glow, state);

            state.WriteEndElement();
            return(null);
        }
示例#5
0
        bool IGlowVisitor <object, bool> .Visit(GlowQualifiedParameter glow, object state)
        {
            if (_onParameter != null)
            {
                _onParameter(glow);
                return(true);
            }

            return(false);
        }
        public void NotifyParameterValueChanged(int[] parameterPath, GlowValue value)
        {
            var glowParam = new GlowQualifiedParameter(parameterPath)
            {
                Value = value,
            };

            var glow = GlowRootElementCollection.CreateRoot();

            glow.Insert(glowParam);

            OnGlowRootReady(new GlowRootReadyArgs(glow, null));
        }
示例#7
0
            public GlowContainer Visit(GlowQualifiedParameter glow, object state)
            {
                var newPath      = PrependPathWithEndPointNumber(glow.Path);
                var newQualified = new GlowQualifiedParameter(newPath);

                foreach (var ember in glow)
                {
                    if (ember.Tag != GlowTags.QualifiedParameter.Path)
                    {
                        newQualified.Insert(ember);
                    }
                }

                return(newQualified);
            }
示例#8
0
            // - handle Qualified..., stripping first number in path
            public IEnumerable <GlowContainer> Visit(GlowQualifiedParameter glow, object state)
            {
                EndPointNumber = glow.Path[0];

                var newPath      = glow.Path.Skip(1).ToArray();
                var newQualified = new GlowQualifiedParameter(newPath);

                foreach (var ember in glow)
                {
                    if (ember.Tag != GlowTags.QualifiedParameter.Path)
                    {
                        newQualified.Insert(ember);
                    }
                }

                yield return(newQualified);
            }
        //GlowContainer IElementVisitor<ElementToGlowOptions, GlowContainer>.Visit(EnumParameter 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)
        //    {
        //        glow.Minimum = new GlowMinMax(element.Minimum);
        //        glow.Maximum = new GlowMinMax(element.Maximum);
        //        glow.Enumeration = element.Enumeration;

        //        if (element.IsWritable)
        //            glow.Access = GlowAccess.ReadWrite;
        //    }

        //    if ((dirFieldMask == GlowFieldFlags.All)
        //        && String.IsNullOrEmpty(element.SchemaIdentifier) == false)
        //        glow.SchemaIdentifiers = element.SchemaIdentifier;

        //    return glow;
        //}

        GlowContainer Model.IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(RealParameter 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)
            {
                glow.Minimum = new GlowMinMax(element.Minimum);
                glow.Maximum = new GlowMinMax(element.Maximum);

                if (element.IsWritable)
                {
                    glow.Access = GlowAccess.ReadWrite;
                }
            }

            if ((dirFieldMask == GlowFieldFlags.All) &&
                String.IsNullOrEmpty(element.SchemaIdentifier) == false)
            {
                glow.SchemaIdentifiers = element.SchemaIdentifier;
            }

            return(glow);
        }
示例#10
0
文件: Model.cs 项目: scy/ember-plus
        static GlowRootElementCollection BuildQualified(Element local, GlowElement glow)
        {
            var qualified = null as GlowElement;

            if (local.Type != ElementType.Root)
            {
                var path = local.BuildPath();

                if (local.Type == ElementType.Parameter)
                {
                    var qparam = new GlowQualifiedParameter(path);
                    qparam.Children = new GlowElementCollection(GlowTags.QualifiedParameter.Children);
                    qparam.Children.Insert(glow);
                    qualified = qparam;
                }
                else if (local.Type == ElementType.Node)
                {
                    var qnode = new GlowQualifiedNode(path);
                    qnode.Children = new GlowElementCollection(GlowTags.QualifiedNode.Children);
                    qnode.Children.Insert(glow);
                    qualified = qnode;
                }
            }
            else
            {
                qualified = glow;
            }

            if (qualified != null)
            {
                var root = GlowRootElementCollection.CreateRoot();
                root.Insert(qualified);
                return(root);
            }

            return(null);
        }
        void IDynamicPathHandler.HandleCommand(GlowCommand command, int[] path, Client source)
        {
            if (command.Number == GlowCommandType.GetDirectory)
            {
                var offset = Path.Length;

                if (path.Length == offset + 4 &&
                    path[offset + 0] == ParametersSubIdentifier &&
                    path[offset + 1] == 3) // connections
                {
                    Dictionary <int, XpointParams> dict;

                    if (_xpointParameters.TryGetValue(path[offset + 2], out dict)) // target
                    {
                        XpointParams xpointParams;

                        if (dict.TryGetValue(path[offset + 3], out xpointParams)) // source
                        {
                            var gainPath = path.Concat(new[] { 1 }).ToArray();

                            var glow = new GlowQualifiedParameter(gainPath)
                            {
                                Identifier = "dynamicGain",
                                Value      = new GlowValue(xpointParams.Gain),
                                Minimum    = new GlowMinMax(XpointParams.MinimumGain),
                                Maximum    = new GlowMinMax(XpointParams.MaximumGain),
                            };

                            var root = GlowRootElementCollection.CreateRoot();
                            root.Insert(glow);
                            source.Write(root);
                        }
                    }
                }
            }
        }
示例#12
0
            void CreateGlowParameter(Item item, int[] path, int?number, int fields, GlowElementCollectionBase parent)
            {
                var glowValue   = null as GlowValue;
                var isWriteable = false;

                if ((fields & GlowFieldFlags.Value) != 0)
                {
                    var valueKind = item.Parent.Key.GetValueKind(item.Name);
                    var value     = item.Parent.Key.GetValue(item.Name);

                    switch (valueKind)
                    {
                    case RegistryValueKind.Binary:
                        glowValue = new GlowValue((byte[])value);
                        break;

                    case RegistryValueKind.DWord:
                        glowValue   = new GlowValue((long)(int)value);
                        isWriteable = true;
                        break;

                    case RegistryValueKind.ExpandString:
                        glowValue = new GlowValue((string)value);
                        break;

                    case RegistryValueKind.MultiString:
                        glowValue = new GlowValue(String.Join("\n", (string[])value));
                        break;

                    case RegistryValueKind.QWord:
                        glowValue   = new GlowValue((long)value);
                        isWriteable = true;
                        break;

                    case RegistryValueKind.String:
                        glowValue   = new GlowValue((string)value);
                        isWriteable = true;
                        break;
                    }
                }

                if (number != null)
                {
                    path = path.Concat(new[] { number.Value }).ToArray();
                }

                var glow = new GlowQualifiedParameter(path);

                if ((fields & GlowFieldFlags.Identifier) != 0)
                {
                    glow.Identifier = item.Identifier;
                }

                if ((fields & GlowFieldFlags.Description) != 0 &&
                    String.IsNullOrEmpty(item.Name) == false)
                {
                    glow.Description = item.Name;
                }

                if (fields == GlowFieldFlags.All &&
                    isWriteable)
                {
                    glow.Access = GlowAccess.ReadWrite;
                }

                if (glowValue != null)
                {
                    glow.Value = glowValue;
                }

                parent.Insert(glow);
            }
示例#13
0
 GlowQualifiedParameter ConvertQualifiedParameter(XElement xml)
 {
     var glow = new GlowQualifiedParameter(ConvertPath(xml.Attribute("path").Value));
      FillParameter(glow, xml);
      return glow;
 }
示例#14
0
            void CreateGlowParameter(Item item, int[] path, int? number, int fields, GlowElementCollectionBase parent)
            {
                var glowValue = null as GlowValue;
                var isWriteable = false;

                if((fields & GlowFieldFlags.Value) != 0)
                {
                   var valueKind = item.Parent.Key.GetValueKind(item.Name);
                   var value = item.Parent.Key.GetValue(item.Name);

                   switch(valueKind)
                   {
                  case RegistryValueKind.Binary:
                     glowValue = new GlowValue((byte[])value);
                     break;
                  case RegistryValueKind.DWord:
                     glowValue = new GlowValue((long)(int)value);
                     isWriteable = true;
                     break;
                  case RegistryValueKind.ExpandString:
                     glowValue = new GlowValue((string)value);
                     break;
                  case RegistryValueKind.MultiString:
                     glowValue = new GlowValue(String.Join("\n", (string[])value));
                     break;
                  case RegistryValueKind.QWord:
                     glowValue = new GlowValue((long)value);
                     isWriteable = true;
                     break;
                  case RegistryValueKind.String:
                     glowValue = new GlowValue((string)value);
                     isWriteable = true;
                     break;
                   }
                }

                if(number != null)
                   path = path.Concat(new[] { number.Value }).ToArray();

                var glow = new GlowQualifiedParameter(path);

                if((fields & GlowFieldFlags.Identifier) != 0)
                   glow.Identifier = item.Identifier;

                if((fields & GlowFieldFlags.Description) != 0
                && String.IsNullOrEmpty(item.Name) == false)
                   glow.Description = item.Name;

                if(fields == GlowFieldFlags.All
                && isWriteable)
                   glow.Access = GlowAccess.ReadWrite;

                if(glowValue != null)
                   glow.Value = glowValue;

                parent.Insert(glow);
            }