예제 #1
0
        /// <summary>
        /// Generate default clients, identity and api resources
        /// </summary>
        private static async Task EnsureSeedIdentityServerData <TIdentityServerDbContext>(TIdentityServerDbContext context, IAdminAppConfiguration adminConfiguration)
            where TIdentityServerDbContext : DbContext, IAdminConfigurationDbContext
        {
            if (!context.Clients.Any())
            {
                foreach (var client in Clients.GetAdminClient(adminConfiguration).ToList())
                {
                    await context.Clients.AddAsync(client.ToEntity());
                }

                await context.SaveChangesAsync();
            }

            if (!context.IdentityResources.Any())
            {
                var identityResources = ClientResources.GetIdentityResources().ToList();

                foreach (var resource in identityResources)
                {
                    await context.IdentityResources.AddAsync(resource.ToEntity());
                }

                await context.SaveChangesAsync();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in ClientResources.GetApiResources(adminConfiguration).ToList())
                {
                    await context.ApiResources.AddAsync(resource.ToEntity());
                }

                await context.SaveChangesAsync();
            }
        }
예제 #2
0
        private Label GetPlayerLabel(Country player)
        {
            DiplomaticTie tie;
            Country       localPlayer = ClientApplication.Instance.Player;
            Label         playerLabel = new Label();
            string        labelText   = string.Empty;
            int           width       = 0;

            tie = localPlayer.GetDiplomaticTie(player);

            if (tie != null || player == localPlayer)
            {
                labelText = GetPlayerString(player);
            }
            else
            {
                labelText = ClientResources.GetString("unknownOpponent");
            }

            Graphics g = CreateGraphics();

            width  = g.MeasureString(labelText, this.Font).ToSize().Width;
            width += 100;

            playerLabel.Text       = labelText;
            playerLabel.ImageList  = _imageList;
            playerLabel.ImageIndex = 0;
            playerLabel.Font       = new Font("Tahoma", 8.25F, FontStyle.Bold);
            playerLabel.ImageAlign = ContentAlignment.MiddleLeft;
            playerLabel.TextAlign  = ContentAlignment.MiddleCenter;
            playerLabel.Size       = new Size(width, 50);
            playerLabel.Location   = GetNextPoint();

            return(playerLabel);
        }
예제 #3
0
 public static void AddStylesheetReference(IContent content, string path)
 {
     if (!MarkupEventManager.EvaluateReference(content.ContentLink, path))
     {
         ClientResources.RequireStyle(ResolveReferencePath(content, path));
     }
 }
예제 #4
0
        private static async Task EnsureSeedIdentityServerData(AdminDbContext context)
        {
            if (!context.Clients.Any())
            {
                foreach (var client in Clients.GetAdminClient().ToList())
                {
                    await context.Clients.AddAsync(client.ToEntity());
                }

                await context.SaveChangesAsync();
            }

            if (!context.IdentityResources.Any())
            {
                var identityResources = ClientResources.GetIdentityResources().ToList();

                foreach (var resource in identityResources)
                {
                    await context.IdentityResources.AddAsync(resource.ToEntity());
                }

                await context.SaveChangesAsync();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in ClientResources.GetApiResources().ToList())
                {
                    await context.ApiResources.AddAsync(resource.ToEntity());
                }

                await context.SaveChangesAsync();
            }
        }
