Пример #1
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
            {
            }
             }

             if(reader != null)
            reader.Dispose();
        }
Пример #2
0
        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;
        }
Пример #3
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;
        }
Пример #4
0
 void GlowReader_Error(object sender, GlowReader.ErrorArgs e)
 {
     Console.WriteLine("GlowReader error {0}: {1}", e.ErrorCode, e.Message);
 }
Пример #5
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;
        }
Пример #6
0
        /// <summary>
        /// Closes the endpoint.
        /// </summary>
        public void Close()
        {
            lock(_sync)
             {
            if(_glowReader != null)
               _glowReader.Dispose();

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

            _glowReader = null;
            _tcpClient = null;
            State = GlowEndPointState.Closed;
             }
        }
Пример #7
0
        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());
            }
             }
        }