コード例 #1
0
ファイル: Bootstrap.cs プロジェクト: PlumpMath/NBlockchain-1
 /// <summary>
 /// Run the communication machine
 /// </summary>
 public void Run()
 {
     m_BlockchainStore = new BlockchainStore();
     Network.INetworkAgentAPI _newNetwork = new CommunicationEngine(m_BlockchainStore);
     m_Agent = new AgentAPI.AgentServices(m_BlockchainStore, _newNetwork, Log);
     _newNetwork.initP2PServer();
 }
コード例 #2
0
        public async Task ConnectToPeersTestMethod()
        {
            WebSocketConnection _connection = null;
            List <string>       _log        = new List <string>();
            Task _server = WebSocketServer.Server(3001, x => { _connection = x; x.onMessage = m => _log.Add($"received message by test WS: {m}"); });
            TestRepositoryNetwork _repository = new TestRepositoryNetwork();

            using (CommunicationEngine _new = new CommunicationEngine(_repository, -1, x => _log.Add(x)))
            {
                Assert.AreEqual <int>(2, _log.Count);
                Assert.IsTrue(_repository.IsCosistent);
                Uri[] _peers = new Uri[] { new Uri("ws://localhost:3001") };
                _new.ConnectToPeers(_peers);
                await Task.Delay(200);

                Assert.IsNotNull(_connection);
                Assert.AreEqual <int>(5, _log.Count);
                Message _requestLast = new Message()
                {
                    data = string.Empty, type = Message.MessageType.QUERY_LATEST
                };
                await _connection.SendAsync(_requestLast.Stringify <Message>());

                await Task.Delay(300);

                Assert.AreEqual <int>(8, _log.Count);
                Assert.IsTrue(_log[7].Contains("received message by test"));
            }
            foreach (string _message in _log.ToArray())
            {
                Debug.WriteLine(_message);
            }
        }
コード例 #3
0
        public MainshellViewModel()
        {
            TopMenu = new ObservableCollection <UserControl>();
            TopMenu.Add(new TopMenu());

            configPath = Directory.GetCurrentDirectory() + "..\\..\\..\\open_dnp3_slave.xml";

            XDocument  document = XDocument.Load(configPath);
            XNamespace ns       = document.Root.GetDefaultNamespace();

            switch (ns.NamespaceName)
            {
            case "http://www.dnp3.org/DNP3/DeviceProfile/Jan2010":

                configParser = new DNP3DeviceProfileJan2010Parser(document);
                ((DNP3DeviceProfileJan2010Parser)configParser).Parse();

                lock (Database.DatabaseLock)
                {
                    foreach (AnalogInputPoint analog in ((DNP3DeviceProfileJan2010Parser)configParser).Configuration.DataPointsListConfiguration.AnalogInputPoints)
                    {
                        Database.AnalogInputPoints.Add(analog);
                    }
                }

                CommunicationEngine communicationEngine = new CommunicationEngine(((DNP3DeviceProfileJan2010Parser)configParser).Configuration.NetworkConfiguration.IpAddress, 20000);
                break;
            }

            Task.Factory.StartNew(() => AnalogPointsSimulation());
        }
コード例 #4
0
        public void ConstructorTestMethod()
        {
            List <string>         _log        = new List <string>();
            TestRepositoryNetwork _repository = new TestRepositoryNetwork();

            using (CommunicationEngine _new = new CommunicationEngine(_repository, -1, x => _log.Add(x)))
            {
                Assert.AreEqual <int>(2, _log.Count);
                Assert.IsTrue(_repository.IsCosistent);
            }
        }
コード例 #5
0
 /// <summary>
 /// Run the communication machine
 /// </summary>
 public async Task Run(int p2pPortNumber, int _AgentHTTPServerPortNumber)
 {
     try
     {
         m_BlockchainStore     = new BlockchainStore(Log);
         m_CommunicationEngine = new CommunicationEngine(m_BlockchainStore, p2pPortNumber, Log);
         m_Agent = new AgentAPI.AgentServices(m_BlockchainStore, m_CommunicationEngine, _AgentHTTPServerPortNumber, Log);
         await m_CommunicationEngine.InitP2PServerAsync();
     }
     catch (Exception ex)
     {
         Log($"The aplikcation has been handled by the exception {ex}");
     }
 }