Exemplo n.º 1
0
        public override int GetHashCode()
        {
            var result = 0;

            result = (result * 397) ^ (StyleSheetHolder?.GetHashCode() ?? 0);
            result = (result * 397) ^ (StyleSheet?.GetHashCode() ?? 0);
            result = (result * 397) ^ (StartFrom?.GetHashCode() ?? 0);
            result = (result * 397) ^ (RenderTargetKind.GetHashCode());
            result = (result * 397) ^ (ChangeKind.GetHashCode());
            return(result);
        }
Exemplo n.º 2
0
 public ControlDict()
 {
     _application       = "simpleFoam";
     _startFrom         = StartFrom.latestTime;
     _startTime         = 0.0;
     _stopAt            = StopAtControl.endTime;
     _endTime           = 100.0;
     _deltaT            = 1.0;
     _writeControl      = WriteControl.timeStep;
     _writeInterval     = 20.0;
     _purgeWrite        = 0.0;
     _writeFormat       = Format.binary;
     _writePrecision    = 6;
     _writeCompression  = Compression.uncompressed;
     _timeFormat        = TimeFormat.general;
     _timePrecision     = 6;
     _runTimeModifiable = SwitchType.on;
     _libs = new List <string>();
 }
        private static int CalculateSkipped(int total, int size, int current, StartFrom startFrom)
        {
            if (startFrom == StartFrom.FirstPage)
            {
                return((current - 1) * size);
            }

            if (size == 0)
            {
                return(0);
            }

            var result = (total / size) - 1;

            var remaining = total % size;

            if (remaining > 0)
            {
                return((result + 1) * size);
            }

            return(result * size);
        }
Exemplo n.º 4
0
 public override string ToString()
 {
     return($"{ChangeKind} {RenderTargetKind} {StartFrom?.GetType().Name ?? "null"} {GetHashCode()}");
 }
        public static Paginated <TResult> Paginate <TSource, TResult>(this IQueryable <TSource> query, int size, int current, Expression <Func <TSource, TResult> > target, StartFrom startFrom = StartFrom.FirstPage)
        {
            var total = query.Count();

            List <TResult> result;

            if (total > 0)
            {
                var skipped = CalculateSkipped(total, size, current, startFrom);

                result = query.Skip(skipped)
                         .Take(size)
                         .Select(target)
                         .ToList();
            }
            else
            {
                result = query.Select(target).ToList();
            }

            return(new Paginated <TResult>(result, current, size, total));
        }
        public static IQueryable <TResult> Limit <TSource, TResult>(this IQueryable <TSource> query, int size, int current, Expression <Func <TSource, TResult> > target, StartFrom startFrom = StartFrom.FirstPage)
        {
            var total = query.Count();

            var skipped = CalculateSkipped(total, size, current, startFrom);

            return(query.Skip(skipped)
                   .Take(size)
                   .Select(target));
        }
        public static async Task <Paginated <TSource> > PaginateAsync <TSource>(this IQueryable <TSource> query, int size, int current, StartFrom startFrom = StartFrom.FirstPage)
        {
            var total = await query.CountAsync();

            List <TSource> result;

            if (total > 0)
            {
                var skipped = CalculateSkipped(total, size, current, startFrom);

                result = await query.Skip(skipped)
                         .Take(size)
                         .ToListAsync();
            }
            else
            {
                result = await query.ToListAsync();
            }

            return(new Paginated <TSource>(result, current, size, total));
        }
        public static IQueryable <TSource> Limit <TSource>(this IQueryable <TSource> query, int size, int current, StartFrom startFrom = StartFrom.FirstPage)
        {
            var total = query.Count();

            var skipped = CalculateSkipped(total, size, current, startFrom);

            return(query.Skip(skipped)
                   .Take(size));
        }
Exemplo n.º 9
0
 public static Task <Paginated <TResult> > PaginateAsync <TSource, TResult>(this IQueryable <TSource> query, IPaginationRequest request, Func <TSource, TResult> target, StartFrom startFrom = StartFrom.FirstPage)
 => PaginateAsync(query, request.PageSize, request.CurrentPage, target, startFrom);
