Beispiel #1
0
    /// <summary>Called asynchronously to execute the request</summary>
    /// <param name="state">Not used</param>
    private void execute(object state) {
      lock(this.protocol.SyncRoot) {
        try {
          this.protocol.SendLine(
            string.Format("cddb read {0} {1:x8} ", this.category, this.discId),
            5000
          );

          // The first reply will indicate the status of the request.
          string statusLine = this.protocol.ReceiveLine(5000);
          int statusCode = CddbProtocol.GetStatusCode(statusLine);

          switch(statusCode) {
            case 210: {
              this.results = receiveDatabaseFile();
              break;
            }
            default: {
              this.exception = exceptionFromQueryStatus(
                statusCode, statusLine.Substring((statusLine.Length >= 4) ? 4 : 3)
              );
              break;
            }
          }

        }
        catch(Exception exception) {
          if(!(this.exception is AbortedException)) {
            this.exception = exception;
          }
        }
      }

      OnAsyncEnded();
    }
Beispiel #2
0
    /// <summary>Queries the server for its active protocol level</summary>
    private void queryProtocolLevel() {

      // Issue the command to the CDDB server
      this.protocol.SendLine("proto", 5000);

      // Receive the reply from the server
      string statusLine = this.protocol.ReceiveLine(5000);

      // Obtain the status code returned by the server
      int statusCode = CddbProtocol.GetStatusCode(statusLine);

      // Decode the server reply
      switch(statusCode) {
        case 200: {
          this.protocolLevel = decodeDetailedProtocolLevel(statusLine);
          break;
        }
        case 201: {
          this.protocolLevel = decodeShortProtocolLevel(statusLine);
          break;
        }
        default: {
          this.exception = exceptionFromProtocolStatus(
            statusCode, statusLine.Substring((statusLine.Length >= 4) ? 4 : 3)
          );
          break;
        }
      }

    }
    /// <summary>Called asynchronously to execute the request</summary>
    /// <param name="state">Not used</param>
    private void execute(object state) {
      lock(this.protocol.SyncRoot) {
        try {
          this.protocol.SendLine("quit", 5000);

          // The first reply will indicate the status of the request.
          string statusLine = this.protocol.ReceiveLine(5000);
          int statusCode = CddbProtocol.GetStatusCode(statusLine);

          switch(statusCode) {
            case 230: {
              break;
            }
            default: {
              this.exception = exceptionFromQueryStatus(
                statusCode, statusLine.Substring((statusLine.Length >= 4) ? 4 : 3)
              );
              break;
            }
          }

        }
        catch(Exception exception) {
          this.exception = exception;
        }

        // Close the connection, whether an error occured or not
        this.protocol.Dispose();
      }

      OnAsyncEnded();
    }
Beispiel #4
0
    /// <summary>Receives the repy to the 'hello' and validates it</summary>
    private void receiveHelloReply() {
      string replyLine = this.protocol.ReceiveLine(5000);

      int statusCode = CddbProtocol.GetStatusCode(replyLine);
      this.exception = exceptionFromHelloResponseStatus(
        statusCode, replyLine.Substring((replyLine.Length >= 4) ? 4 : 3)
      );
    }
Beispiel #5
0
    /// <summary>
    ///   Performs the client/server handshake upon connecting to a CDDB server
    /// </summary>
    /// <param name="status">Not used</param>
    private void performClientServerHandshake(object status) {
      try {
        this.protocol = new CddbProtocol(this.socket);

        // Receive the server greeting string. This is sent by the CDDB server to
        // any client as soon as it connects and contains the server status and
        // software running on the server
        string greetingLine = this.protocol.ReceiveLine(5000);

        OnProgressAchieved(0.6f);

        // Obtain the status code returned from the server and convert it to
        // an exception if it indicates an error
        int greetingStatusCode = CddbProtocol.GetStatusCode(greetingLine);
        this.exception = exceptionFromGreetingStatus(
          greetingStatusCode, greetingLine.Substring((greetingLine.Length >= 4) ? 4 : 3)
        );

        // If no error has occured, decode the server greeting string
        if(this.exception == null) {
          ServerGreeting greeting = decodeServerGreeting(greetingLine);

          // The server greeting was decoded successfully, now let's identify ourselves
          // to the CDDB server
          sendHello();

          OnProgressAchieved(0.8f);

          // Receive the reply to our 'hello' from the server
          receiveHelloReply();

          // If everything went fine the CDDB connection is ready to enter normal service
          if(this.exception == null) {
            this.connection = new CddbConnection(
              protocol,
              greeting.Hostname,
              greeting.Version,
              (greetingStatusCode == 201) // Read only connection?
            );
          }
        }
      }
      catch(ObjectDisposedException exception) {
        if(!(this.exception is AbortedException)) {
          this.exception = exception;
        }
      }
      catch(Exception exception) {
        this.exception = exception;
      }

      OnAsyncEnded();
    }
