Beispiel #1
0
        public async Task <String> NewLogin(String login, String pass)
        {
            try
            {
                if (WebRequestHelper.CheckNet() == false)
                {
                    return(null);
                }

                WriteConsole.WriteInLine("Logando ", 1, 1);

                this.login = login;
                this.pass  = pass;

                if ((IdAccess = await LoginAsync("http://gspn6.samsungcsportal.com/")) != null)
                {
                    return(IdAccess);
                }

                return(null);
            }
            catch
            {
                throw;
            }
        }
Beispiel #2
0
        //pesquisa a quantidade de registros em uma data
        public async Task GetRegisterByDate()
        {
            try
            {
                DateTime date = await new DateSelectionConsole().RunConsoleDateSelection();

                WriteConsole.WriteInLine("Pesquisando ", Console.CursorTop + 1, 1);
                List <Registro> aps = await WebApi.GetListRegistroByDate(date);

                if (aps == null)
                {
                    return;
                }

                Console.Clear();

                //escreve o resultado da pesquisa na tela
                aps.ForEach(x =>
                {
                    Console.Write(x.Cliente.Nome + x.Aparelho.Modelo + " " + (x.DiagnosticGD.consul != 1 ? "N" : "Y"));

                    WriteConsole.Separator('/');
                });

                //await aps.ForEachAsync(x =>
                //{
                //    try
                //    {
                //        x.ToString();

                //        //var ap = await WebApi.GetRegistroById(x.Id);

                //        //Console.Write(ap.ToString());

                //        WriteConsole.Separator('/', 1, 1);
                //    }
                //    catch (Exception e)
                //    {
                //        Console.WriteLine(e.Message);
                //    }
                //});
                var aa = aps.Select(x => x.DiagnosticGD.consul != 0);

                Console.WriteLine("\n" + (aps == null ? 0 : aps.Count()) + " registros e "
                                  + (aps.Where(x => x.DiagnosticGD.consul == 1).ToList().Count() == 0 ? 0 : aps.Where(x => x.DiagnosticGD.consul == 1).ToList().Count())
                                  + " diagnosticos no dia " + date.Date.ToString("dd/MM/yyyy"));
            }
            catch (Exception e)
            {
            }
        }
Beispiel #3
0
        public async Task <string> ExecuteCommand(String command, String comPort)
        {
            try
            {
                String result = "";

                sp = new SerialPort(comPort, 115200);

                sp.DtrEnable = true;
                sp.Open();

                sp.Write(command);

                WriteConsole.WriteInLine("Aguardando ", 1, 1);
                spinner.Start();

                while (sp.BytesToRead <= sp.ReceivedBytesThreshold)
                {
                }

                spinner.Stop();

                var data2 = await sp.SerialReadLineAsync().ConfigureAwait(true);

                sp.Close();

                if (data2 == null)
                {
                    new Exception("Erro ao aguardar retorno de aplicativo");
                }
                return(data2);
            }
            catch (Exception er)
            {
                Console.WriteLine("\nOcorreu um erro inesperado ao solicitar data via serial\n");
                sp.Close();
                return(er.Message);
            }
            finally
            {
                if (sp.IsOpen)
                {
                    sp.Close();
                }
            }
        }
Beispiel #4
0
        //the openData = false not open txt file
        public static async Task <List <Aparelho> > SearchAparelhoSerial(bool openData = true, bool saveData = true)
        {
            String[] sp = SerialPort.GetPortNames();

            Func <Task <bool> > taskSearchDevice = async() =>
            {
                sp = SerialPort.GetPortNames();
                var spinner = new Spinner();

                WriteConsole.WriteInLine("Pesquisando ", 1, 1);
                spinner.Start();

                int count = 0;
                while (sp.Count() == 0)
                {
                    sp = SerialPort.GetPortNames();
                    count++;
                    await Task.Delay(1000);

                    if (count >= 5)
                    {
                        spinner.Stop();
                        Console.Clear();
                        return(false);
                    }
                }

                spinner.Stop();

                return(true);
            };

            if (!await taskSearchDevice())
            {
                return(null);
            }

            var aps = await CallDeviceInfo(sp);

            if (aps == null)
            {
                return(null);
            }

            aps.ForEach(ap =>
            {
                Console.WriteLine("\n" + ap.ToString() + "\n");

                if (!saveData)
                {
                    return;
                }

                FileHelper.SaveFile("dataSerial.txt",
                                    Environment.NewLine + "\n-----------------------------"
                                    + Environment.NewLine + ap.Modelo
                                    + Environment.NewLine + ap.RN
                                    + Environment.NewLine + ap.Imei, false);
            });

            if (!openData || !saveData)
            {
                return(aps);
            }

            await ProcessHelper.CloseProcessByTitle("notepad", "dataSerial ");

            ProcessHelper.StartProcess("notepad.exe", "database/dataSerial.txt",
                                       Screen.PrimaryScreen.Bounds.Width / 20,
                                       Screen.PrimaryScreen.Bounds.Height / 8);

            return(aps);
        }