Esempio n. 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            frm = this;

            try
            {
                var server_config = new SuperSocket.SocketBase.Config.ServerConfig()
                {
                    Port = 80,
                    Ip   = "127.0.0.1",
                    MaxConnectionNumber = 100,
                    Mode             = SuperSocket.SocketBase.SocketMode.Tcp,
                    Name             = "SuperSocket.WebSocket Sample Server",
                    MaxRequestLength = 1024 * 1024 * 10
                };

                setup_server(ref server, server_config);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            frm = this;

            try
            {
                var server_config = new SuperSocket.SocketBase.Config.ServerConfig()
                {
                    Port = 80,
                    Ip   = "127.0.0.1",
                    MaxConnectionNumber = 100,
                    Mode             = SuperSocket.SocketBase.SocketMode.Tcp,
                    Name             = "SuperSocket.WebSocket Sample Server",
                    MaxRequestLength = 1024 * 1024 * 10
                };

                setup_server(ref server, server_config);

                var result = NfcApi.SCardEstablishContext(
                    NfcConstant.SCARD_SCOPE_USER,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    out _hContext
                    );

                if (result != 0)
                {
                    if (result == NfcConstant.SCARD_E_NO_SERVICE)
                    {
                        frm.add_log(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), "Smart Card Servise is not Started.");
                    }
                    else
                    {
                        frm.add_log(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), string.Format("SCardEstablishContext Error.\nErrorCode.{0:X}\n", result));
                    }
                }
                else
                {
                    _is_connect = true;

                    try
                    {
                        uint pcchReaders = 0;

                        result = NfcApi.SCardListReaders(_hContext, null, null, ref pcchReaders);

                        if (result != NfcConstant.SCARD_S_SUCCESS)
                        {
                            throw new ApplicationException("リーダーの情報が取得できません。\nErrorCode: " + String.Format("{0:X}", result));
                        }

                        byte[] mszReaders = new byte[pcchReaders * 2];

                        result = NfcApi.SCardListReaders(_hContext, null, mszReaders, ref pcchReaders);

                        if (result != NfcConstant.SCARD_S_SUCCESS)
                        {
                            throw new ApplicationException("リーダーの情報が取得できません。\nErrorCode: " + String.Format("{0:X}", result));
                        }

                        UnicodeEncoding unicodeEncoding       = new UnicodeEncoding();
                        string          readerNameMultiString = unicodeEncoding.GetString(mszReaders);

                        int nullindex = readerNameMultiString.IndexOf((char)0);   // 装置は1台のみ
                        _readername = readerNameMultiString.Substring(0, nullindex);

                        frm.add_log(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), "リーダー名:" + _readername);

                        _readerStateArray = new NfcApi.SCARD_READERSTATE[1];


                        timer1.Start();
                    }
                    catch (ApplicationException ex)
                    {
                        frm.add_log(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 3
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            frm = null;

            server.Stop();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            frm = this;

            try
            {
                var server_config_ssl = new SuperSocket.SocketBase.Config.ServerConfig()
                {
                    Port = 443,
                    Ip   = "127.0.0.1",
                    MaxConnectionNumber = 100,
                    Mode             = SuperSocket.SocketBase.SocketMode.Tcp,
                    Name             = "SuperWebSocket Sample Server",
                    MaxRequestLength = 1024 * 1024 * 10,
                    Security         = "tls",
                    Certificate      = new SuperSocket.SocketBase.Config.CertificateConfig
                    {
                        FilePath = ConfigurationManager.AppSettings["cert_file_path"],
                        Password = ConfigurationManager.AppSettings["cert_password"]
                    }
                };

                setup_server(ref server_ssl, server_config_ssl);

                valid_cert();

                var result = NfcApi.SCardEstablishContext(
                    NfcConstant.SCARD_SCOPE_USER,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    out _hContext
                    );

                if (result != 0)
                {
                    if (result == NfcConstant.SCARD_E_NO_SERVICE)
                    {
                        frm.add_log(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), "Smart Card Servise is not Started.");
                    }
                    else
                    {
                        frm.add_log(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), string.Format("SCardEstablishContext Error.\nErrorCode.%08X\n", result));
                    }
                }
                else
                {
                    _is_connect = true;

                    try
                    {
                        uint pcchReaders = 0;

                        result = NfcApi.SCardListReaders(_hContext, null, null, ref pcchReaders);

                        if (result != NfcConstant.SCARD_S_SUCCESS)
                        {
                            throw new ApplicationException("リーダーの情報が取得できません。");
                        }

                        byte[] mszReaders = new byte[pcchReaders * 2];

                        result = NfcApi.SCardListReaders(_hContext, null, mszReaders, ref pcchReaders);

                        if (result != NfcConstant.SCARD_S_SUCCESS)
                        {
                            throw new ApplicationException("リーダーの情報が取得できません。");
                        }

                        UnicodeEncoding unicodeEncoding       = new UnicodeEncoding();
                        string          readerNameMultiString = unicodeEncoding.GetString(mszReaders);

                        int nullindex = readerNameMultiString.IndexOf((char)0);   // 装置は1台のみ
                        _readername = readerNameMultiString.Substring(0, nullindex);

                        frm.add_log(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), "リーダー名:" + _readername);

                        _readerStateArray = new NfcApi.SCARD_READERSTATE[1];


                        timer1.Start();
                    }
                    catch (ApplicationException ex)
                    {
                        frm.add_log(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                reflesh_cert();

                MessageBox.Show("証明書を更新しました。\nアプリケーションを再起動します。");

                Application.Restart();
            }
        }