Exemplo n.º 1
0
 public PointReader(StreamEncodingBase <TKey, TValue> encodingMethod, RemoteBinaryStream stream, Action onComplete)
 {
     m_onComplete     = onComplete;
     m_encodingMethod = encodingMethod;
     m_stream         = stream;
     encodingMethod.ResetEncoder();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a streaming wrapper around a database.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="onDispose"></param>
 /// <param name="info"></param>
 public StreamingClientDatabase(RemoteBinaryStream stream, Action onDispose, DatabaseInfo info)
 {
     m_info      = info;
     m_tmpKey    = new TKey();
     m_tmpValue  = new TValue();
     m_onDispose = onDispose;
     m_stream    = stream;
 }
        /// <summary>
        /// Creates a <see cref="SnapStreamingClient"/>
        /// </summary>
        /// <param name="stream">The config to use for the client</param>
        /// <param name="credentials">Authenticates using the supplied user credentials.</param>
        /// <param name="useSsl">specifies if a ssl connection is desired.</param>
        protected void Initialize(Stream stream, SecureStreamClientBase credentials, bool useSsl)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }

            m_credentials = credentials;
            m_rawStream   = stream;
            m_rawStream.Write(0x2BA517361121L);
            m_rawStream.Write(useSsl); //UseSSL

            var command = (ServerResponse)m_rawStream.ReadNextByte();

            switch (command)
            {
            case ServerResponse.UnknownProtocol:
                throw new Exception("Client and server cannot agree on a protocol, this is commonly because they are running incompatible versions.");

            case ServerResponse.KnownProtocol:
                break;

            default:
                throw new Exception("Unknown server response: " + command.ToString());
            }

            useSsl = m_rawStream.ReadBoolean();

            if (!m_credentials.TryAuthenticate(m_rawStream, useSsl, out m_secureStream))
            {
                throw new Exception("Authentication Failed");
            }

            m_stream = new RemoteBinaryStream(m_secureStream);

            command = (ServerResponse)m_stream.ReadUInt8();
            switch (command)
            {
            case ServerResponse.UnhandledException:
                string exception = m_stream.ReadString();
                throw new Exception("Server UnhandledExcetion: \n" + exception);

            case ServerResponse.UnknownProtocol:
                throw new Exception("Client and server cannot agree on a protocol, this is commonly because they are running incompatible versions.");

            case ServerResponse.ConnectedToRoot:
                break;

            default:
                throw new Exception("Unknown server response: " + command.ToString());
            }

            RefreshDatabaseInfo();
        }
Exemplo n.º 4
0
        /// <summary>
        /// This function will verify the connection, create all necessary streams, set timeouts, and catch any exceptions and terminate the connection
        /// </summary>
        /// <remarks></remarks>
        public void ProcessClient()
        {
            try
            {
                long code = m_rawStream.ReadInt64();
                if (code != 0x2BA517361121L)
                {
                    m_rawStream.Write((byte)ServerResponse.UnknownProtocol);
                    m_rawStream.Flush();
                    return;
                }
                bool useSsl = m_rawStream.ReadBoolean();
                if (RequireSSL)
                {
                    useSsl = true;
                }

                m_rawStream.Write((byte)ServerResponse.KnownProtocol);
                m_rawStream.Write(useSsl);

                if (!m_authentication.TryAuthenticateAsServer(m_rawStream, useSsl, out m_secureStream, out m_permissions))
                {
                    return;
                }

                m_stream = new RemoteBinaryStream(m_secureStream);
                m_stream.Write((byte)ServerResponse.ConnectedToRoot);
                m_stream.Flush();
                ProcessRootLevelCommands();
            }
            catch (Exception ex)
            {
                try
                {
                    m_stream.Write((byte)ServerResponse.UnhandledException);
                    m_stream.Write(ex.ToString());
                    m_stream.Flush();
                }
                catch (Exception)
                {
                }
                Log.Publish(MessageLevel.Warning, "Socket Exception", "Exception occured, Client will be disconnected.", null, ex);
            }
            finally
            {
                Dispose();
                Log.Publish(MessageLevel.Info, "Client Disconnected", "Client has been disconnected");
                m_stream = null;
            }
        }
Exemplo n.º 5
0
            internal BulkWriting(StreamingClientDatabase <TKey, TValue> client)
            {
                if (client.m_writer != null)
                {
                    throw new Exception("Duplicate call to StartBulkWriting");
                }

                m_client          = client;
                m_client.m_writer = this;
                m_stream          = m_client.m_stream;
                m_encodingMode    = m_client.m_encodingMode;

                m_stream.Write((byte)ServerCommand.Write);
                m_encodingMode.ResetEncoder();
            }
Exemplo n.º 6
0
 public StreamingServerDatabase(RemoteBinaryStream netStream, SnapServerDatabase <TKey, TValue> .ClientDatabase engine)
 {
     m_stream           = netStream;
     m_sortedTreeEngine = engine;
     m_encodingMethod   = Library.CreateStreamEncoding <TKey, TValue>(EncodingDefinition.FixedSizeCombinedEncoding);
 }