private void WriteSale(EsoSale sale, int saleIndex)
        {
            string saleText = string.Format(SaleTemplate, saleIndex, sale.Seller, sale.WasKiosk.ToString().ToLower(),
                                            sale.SaleTimestamp, sale.ItemLink, sale.Buyer, sale.Price, sale.Quantity, sale.GuildName);

            _writer.Write(saleText);
        }
        private EsoSale CreateRandomSale()
        {
            string randomGuild     = _guilds[new Random().Next(_guilds.Length)];
            int    randomQuantity  = new Random().Next(100) + 1;
            int    randomPrice     = new Random().Next(10000) + 1;
            int    randomTimestamp = new Random().Next(10) + 1425340800;

            string[] randomItemParts = _items[new Random().Next(_items.Length)].Split(';');
            string   itemBaseId      = randomItemParts[0];
            string   itemIndex       = randomItemParts[1];
            string   itemLink        = randomItemParts[2];
            var      sale            = new EsoSale(false)
            {
                GuildName     = randomGuild,
                Buyer         = "@" + Guid.NewGuid().ToString("N"),
                Seller        = "@" + Guid.NewGuid().ToString("N"),
                ItemBaseId    = itemBaseId,
                ItemIndex     = itemIndex,
                ItemLink      = itemLink,
                Quantity      = randomQuantity,
                Price         = randomPrice,
                SaleTimestamp = randomTimestamp
            };

            sale.GenerateRowKey();
            return(sale);
        }
Beispiel #3
0
        /// <summary>
        ///     Enter a parse tree produced by <see cref="LuaParser.tableconstructor" />.
        ///     <para>The default implementation does nothing.</para>
        /// </summary>
        /// <param name="context">The parse tree.</param>
        public override void EnterTableconstructor(LuaParser.TableconstructorContext context)
        {
            var field = GetParentField(context);

            _currentScope++;
            switch (_currentScope)
            {
            case MMSavedVariableScope.AccountData:
                if (field != null)
                {
                    CurrentAccountName = field.Name;
                }
                break;

            case MMSavedVariableScope.EsoItemBase:

                // Save the name of the base item scope field as the item id for all items within the scope.
                if (field != null)
                {
                    _currentItemBaseId = field.Name;
                }
                break;

            case MMSavedVariableScope.EsoItem:

                // Instantiate new item variety
                if (string.IsNullOrEmpty(_currentItemBaseId) ||
                    field == null ||
                    string.IsNullOrEmpty(field.Name))
                {
                    CurrentItem = null;
                }
                else
                {
                    CurrentItem = new EsoItem
                    {
                        BaseId    = _currentItemBaseId,
                        ItemIndex = field.Name
                    };
                    _currentItemSales.Clear();
                }
                break;

            case MMSavedVariableScope.EsoGuildStoreSale:

                if (CurrentItem == null)
                {
                    CurrentSale = null;
                }
                else
                {
                    CurrentSale = new EsoSale
                    {
                        Submitter = CurrentAccountName
                    };
                }
                break;
            }
        }
        public void TableStorageRepository_FindByPartition()
        {
            string    tablePrefix      = "TEST" + Guid.NewGuid().ToString("N");
            var       data             = new TableStorageRepository(ConnectionString, tablePrefix);
            string    tableName        = data.GetTable <EsoSale>().Name;
            var       salesByPartition = new Dictionary <int, List <EsoSale> >();
            const int saleCount        = 100;

            try
            {
                for (int i = 0; i < saleCount; i++)
                {
                    // Arrange
                    var sale = CreateRandomSale();
                    data.InsertOrReplace(sale);
                    List <EsoSale> partition;
                    if (!salesByPartition.TryGetValue(sale.TimestampId, out partition))
                    {
                        partition = new List <EsoSale>();
                        salesByPartition.Add(sale.TimestampId, partition);
                    }

                    // Act
                    partition.Add(sale);
                }

                foreach (int timestampId in salesByPartition.Keys)
                {
                    // Arrange
                    List <EsoSale> expectedSales = salesByPartition[timestampId];

                    // Act
                    EsoSale[] partitionSales =
                        data.Find <EsoSale>(timestampId.ToString(CultureInfo.InvariantCulture)).ToArray();

                    // Assert
                    EsoSale missingSale = partitionSales.FirstOrDefault(x => expectedSales.All(y => y.RowKey != x.RowKey));
                    if (missingSale != null)
                    {
                        Assert.Fail("Table {0} Partition {1} missing expected entity with row key {2}", tableName,
                                    missingSale.PartitionKey,
                                    missingSale.RowKey);
                    }
                    EsoSale extraSale = expectedSales.FirstOrDefault(x => partitionSales.All(y => y.RowKey != x.RowKey));
                    if (extraSale != null)
                    {
                        Assert.Fail("Table {0} Partition {1} contains unexpected entity with row key {2}", tableName,
                                    extraSale.PartitionKey,
                                    extraSale.RowKey);
                    }
                }
            }
            finally
            {
                // Clean up
                data.RemoveTable <EsoSale>();
            }
        }
        public void Write(string variableName, string accountName, SortedSet <EsoSale> sales)
        {
            WriteHeader(variableName, accountName);

            EsoSale previousSale = null;
            int     saleIndex    = 0;

            foreach (var sale in sales)
            {
                if (previousSale != null)
                {
                    if (previousSale.ItemIndex != sale.ItemIndex)
                    {
                        WriteSaleFooter(previousSale);
                    }
                    if (previousSale.ItemBaseId != sale.ItemBaseId)
                    {
                        WriteItemFooter();
                    }
                }
                if (previousSale == null || previousSale.ItemBaseId != sale.ItemBaseId)
                {
                    WriteItemHeader(sale);
                }
                if (previousSale == null || previousSale.ItemIndex != sale.ItemIndex)
                {
                    WriteSaleHeader(sale);
                    saleIndex = 1;
                }
                else
                {
                    saleIndex++;
                }
                WriteSale(sale, saleIndex);

                previousSale = sale;
            }
            if (previousSale != null)
            {
                WriteSaleFooter(previousSale);
                WriteItemFooter();
            }
            WriteFooter();
        }
