Exemplo n.º 1
0
        /// <summary>
        ///   Reads the string representation from the specified <see cref="TextReader"/>.
        /// </summary>
        /// <param name="stream">
        ///   The <see cref="TextReader"/> to read from
        /// </param>
        /// <remarks>
        ///   The string representation is a sequence of <see cref="NetworkProtocol">network protocols</see>.
        /// </remarks>
        void Read(TextReader stream)
        {
            if (stream.Read() != '/')
            {
                throw new FormatException("An IFPS multiaddr must start with '/'.");
            }

            var name = new StringBuilder();
            Protocols.Clear();
            int c;
            while (true)
            {
                name.Clear();
                while (-1 != (c = stream.Read()) && c != '/')
                {
                    name.Append((char)c);
                }
                if (name.Length == 0)
                    break;
                if (!NetworkProtocol.Names.TryGetValue(name.ToString(), out Type protocolType))
                    throw new FormatException(string.Format("The IPFS network protocol '{0}' is unknown.", name.ToString()));
                var p = (NetworkProtocol)Activator.CreateInstance(protocolType);
                p.ReadValue(stream);
                Protocols.Add(p);
            }

            if (Protocols.Count == 0)
                throw new FormatException("The IFPS multiaddr has no protocol specified.");
        }
Exemplo n.º 2
0
 public static void Clear()
 {
     MemoryCoordinator.Reset();
     GpfProgramCompiler.Clear();
     Protocols.Clear();
     Kernels.Clear();
     head = null;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Will reset the device information and initialize with the info fromteh DeviceInstance
 /// </summary>
 /// <param name="pDev">DeviceInstance that has the EPR info</param>
 public void ResetDevice(DeviceInstance pDev)
 {
     HostName = pDev.HostName;
     Profile  = pDev.Name;
     Protocols.Clear();
     foreach (ProtocolService _prot in pDev.ImplementedProtocolServices)
     {
         Protocols.Add(_prot.Protocol);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 ///   Reads the binary representation of the specified <see cref="CodedInputStream"/>.
 /// </summary>
 /// <param name="stream">
 ///   The <see cref="CodedInputStream"/> to read from.
 /// </param>
 /// <remarks>
 ///   The binary representation is a sequence of <see cref="NetworkProtocol">network protocols</see>.
 /// </remarks>
 void Read(CodedInputStream stream)
 {
     Protocols.Clear();
     do
     {
         uint code = (uint)stream.ReadInt64();
         if (!NetworkProtocol.Codes.TryGetValue(code, out Type protocolType))
             throw new InvalidDataException(string.Format("The IPFS network protocol code '{0}' is unknown.", code));
         var p = (NetworkProtocol)Activator.CreateInstance(protocolType);
         p.ReadValue(stream);
         Protocols.Add(p);
     } while (!stream.IsAtEnd);
 }
Exemplo n.º 5
0
        /// <summary>
        ///   Reads the binary representation of the specified <see cref="Google.Protobuf.CodedInputStream"/>.
        /// </summary>
        /// <param name="stream">
        ///   The <see cref="Google.Protobuf.CodedInputStream"/> to read from.
        /// </param>
        /// <remarks>
        ///   The binary representation is a sequence of <see cref="NetworkProtocol">network protocols</see>.
        /// </remarks>
        private void Read(CodedInputStream stream)
        {
            Protocols.Clear();
            do
            {
                var code = (uint)stream.ReadInt64();
                if (!NetworkProtocol.Codes.TryGetValue(code, out var protocolType))
                {
                    throw new InvalidDataException($"The IPFS network protocol code '{code}' is unknown.");
                }

                var p = (NetworkProtocol)Activator.CreateInstance(protocolType);
                p.ReadValue(stream);
                Protocols.Add(p);
            } while (!stream.IsAtEnd);
        }
Exemplo n.º 6
0
        public void Connect(SCardShareMode shareMode = SCardShareMode.Shared)
        {
            PCSCResult result;

            // Are we already connected?
            if (myHandle != IntPtr.Zero)
            {
                return;
            }

            // Establish a new session context for this card
            result = NativeMethods.SCardEstablishContext(SCardScope.User, IntPtr.Zero, IntPtr.Zero, out myContext);
            if (PCSCResult.None != result)
            {
                throw PCSCException.ThrowByResult(result);
            }

            // Connect to the card
            result = NativeMethods.SCardConnect(myContext, myReaderName, shareMode, DefaultRequestedProtocols, ref myHandle, ref myCommsProtocol);

            if (PCSCResult.None != result)
            {
                // Disconnect (this will gracefully handle the context release)
                Disconnect();
                throw PCSCException.ThrowByResult(result);
            }

            // Retrieve our ATR
            byte[]        readerName   = new byte[255];
            uint          readerLen    = 255;
            SCardState    state        = 0;
            SCardProtocol cardProtocol = 0;
            uint          atrLen       = NativeMethods.SCARD_ATR_LENGTH;

            byte[] atr = new byte[atrLen];

            result = NativeMethods.SCardStatus(myHandle, readerName, ref readerLen, out state, out cardProtocol, atr, ref atrLen);
            if (result != PCSCResult.None)
            {
                // Disconnect from the card
                Disconnect();
                throw PCSCException.ThrowByResult(result);
            }


            //
            // Protocol Enumeration
            //
            try
            {
                // Add the default 7816 protocol
                Protocols.Add(new PCSCIso7816Protocol(atr, this));

                // Determine whether this card is contactless or not
                if (SupportsIso14443)
                {
                    // Replace the 7816 protocol with 14443
                    Protocols.Clear();

                    var protocol = new PCSCIso14443AProtocol(atr, this);
                    Protocols.Add(protocol);

                    // Create our OptionalCommands object
                    OptionalCommands = new PCSCOptionalCommands(protocol);

                    //
                    // HACK: Adding a PCSCMifareProtocol to all ISO14443 cards, what
                    //       we should be doing is somehow determining if this card
                    //       supports Mifare or Mifare emulation
                    //
                    Protocols.Add(new PCSCMifareProtocol(this));
                }
            }
            catch (Exception)
            {
                // Disconnect from the card
                Disconnect();
                throw PCSCException.ThrowUnsupportedProtocol();
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Utility method that clears the protocol and profile fields - basically making the EPR Instance appear idle
 /// or as it would be if it was idle.
 /// </summary>
 public void ClearDevice()
 {
     Protocols.Clear();
     Profile = NOPROFILE;
 }