Exemplo n.º 1
0
        public MainViewModel(RCViewModel rcViewModel, IConfigReaderService configReaderService, ILogService logService, IRCService rcService, ICCService ccService, IConnectivityService connectivityService)
        {
            x = rcViewModel;
            _configReaderService = configReaderService;
            _logService          = logService;
            _rcService           = rcService;
            _ccService           = ccService;
            _connectivityService = connectivityService;
            _connectivityService.MessageReceived += OnMessageReceived;
            BindingOperations.EnableCollectionSynchronization(Logs, _lock);

            try
            {
                SubnetworkConfig = configReaderService.ReadSubnetworkConfig();
            }
            catch (Exception e)
            {
                _logService.LogError("WRONG CONFIG: " + e.Message);
            }

            if (SubnetworkConfig.IsDomain)
            {
                _connectivityService.ConnectToNCCorDomain("127.0.0.1", SubnetworkConfig.NCCPort, SubnetworkConfig.Name);
                _connectivityService.StartListening("127.0.0.1", SubnetworkConfig.ServerPort);
            }
            else
            {
                //_cableCloudConnectionService.StartClient("127.0.0.1", SubnetworkConfig.CableCloudPort, SubnetworkConfig.Name);
                _connectivityService.ConnectToNCCorDomain("127.0.0.1", SubnetworkConfig.ClientPort, SubnetworkConfig.Name);
                _connectivityService.StartListening("127.0.0.1", SubnetworkConfig.ServerPort);
            }

            Task.Run(async() =>
            {
                while (true)
                {
                    await CheckList();
                    Thread.Sleep(50);
                }
            });
        }