コード例 #1
0
 public SessionReplyMessage(Message message, HandShakeResponse handshake, VaspInformation vasp)
 {
     MessageType = MessageType.SessionReply;
     Message     = message;
     HandShake   = handshake;
     VASP        = vasp;
 }
コード例 #2
0
 public SessionReplyMessage(string sessionId, HandShakeResponse handshake, VaspInformation vasp)
 {
     MessageType = MessageType.SessionReply;
     Message     = new Message(Guid.NewGuid().ToString(), sessionId, "1");
     HandShake   = handshake;
     VASP        = vasp;
 }
コード例 #3
0
        public static SessionReplyMessage MapFromProto(ProtoSessionReplyMessage message)
        {
            var messageIn = new Message(
                message.Message.MessageId,
                message.Message.SessionId,
                message.Message.MessageCode);
            var handshake = new HandShakeResponse(message.TopicB);
            var vasp      = Mapper.MapVaspInformationFromProto(message.VaspInfo);

            var proto = new SessionReplyMessage(messageIn, handshake, vasp)
            {
                Comment = message.Comment,
            };

            return(proto);
        }
コード例 #4
0
        private static SessionReplyMessage GetSessionReplyMessage()
        {
            //Should be a contract
            var vaspKey = EthECKey.GenerateKey();

            //4Bytes
            var topic = "0x12345678"; //"0x" + "My Topic".GetHashCode().ToString("x");

            var message = new Message(
                Guid.NewGuid().ToByteArray().ToHex(prefix: false),
                Guid.NewGuid().ToByteArray().ToHex(prefix: false),
                "1");
            var handshake     = new HandShakeResponse(topic);
            var postalAddress = new PostalAddress(
                "TestingStreet",
                61,
                "Test Address Line",
                "410000",
                "TownN",
                Country.List["DE"]
                );
            var placeOfBirth    = new PlaceOfBirth(DateTime.UtcNow, "TownN", Country.List["DE"]);
            var vaspInformation = new VaspInformation(
                "Test test",
                vaspKey.GetPublicAddress(),
                vaspKey.GetPubKey().ToHex(prefix: false),
                postalAddress,
                placeOfBirth,
                new NaturalPersonId[]
            {
                new NaturalPersonId("SomeId2", NaturalIdentificationType.AlienRegistrationNumber,
                                    Country.List["DE"]),
            },
                new JuridicalPersonId[]
            {
                new JuridicalPersonId("SomeId1", JuridicalIdentificationType.BankPartyIdentification,
                                      Country.List["DE"]),
            },
                "DEUTDEFF");

            var request = new SessionReplyMessage(message, handshake, vaspInformation)
            {
                Comment = "This is test message",
            };

            return(request);
        }
コード例 #5
0
        private void InitializeWithoutAutoBootstrap()
        {
            // Without auto bootstrap, we just try to send a handshake request (the listener should already be
            // deployed). If that fails, we try nothing else.
            InitializePort();
            HandShakeResponse handshakeResponse = ExecuteHandshake();

            if (handshakeResponse == null)
            {
                port.Close();
                port.Dispose();
                throw new IOException(
                          $"Unable to get a handshake ACK when sending a handshake request to the Arduino on port {config.PortName}. " +
                          "Pass 'true' for optional parameter autoBootStrap in one of the ArduinoDriver constructors to " +
                          "automatically configure the Arduino (please note: this will overwrite the existing sketch " + "on the Arduino)."
                          );
            }
        }
コード例 #6
0
        private async Task InitializeWithAutoBootstrapAsync()
        {
            var alwaysReDeployListener             = alwaysRedeployListeners.Count > 500;
            HandShakeResponse handshakeResponse    = null;
            var handShakeAckReceived               = false;
            var handShakeIndicatesOutdatedProtocol = false;

            if (!alwaysReDeployListener)
            {
                logger.Info("Initiating handshake...");
                InitializePort();
                handshakeResponse = await ExecuteHandshakeAsync();

                handShakeAckReceived = handshakeResponse != null;
                if (handShakeAckReceived)
                {
                    logger.Info("Handshake ACK Received ...");
                    const int currentVersion  = (CurrentProtocolMajorVersion * 10) + CurrentProtocolMinorVersion;
                    var       listenerVersion = (handshakeResponse.ProtocolMajorVersion * 10) + handshakeResponse.ProtocolMinorVersion;
                    logger.Info("Current ArduinoDriver C# Protocol: {0}.{1}.",
                                CurrentProtocolMajorVersion, CurrentProtocolMinorVersion);
                    logger.Info("Arduino Listener Protocol Version: {0}.{1}",
                                handshakeResponse.ProtocolMajorVersion, handshakeResponse.ProtocolMinorVersion);
                    handShakeIndicatesOutdatedProtocol = currentVersion > listenerVersion;
                    if (handShakeIndicatesOutdatedProtocol)
                    {
                        logger.Debug("Closing port...");
                        port.Close();
                        port.Dispose();
                    }
                }
                else
                {
                    logger.Debug("Closing port...");
                    port.Close();
                    port.Dispose();
                }
            }

            // If we have received a handshake ack, and we have no need to upgrade, simply return.
            if (handShakeAckReceived && !handShakeIndicatesOutdatedProtocol)
            {
                return;
            }

            var arduinoModel = config.ArduinoModel;

            // At this point we will have to redeploy our listener
            logger.Info("Boostrapping ArduinoDriver Listener...");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            ExecuteAutoBootStrap(arduinoModel, config.PortName);
            stopwatch.Stop();
            logger.Info("Bootstrapping device took {0}ms.", stopwatch.ElapsedMilliseconds);

            // Now wait a bit, since the bootstrapped Arduino might still be restarting !
            var graceTime =
                rebootGraceTimes.ContainsKey(arduinoModel) ?
                rebootGraceTimes[arduinoModel] : defaultRebootGraceTime;

            logger.Info("Grace time after reboot, waiting {0}ms...", graceTime);
            Thread.Sleep(graceTime);


            // Listener should now (always) be deployed, handshake should yield success.
            InitializePort();
            handshakeResponse = await ExecuteHandshakeAsync();

            if (handshakeResponse == null)
            {
                throw new IOException("Unable to get a handshake ACK after executing auto bootstrap on the Arduino!");
            }
            logger.Info("ArduinoDriver fully initialized!");
        }