public FileResult fileDownload(string file)
        {
            if (!Program.registrado)
            {
            }
            try
            {
                string        tempStr = "";
                List <string> temp    = new List <string>();
                Stream        stream  = new MemoryStream();
                byte[]        bite;


                temp = dxm.getFile(file);
                if (temp[0] == "")
                {
                }
                else
                {
                    for (int x = 0; x < temp.Count; x++)
                    {
                        tempStr = tempStr + temp[x];
                    }
                }
                bite = Encoding.UTF8.GetBytes(tempStr);
                stream.Write(bite, 0, bite.Length);
                return(File(bite, "text/dat", file));
            }
            catch (Exception ex) { return(File(Encoding.UTF8.GetBytes(ex.Message), "text/dat", "falha.dat")); }
        }
示例#2
0
        public static void DXMLog()
        {
            int contador = 0;

            while (true)
            {
                long hora       = DateTime.Now.ToFileTime();
                int  linhas     = vt.quantidade;
                int  comparador = vt.tickLog + 60;
                contador++;

                if (contador > comparador && dxm.Connected)
                {
                    ///*
                    loging = true;
                    try
                    {
                        DXM_Procotolo dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                        if (dxm_api.FileExist("Sbfile1.dat"))
                        {
                            dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                            string        tempStr  = "";
                            string        tempStr2 = "";
                            List <string> temp     = new List <string>();
                            List <string> temp2    = new List <string>();
                            dxm_api.destravar();
                            dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                            temp2   = dxm_api.getFile("LogFile1.txt");
                            Thread.Sleep(200);
                            dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                            temp    = dxm_api.getFile("Sbfile1.dat");
                            try {
                                if (temp[0] == "")
                                {
                                }
                                else
                                {
                                    for (int x = 0; x < temp2.Count; x++)
                                    {
                                        tempStr2 = tempStr2 + temp2[x];
                                    }
                                    for (int x = 0; x < temp.Count; x++)
                                    {
                                        tempStr = tempStr + temp[x];
                                    }
                                    vt.flush();
                                    banco.exec_log(tempStr, vt.quantidade, tempStr2);
                                    dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                                    dxm_api.deleteFile("Sbfile1.dat");
                                    Thread.Sleep(200);
                                    dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                                    dxm_api.deleteFile("LogFile1.txt");
                                    Thread.Sleep(1000);
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                            }

                            dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                            dxm_api.travar();
                        }
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex);
                    }

                    /*
                     * contador = 0;
                     * for (int z = 0; z < linhas; z++)
                     * {
                     *  try
                     *  {
                     *      if (!vt.motores[z].Estado.Contains("DXM")) {
                     *          vt.flush();
                     *          banco.exec_log(vt.motores[z]);
                     *      }
                     *  }
                     *  catch { }
                     * }
                     */
                    banco.set_fabrica(JsonConvert.SerializeObject(vt));
                    contador = 0;
                }
                else
                {
                    loging = false;
                }
                Thread.Sleep(1000);
            }
        }
        public string forceLoging()
        {
            string ret = "falha";

            if (Program.dxm.Connected)
            {
                try
                {
                    Program.loging = true;
                    DXM_Procotolo dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                    if (dxm_api.FileExist("Sbfile1.dat"))
                    {
                        Program.loging = true;
                        dxm_api        = new DXM_Procotolo(Program.dxm.IPAddress);
                        string        tempStr  = "";
                        string        tempStr2 = "";
                        List <string> temp     = new List <string>();
                        List <string> temp2    = new List <string>();
                        dxm_api.destravar();
                        dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                        temp2   = dxm_api.getFile("LogFile1.txt");
                        Thread.Sleep(200);
                        dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                        temp    = dxm_api.getFile("Sbfile1.dat");
                        try
                        {
                            if (temp[0] == "")
                            {
                            }
                            else
                            {
                                for (int x = 0; x < temp2.Count; x++)
                                {
                                    tempStr2 = tempStr2 + temp2[x];
                                }
                                for (int x = 0; x < temp.Count; x++)
                                {
                                    tempStr = tempStr + temp[x];
                                }
                                Program.vt.flush();
                                Program.banco.exec_log(tempStr, Program.vt.quantidade, tempStr2);
                                dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                                dxm_api.deleteFile("Sbfile1.dat");
                                Thread.Sleep(200);
                                dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                                dxm_api.deleteFile("LogFile1.txt");
                                Thread.Sleep(200);
                                ret = "ok";
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }

                        dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                        dxm_api.travar();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                Program.loging = false;
            }
            return(ret);
        }
        public string baixaLog()
        {
            string ret = "falha";

            if (Program.dxm.Connected)
            {
                try
                {
                    Program.loging = true;
                    DXM_Procotolo dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                    if (dxm_api.FileExist("Sbfile1.dat"))
                    {
                        dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                        string        tempStr  = "";
                        string        tempStr2 = "";
                        List <string> temp     = new List <string>();
                        List <string> temp2    = new List <string>();
                        temp2 = dxm_api.getFile("LogFile1.txt");
                        Thread.Sleep(200);
                        dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                        temp    = dxm_api.getFile("Sbfile1.dat");
                        try
                        {
                            if (temp[0] == "")
                            {
                            }
                            else
                            {
                                for (int x = 0; x < temp2.Count; x++)
                                {
                                    tempStr2 = tempStr2 + temp2[x];
                                }
                                for (int x = 0; x < temp.Count; x++)
                                {
                                    tempStr = tempStr + temp[x];
                                }
                                Program.vt.flush();
                                Program.banco.exec_log(tempStr, Program.vt.quantidade, tempStr2);
                                dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                                dxm_api.deleteFile("Sbfile1.dat");
                                Thread.Sleep(200);
                                dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                                dxm_api.deleteFile("LogFile1.txt");
                                ret = "ok";
                            }
                        }
                        catch
                        {
                            ret     = "falha - não foi possivel baixar o log, execute um diagnóstico e tente novamente";
                            dxm_api = new DXM_Procotolo(Program.dxm.IPAddress);
                            dxm_api.travar();
                        }
                    }
                }
                catch
                {
                    ret = "falha - não foi possivel baixar o log, execute um diagnóstico e tente novamente";
                }
            }
            Program.loging = false;
            return(ret);
        }