Exemple #1
0
        /// <summary>
        /// Synchronously connects to the remote host.
        /// </summary>
        /// <returns>True if the connection attempt completed successfully, otherwise false.</returns>
        public bool Connect()
        {
            Close();

            lock (_sync)
            {
                State      = GlowEndPointState.Connecting;
                _tcpClient = new TcpClient();

                try
                {
                    _tcpClient.Connect(HostName, TcpPort);

                    _glowReader        = new GlowReader(GlowReader_RootReady, GlowReader_KeepAliveRequestReceived);
                    _glowReader.Error += GlowReader_Error;

                    var stream = _tcpClient.GetStream();
                    stream.BeginRead(_buffer, 0, _buffer.Length, ReceiveCallback, stream);

                    State = GlowEndPointState.ProtocolProbing;

                    var glow = GlowRootElementCollection.CreateRoot();
                    glow.Insert(new GlowCommand(GlowCommandType.GetDirectory));
                    Write(glow);
                    return(true);
                }
                catch (Exception ex)
                {
                    State = GlowEndPointState.Error;
                    Console.WriteLine(ex.Message);
                }
            }

            return(false);
        }
Exemple #2
0
        public void Dispose()
        {
            Socket     socket;
            GlowReader reader;

            lock (_sync)
            {
                socket = Socket;
                reader = _reader;

                Socket  = null;
                _reader = null;
                Host    = null;
            }

            if (socket != null)
            {
                try
                {
                    socket.Close();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Exception: Client/Dispose: {ex.Message}");
                }
            }

            reader?.Dispose();
        }
Exemple #3
0
        /// <summary>
        /// Synchronously connects to the remote host.
        /// </summary>
        /// <returns>True if the connection attempt completed successfully, otherwise false.</returns>
        public bool Connect()
        {
            Close();

            lock (_sync)
            {
                _tcpClient = new TcpClient();

                try
                {
                    _tcpClient.Connect(HostName, TcpPort);

                    _glowReader        = new GlowReader(GlowReader_RootReady, GlowReader_KeepAliveRequestReceived);
                    _glowReader.Error += GlowReader_Error;

                    var stream = _tcpClient.GetStream();
                    stream.BeginRead(_buffer, 0, _buffer.Length, ReceiveCallback, stream);

                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return(false);
        }
        public void Dispose()
        {
            Socket     socket;
            GlowReader reader;

            lock (_sync)
            {
                socket = Socket;
                reader = _reader;

                Socket  = null;
                _reader = null;
                Host    = null;
            }

            if (socket != null)
            {
                try
                {
                    socket.Close();
                }
                catch
                {
                }
            }

            if (reader != null)
            {
                reader.Dispose();
            }
        }
        static void Main(string[] args)
        {
            int port;
            int maxPackageLength;

            var settings = Settings.Load();

            ParseArgs(args, out port, out maxPackageLength);

            Console.WriteLine("Ember+ Proxy v{0} (GlowDTD v{1} - EmBER v{2}) started.",
                              typeof(Program).Assembly.GetName().Version,
                              GlowReader.UshortVersionToString(EmberLib.Glow.GlowDtd.Version),
                              GlowReader.UshortVersionToString(EmberLib.EmberEncoding.Version));

            using (var proxy = new Proxy(settings.EndPoints, maxPackageLength))
            {
                proxy.Connect();

                using (var listener = new Provider.GlowListener(port, maxPackageLength, proxy))
                {
                    Console.WriteLine("Listening on port {0}. Press enter to quit...", port);
                    Console.ReadLine();
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Entry point
        /// </summary>
        /// <param name="args">Command line arguments</param>
        static void Main(string[] args)
        {
            string hostName;
            int    tcpPort;
            int    maxPackageLength;

            ParseArgs(args, out hostName, out tcpPort, out maxPackageLength);

            var endPoint = new GlowEndPoint(hostName, tcpPort, maxPackageLength);

            Console.WriteLine("Ember+ Walker v{0} (GlowDTD v{1} - EmBER v{2}) connecting...",
                              typeof(Program).Assembly.GetName().Version,
                              GlowReader.UshortVersionToString(EmberLib.Glow.GlowDtd.Version),
                              GlowReader.UshortVersionToString(EmberLib.EmberEncoding.Version));

            if (endPoint.Connect())
            {
                Console.WriteLine("Connected. Enter '?' for help.");

                var program = new Program(endPoint);

                program.Run();
            }

            endPoint.Close();
        }
Exemple #7
0
        public Client(GlowListener host, Socket socket, int maxPackageLength, Dispatcher dispatcher)
        {
            Host             = host;
            Socket           = socket;
            MaxPackageLength = maxPackageLength;
            Dispatcher       = dispatcher;

            _reader               = new GlowReader(GlowReader_RootReady, GlowReader_KeepAliveRequestReceived);
            _reader.Error        += GlowReader_Error;
            _reader.FramingError += GlowReader_FramingError;
        }
        public Client(GlowListener host, Socket socket, int maxPackageLength, RegistryProvider registry)
        {
            Host             = host;
            Socket           = socket;
            MaxPackageLength = maxPackageLength;
            Registry         = registry;

            _reader               = new GlowReader(GlowReader_RootReady, GlowReader_KeepAliveRequestReceived);
            _reader.Error        += GlowReader_Error;
            _reader.FramingError += GlowReader_FramingError;
        }
Exemple #9
0
      static void Main(string[] args)
      {
         int port;
         int maxPackageLength;

         ParseArgs(args, out port, out maxPackageLength);

         Console.WriteLine("Ember+ Router v{0} (GlowDTD v{1} - EmBER v{2}) started.",
                           typeof(Program).Assembly.GetName().Version,
                           GlowReader.UshortVersionToString(EmberLib.Glow.GlowDtd.Version),
                           GlowReader.UshortVersionToString(EmberLib.EmberEncoding.Version));

         var dispatcher = new Dispatcher();
         dispatcher.Root = CreateTree(dispatcher);

         using(var listener = new GlowListener(port, maxPackageLength, dispatcher))
         {
            Console.WriteLine("Listening on port {0}. Press Enter to quit...", port);
            Console.ReadLine();
         }
      }
        void loadWithFramingButton_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                Filter = S101FileDialogFilter,
            };

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.File.OpenRead())
                {
                    var buffer = new byte[1024];
                    int read;

                    var reader = new GlowReader(
                        (_, rootReadyArgs) =>
                    {
                        var root = rootReadyArgs.Root as GlowContainer;

                        if (root != null)
                        {
                            DecodeGlow(root);
                        }
                    },
                        (_, keepAliveArgs) => { });

                    while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        reader.ReadBytes(buffer, 0, read);
                    }

                    if (reader.BaseReader.IsEmpty == false)
                    {
                        MessageBox.Show("Incomplete data! Position: " + reader.BaseReader.GetPositionString());
                    }
                }
            }
        }