Beispiel #1
0
        static void Main(string[] args)
        {
            var connection = new ConnectionBuilder().WithLogging(minimumLogLevel: Microsoft.Extensions.Logging.LogLevel.Trace).Build();

            var cardAssociationRepository = new CardAssociationRepository();

            SetupMemorizationPageViewModel(connection, cardAssociationRepository);
            SetupRecallPageViewModel(connection);

            connection.OnAsync <IEnumerable <CardAssociationViewModel> >("cardAssociations.getAll", async() =>
            {
                return(await cardAssociationRepository.GetAssociationsAsync());
            });

            connection.OnAsync <IEnumerable <CardAssociationViewModel> >("cardAssociations.save", async(newAssociations) =>
            {
                await cardAssociationRepository.SaveAssociationsAsync(newAssociations);
            });


            var highscoreTable = new HighscoreTable();

            connection.OnAsync <Highscore>("highscores.save", async highscore =>
                                           await highscoreTable.SaveHighScoreAsync(highscore.NumberOfCards, highscore.MemorizationTime));

            connection.OnAsync("highscores.getAll", async() => await highscoreTable.GetHighscoresAsync());

            connection.Listen();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var connection = new ConnectionBuilder()
                             .WithLogging()
                             .Build();

            connection.On <string, string>("ipc-ack", name => "TestEasy-API acknowledges: " + name);
            Task handler = new Task(() => { });

            connection.OnAsync("ipc", async() => { await handler; });
            connection.Listen();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var redditClient = new RedditClient();
            var connection   = new ConnectionBuilder().WithLogging(minimumLogLevel: LogLevel.Trace).Build();

            var selectedSubreddit = "";

            connection.On("select-subreddit", (string newSubreddit) =>
            {
                selectedSubreddit = newSubreddit;
            });

            CancellationTokenSource cancelationTokenSource = new CancellationTokenSource();

            connection.OnAsync("start", async() =>
            {
                Console.Error.WriteLine("started"); //this will show up in the node console
                await Task.Run(async() =>
                {
                    while (true)
                    {
                        if (cancelationTokenSource.Token.IsCancellationRequested)
                        {
                            return;
                        }
                        try
                        {
                            var posts = await redditClient.GetLatestPostsFromSubreddit(selectedSubreddit);
                            connection.Send("show-posts", posts);
                            await Task.Delay(1000);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine($"Failed to get posts for {selectedSubreddit} (maybe it does not exist?)"); //this will show up in the node console
                            Console.Error.WriteLine(ex.Message);
                            return;
                        }
                    }
                }, cancelationTokenSource.Token);
            });

            connection.On("stop", () =>
            {
                Console.Error.WriteLine("Stop");
                if (cancelationTokenSource != null)
                {
                    cancelationTokenSource.Cancel(); //this will cause the start request to complete
                }
            });

            connection.Listen();
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            /// Electron IPC connection...
            var connection = new ConnectionBuilder()
                             .WithLogging()
                             .Build();

            connection.On <string, string>("ipc-ack", name => "TestEasy-API acknowledges: " + name);
            Task handler = new Task(() => { /*Some ipc-related logic*/ });

            connection.OnAsync("ipc", async() => { await handler; });
            Task.Run(() => connection.Listen());

            /// WebApi...
            CreateHostBuilder(args).Build().Run();
        }