Пример #1
0
        /// <summary>
        /// Creates an app service thread
        /// </summary>
        static void Main(string[] args)
        {
            try
            {
                reader = new IDCardReader();
            }
            catch (Exception)
            {
            }


            Thread appServiceThread = new Thread(new ThreadStart(ThreadProc));

            appServiceThread.Start();
            while (true)
            {
                Thread.Sleep(10000);
            }
        }
Пример #2
0
        /// <summary>
        /// Receives message from UWP app and sends a response back
        /// </summary>
        private static async void Connection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            string key   = args.Request.Message.First().Key;
            string value = args.Request.Message.First().Value.ToString();

            ValueSet valueSet = new ValueSet();


            if (key == "check")
            {
                if (reader != null)
                {
                    valueSet.Add("run", "run");
                }
                else
                {
                    try
                    {
                        reader = new IDCardReader();
                        valueSet.Add("run", "run");
                    }
                    catch (Exception)
                    {
                        valueSet.Add("noReader", "run");
                    }
                }
            }
            else if (key == "install")
            {
                RunBat(value + "Core\\device\\install.bat");
            }
            else
            {
                if (reader == null)
                {
                    try
                    {
                        reader = new IDCardReader();
                    }
                    catch
                    {
                    }
                }
                if (reader != null)
                {
                    var idcard = reader.Read();
                    if (idcard != null)
                    {
                        if (idcard.number != "")
                        {
                            valueSet.Add("data", ConvertJsonString(idcard));
                        }
                    }
                    else
                    {
                    }
                }
            }

            await args.Request.SendResponseAsync(valueSet);
        }