Ejemplo n.º 1
0
        // GET: Products
        public IActionResult Index()
        {
            _logger.LogInformation("\nEn person " + GetIpAddress.GetIPAddress() + " har besøgt produkt siden!\n");

            byte[] myDataBuffer     = webClient.DownloadData(urlApi);
            string downloadedString = Encoding.UTF8.GetString(myDataBuffer);

            var products = JsonConvert.DeserializeObject <List <Product> >(downloadedString);

            return(View(products));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 接受来自UPD的广播包
        /// </summary>
        private void OnUdpReceive()
        {
            UdpClient receivingUdpClient = new UdpClient(5901);

            isReceive = true;
            //这里指定远端机器的ip和端口,如果只是接收不发送的话,可以随便指定
            IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

            try
            {
                while (isReceive)
                {
                    //接收数据,并返回远程机器的ep
                    Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);

                    string returnData = Encoding.ASCII.GetString(receiveBytes);
                    //PmtsMessageBox.CustomControl1.Show(returnData);
                    if (Regex.IsMatch(returnData, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"))
                    {
                        isReceive = false;
                        if (timeOut.IsEnabled == true)
                        {
                            timeOut.Stop();
                        }
                        ///与主线程建立委托
                        GetIpAddress methodFroIp = OnIpChanged;
                        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, methodFroIp, returnData);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            finally
            {
                receivingUdpClient.Close();
                receivingUdpClient = null;
            }
        }
        public async ValueTask <string> HangMan(string guess)
        {
            var word = "hangman";

            var ip = GetIpAddress.GetClientIp(Request);

            if (!_dic.ContainsKey(ip))
            {
                _dic.Add(ip, "");
            }

            if (guess.Length != 1)
            {
                return("no");
            }

            if (word.Contains(guess))
            {
                var result = string.Empty;
                foreach (var c in word)
                {
                    if (guess.Equals(c))
                    {
                        result += c;
                    }
                    else
                    {
                        result += '_';
                    }
                }

                return(result);
            }
            else
            {
                return("no");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 登录动作
        /// </summary>
        private void OnLogin()
        {
            if (String.IsNullOrEmpty(this.userText.Text) || String.IsNullOrEmpty(this.pwdText.Password))
            {
                PmtsMessageBox.CustomControl1.Show("请输入用户ID或密码", PmtsMessageBox.ServerMessageBoxButtonType.OK);
            }
            else
            {
                bool isAdd = true;
                if (objNodeXml.uList.Count > 0)
                {
                    for (int i = 0; i < objNodeXml.uList.Count; i++)
                    {
                        String nameStr = objNodeXml.uList[i].uName;
                        if (nameStr == this.userText.Text)
                        {
                            isAdd = false;
                            break;
                        }
                    }
                }
                else
                {
                    isAdd = true;
                }
                if (isAdd)
                {
                    try
                    {
                        LogUserList addUser = new LogUserList();
                        addUser.uName = this.userText.Text;
                        objNodeXml.uList.Add(addUser);
                        String        xmlTest       = "./Config/UserList.xml";
                        XmlSerializer objSerializer = new XmlSerializer(typeof(NodeXml));
                        StreamWriter  objStream     = new StreamWriter(xmlTest);
                        objSerializer.Serialize(objStream, objNodeXml);
                        objStream.Close();
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.Write("生成XML时出错:" + ex.Message + "\n");
                    }
                }
                /*-------------------------------------------------------------------------------------*/
                try
                {
                    //开始线程

/*                    Thread udpT = new Thread(OnUdpReceive);
 *                  udpT.Name = "UDP_GET_IP";
 *                  udpT.IsBackground = true;
 *                  udpT.Start();
 *                  //启用超时定时器
 *                  timeOut = new DispatcherTimer();
 *                  timeOut.Interval = new TimeSpan(0, 0, 5);
 *                  timeOut.Tick += OnUDPTimeOut;
 *                  timeOut.Start();
 * by lich*/
                    string       returnData  = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$";
                    GetIpAddress methodFroIp = OnIpChanged;
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, methodFroIp, returnData);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                /*---------------------------------------记录用户登录历史(完成后需要移动到OnIpChanged方法中)----------------------------------------------*/
                //Main mainWindow = new Main("127.0.0.1", this.userText.Text);
                //mainWindow.Show();
                //this.Close();
            }
        }
Ejemplo n.º 5
0
 public IActionResult Index()
 {
     _logger.LogInformation("\nEn person " + GetIpAddress.GetIPAddress() + " har besøgt forsiden!\n");
     return(View());
 }
Ejemplo n.º 6
0
 // GET: Products
 public async Task <IActionResult> Index()
 {
     _logger.LogInformation("\nEn person " + GetIpAddress.GetIPAddress() + " har besøgt produkt siden!\n");
     return(View(await _context.Product.ToListAsync()));
 }