Beispiel #6
0
        /// <summary>
        ///     Exit a parse tree produced by <see cref="LuaParser.tableconstructor" />.
        ///     <para>The default implementation does nothing.</para>
        /// </summary>
        /// <param name="context">The parse tree.</param>
        public override void ExitTableconstructor(LuaParser.TableconstructorContext context)
        {
            switch (_currentScope)
            {
            case MMSavedVariableScope.EsoGuildStoreSale:
                // Exiting a sale scope
                if (CurrentSale != null)
                {
                    _currentItemSales.Add(CurrentSale);
                }
                break;

            case MMSavedVariableScope.EsoItem:
                if (CurrentItem != null && _currentItemSales.Count > 0)
                {
                    // Extract the item's name from the last sale's ItemLink property, since it's not stored in the item scope as a field.
                    if (string.IsNullOrEmpty(CurrentItem.Name))
                    {
                        EsoSale lastSale = _currentItemSales.Last();
                        CurrentItem.Name = lastSale.GetItemNameFromLink();
                    }

                    // Report the sale.
                    if (SaleFound != null)
                    {
                        foreach (var sale in _currentItemSales)
                        {
                            sale.Set(CurrentItem);
                            SaleFound(this, new EsoGuildStoreSaleEventArgs {
                                Sale = sale
                            });
                        }
                    }
                }
                break;
            }
            _currentScope--;
        }
        private void WriteSaleHeader(EsoSale sale)
        {
            string saleHeader = string.Format(SaleHeader, sale.ItemIndex);

            _writer.Write(saleHeader);
        }
        private void WriteSaleFooter(EsoSale sale)
        {
            string saleFooter = string.Format(SaleFooter, sale.ItemIcon);

            _writer.Write(saleFooter);
        }
        private void WriteItemHeader(EsoSale sale)
        {
            string itemHeader = string.Format(ItemHeader, sale.ItemBaseId);

            _writer.Write(itemHeader);
        }