/// <summary> /// Funkcja zapisuje wynik w TOP 10 /// </summary> /// <param name="score">Wynik skończonej gry</param> /// <returns>Czy wynik jest najwyższym wynikiem do tej pory (TOP 1)</returns> public Boolean SaveScore(Int64 score) { Boolean isHighscore = false; AppMemory am = new AppMemory(); for (int i = 0; i < _amountOfPlaces; i++) { if (score > TopTen[i].Value) { TopTen.Insert(i, new KeyValuePair<string, Int64>(_playerName, score)); if (i == 0) { //TODO: highscore isHighscore = true; } break; } } for (int i = 0; i < _amountOfPlaces; i++) { am.SaveValue("score" + Convert.ToString(i + 1), TopTen[i].Value); am.SaveValue("playerName" + Convert.ToString(i + 1), TopTen[i].Key); } return isHighscore; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //singleton to mimic memory AppMemory memory = new AppMemory(); services.AddSingleton <AppMemory>(memory); //Add CORS Policy services.AddCors(op => { op.AddPolicy("AllowAll", policy => { policy.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); services.AddSingleton <ITracer>(serviceProvider => { ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); Jaeger.Configuration.SenderConfiguration.DefaultSenderResolver = new SenderResolver(loggerFactory).RegisterSenderFactory <ThriftSenderFactory>(); var config = Jaeger.Configuration.FromEnv(loggerFactory); ITracer tracer = config.GetTracer(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); services.AddMassTransit(x => { x.AddConsumer <OrderConsumer>(); x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg => { cfg.UseHealthCheck(provider); cfg.Host(new Uri($"rabbitmq://{Configuration["RabbitMQHostName"]}"), h => { h.Username("guest"); h.Password("guest"); }); cfg.ReceiveEndpoint("ServiceTicketQueue", ep => { ep.PrefetchCount = 16; ep.ConfigureConsumer <OrderConsumer>(provider); }); })); }); services.AddMassTransitHostedService(); services.AddControllers(); //Service Discovery and Registry services.AddDiscoveryClient(Configuration); services.AddHealthChecks(); services.AddSingleton <IHealthCheckHandler, ScopedEurekaHealthCheckHandler>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); }
public ServiceProviderController(ILogger <ServiceProviderController> logger, IBus bus, IConfiguration config, IOptions <AppMemory> options) { memory = options.Value; _logger = logger; _bus = bus; _configuration = config; }
public AdminController(ILogger <AdminController> logger, IBus bus, IConfiguration config, IOptions <AppMemory> options) { memory = options.Value; _logger = logger; _bus = bus; _configuration = config; _services = memory.AllServices; _servicesRegions = memory.ServiceRegions; }
/// <summary> /// Funkcja wczytująca z pamięci telefonu dziesięć najlepszych wyników /// </summary> private void LoadTopTen() { AppMemory am = new AppMemory(); TopTen = new List<KeyValuePair<string, Int64>>(); for (int i = 1; i <= _amountOfPlaces; i++) { string playerName = am.GetValueOrDefault<string>("playerName" + Convert.ToString(i), "Player"); Int64 score = am.GetValueOrDefault<Int64>("score" + Convert.ToString(i), 0); TopTen.Add(new KeyValuePair<string, long>(playerName, score)); } }
public OrderConsumer(IOptions <AppMemory> options, IConfiguration config, IBus bus) { memory = options.Value; _configuration = config; _bus = bus; }
/// <summary> /// Funkcja zapisująca stan gry i wynik /// </summary> private void SaveGameState() { AppMemory appMemory = new AppMemory(); appMemory.SaveGameState(_game.GetGameBoard(), _calculate.GlobalResult); }
/// <summary> /// Metoda wywoływana w momencie ładowania strony (zaraz po konstruktorze) /// Tutaj ładujemy wszystkie dane z pamięci i wyświetlamy stary stan planszy. /// </summary> /// <param name="sender">Obiekt, który wywołuje metodę.</param> /// <param name="e"> Paramery routingu.</param> private void PhoneApplicationPageLoaded(object sender, RoutedEventArgs e) { AppMemory appMemory = new AppMemory(); Int64 score = 0; Id[,,] memBoard = appMemory.LoadGameState(ref score); UpdateScore(score); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 3; k++) { if (memBoard[k, i, j] != null) { Image imageToLoad; if (k == (int) PlaceType.Grid) { imageToLoad = this.LoadCardsFromMemory(memBoard[k, i, j], i, j); memBoard[k, i, j].Image = imageToLoad; } else if (k == (int) PlaceType.Joker) { LoadJokerFromMemory(i, j); } else if (k == (int) PlaceType.Rand) { imageToLoad = this.LoadRandFromMemory(memBoard[k, i, j], i, j); memBoard[k, i, j].Image = imageToLoad; } } } } } _game.SetGameBoard(memBoard); }
/// <summary> /// Czyszczenie Pamięci. /// </summary> private void ClearMemory() { ControlPanel controlClear = new ControlPanel(); Game gameClear = new Game(controlClear); CardImage[] cardImage = gameClear.RandNewCards(); AppMemory appMemory = new AppMemory(); appMemory.SaveGameState(gameClear.GetGameBoard(), 0); }
/// <summary> /// Metoda odczytuje ustawienia z pamięci /// </summary> private void LoadSettings() { AppMemory am = new AppMemory(); nameBox.Text = am.GetValueOrDefault("playerName", "Player"); }
private void SaveName(String name) { if (name.Length <= 30) { AppMemory am = new AppMemory(); am.SaveValue("playerName", name); MessageBox.Show("Player's name successfully changed to \"" + nameBox.Text + "\""); } else { MessageBox.Show("Player's name is too long. Limit is 30 characters."); } }
private void LoadPlayerName() { AppMemory am = new AppMemory(); _playerName = am.GetValueOrDefault("playerName", "Player"); }