public static void Main(string[] args) { System.Collections.Generic.IEnumerable <FontFamily> families = SystemFonts.Families; IOrderedEnumerable <FontFamily> orderd = families.OrderBy(x => x.Name); int len = families.Max(x => x.Name.Length); foreach (FontFamily f in orderd) { Console.Write(f.Name.PadRight(len)); Console.Write('\t'); Console.Write(string.Join(",", f.AvailableStyles.OrderBy(x => x).Select(x => x.ToString()))); Console.WriteLine(); GlyphInstance g = f.CreateFont(10).Instance.GetGlyph(1); } if (Debugger.IsAttached) { Console.WriteLine(string.Empty); while (!Console.KeyAvailable) { Thread.Sleep(100); } } }
public static MvcHtmlString RenderDashboardArea(this HtmlHelper htmlHelper, DashboardArea dashboardArea) { System.Collections.Generic.IEnumerable <ActionMethodInfo <DashboardAreaAction> > actionMethodsWithAttribute = MrCMSControllerFactory.GetActionMethodsWithAttribute <DashboardAreaAction>() .Where(info => info.Attribute.DashboardArea == dashboardArea); return(actionMethodsWithAttribute.OrderBy(info => info.Attribute.Order) .Aggregate(MvcHtmlString.Empty, (current, actionMethodInfo) => current.Concat(htmlHelper.Action(actionMethodInfo.Descriptor.ActionName, actionMethodInfo.Descriptor.ControllerDescriptor.ControllerName)))); }
/// <summary> /// Filter Shipping Weight Records /// </summary> /// <param name="shippingMethodId">Shipping method identifier</param> /// <param name="storeId">Store identifier</param> /// <param name="warehouseId">Warehouse identifier</param> /// <param name="countryId">Country identifier</param> /// <param name="stateProvinceId">State identifier</param> /// <param name="zip">Zip postal code</param> /// <param name="weight">Weight</param> /// <param name="orderSubtotal">Order subtotal</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>List of the shipping by weight record</returns> public virtual IPagedList <ShippingByWeightByTotalRecord> FindRecords(int shippingMethodId, int storeId, int warehouseId, int countryId, int stateProvinceId, string zip, decimal?weight, decimal?orderSubtotal, int pageIndex, int pageSize) { zip = zip?.Trim() ?? string.Empty; //filter by weight and shipping method System.Collections.Generic.List <ShippingByWeightByTotalRecord> existingRates = GetAll() .Where(sbw => sbw.ShippingMethodId == shippingMethodId && (!weight.HasValue || (weight >= sbw.WeightFrom && weight <= sbw.WeightTo))) .ToList(); //filter by order subtotal System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedBySubtotal = !orderSubtotal.HasValue ? existingRates : existingRates.Where(sbw => orderSubtotal >= sbw.OrderSubtotalFrom && orderSubtotal <= sbw.OrderSubtotalTo); //filter by store System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByStore = storeId == 0 ? matchedBySubtotal : matchedBySubtotal.Where(r => r.StoreId == storeId || r.StoreId == 0); //filter by warehouse System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByWarehouse = warehouseId == 0 ? matchedByStore : matchedByStore.Where(r => r.WarehouseId == warehouseId || r.WarehouseId == 0); //filter by country System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByCountry = countryId == 0 ? matchedByWarehouse : matchedByWarehouse.Where(r => r.CountryId == countryId || r.CountryId == 0); //filter by state/province System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByStateProvince = stateProvinceId == 0 ? matchedByCountry : matchedByCountry.Where(r => r.StateProvinceId == stateProvinceId || r.StateProvinceId == 0); //filter by zip System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByZip = string.IsNullOrEmpty(zip) ? matchedByStateProvince : matchedByStateProvince.Where(r => string.IsNullOrEmpty(r.Zip) || r.Zip.Equals(zip, StringComparison.InvariantCultureIgnoreCase)); //sort from particular to general, more particular cases will be the first IOrderedEnumerable <ShippingByWeightByTotalRecord> foundRecords = matchedByZip.OrderBy(r => r.StoreId == 0).ThenBy(r => r.WarehouseId == 0) .ThenBy(r => r.CountryId == 0).ThenBy(r => r.StateProvinceId == 0) .ThenBy(r => string.IsNullOrEmpty(r.Zip)); PagedList <ShippingByWeightByTotalRecord> records = new PagedList <ShippingByWeightByTotalRecord>(foundRecords.AsQueryable(), pageIndex, pageSize); return(records); }
public double Mediana(System.Collections.Generic.IEnumerable <double> Numbers) { if (Numbers.Count() == 0) { throw new InvalidOperationException("Nie można obliczyć mediany z pustego zbioru!"); } var sortedNumbers = Numbers.OrderBy(x => x).ToArray(); //from number in Numbers orderby number select number; int NumberIndex = sortedNumbers.Count() / 2; if (sortedNumbers.Count() % 2 == 0) { return((float)(sortedNumbers[NumberIndex] + sortedNumbers[NumberIndex - 1]) / 2); } else { return(sortedNumbers[NumberIndex]); } }
public VendorView_Window(NPCCharacter character, Simulation simulation, NPCVendor vendor) { InitializeComponent(); Vendor = vendor; Simulation = simulation; formatter.Markup(title, SimulationTool.ReplacePlaceholders(character, simulation, vendor.vendorTitle)); formatter.Markup(desc, SimulationTool.ReplacePlaceholders(character, simulation, vendor.vendorDescription)); UIElement createElement(VendorItem item) { Button b = new Button() { Margin = new Thickness(2.5), Height = 64, HorizontalContentAlignment = HorizontalAlignment.Stretch, VerticalContentAlignment = VerticalAlignment.Stretch }; Grid g = new Grid(); TextBlock tb = new TextBlock(); formatter.Markup(tb, LocalizationManager.Current.Simulation["Vendor"].Translate("Item_Cost", item.cost)); Label l = new Label() { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Content = tb }; string nameKey; switch (item.type) { case ItemType.ITEM: nameKey = "Item_Name"; break; case ItemType.VEHICLE: nameKey = "Vehicle_Name"; break; default: throw new Exception("Invalid ItemType"); } TextBlock tb2 = new TextBlock(); formatter.Markup(tb2, LocalizationManager.Current.Simulation["Vendor"].Translate(nameKey, item.id)); Label l2 = new Label() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Content = tb2 }; g.Children.Add(l); g.Children.Add(l2); b.Content = g; return(b); } System.Collections.Generic.IEnumerable <VendorItem> buyItems = vendor.BuyItems.Where(d => d.conditions.All(c => c.Check(simulation))); System.Collections.Generic.IEnumerable <VendorItem> sellItems = vendor.SellItems.Where(d => d.conditions.All(c => c.Check(simulation))); if (!vendor.disableSorting) // enable sorting { buyItems = buyItems.OrderBy(v => v.id); sellItems = sellItems.OrderBy(v => v.id); } foreach (VendorItem b in buyItems) { UIElement elem = createElement(b); elem.PreviewMouseLeftButtonDown += (sender, e) => { if (Simulation.Items.Any(d => d.ID == b.id)) { Simulation.Items.Remove(Simulation.Items.First(d => d.ID == b.id)); changeCurrency(b.cost, false); } }; buyingPanel.Children.Add(elem); } foreach (VendorItem s in sellItems) { UIElement elem = createElement(s); elem.PreviewMouseLeftButtonDown += (sender, e) => { if (getCurrency() >= s.cost) { changeCurrency(s.cost, true); switch (s.type) { case ItemType.ITEM: { Simulation.Items.Add(new Simulation.Item() { ID = s.id, Amount = 1, Quality = 100 }); } break; case ItemType.VEHICLE: { MessageBox.Show(LocalizationManager.Current.Simulation["Vendor"].Translate("Vehicle_Spawned", s.id, s.spawnPointID)); } break; } } }; sellingPanel.Children.Add(elem); } updateCurrency(); }
public VendorView_Window(NPCCharacter character, Simulation simulation, NPCVendor vendor) { InitializeComponent(); Vendor = vendor; Simulation = simulation; formatter.Markup(title, SimulationTool.ReplacePlaceholders(character, simulation, vendor.Title)); formatter.Markup(desc, SimulationTool.ReplacePlaceholders(character, simulation, vendor.vendorDescription)); UIElement createElement(VendorItem item) { Button b = new Button() { Margin = new Thickness(2.5), MinHeight = 64, HorizontalContentAlignment = HorizontalAlignment.Stretch, VerticalContentAlignment = VerticalAlignment.Stretch }; Grid g = new Grid(); g.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); g.ColumnDefinitions.Add(new ColumnDefinition()); TextBlock tb = new TextBlock(); formatter.Markup(tb, LocalizationManager.Current.Simulation["Vendor"].Translate("Item_Cost", item.cost)); Label l = new Label() { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Content = tb }; string nameKey; switch (item.type) { case ItemType.ITEM: nameKey = "Item_Name"; break; case ItemType.VEHICLE: nameKey = "Vehicle_Name"; break; default: throw new Exception("Invalid ItemType"); } TextBlock tb2 = new TextBlock(); Label l2 = new Label() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Content = tb2 }; TextBlock tb3 = new TextBlock() { FontSize = 9 }; Label l3 = new Label() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Content = tb3 }; Grid g2 = new Grid(); g2.RowDefinitions.Add(new RowDefinition()); g2.RowDefinitions.Add(new RowDefinition()); g2.RowDefinitions.Add(new RowDefinition()); g2.Children.Add(l); g2.Children.Add(l2); g2.Children.Add(l3); Grid.SetRow(l2, 0); Grid.SetRow(l3, 1); Grid.SetRow(l, 2); g.Children.Add(g2); Grid.SetColumn(g2, 1); if (item.type == ItemType.ITEM && GameAssetManager.TryGetAsset <GameItemAsset>(item.id, out var asset)) { g.Children.Add(new Image() { Source = new BitmapImage(asset.ImagePath), Width = 48, Height = 48, Margin = new Thickness(5) }); formatter.Markup(tb2, asset.name); formatter.Markup(tb3, asset.itemDescription); } else { formatter.Markup(tb2, LocalizationManager.Current.Simulation["Vendor"].Translate(nameKey, item.id)); tb3.Text = string.Empty; } b.Content = g; return(b); } System.Collections.Generic.IEnumerable <VendorItem> buyItems = vendor.BuyItems.Where(d => d.conditions.All(c => c.Check(simulation))); System.Collections.Generic.IEnumerable <VendorItem> sellItems = vendor.SellItems.Where(d => d.conditions.All(c => c.Check(simulation))); if (!vendor.disableSorting) // enable sorting { buyItems = buyItems.OrderBy(v => v.id); sellItems = sellItems.OrderBy(v => v.id); } foreach (VendorItem b in buyItems) { UIElement elem = createElement(b); elem.PreviewMouseLeftButtonDown += (sender, e) => { if (Simulation.Items.Any(d => d.ID == b.id)) { Simulation.Items.Remove(Simulation.Items.First(d => d.ID == b.id)); changeCurrency(b.cost, false); } }; buyingPanel.Children.Add(elem); } foreach (VendorItem s in sellItems) { UIElement elem = createElement(s); elem.PreviewMouseLeftButtonDown += (sender, e) => { if (getCurrency() >= s.cost) { changeCurrency(s.cost, true); switch (s.type) { case ItemType.ITEM: { Simulation.Items.Add(new Simulation.Item() { ID = s.id, Amount = 1, Quality = 100 }); } break; case ItemType.VEHICLE: { MessageBox.Show(LocalizationManager.Current.Simulation["Vendor"].Translate("Vehicle_Spawned", s.id, s.spawnPointID)); } break; } } }; sellingPanel.Children.Add(elem); } if (string.IsNullOrEmpty(vendor.currency)) { isCurrency = false; } else { isCurrency = true; } setupCurrency(); updateCurrency(); }
// Convenience method on IEnumerable<T> to allow passing of a // Comparison<T> delegate to the OrderBy method. public static System.Collections.Generic.IEnumerable <T> OrderBy <T>( this System.Collections.Generic.IEnumerable <T> list, System.Comparison <T> comparison) { return(list.OrderBy(t => t, new ComparisonComparer <T>(comparison))); }