Exemplo n.º 10
0
        public static async Task <Paginated <TResult> > PaginateAsync <TSource, TResult>(this IQueryable <TSource> query, int size, int current, Func <TSource, TResult> target, StartFrom startFrom = StartFrom.FirstPage)
        {
            var total = await query.CountAsync();

            List <TResult> result;

            if (total > 0)
            {
                var skipped = PaginationExtensions
                              .CalculateSkipped(total, size, current, startFrom);

                result = await Task.Run(() => query.Skip(skipped)
                                        .Take(size)
                                        .Select(target)
                                        .ToList());
            }
            else
            {
                result = await Task.Run(() => query.Select(target)
                                        .ToList());
            }


            return(new Paginated <TResult>(result, current, size, total));
        }
Exemplo n.º 11
0
        public static void ProcessLcdBlock(IMyTextPanel textPanel)
        {
            //counter++;

            var writer = TextPanelWriter.Create(textPanel);

            // Use the update interval on the LCD Panel to determine how often the display is updated.
            // It can only go as fast as the timer calling this code is.
            float interval;

            try
            {
                interval = Math.Max((float)EconomyScript.Instance.ServerConfig.MinimumLcdDisplayInterval, textPanel.GetValueFloat("ChangeIntervalSlider"));
            }
            catch (Exception ex)
            {
                // The game may generate an exception from the GetValueFloat(GetValue) call.
                EconomyScript.Instance.ServerLogger.WriteException(ex, UpdateCrashMessage);
                EconomyScript.Instance.ClientLogger.WriteException(ex, UpdateCrashMessage);
                // We can't safely ignore this one if it doesn't work, because this can affect the display timing.
                return;
            }
            if (writer.LastUpdate > DateTime.Now.AddSeconds(-interval))
            {
                return;
            }

            var       checkArray    = textPanel.GetPublicTitle().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var       showAll       = false;
            bool      showOre       = false;
            bool      showIngot     = false;
            bool      showComponent = false;
            bool      showAmmo      = false;
            bool      showTools     = false;
            bool      showGasses    = false;
            bool      showStock     = false;
            bool      showPrices    = true;
            bool      showTest1     = false;
            bool      showTest2     = false;
            StartFrom startFrom     = StartFrom.None; //if # is specified eg #20  then run the start line logic
            int       startLine     = 0;              //this is where our start line placeholder sits
            int       pageNo        = 1;

            // removed Linq, to reduce the looping through the array. This should only have to do one loop through all items in the array.
            foreach (var str in checkArray)
            {
                if (str.Equals("stock", StringComparison.InvariantCultureIgnoreCase))
                {
                    showStock = true;
                }
                if (str.Contains("#"))
                {
                    string[] lineNo = str.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    if (lineNo.Length != 0 && int.TryParse(lineNo[0], out startLine))
                    {
                        //this only runs if they put a number in
                        startFrom = StartFrom.Line;
                    }
                }
                if (str.StartsWith("P", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (int.TryParse(str.Substring(1), out pageNo))
                    {
                        startFrom = StartFrom.Page;
                    }
                }
                if (str.Equals("*", StringComparison.InvariantCultureIgnoreCase))
                {
                    showAll = true;
                }
                if (!showAll)
                {
                    if (str.Equals("test1", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showTest1 = true;
                    }
                    else if (str.Equals("test2", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showTest2 = true;
                    }
                    else if (str.StartsWith("ore", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showOre = true;
                    }
                    else if (str.StartsWith("ingot", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showIngot = true;
                    }
                    else if (str.StartsWith("component", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showComponent = true;
                    }
                    else if (str.StartsWith("ammo", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showAmmo = true;
                    }
                    else if (str.StartsWith("tool", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showTools = true;
                    }
                    else if (str.StartsWith("gas", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showGasses = true;
                    }
                }
            }

            bool showHelp = !showAll && !showOre && !showIngot && !showComponent && !showAmmo && !showTools && !showGasses;



            showPrices = !showStock || writer.IsWide;

            if (showTest1)
            {
                Test1(writer);
                writer.UpdatePublic();
                return;
            }
            if (showTest2)
            {
                Test2(writer);
                writer.UpdatePublic();
                return;
            }

            if (showHelp)
            {
                writer.AddPublicLine("Please add a tag to the private or public title.");
                writer.AddPublicLine("ie., * ingot ore component ammo tools.");
                writer.UpdatePublic();
                return;
            }

            var buyColumn   = TextPanelWriter.LcdLineWidth - 180;
            var sellColumn  = TextPanelWriter.LcdLineWidth - 0;
            var stockColumn = TextPanelWriter.LcdLineWidth - 0;

            if (showPrices && showStock)
            {
                buyColumn   = TextPanelWriter.LcdLineWidth - 280;
                sellColumn  = TextPanelWriter.LcdLineWidth - 180;
                stockColumn = TextPanelWriter.LcdLineWidth - 0;
            }

            // This might be a costly operation to run.
            var markets = MarketManager.FindMarketsFromLocation(textPanel.WorldMatrix.Translation);

            if (markets.Count == 0)
            {
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "« {0} »", EconomyScript.Instance.ServerConfig.TradeNetworkName);
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "« No market in range »");
            }
            else
            {
                // TODO: not sure if we should display all markets, the cheapest market item, or the closet market.
                // LOGIC summary: it needs to show the cheapest in stock(in range) sell(to player) price, and the highest (in range) has funds buy(from player) price
                // but this logic depends on the buy/sell commands defaulting to the same buy/sell rules as above.
                // where buy /sell commands run out of funds or supply in a given market and need to pull from the next market
                //it will either have to stop at each price change and notify the player, and/or prompt to keep transacting at each new price, or blindly keep buying until the
                //order is filled, the market runs out of stock, or the money runs out. Blindly is probably not optimal unless we are using stockmarket logic (buy orders/offers)
                //so the prompt option is the safer
                var market = markets.FirstOrDefault();

                // Build a list of the items, so we can get the name so we can the sort the items by name.
                var list = new Dictionary <MarketItemStruct, string>();

                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, market.DisplayName);

                if (startFrom == StartFrom.Page)
                {
                    // convert the page to lines required.
                    if (pageNo < 1)
                    {
                        pageNo = 1;
                    }
                    startLine = ((writer.DisplayLines - 2) * (pageNo - 1));
                    startFrom = StartFrom.Line;
                }

                string fromLine = " (From item #" + startLine + ".)";
                writer.AddPublicText("« Market List");
                if (startLine >= 1)
                {
                    writer.AddPublicText(fromLine);
                }
                else
                {
                    startLine = 1; // needed for truncating end line.
                }
                if (showPrices && showStock)
                {
                    writer.AddPublicRightText(buyColumn, "Buy");
                    writer.AddPublicRightText(sellColumn, "Sell");
                    writer.AddPublicRightLine(stockColumn, "Stock »");
                }
                else if (showStock)
                {
                    writer.AddPublicRightLine(stockColumn, "Stock »");
                }
                else if (showPrices)
                {
                    writer.AddPublicRightText(buyColumn, "Buy");
                    writer.AddPublicRightLine(sellColumn, "Sell »");
                }

                foreach (var marketItem in market.MarketItems)
                {
                    if (marketItem.IsBlacklisted)
                    {
                        continue;
                    }

                    MyObjectBuilderType result;
                    if (MyObjectBuilderType.TryParse(marketItem.TypeId, out result))
                    {
                        var id      = new MyDefinitionId(result, marketItem.SubtypeName);
                        var content = Support.ProducedType(id);

                        //if (((Type)id.TypeId).IsSubclassOf(typeof(MyObjectBuilder_GasContainerObject))) // TODO: Not valid call yet.

                        // Cannot check the Type of the item, without having to use MyObjectBuilderSerializer.CreateNewObject().

                        if (showAll ||
                            (showOre && content is MyObjectBuilder_Ore) ||
                            (showIngot && content is MyObjectBuilder_Ingot) ||
                            (showComponent && content is MyObjectBuilder_Component) ||
                            (showAmmo && content is MyObjectBuilder_AmmoMagazine) ||
                            (showTools && content is MyObjectBuilder_PhysicalGunObject) ||   // guns, welders, hand drills, grinders.
                            (showGasses && content is MyObjectBuilder_GasContainerObject) || // aka gas bottle.
                            (showGasses && content is MyObjectBuilder_GasProperties))        // Type check here allows mods that inherit from the same type to also appear in the lists.
                        {
                            MyDefinitionBase definition;
                            if (MyDefinitionManager.Static.TryGetDefinition(id, out definition))
                            {
                                list.Add(marketItem, definition == null ? marketItem.TypeId + "/" + marketItem.SubtypeName : definition.GetDisplayName());
                            }
                        }
                    }
                }
                int line = 0;
                foreach (var kvp in list.OrderBy(k => k.Value))
                {
                    line++;
                    if (startFrom == StartFrom.Line && line < startLine) //if we have a start line specified skip all lines up to that
                    {
                        continue;
                    }
                    if (startFrom == StartFrom.Line && line - startLine >= writer.WholeDisplayLines - 2) // counts 2 lines of headers.
                    {
                        break;                                                                           // truncate the display and don't display the text on the bottom edge of the display.
                    }
                    writer.AddPublicLeftTrim(buyColumn - 120, kvp.Value);

                    decimal showBuy  = kvp.Key.BuyPrice;
                    decimal showSell = kvp.Key.SellPrice;
                    if ((EconomyScript.Instance.ServerConfig.PriceScaling) && (market.MarketId == EconomyConsts.NpcMerchantId))
                    {
                        showBuy  = EconDataManager.PriceAdjust(kvp.Key.BuyPrice, kvp.Key.Quantity, PricingBias.Buy);
                        showSell = EconDataManager.PriceAdjust(kvp.Key.SellPrice, kvp.Key.Quantity, PricingBias.Sell);
                    }

                    if (showPrices && showStock)
                    {
                        writer.AddPublicRightText(buyColumn, showBuy.ToString("\t0.000", EconomyScript.ServerCulture));
                        writer.AddPublicRightText(sellColumn, showSell.ToString("\t0.000", EconomyScript.ServerCulture));

                        // TODO: components and tools should be displayed as whole numbers. Will be hard to align with other values.
                        writer.AddPublicRightText(stockColumn, kvp.Key.Quantity.ToString("\t0.0000", EconomyScript.ServerCulture)); // TODO: recheck number of decimal places.
                    }
                    else if (showStock)                                                                                             //does this ever actually run? seems to already be in the above?
                    {
                        // TODO: components and tools should be displayed as whole numbers. Will be hard to align with other values.

                        writer.AddPublicRightText(stockColumn, kvp.Key.Quantity.ToString("\t0.0000", EconomyScript.ServerCulture)); // TODO: recheck number of decimal places.
                    }
                    else if (showPrices)
                    {
                        writer.AddPublicRightText(buyColumn, showBuy.ToString("\t0.000", EconomyScript.ServerCulture));
                        writer.AddPublicRightText(sellColumn, showSell.ToString("\t0.000", EconomyScript.ServerCulture));
                    }
                    writer.AddPublicLine();
                }
            }

            writer.UpdatePublic();
        }
Exemplo n.º 12
0
 public static IEnumerable <TSource> Limit <TSource>(this IEnumerable <TSource> query, IPaginationRequest request, StartFrom startFrom = StartFrom.FirstPage)
 => Limit(query, request.PageSize, request.CurrentPage, startFrom);
Exemplo n.º 13
0
        public static Paginated <TSource> Paginate <TSource>(this IEnumerable <TSource> query, int size, int current, StartFrom startFrom = StartFrom.FirstPage)
        {
            var total = query.Count();

            List <TSource> result;

            if (total > 0)
            {
                var skipped = CalculateSkipped(total, size, current, startFrom);

                result = query.Skip(skipped)
                         .Take(size)
                         .ToList();
            }
            else
            {
                result = query.ToList();
            }

            return(new Paginated <TSource>(result, current, size, total));
        }
Exemplo n.º 14
0
 public static Paginated <TResult> Paginate <TSource, TResult>(this IEnumerable <TSource> query, IPaginationRequest request, Func <TSource, TResult> target, StartFrom startFrom = StartFrom.FirstPage)
 => Paginate(query, request.PageSize, request.CurrentPage, target, startFrom);
Exemplo n.º 15
0
 public static IQueryable <TResult> Limit <TSource, TResult>(this IQueryable <TSource> query, IPaginationRequest request, Expression <Func <TSource, TResult> > target, StartFrom startFrom = StartFrom.FirstPage)
 => Limit(query, request.PageSize, request.CurrentPage, target, startFrom);