Ejemplo n.º 1
0
  public int loadAuctionsFromDatabase() {
    int totalCount = AuctionInfo.count();
    int activeCount = AuctionEntry.activeCount();

    MQFactory.getConcrete("splash").enqueue("WIDTH " + activeCount);
    MQFactory.getConcrete("splash").enqueue("SET 0");

    AuctionServer newServer = AuctionServerManager.getInstance().getServer();
    AuctionServerManager.setEntryManager(this);
    if (totalCount == 0) {
      if (JConfig.queryConfiguration("stats.auctions") == null)
        JConfig.setConfiguration("stats.auctions", "0");
      return totalCount;
    }

    AuctionServerManager.getInstance().loadAuctionsFromDB(newServer);
    AuctionStats as = AuctionServerManager.getInstance().getStats();

    //  TODO -- Do something more valuable than just notify, when the auction counts are off.
    int savedCount = Integer.parseInt(JConfig.queryConfiguration("last.auctioncount", "-1"));
    if (as != null) {
      if (as.getCount() != activeCount || (savedCount != -1 && as.getCount() != savedCount)) {
        MQFactory.getConcrete("Swing").enqueue("NOTIFY Failed to load all auctions.");
      }
    }

    return activeCount;
  }
Ejemplo n.º 2
0
  public void loadAuctionsFromDB() {
    int auctionTotal = AuctionServerManager.getInstance().getServer().getCount();
    MQFactory.getConcrete("splash").enqueue("SET 0");
    MQFactory.getConcrete("splash").enqueue("WIDTH " + auctionTotal);

    MQFactory.getConcrete("splash").enqueue("SET 100");
  }
Ejemplo n.º 3
0
  /**
   * @brief Load auctions from a save file, with a pretty splash screen and everything, if
   *     necessary.
   *     <p>I'd like to abstract this, and make it work with arbitrary streams, so that we could
   *     send an XML file of auctions over a network to sync between JBidwatcher instances.
   */
  public void loadAuctions() {
    XMLElement xmlFile = new XMLElement(true);
    String loadFile = JConfig.queryConfiguration("savefile", "auctions.xml");
    String oldLoad = loadFile;

    loadFile = JConfig.getCanonicalFile(loadFile, "jbidwatcher", true);
    if (!loadFile.equals(oldLoad)) {
      JConfig.setConfiguration("savefile", loadFile);
    }

    File toLoad = new File(loadFile);
    if (toLoad.exists() && toLoad.length() != 0) {
      try {
        loadXMLFromFile(loadFile, xmlFile);
      } catch (IOException ioe) {
        JConfig.log()
            .handleException("A serious problem occurred trying to load from auctions.xml.", ioe);
        MQFactory.getConcrete("Swing")
            .enqueue(
                "ERROR Failure to load your saved auctions.  Some or all items may be missing.");
      } catch (XMLParseException xme) {
        JConfig.log().handleException("Trying to load from auctions.xml.", xme);
        MQFactory.getConcrete("Swing")
            .enqueue(
                "ERROR Failure to load your saved auctions.  Some or all items may be missing.");
      }
    } else {
      //  This is a common thing, and we don't want to frighten new
      //  users, who are most likely to see it.
      JConfig.log()
          .logDebug(
              "JBW: Failed to load saved auctions, the auctions file is probably not there yet.");
      JConfig.log().logDebug("JBW: This is not an error, unless you're constantly getting it.");
    }
  }
Ejemplo n.º 4
0
  private int preSnipe() {
    UpdateBlocker.startBlocking();
    mEntry.setLastStatus("Preparing snipe.");
    //  Log in
    mCJ = mLogin.getSignInCookie(null);
    if (mCJ == null) {
      //  Alert somebody that we couldn't log in?
      mEntry.setLastStatus(
          "Pre-snipe login failed.  Snipe will be retried, but is unlikely to fire.");
      MQFactory.getConcrete("Swing").enqueue("NOTIFY Pre-snipe login failed.");
      JConfig.log().logDebug("Pre-snipe login failed.");
      UpdateBlocker.endBlocking();
      return RESNIPE;
    }

    int presnipeResult = SUCCESSFUL;

    //  Get Bid Key/Form
    try {
      JConfig.increment("stats.presniped");
      mBidForm = mBidder.getBidForm(mCJ, mEntry, mEntry.getSnipeAmount());
    } catch (BadBidException bbe) {
      String result = getSnipeResult(bbe.getResult(), mEntry.getTitle(), mEntry);
      mEntry.setLastStatus(result);
      MQFactory.getConcrete("Swing").enqueue("NOTIFY " + result);
      JConfig.log().logDebug(result);
      presnipeResult = FAIL;
    }
    UpdateBlocker.endBlocking();

    return presnipeResult;
  }
Ejemplo n.º 5
0
  private int doSnipe() {
    //  Just punt if we had failed to get the bidding form initially.
    if (mBidForm == null) return FAIL;
    UpdateBlocker.startBlocking();
    if (mEntry.isMultiSniped()) {
      MultiSnipe ms = mEntry.getMultiSnipe();
      //  Make sure there aren't any update-unfinished items.
      if (ms.anyEarlier(mEntry)) {
        mEntry.setLastStatus(
            "An earlier snipe in this multisnipe group has not ended, or has not been updated after ending.");
        mEntry.setLastStatus(
            "This snipe is NOT being fired, as it could end up winning two items.");
        UpdateBlocker.endBlocking();
        return RESNIPE;
      }
    }
    MQFactory.getConcrete("Swing").enqueue("Sniping on " + mEntry.getTitle());
    mEntry.setLastStatus("Firing actual snipe.");

    int rval =
        mBidder.placeFinalBid(
            mCJ, mBidForm, mEntry, mEntry.getSnipeAmount(), mEntry.getSnipeQuantity());
    JConfig.increment("stats.sniped");
    String snipeResult = getSnipeResult(rval, mEntry.getTitle(), mEntry);
    mEntry.setLastStatus(snipeResult);

    MQFactory.getConcrete("Swing").enqueue("NOTIFY " + snipeResult);
    JConfig.log().logDebug(snipeResult);

    mEntry.snipeCompleted();
    UpdateBlocker.endBlocking();
    return DONE;
  }
