Skip to content

Instantly share code, notes, and snippets.

View kirshiyin89's full-sized avatar

Kirshi Yin kirshiyin89

View GitHub Profile
@kirshiyin89
kirshiyin89 / Api.java
Last active August 25, 2020 13:34
Spring boot main class
package com.serverchecker;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Api {
/**
* @param args the command line arguments
*/
@kirshiyin89
kirshiyin89 / ServerInfo.java
Created August 24, 2020 17:51
ServerInfo DTO
public class ServerInfo {
public final String name;
public final List<ServiceInfo> services;
public ServerInfo(String name, List<ServiceInfo> services) {
this.name = name;
this.services = services;
}
@kirshiyin89
kirshiyin89 / ServiceInfo.java
Created August 24, 2020 17:54
The Service Info DTO.
public class ServiceInfo {
public final String name;
public final boolean running;
public ServiceInfo(String name, boolean running) {
this.name = name;
this.running = running;
}
@kirshiyin89
kirshiyin89 / application.properties
Last active August 25, 2020 15:43
The global application properties file.
datapath=./data
@kirshiyin89
kirshiyin89 / DataService.java
Last active August 25, 2020 13:35
The DataService collecting the information from the server output file.
package com.serverchecker.service;
import com.serverchecker.dto.ServerInfo;
import com.serverchecker.dto.ServiceInfo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
@kirshiyin89
kirshiyin89 / DataService.java
Created August 24, 2020 18:17
The DataService.java processing the server info and mapping it to the final result.
public List<ServerInfo> getServerInfo() {
List<ServerInfo> result = new ArrayList<>();
Map<String, String> serverData = getServerData();
for (Map.Entry<String, String> info : serverData.entrySet()) {
result.add(new ServerInfo(info.getKey(), map(info.getValue())));
}
return result;
}
private static List<ServiceInfo> map(String data) {
@kirshiyin89
kirshiyin89 / ApiController.java
Last active August 25, 2020 13:32
The application's controller.
package com.serverchecker;
import com.serverchecker.dto.ServerInfo;
import com.serverchecker.service.DataService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class ApiController {
@kirshiyin89
kirshiyin89 / ServerInfo.dart
Last active August 25, 2020 13:31
The Server Info dto.
import 'package:myapp/serviceinfo.dart';
class ServerInfo {
const ServerInfo({this.name, this.services});
final String name;
final List<ServiceInfo> services;
factory ServerInfo.fromJson(Map<String, dynamic> json) {
@kirshiyin89
kirshiyin89 / ServiceInfo.dart
Created August 24, 2020 18:40
The ServiceInfo dto hodling information on the services status.
class ServiceInfo {
const ServiceInfo({this.name, this.running});
final String name;
final bool running;
String status() {
if (running) {
return "running";
@kirshiyin89
kirshiyin89 / StartPage.dart
Last active August 25, 2020 13:29
The StartPage of the Flutter application holding the Grid Cards.
import 'package:flutter/material.dart';
import 'package:myapp/serverinfo.dart';
import 'package:myapp/serviceinfo.dart';
import 'package:myapp/utils.dart';
class StartPage extends StatelessWidget {
StartPage({Key key, this.title, this.serverInfo}) : super(key: key);
final String title;
final Future<List<ServerInfo>> serverInfo;