Пример #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;
  }
Пример #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");
  }
Пример #3
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.");
      }
    }
  }
Пример #4
0
  /**
   * @brief Save auctions out to the savefile, in XML format.
   *     <p>Similar to the loadAuctions code, this would be nice if it were abstracted to write to
   *     any outputstream, allowing us to write to a remote node to update it with our auctions and
   *     snipes.
   * @return - true if it successfully saved, false if an error occurred.
   */
  public boolean saveAuctions() {
    XMLElement auctionsData = AuctionServerManager.getInstance().toXML();
    String oldSave = JConfig.queryConfiguration("savefile", "auctions.xml");
    String saveFilename =
        JConfig.getCanonicalFile(
            JConfig.queryConfiguration("savefile", "auctions.xml"), "jbidwatcher", false);
    String newSave = saveFilename;

    //  If there's no data to save, then pretend we did it.
    if (auctionsData == null) return true;

    ensureDirectories(saveFilename);

    boolean swapFiles = needSwapSaves(saveFilename);

    if (!saveFilename.equals(oldSave)) {
      JConfig.setConfiguration("savefile", saveFilename);
    }

    //  If we already have a save file, preserve its name, and write
    //  the new one to '.temp'.
    if (swapFiles) {
      newSave = saveFilename + ".temp";
      File newSaveFile = new File(newSave);
      if (newSaveFile.exists()) newSaveFile.delete();
    }

    StringBuffer buf = buildSaveBuffer(auctionsData, null);
    boolean saveDone = true;

    //  Dump the save file out!
    try {
      PrintStream ps = new PrintStream(new FileOutputStream(newSave));
      ps.println(buf);
      ps.close();
    } catch (IOException e) {
      JConfig.log().handleException("Failed to save auctions.", e);
      saveDone = false;
    }

    //  If the save was complete, and we have to swap old/new files,
    //  then [remove prior '.old' file if necessary], save current XML
    //  as '.old', and move most recent save file to be just a normal
    //  save file.
    if (saveDone && swapFiles) {
      preserveFiles(saveFilename);
    }

    return saveDone;
  }
Пример #5
0
  private void setupAuctionResolver() {
    mEbay = new ebayServer(mCountry, mUsername, mPassword);
    mEbayUK = new ebayServer("ebay.co.uk", mUsername, mPassword);

    Resolver r =
        new Resolver() {
          public AuctionServerInterface getServer() {
            return mEbay;
          }
        };
    AuctionServerManager.getInstance().setServer(mEbay);
    mEbay.setBackupServer(mEbayUK);
    EntryFactory.setResolver(r);
  }