Beispiel #6
0
    /// <summary>Called asynchronously to execute the request</summary>
    /// <param name="state">Not used</param>
    private void execute(object state) {
      lock(this.protocol.SyncRoot) {
        try {
          sendQuery();

          // The first reply will indicate the status of the request.
          string statusLine = this.protocol.ReceiveLine(5000);
          int statusCode = CddbProtocol.GetStatusCode(statusLine);

          switch(statusCode) {
            case 200: { // Exact match found
              this.results = new Cddb.Disc[1] {
                decodeDiscFromStatusLine(statusLine)
              };
              break;
            }
            case 202: { // No matches found
              this.results = new Cddb.Disc[0];
              break;
            }
            case 211: { // Inexact matches found
              this.results = receiveDiscs();
              break;
            }
            default: {
              this.exception = exceptionFromQueryStatus(
                statusCode, statusLine.Substring((statusLine.Length >= 4) ? 4 : 3)
              );
              break;
            }
          }

        }
        catch(Exception exception) {
          if(!(this.exception is AbortedException)) {
            this.exception = exception;
          }
        }
      }

      OnAsyncEnded();
    }
Beispiel #7
0
    /// <summary>Changes the CDDB server's active protocol level</summary>
    private void changeProtocolLevel() {

      // Issue the command to the CDDB server
      this.protocol.SendLine(string.Format("proto {0}", this.newLevel.Value), 5000);

      // Receive the reply from the server
      string statusLine = this.protocol.ReceiveLine(5000);

      // Obtain the status code returned by the server
      int statusCode = CddbProtocol.GetStatusCode(statusLine);

      // Decode the server reply
      switch(statusCode) {
        case 200: {
          this.protocolLevel = decodeDetailedProtocolLevel(statusLine);
          break;
        }
        case 201: {
          this.protocolLevel = decodeShortProtocolLevel(statusLine);
          break;
        }
        default: {
          this.exception = exceptionFromProtocolStatus(
            statusCode, statusLine.Substring((statusLine.Length >= 4) ? 4 : 3)
          );
          return;
        }
      }

      // Because we're pedantic, we'll check whether the server actually reported
      // the new protocol level we requested back to us.
      if(this.newLevel.Value != this.protocolLevel.ActiveProtocolLevel) {
        this.exception = new BadResponseException(
          "Server sent a positive response but didn't change the protocol level"
        );
      } else { // Everything went well
        this.callback(this.newLevel.Value);
      }

    }
    /// <summary>Called asynchronously to execute the request</summary>
    /// <param name="state">Not used</param>
    private void execute(object state) {
      lock(this.protocol.SyncRoot) {
        try {
          // Issue the command to the CDDB server
          this.protocol.SendLine("cddb lscat", 5000);

          // The first reply will indicate the status of the request.
          string statusLine = this.protocol.ReceiveLine(5000);
          int statusCode = CddbProtocol.GetStatusCode(statusLine);

          // Process the response according to its status code
          switch(statusCode) {

            // Request was accepted and genre list follows
            case 210: {
              this.categories = receiveCategoryList();
              break;
            }

            // No success code, find out what exactly went wrong
            default: {
              this.exception = exceptionFromGenreListStatus(
                statusCode, statusLine.Substring((statusLine.Length >= 4) ? 4 : 3)
              );
              break;
            }

          }
        }
        catch(Exception exception) {
          this.exception = exception;
        }
      }

      OnAsyncEnded();
    }