コード例 #1
0
        /// <summary>
        /// Converts the glow tree with the root <paramref name="glow"/> to XML,
        /// writing the XML to <paramref name="writer"/>.
        /// </summary>
        /// <param name="glow">The root of the Glow tree to convert.</param>
        /// <param name="writer">The XmlWriter instance to write XML to.</param>
        public static void Export(GlowContainer glow, XmlWriter writer)
        {
            var instance = new GlowXmlExport();

            glow.Accept(instance, writer);

            writer.WriteWhitespace(Environment.NewLine);
        }
コード例 #2
0
        public void DispatchGlow(GlowContainer glow, Provider.Client source)
        {
            var visitor = new ConsumerToProviderTranslator(_endPoints);
            var newGlow = glow.Accept(visitor, null).FirstOrDefault();

            if (newGlow != null)
            {
                if (visitor.EndPointNumber != null)
                {
                    // message to provider
                    var endPoint = (from ep in _endPoints
                                    where ep.LocalNumber == visitor.EndPointNumber.Value
                                    select ep)
                                   .FirstOrDefault();

                    if (endPoint.State == Consumer.GlowEndPointState.Connected ||
                        endPoint.State == Consumer.GlowEndPointState.ProtocolProbing)
                    {
                        endPoint.Write(newGlow);
                    }
                    else
                    {
                        // if endpoint is offline, and a dir command has been issued
                        // on the endpoint node (top-level node) -> send empty top-level node
                        if (newGlow is GlowRootElementCollection)
                        {
                            var command = newGlow.FirstOrDefault() as GlowCommand;

                            if (command != null &&
                                command.Number == GlowCommandType.GetDirectory)
                            {
                                var root = GlowRootElementCollection.CreateRoot();
                                root.Insert(new GlowNode(endPoint.LocalNumber));
                                source.Write(root);
                            }
                        }
                    }
                }
                else
                {
                    // message to proxy - usually command at root level
                    source.Write(newGlow);
                }
            }
        }