Ejemplo n.º 6
0
  public void receiveDropString(StringBuffer dropped) {
    if (dropped == null) {
      JConfig.log().logDebug("Dropped is (null)");
      return;
    }

    dropped = new StringBuffer(stripNewlines(dropped.toString()));
    if (sUberDebug) JConfig.log().logDebug("Dropping :" + dropped + ":");

    //  Is it an 'HTML Fragment' as produced by Mozilla, NS6, and IE5+?
    //  BOY it's a small bit to test against, but Mozilla starts with <HTML>,
    //  and IE5 starts with <!DOCTYPE...  The only commonality I can trust is
    //  that they'll start with a tag, not content.  I could look for <HTML>
    //  someplace in the document...  --  mrs: 28-September-2001 03:53
    if (dropped.charAt(0) == '<') {
      JHTML tinyDocument = new JHTML(dropped);
      List<String> allItemsOnPage = tinyDocument.getAllURLsOnPage(true);
      String auctionURL;

      if (allItemsOnPage == null) return;

      for (String anAllItemsOnPage : allItemsOnPage) {
        auctionURL = anAllItemsOnPage;
        if (auctionURL != null) {
          JConfig.log().logDebug("Adding: " + auctionURL.trim());
          MQFactory.getConcrete("drop")
              .enqueue(
                  new DropQObject(auctionURL.trim(), mTargetName, true)); // NONSTRING Queue Object
        }
      }
    } else {
      String newEntry = dropped.toString();

      MQFactory.getConcrete("drop")
          .enqueue(new DropQObject(newEntry.trim(), mTargetName, true)); // NONSTRING Queue Object
    }
  }
Ejemplo n.º 7
0
  private void handleSave(boolean success) {
    if (success) {
      JOptionPane.showMessageDialog(
          null, "Searches Saved!", "Save Complete", JOptionPane.INFORMATION_MESSAGE);
    } else {
      String saveFile = JConfig.queryConfiguration("search.savefile", "searches.xml");
      saveFile = Path.getCanonicalFile(saveFile, "jbidwatcher", false);

      MQFactory.getConcrete("Swing")
          .enqueue(
              "ERROR Failed to save searches.  Check that the directory for\n"
                  + saveFile
                  + " exists, and is writable.");
    }
  }
Ejemplo n.º 8
0
  public void execute() {
    setupAuctionResolver();

    if (mRunServer) {
      spawnServer();
    } else if (mJustMyeBay) {
      MQFactory.getConcrete(mEbay.getFriendlyName())
          .enqueueBean(new AuctionQObject(AuctionQObject.LOAD_MYITEMS, null, null));
      try {
        Thread.sleep(120000);
      } catch (Exception ignored) {
      }
    } else if (mParseFile != null) {
      JConfig.setHomeDirectory("./");
      buildAuctionEntryFromFile(mParseFile);
    } else {
      retrieveAndVerifyAuctions(mParams);
    }
  }
Ejemplo n.º 9
0
  private void loadXMLFromFile(String loadFile, XMLElement xmlFile) throws IOException {
    InputStreamReader isr = new InputStreamReader(new FileInputStream(loadFile));
    MQFactory.getConcrete("splash").enqueue("WIDTH " + MAX_PERCENT);
    MQFactory.getConcrete("splash").enqueue("SET " + MAX_PERCENT / 2);

    xmlFile.parseFromReader(isr);
    MQFactory.getConcrete("splash").enqueue("SET " + MAX_PERCENT);

    String formatVersion = xmlFile.getProperty("FORMAT", "0101");
    XMLElement auctionsXML = xmlFile.getChild("auctions");
    JConfig.setConfiguration("savefile.format", formatVersion);
    //  set the width of the splash progress bar based on the number
    //  of auctions that will be loaded!
    if (auctionsXML == null) {
      throw new XMLParseException(
          xmlFile.getTagName(), "AuctionsManager requires an <auctions> tag!");
    }
    String auctionQuantity = auctionsXML.getProperty("COUNT", null);

    int auctionTotal = 0;
    if (auctionQuantity != null) {
      auctionTotal = Integer.parseInt(auctionQuantity);
      MQFactory.getConcrete("splash").enqueue("SET 0");
      MQFactory.getConcrete("splash").enqueue("WIDTH " + auctionTotal);
    }

    AuctionServerManager.setEntryManager(this);
    AuctionServerManager.getInstance().fromXML(auctionsXML);

    AuctionStats as = AuctionServerManager.getInstance().getStats();

    //  TODO -- Do something more valuable than just notify, when the auction counts are off.
    int savedCount = Integer.parseInt(JConfig.queryConfiguration("last.auctioncount", "-1"));
    if (as != null) {
      if (as.getCount() != auctionTotal || (savedCount != -1 && as.getCount() != savedCount)) {
        MQFactory.getConcrete("Swing").enqueue("NOTIFY Failed to load all auctions.");
      }
    }
  }