예제 #1
0
파일: ERunner.cs 프로젝트: FVillaf/cf.net
        /// <summary>
        /// Ejecuta un comando mientras verifica errores, etc.
        /// </summary>
        ///
        /// <param name="cmd">El comando a ejecutar</param>
        /// <returns><b>true</b> si todo salió bien.</returns>
        bool ExecCommand(CMD_Generic cmd)
        {
            var mo = proto.ExchangePacket(cmd);

            if (mo == null)
            {
                errorShow(proto.LastError ?? "Error de Comunicación");
                return(false);
            }
            if (mo.ErrorCodeInt != 0)
            {
                errorShow($"Error {mo.ErrorCode} - '{mo.Error}'");
                return(false);
            }
            return(true);
        }
예제 #2
0
        private void CommonDoWork(ProtoHandler proto, CMD_Generic start, Func <CMD_Generic, string> getFileName)
        {
            StringBuilder data = new StringBuilder();

            try
            {
                // Lanza la descarga.
                var mo = proto.ExchangePacket(start);
                if (mo == null || mo.ErrorCodeInt != 0)
                {
                    string msg =
                        (start as CMD_DNL_RangoFechas)?.Output.ErrorCode ??
                        (start as CMD_DNL_RangoZetas)?.Output.ErrorCode ??
                        "<Error Desconocido>";

                    Console.WriteLine($"ERROR: '{msg}'");
                    return;
                }

                // Lazo de descarga
                int prog = 0;
                Console.Write("Descargando: ");
                while (true)
                {
                    mo = proto.ExchangePacket(gloop);
                    if (mo.ErrorCodeInt != 0)
                    {
                        throw new Exception(mo.Error);
                    }
                    data.Append(gloop.Output.Data);
                    if (!gloop.Output.Continua)
                    {
                        break;
                    }

                    if (prog++ == 5)
                    {
                        Console.Write("\b\b\b\b\b     \b\b\b\b\b");
                        prog = 0;
                    }
                    else
                    {
                        Console.Write(".");
                    }
                }

                // Finaliza
                proto.ExchangePacket(end);
                var fn = Path.Combine(carpeta, getFileName(start));
                Console.Write($"\r                         \r==> '{ShortPath(fn)}'\n");
                File.WriteAllText(fn, data.ToString());
                if (decrypt)
                {
                    var xml = Path.ChangeExtension(fn, "xml");
                    Console.WriteLine($" Decrypt  '{ShortPath(fn)}' => '{ShortPath(xml)}");
                    DecryptPEMFile(fn);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR - '{ex.Message}'");
                try
                {
                    proto.ExchangePacket(canc);
                }
                catch { }
            }
        }