123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using ICommunication;
- using Shaker.Model;
- using Shaker.Models;
- using ShakerService.ViewModel;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace ShakerService
- {
- internal class Communication
- {
- public ICommunication.ICommunication Context { get; }
- private Communication()
- {
- Context = new LocalCommunication.Communication();
- string path = "ShakerConfig.db";
- if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- path = Path.Combine(Environment.CurrentDirectory, path);
- }
- else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
- {
- path = Path.Combine("/etc/", path);
- }
- DbConnection = new SQLite.SQLiteConnection(path);
- }
- static Communication()
- {
- }
- public void StartService(string ip,int port)
- {
- Context.StartService(ip, port);
- Context.GetEvent<string>(Topic.SERVICERESULT)?.Subscrip((_, _) => Topic.SERVICERESULT);
- Context.Disconnected += (sender, args) => EventBus.EventBroker.Instance.GetEvent(Topic.STOP).Publish(this,null);
- }
- public SQLite.SQLiteConnection DbConnection { get; private set; }
- public static Communication Instance { get; } = new Communication();
- }
- }
|