Пример #1
0
        public void Upload(List <BidData> bidData, UploadServer server, System.Windows.Forms.WebBrowser webBrowser)
        {
            errorMsg = "";

            if (bidData == null)
            {
                errorMsg = "No bid data to upload";
                return;
            }
            if (bidData.Count <= 0)
            {
                errorMsg = "No bid data to upload";
                return;
            }

            if (!IsInitialized)
            {
                Initialize(server);
            }

            if (errorMsg.Length > 0)
            {
                return;
            }

            CommodMap commodMap = null;

            string url = server.UploadUrl.ToString() + "?action=upload&biddata=";

            //string url = ConfigurationSettings.AppSettings["HostUrl"].ToString() + "/upload.php?action=upload&biddata=";
            foreach (BidData b in bidData)
            {
                if (commodInfo.CommodMapsDict.TryGetValue(b.CommodityName, out commodMap))
                {
                    url += commodMap.Index.ToString();
                    url += "," + b.HighBid.ToString();
                    url += "," + b.Qty.ToString() + ",";
                }
                else
                {
                    errorMsg = "Could not find commodity in commodity map: " + b.CommodityName;
                    return;
                }
            }
            webBrowser.Url = new Uri(url);  // Upload data
        }
Пример #2
0
        private void UpdateLists(out List <string> missingCommodityMaps)
        {
            errorMsg = "";

            missingCommodityMaps = new List <string>();

            // Create mapping of unique stall names to index
            stallNames.Clear();

            int stallCount = 0;

            foreach (Commodity c in commods.Values)
            {
                // Check if name is too short (not wide enough window)
                string shortShopName = c.Shop;
                int    index         = shortShopName.IndexOf("'s");
                if (index > 0)
                {
                    shortShopName = c.Shop.Substring(0, index);
                }
                if (shortShopName.Contains("..."))
                {
                    errorMsg = "Could not upload data due to incomplete shop/stall names (names contain '...').  Try using a wider window size or avoid capturing from a ship.";
                    return;
                }

                // Add name
                if (!stallNames.ContainsKey(c.Shop))
                {
                    stallCount++;
                    stallNames.Add(c.Shop, stallCount);
                }
            }

            // Create sorted list of commodity names where the key is the commodity name index and the value
            // is a Dictionary List of Commodity (stalls with buy/sell info) with the key being the stall index.

            // Sorted list of commodity (stalls with buy offers... sorted in descending order of buy price)
            buys.Clear();
            sells.Clear();
            buyCount  = 0;
            sellCount = 0;
            //int commodIndex = 0;
            CommodMap commodMap = null;

            foreach (Commodity c in commods.Values)
            {
                if (c.BuyQty <= 0 && c.SellQty <= 0)
                {
                    continue;
                }

                // Ignore some commodities that we won't be supporting
                if (c.Name.Equals("Navy Dye"))
                {
                    continue;
                }

                if (commodInfo.CommodMapsDict.TryGetValue(c.Name, out commodMap))
                {
                    List <Commodity> stalls;
                    if (c.BuyQty > 0)
                    {
                        if (!buys.TryGetValue(commodMap.Index, out stalls))
                        {
                            stalls = new List <Commodity>();
                            buys.Add(commodMap.Index, stalls);
                        }
                        stalls.Add(c);
                        buyCount++;
                    }

                    if (c.SellQty > 0)
                    {
                        if (!sells.TryGetValue(commodMap.Index, out stalls))
                        {
                            stalls = new List <Commodity>();
                            sells.Add(commodMap.Index, stalls);
                        }

//                        stalls.Add(stallNames[c.Stall], c);
                        stalls.Add(c);
                        sellCount++;
                    }
                }
                else
                {
                    // Could not find this commodity in the commodity map
                    // Only add it once per commodity name.
                    if (!missingCommodityMaps.Contains(c.Name))
                    {
                        missingCommodityMaps.Add(c.Name);
                    }
//                    errorMsg = errorMsg + "\n" + "Could not find commodity in commodity map: " + c.Name;
                }
            }

            // Sort buy list in descending order of price
            foreach (List <Commodity> list in buys.Values)
            {
                list.Sort(new DescendingBuyComparer());
            }

            // Sort sell list in ascending order of price
            foreach (List <Commodity> list in sells.Values)
            {
                list.Sort(new AscendingSellComparer());
            }
        }