예제 #5
0
 public static void AddScriptReference(IContent content, string path)
 {
     if (!MarkupEventManager.EvaluateReference(content.ContentLink, path))
     {
         ClientResources.RequireScript(ResolveReferencePath(content, path)).AtFooter();
     }
 }
        private static void EnsureSeedData(AdminDbContext context)
        {
            if (!context.Clients.Any())
            {
                foreach (var client in Clients.GetAdminClient().ToList())
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.IdentityResources.Any())
            {
                var identityResources = ClientResources.GetIdentityResources().ToList();

                foreach (var resource in identityResources)
                {
                    context.IdentityResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in ClientResources.GetApiResources().ToList())
                {
                    context.ApiResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }
        }
        private static string GenerateGoldAmountString(int goldAmount)
        {
            string format     = ClientResources.GetString("goldAmount");
            string goldString = Convert.ToString(goldAmount, CultureInfo.CurrentCulture);

            return(string.Format(CultureInfo.CurrentCulture, format, goldString));
        }
        private void FillBalanceSheet()
        {
            Country player = ClientApplication.Instance.Player;

            if (player.ResearchedTechnology != null)
            {
                lblTechnology.Text = player.ResearchedTechnology.Name;
            }

            string format = ClientResources.GetString("turnsUntilCompleteMinimal");
            string text   = string.Format(CultureInfo.CurrentCulture, format, player.CalculateTurnsUntilTechnologyAdvance());

            lblTechAdvanceCompletion.Text = text;
            lblTreasuryAmount.Text        = GenerateGoldAmountString(player.Gold);
            lblCityIncome.Text            = GenerateGoldAmountString(player.CalculateIncomePerTurnFromCities());
            lblTaxIncome.Text             = GenerateGoldAmountString(player.CalculateIncomePerTurnFromTaxmen());
            lblTotalIncome.Text           = GenerateGoldAmountString(player.CalculateTotalIncomePerTurn());
            lblScienceExpense.Text        = GenerateGoldAmountString(player.CalculateScienceExpensePerTurn());
            lblMaintenanceExpense.Text    = GenerateGoldAmountString(player.CalculateMaintenanceExpensePerTurn());
            lblTotalExpensePerTurn.Text   = GenerateGoldAmountString(player.CalculateTotalExpensePerTurn());

            int netGain = player.CalculateNetProfitPerTurn();

            lblNetGain.ForeColor = netGain >= 0 ? Color.Black : Color.Red;
            lblNetGain.Text      = GenerateGoldAmountString(netGain);
        }
예제 #9
0
        private void FormatGoldAmount(object sender, ConvertEventArgs e)
        {
            string format = ClientResources.GetString(StringKey.GoldAmount);
            int    amount = Convert.ToInt32(e.Value, CultureInfo.CurrentCulture);

            format  = string.Format(CultureInfo.CurrentCulture, format, amount.ToString(CultureInfo.CurrentCulture));
            e.Value = format;
        }
예제 #10
0
        private void RefreshGovernment()
        {
            string            format = ClientResources.GetString("rejectGovernmentChange");
            ClientApplication client = ClientApplication.Instance;
            Government        gov    = client.Player.Government;

            btnNo.Text = string.Format(CultureInfo.CurrentCulture, format, gov.Name);
        }
예제 #11
0
        private void RefreshLocalMilitaryInfo()
        {
            this.tvwLocal.Nodes.Clear();
            TreeNode root = new TreeNode();
            TreeNode unitNode;

            this.tvwLocal.Nodes.Add(root);
            Country player = ClientApplication.Instance.Player;

            if (this.localViewStyle == ViewStyle.ByUnit)
            {
                root.Text = ClientResources.GetString("units");
                foreach (Unit unit in player.Units)
                {
                    bool found = false;
                    unitNode = CreateUnitNode(unit);
                    foreach (TreeNode childNode in root.Nodes)
                    {
                        if (((Unit)childNode.Tag).Name == unit.Name)
                        {
                            found = true;
                            childNode.Nodes.Add(unitNode);
                        }
                    }
                    if (!found)
                    {
                        TreeNode typeNode = new TreeNode(unit.Name);
                        root.Nodes.Add(typeNode);
                        root.Tag = unit;
                        typeNode.Nodes.Add(unitNode);
                    }
                }
            }
            else
            {
                root.Text = ClientResources.GetString("cities");
                Grid grid = ClientApplication.Instance.ServerInstance.Grid;
                foreach (City city in player.Cities)
                {
                    TreeNode cityNode = root.Nodes.Add(city.Name);
                    GridCell cell     = grid.GetCell(city.Coordinates);
                    cityNode.Tag = city;
                    foreach (Unit unit in cell.Units)
                    {
                        cityNode.Nodes.Add(CreateUnitNode(unit));
                    }
                }
                TreeNode fieldNode = root.Nodes.Add(ClientResources.GetString("militaryAdvisor_unitsInField"));
                foreach (Unit unit in player.Units)
                {
                    GridCell cell = grid.GetCell(unit.Coordinates);
                    if (cell.City == null)
                    {
                        fieldNode.Nodes.Add(CreateUnitNode(unit));
                    }
                }
            }
        }
예제 #12
0
 public static void AddInlineScript(IContent content, string script)
 {
     if (String.IsNullOrWhiteSpace(script))
     {
         return;
     }
     script = MarkupEventManager.OutputScript(script, null, content);
     ClientResources.RequireScriptInline(script).AtFooter();
 }
예제 #13
0
 public static void AddInlineStyles(IContent content, string css)
 {
     if (String.IsNullOrWhiteSpace(css))
     {
         return;
     }
     css = MarkupEventManager.OutputStylesheet(css, null, content);
     ClientResources.RequireStyleInline(css);
 }
예제 #14
0
        static async Task Main(string[] args)
        {
            var mailboxName = GetMailboxName(args);

            Console.WriteLine($"Creating client to mailbox '{mailboxName}'");
            Console.WriteLine();

            var httpClient = ClientResources.CreateHttpClient("localhost:50051");
            var client     = GrpcClient.Create <Mailer.MailerClient>(httpClient);

            Console.WriteLine("Client created");
            Console.WriteLine("Press escape to disconnect. Press any other key to forward mail.");

            using (var mailbox = client.Mailbox(headers: new Metadata {
                new Metadata.Entry("mailbox-name", mailboxName)
            }))
            {
                _ = Task.Run(async() =>
                {
                    try
                    {
                        while (await mailbox.ResponseStream.MoveNext(CancellationToken.None))
                        {
                            var response = mailbox.ResponseStream.Current;

                            Console.ForegroundColor = response.Reason == MailboxMessage.Types.Reason.Received ? ConsoleColor.White : ConsoleColor.Green;
                            Console.WriteLine();
                            Console.WriteLine(response.Reason == MailboxMessage.Types.Reason.Received ? "Mail received" : "Mail forwarded");
                            Console.WriteLine($"New mail: {response.New}, Forwarded mail: {response.Forwarded}");
                            Console.ResetColor();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error reading reaponse: " + ex);
                    }
                });

                while (true)
                {
                    var result = Console.ReadKey(intercept: true);
                    if (result.Key == ConsoleKey.Escape)
                    {
                        break;
                    }

                    await mailbox.RequestStream.WriteAsync(new ForwardMailMessage());
                }

                Console.WriteLine("Disconnecting");
                await mailbox.RequestStream.CompleteAsync();
            }

            Console.WriteLine("Disconnected. Press any key to exit.");
            Console.ReadKey();
        }
예제 #15
0
        static async Task Main(string[] args)
        {
            var httpClient = ClientResources.CreateHttpClient(Address);
            var client     = GrpcClient.Create <Aggregator.AggregatorClient>(httpClient);

            await ServerStreamingCallExample(client);

            await ClientStreamingCallExample(client);

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
예제 #16
0
        private static TreeNode CreateUnitNode(Unit unit)
        {
            string format   = ClientResources.GetString("militaryAdvisor_unitPlusRank");
            string nodeText = string.Format(
                CultureInfo.CurrentCulture,
                format,
                unit.Name,
                ClientResources.GetRankString(unit.Rank));
            TreeNode node = new TreeNode(nodeText);

            return(node);
        }
예제 #17
0
        /// <summary>
        /// Renders an HTML container in which a React component will be mounted
        /// </summary>
        /// <param name="html">Associated HTML helper</param>
        /// <param name="component">Class or function name of React component</param>
        /// <param name="props">Optional object to pass as props to the component</param>
        /// <remarks>This HTML helper also ensure required script resources are loaded</remarks>
        /// <returns></returns>
        public static IHtmlString ReactComponent(this HtmlHelper html, string component, object props = null)
        {
            var propsJson = JsonConvert.SerializeObject(props, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            // Ensure scripts for React components is included on the page
            ClientResources.RequireScript("", "ReactComponent", new[] { "react" });

            // Render container element for the React component (for more attributes, see http://world.episerver.com/documentation/developer-guides/CMS/editing/)
            return(new MvcHtmlString($"<div data-react-component=\"{component}\" data-props='{propsJson ?? "{ }"}'></div>"));
        }
예제 #18
0
        private static string GetPlayerString(Country player)
        {
            string format       = ClientResources.GetString("civilizationDetail");
            string playerString = string.Format(
                CultureInfo.CurrentCulture,
                format,
                player.Government.LeaderTitle,
                player.LeaderName, player.Name
                );

            return(playerString);
        }
예제 #19
0
        static async Task Main(string[] args)
        {
            var httpClient = ClientResources.CreateHttpClient("localhost:50051");
            var client     = GrpcClient.Create <Counter.CounterClient>(httpClient);

            await UnaryCallExample(client);

            await ClientStreamingCallExample(client);

            Console.WriteLine("Shutting down");
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
예제 #20
0
        public GuiResourceLoading(GameWindow window)
        {
            CommonResources.Load();
            PluginManager.AddPlugin(new FileSystemRaw(new DirectoryInfo("Plugins\\System")));
            ResourceReader.ClearCache();
            ClientResources.Load(window);
            BoundingBoxRenderer.Load();

            _background      = ResourceReader.ReadTexture("System/Textures/Gui/ResourceLoadingBackground.png");
            _progressBar     = ResourceReader.ReadTexture("System/Textures/Gui/Progressbar.png");
            _progressBarFull = ResourceReader.ReadTexture("System/Textures/Gui/ProgressbarFull.png");

            Start(false);
        }
예제 #21
0
        private void DataBind()
        {
            this.ctlCity.City = this.city;
            //single line databining statements.  We can bind straight to the city property.
            lblCityName.DataBindings.Add("Text", this.city, "Name");
            lblGoldPerTurnValue.DataBindings.Add("Text", this.city, "GoldPerTurn");
            lblFoodPerTurn.DataBindings.Add("Text", this.city, "FoodPerTurn");
            lblFoodAvailable.DataBindings.Add("Text", this.city, "AvailableFood");
            lblTurnsUntilGrowth.DataBindings.Add("Text", this.city, "TurnsUntilGrowth");
            lblGovernment.DataBindings.Add("Text", this.city, "ParentCountry.Government.Name");

            //complex-bound properties
            cboImprovement.DataSource    = this.city.BuildableItems;
            cboImprovement.DisplayMember = "Name";
            cboImprovement.DataBindings.Add("SelectedItem", this.city, "NextImprovement");
            lstImprovements.DataSource = this.city.Improvements;
            lstUnits.DataSource        = this.gridCell.Units;
            lstUnits.DisplayMember     = "Name";

            //databindings that require associated format delegates
            Binding binding;

            //gold
            binding         = new Binding("Text", this.city, "ParentCountry.Gold");
            binding.Format += new ConvertEventHandler(this.FormatGoldAmount);
            lblGold.DataBindings.Add(binding);

            //year founded
            binding         = new Binding("Text", this.city, "YearFounded");
            binding.Format += new ConvertEventHandler(this.FormatYearFounded);
            lblFoundedValue.DataBindings.Add(binding);

            //culture
            binding         = new Binding("Text", this.city, "CulturePerTurn");
            binding.Format += new ConvertEventHandler(this.FormatCulturePerTurn);
            lblCultureValue.DataBindings.Add(binding);

            //turns until complete.
            string format = ClientResources.GetString(StringKey.TurnsUntilComplete);

            format = string.Format(
                CultureInfo.CurrentCulture,
                format,
                this.city.TurnsUntilComplete.ToString(CultureInfo.CurrentCulture),
                this.city.Shields.ToString(CultureInfo.CurrentCulture),
                this.city.NextImprovement.Cost.ToString(CultureInfo.CurrentCulture),
                this.city.ShieldsPerTurn.ToString(CultureInfo.CurrentCulture));
            lblTurnsToComplete.Text = format;
            lblCultureRatio.Text    = this.city.CulturePoints.ToString(CultureInfo.CurrentCulture) + "/" + this.city.CultureThreshold.ToString(CultureInfo.CurrentCulture);
        }
예제 #22
0
        public AboutBox()
        {
            InitializeComponent();

            //  Initialize the AboutBox to display the product information from the assembly information.
            //  Change assembly information settings for your application through either:
            //  - Project->Properties->Application->Assembly Information
            //  - AssemblyInfo.cs
            this.Text = String.Format(CultureInfo.CurrentCulture, ClientResources.GetString("aboutWindow_about"), AssemblyTitle);
            this.labelProductName.Text   = AssemblyProduct;
            this.labelVersion.Text       = String.Format(CultureInfo.CurrentCulture, ClientResources.GetString("aboutWindow_version"), AssemblyVersion);
            this.labelCopyright.Text     = AssemblyCopyright;
            this.labelCompanyName.Text   = AssemblyCompany;
            this.textBoxDescription.Text = AssemblyDescription;
        }
예제 #23
0
        private void LoadContextMenu()
        {
            this.contextMenu = new ContextMenu();
            this.ContextMenu = this.contextMenu;

            this.terrainInfoMenuItem        = new MenuItem(ClientResources.GetString("terrainInfo"));
            this.terrainInfoMenuItem.Click += new EventHandler(HandleTerrainInfoClick);

            MenuItem splitter = new MenuItem("-");

            this.contextMenu.MenuItems.AddRange(new MenuItem[] {
                this.terrainInfoMenuItem,
                splitter,
            });
        }
예제 #24
0
        /// <summary>
        /// Windows Forms implementation of the <i>InitializePicker</i> method.
        /// </summary>
        /// <param name="ties"></param>
        public void InitializePicker(Collection <DiplomaticTie> ties)
        {
            if (ties == null)
            {
                ties = ClientApplication.Instance.Player.DiplomaticTies;
            }

            foreach (DiplomaticTie tie in ties)
            {
                ListViewItem lvi = new ListViewItem(tie.ForeignCountry.Name);
                string       key = tie.DiplomaticState == DiplomaticState.War ? "atWar" : "atPeace";
                lvi.SubItems.Add(ClientResources.GetString(key));
                lvwTies.Items.Add(lvi);
            }
            this.initialized = true;
        }
예제 #25
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (this.lvwTies.SelectedItems.Count == 0)
     {
         string text = ClientResources.GetString("diplomaticTiePicker_noTieChosen");
         MessageBox.Show(
             text,
             ClientResources.GetString(StringKey.GameTitle),
             MessageBoxButtons.OK,
             MessageBoxIcon.Exclamation,
             MessageBoxDefaultButton.Button1,
             MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign
             );
         this.DialogResult = DialogResult.None;
     }
 }
예제 #26
0
        private void FormatYearFounded(object sender, ConvertEventArgs e)
        {
            string format;
            int    year  = (int)e.Value;
            int    dyear = Math.Abs(year);

            if (year >= 0)
            {
                format = ClientResources.GetString(StringKey.YearAD);
            }
            else
            {
                format = ClientResources.GetString(StringKey.YearBC);
            }
            format  = string.Format(CultureInfo.CurrentCulture, format, dyear.ToString(CultureInfo.CurrentCulture));
            e.Value = format;
        }
예제 #27
0
        private void lnkViewForeign_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string linkText;

            if (this.foreignViewStyle == ViewStyle.ByUnit)
            {
                this.foreignViewStyle = ViewStyle.ByCity;
                linkText = ClientResources.GetString("militaryAdvisor_viewByUnit");
            }
            else
            {
                this.foreignViewStyle = ViewStyle.ByUnit;
                linkText = ClientResources.GetString("militaryAdvisor_viewByCity");
            }
            this.lnkViewForeign.Text = linkText;
            RefreshForeignMilitaryInfo();
        }
예제 #28
0
        /// <summary>
        /// Generate default clients, identity and api resources
        /// </summary>
        private static async Task EnsureSeedIdentityServerData <TIdentityServerDbContext>(TIdentityServerDbContext context, IAdminConfiguration adminConfiguration)
            where TIdentityServerDbContext : DbContext, IAdminConfigurationDbContext
        {
            foreach (var client in Clients.GetAdminClient(adminConfiguration).ToList())
            {
                var existingClient = context.Clients
                                     .Include(c => c.AllowedScopes)
                                     .Where(c => c.ClientId == client.ClientId).SingleOrDefault();;
                if (existingClient == null)
                {
                    await context.Clients.AddAsync(client.ToEntity());
                }
                else
                {
                    //TODO: Update only when change were made
                    var updatedEntity = client.ToEntity();
                    updatedEntity.Id = existingClient.Id;
                    context.Entry(existingClient).CurrentValues.SetValues(updatedEntity);
                }
            }

            await context.SaveChangesAsync();


            if (!context.IdentityResources.Any())
            {
                var identityResources = ClientResources.GetIdentityResources().ToList();

                foreach (var resource in identityResources)
                {
                    await context.IdentityResources.AddAsync(resource.ToEntity());
                }

                await context.SaveChangesAsync();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in ClientResources.GetApiResources(adminConfiguration).ToList())
                {
                    await context.ApiResources.AddAsync(resource.ToEntity());
                }

                await context.SaveChangesAsync();
            }
        }
예제 #29
0
        static async Task Main(string[] args)
        {
            var httpClient = ClientResources.CreateHttpClient("localhost:50051");
            var client     = GrpcClient.Create <ServerReflectionClient>(httpClient);

            var response = await SingleRequestAsync(client, new ServerReflectionRequest
            {
                ListServices = "" // Get all services
            });

            Console.WriteLine("Services:");
            foreach (var item in response.ListServicesResponse.Service)
            {
                Console.WriteLine("- " + item.Name);
            }

            Console.WriteLine("Shutting down");
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
예제 #30
0
        private void _unitListBox_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            Unit unit = lstUnits.SelectedItem as Unit;

            if (unit == null)
            {
                itmUpgrade.Enabled = false;
                itmDisband.Enabled = false;
                return;
            }
            else if (unit.Upgrade == null)
            {
                itmUpgrade.Enabled = true;
                itmDisband.Text    = ClientResources.GetString("upgrade");
                itmDisband.Enabled = false;
            }

            itmDisband.Enabled = true;


            Unit upgrade = GetUpgradeableUnit(unit);

            if (upgrade != null)
            {
                itmUpgrade.Enabled = true;
                string format = ClientResources.GetString("upgradeTo");
                string text   = string.Format(
                    CultureInfo.CurrentCulture,
                    format,
                    upgrade.Name);
                itmUpgrade.Text = text;
            }
            else
            {
                itmUpgrade.Enabled = true;
                itmDisband.Text    = ClientResources.GetString("upgrade");
                itmDisband.Enabled = false;
            }
        }