Ejemplo n.º 1
0
        public void ReceiveEmailData()
        {
            //54b89f4ec0311af3c7c74bd8d5a5089a

              IridiumExtremeBinaryReport report = new IridiumExtremeBinaryReport();
              //byte[] bytes = HexAscii.ConvertToBytes("6504AE00067DDC23EB920016A290CC9D2BEE801036000A1005200C4025BEEE11F46E01808A809BC566517A2C3A875910334C6FCD682E1B6C4683C140A8399D6C07C16032580AC47CBB5BB01ACE35B3D968B8190835A793ED20184C464B81826C3A68158381DA20D49C4EB68360B0D92D053A42A7A079983E07C16820192C366BC5642D180D14ABE968B32A75081286E974102E560255E76539881D769F416537685A76D341F674189494A7C9E97A1B");

              //string path = @"C:\Users\jcorrales\Documents\Visual Studio 2008\Projects\IridiumExtreme\IridiumExtreme\bin\Debug\300215010900550_000007.sbd";
              string path = @"C:\Users\jcorrales\Desktop\300215010900550_000005.sbd";
              byte[] fileBytes = File.ReadAllBytes(path);
              string hex = BitConverter.ToString(fileBytes).Replace("-", string.Empty);
              byte[] bytes = HexAscii.ConvertToBytes(hex);
              //StringBuilder sb = new StringBuilder();
              //foreach (byte b in fileBytes)
              //{
              //  sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
              //}
              //string imei = "309015010008060";

              string imei = "300215010568090";
              Encoding unicode = Encoding.Unicode;
              Encoding utf8 = Encoding.UTF8;
              byte[] imeib = GetBytes(imei);
              imeib = Encoding.Convert(unicode, utf8, imeib);
              crc_32c hash = new crc_32c();
              uint hashvar = hash.toHash2(imeib, imeib.Length);

              if (IridiumExtremeBinaryReport.TryParse(bytes, "300215010568090", out report, "MO"))
              {
            inserts.Add(report.ToInsertSQL(true, "MESSAGE_INBOX"));
              }
        }
Ejemplo n.º 2
0
        public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_CannedMessageIdentifier cannedMessageIdentifier)
        {
            bool reslt = false;
              cannedMessageIdentifier = new DataBlock_CannedMessageIdentifier();

              try
              {
            int offset = baseoffset;
            net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff);

            cannedMessageIdentifier.blockType = stream.GetUint(offset, BlockTypeLen);

            cannedMessageIdentifier.BlockType = (ICDBlockType)cannedMessageIdentifier.blockType;
            offset += BlockTypeLen;

            cannedMessageIdentifier.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen);
            offset += BlockLengthIndicatorLen;

            if (cannedMessageIdentifier.BlockLengthIndicator == 0)
            {
              cannedMessageIdentifier.BlockLengthBytes = stream.GetUint(offset, ICDDataBlock.BlockLengthBytesLen);
              offset += BlockLengthBytesLen;
            }
            else
            {
              cannedMessageIdentifier.BlockLengthBytes = stream.GetUint(offset, BlockLengthExtendedBytesLen);
              offset += BlockLengthExtendedBytesLen;
            }
            cannedMessageIdentifier.CannedMessageNumber = stream.GetUint(offset, CannedMessageNumberLen);
            offset += CannedMessageNumberLen;

            cannedMessageIdentifier.cannedMessageCRC = stream.GetUint(offset, CannedMessageCRCLen);
            offset += CannedMessageCRCLen;

            try
            {
              Encoding unicode = Encoding.Unicode;
              Encoding utf8 = Encoding.UTF8;
              string s = "I have achieved my objective";
              //string s = "123456789";
              //var barray = GsmUtils.ToGSM7BitPacked(s);
             // byte[] array = HexAscii.ConvertToBytes(barray);

              byte[] array = HexAscii.ConvertToBytes("1C49103A6C2F83C26374BA6C2F9341ED3CE82D5697C7F4B4BD0C");
              //byte[] barray = GetBytes(s);

              //1C49103A6C2F83C26374BA6C2F9341ED3CE82D5697C7F4B4BD0C
              crc_32c crc32 = new crc_32c();
              uint crcVar = 0;
              /*ASCII*/
              //array = Encoding.Convert(unicode, utf8, array);
              crcVar = crc32.crc_32c_init();
              crcVar = crc32.crc_32c_update(array, array.Length, crcVar);
              crcVar = crc32.crc_32c_finalize(crcVar);
              /*UTF-16*/
              //array = Encoding.Convert(unicode, utf8, array);
              //crcVar = crc32.crc_32c_init();
              //crcVar = crc32.crc_32c_update_UTF_16(array, array.Length, crcVar);
              //crcVar = crc32.crc_32c_finalize(crcVar);

              //CRC (ASCII): 0xe3069283
              //CRC (UTF-16): 0x9d7b210c
              string imei = "300015010444890";
              byte[] imeib = GetBytes(imei);
              imeib = Encoding.Convert(unicode, utf8, imeib);

              crc_32c hash = new crc_32c();
              uint hashvar = hash.toHash2(imeib, imeib.Length);
            }
            catch (Exception e) { }

            reslt = true;
              }
              catch (Exception ex) { reslt = false; }

              return reslt;
        }
        public ActionResult Login()
        {
            //user_name=userapi
            //password=T3s@m321
            //contentType=json

            //http://vdms5.tesacom.net/abm/abm_equipos.php
            //oper=exists
            //ESN=123123123123
            //contentType=json

            //http://vdms5.tesacom.net/abm/abm_equipos.php
            //oper=add
            //TipoEQP=10004
            //ESN=123123123123
            //IMSI=123123123123
            //contentType=json
            try {
                if (Session["Logueado"] != null) {

                    if (Session["Logueado"].ToString() == "True")
                    {
                        string imei = "";//"300215010568090";
                        uint phoneCode = 0;
                        uint hashvar1 = 0;
                        uint hashvar2 = 0;
                        Encoding unicode = Encoding.Unicode;
                        Encoding utf8 = Encoding.UTF8;
                        crc_32c hash = new crc_32c();
                        if (Request.Form["Imei"] != null && Request.Form["PhoneCode"] != null)
                        {
                            imei = Request.Form["Imei"].ToString();
                            string insertImei = String.Format("IE{0}", imei);
                            phoneCode = Convert.ToUInt32(Request.Form["PhoneCode"]);
                            byte[] imeib = GetBytes(imei);
                            imeib = Encoding.Convert(unicode, utf8, imeib);
                            hashvar1 = hash.toHash1(imeib, imeib.Length);

                            if (hashvar1 == phoneCode)
                            {
                                hashvar2 = hash.toHash2(imeib, imeib.Length);
                                //POST("http://vdms5.tesacom.net/abm/abm_equipos.php", JsonConvert.SerializeObject(json));
                                string oper = "exists";
                                int tipoEq = 10004;
                                string result = "";

                                string loginState = GET("http://vdms5.tesacom.net/login.php?user_name=userapi&password=T3s@m321");

                                string url = String.Format("http://vdms5.tesacom.net/abm/abm_equipos.php?oper={0}&ESN={1}&contentType=json",oper,insertImei);
                                string jsonExists = GET(url);
                                try
                                {
                                    JObject jsonData = new JObject();
                                    jsonData = JObject.Parse(jsonExists);
                                    foreach (JProperty jsonProperty in jsonData.Children().ToList())
                                    {
                                        if (jsonProperty.Name.ToString() == "success")
                                        {
                                            result = jsonProperty.Value.ToString();
                                            logs.Add(string.Format("Se consultó si existía el equipo con IMEI{0} y el resultado es success:{1}", insertImei, jsonProperty.Value.ToString()));
                                            logs = saveLogs(logs);
                                        }
                                    }
                                }
                                catch (Exception ex) { }
                                 if (result == "false")
                                 {
                                     oper = "add";
                                     loginState = GET("http://vdms5.tesacom.net/login.php?user_name=userapi&password=T3s@m321");

                                     url = String.Format("http://vdms5.tesacom.net/abm/abm_equipos.php?oper={0}&TipoEQP={1}&ESN={2}&IMSI={3}&contentType=json", oper, tipoEq, insertImei, insertImei);

                                     string jsonAddEquip = GET(url);
                                     try
                                     {
                                         JObject jsonData = new JObject();
                                         jsonData = JObject.Parse(jsonAddEquip);
                                         foreach (JProperty jsonProperty in jsonData.Children().ToList())
                                         {
                                             if (jsonProperty.Name.ToString() == "success")
                                             {
                                                 logs.Add(string.Format("El alta del equipo con IMEI{0} se ha efectuado con el siguiente resultado success:{1}",insertImei,jsonProperty.Value.ToString()));
                                                 logs = saveLogs(logs);
                                             }

                                         }
                                     }
                                     catch (Exception ex) { }

                                     ViewData["Estado"] = "OK";
                                     ViewData["Validar"] = String.Format("Portal Code :: {0}. Enter this number into your phone to complete the registration.", hashvar2);
                                 }
                                 else {
                                     ViewData["Estado"] = "";
                                     ViewData["Validar"] = String.Format("Error :: The handset with the IMEI{0} is already registered.",imei);
                                 }

                            }
                            else
                            {
                                ViewData["Validar"] = "Error :: Please enter a valid Phone Code.";
                                ViewData["Estado"] = "";
                            }

                        }
                        else
                        {
                            ViewData["Validar"] = "Error :: Please enter a valid Imei and Phone Code.";
                            ViewData["Estado"] = "";
                        }
                    }
                    else
                    {
                        ViewData["Validar"] = "Error :: You must be logged to register the handset.";
                        ViewData["Estado"] = "";
                        logs.Add(string.Format("El usuarioapi no se logueo success:{0}", Session["Logueado"].ToString()));
                        logs = saveLogs(logs);
                    }
                }
                else
                {
                    ViewData["Validar"] = "Error :: You must be logged to register the handset.";
                    ViewData["Estado"] = "";
                    logs.Add(string.Format("El usuarioapi no se logueo session null"));
                    logs = saveLogs(logs);
                }

            }
            catch (Exception ex) {

            }
            return View("Index");
        }
        public ActionResult Login()
        {
            //user_name=userapi
            //password=T3s@m321
            //contentType=json

            //http://vdms.tesacom.net/abm/abm_equipos.php
            //oper=exists
            //ESN=123123123123
            //contentType=json

            //http://vdms.tesacom.net/abm/abm_equipos.php
            //oper=add
            //TipoEQP=10004
            //ESN=123123123123
            //IMSI=123123123123
            //contentType=json
            try {
                if (Session["Logueado"] != null) {

                    if (Session["Logueado"].ToString() == "True")
                    {
                        string imei = "";//"300215010568090";
                        int idProyecto = 0;
                        uint phoneCode = 0;
                        uint hashvar1 = 0;
                        uint hashvar2 = 0;
                        Encoding unicode = Encoding.Unicode;
                        Encoding utf8 = Encoding.UTF8;
                        crc_32c hash = new crc_32c();
                        if (Request.Form["Imei"] != null && Request.Form["PhoneCode"] != null && Request.Form["Imei"] != "" && Request.Form["PhoneCode"] != "" && Regex.IsMatch(Request.Form["Imei"], "^[0-9]*$") == true && Regex.IsMatch(Request.Form["PhoneCode"], "^[0-9]*$") == true)
                        {
                            imei = Request.Form["Imei"].ToString();

                            idProyecto = Convert.ToInt32(Request.Form["idProyecto"]); //DESPUES DESCOMENTALOOOOOOOOOOOOOOOOO

                            string insertImei = String.Format("IE{0}", imei);
                            phoneCode = Convert.ToUInt32(Request.Form["PhoneCode"]);
                            byte[] imeib = GetBytes(imei);
                            imeib = Encoding.Convert(unicode, utf8, imeib);
                            hashvar1 = hash.toHash1(imeib, imeib.Length);

                            if (hashvar1 == phoneCode)
                            {
                                hashvar2 = hash.toHash2(imeib, imeib.Length);
                                //POST("http://vdms.tesacom.net/abm/abm_equipos.php", JsonConvert.SerializeObject(json));
                                string oper = "exists";
                                int tipoEq = 10004;
                                string result = "";

                                string loginState = GET("http://vdms.tesacom.net/login.php?user_name=userapi&password=T3s@m321");

                                string url = String.Format("http://vdms.tesacom.net/abm/abm_equipos.php?oper={0}&ESN={1}&contentType=json",oper,insertImei);
                                string jsonExists = GET(url);
                                try
                                {
                                    JObject jsonData = new JObject();
                                    jsonData = JObject.Parse(jsonExists);
                                    foreach (JProperty jsonProperty in jsonData.Children().ToList())
                                    {
                                        if (jsonProperty.Name.ToString() == "success")
                                        {
                                            result = jsonProperty.Value.ToString();
                                            logs.Add(string.Format("Se consultó si existía el equipo con IMEI{0} y el resultado es success:{1}", insertImei, jsonProperty.Value.ToString()));
                                            logs = saveLogs(logs);
                                        }
                                    }
                                }
                                catch (Exception ex) { }
                                 if (result == "false")
                                 {
                                     oper = "add";
                                     loginState = GET("http://vdms.tesacom.net/login.php?user_name=userapi&password=T3s@m321");

                                     url = String.Format("http://vdms.tesacom.net/abm/abm_equipos.php?oper={0}&TipoEQP={1}&ESN={2}&IMSI={3}&idProyecto={4}&contentType=json", oper, tipoEq, insertImei, insertImei, idProyecto);

                                     string jsonAddEquip = GET(url);
                                     try
                                     {
                                         JObject jsonData = new JObject();
                                         jsonData = JObject.Parse(jsonAddEquip);
                                         foreach (JProperty jsonProperty in jsonData.Children().ToList())
                                         {
                                             if (jsonProperty.Name.ToString() == "success")
                                             {
                                                 logs.Add(string.Format("El alta del equipo con IMEI{0} se ha efectuado con el siguiente resultado success:{1}",insertImei,jsonProperty.Value.ToString()));
                                                 logs = saveLogs(logs);
                                             }
                                         }
                                     }
                                     catch (Exception ex) { }

                                     string dir = System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);//System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                                     if (net.Tesacom.IridiumExtremeUtilities.IridiumToMySQL.SendPortalStatusToHandset(imei, dir))
                                      {
                                          logs.Add("Se envio correctamente el email de Portal Status message");
                                          logs = saveLogs(logs);
                                      }
                                      else
                                      {
                                          logs.Add("No se envio el email de Portal Status message");
                                          logs = saveLogs(logs);
                                      }
                                     ViewData["Estado"] = "OK";
                                     ViewData["Validar"] = String.Format("Código del portal : {0}. Ingrese este número en su teléfono para completar la registración.", hashvar2);
                                 }
                                 else {

                                     ViewData["Estado"] = "";
                                     ViewData["Validar"] = String.Format("El equipo con IMEI{0} ya se encuentra registrado y su portal code es: {1}, debe ingresar otro.",imei,hashvar2);
                                 }

                            }
                            else
                            {
                                ViewData["Validar"] = "Por favor ingrese un Phone Code válido.";
                                ViewData["Estado"] = "";
                            }

                        }
                        else
                        {
                            ViewData["Validar"] = "Por favor ingrese un Imei y Phone Code válido.";
                            ViewData["Estado"] = "";
                        }
                    }
                    else
                    {
                        ViewData["Validar"] = "Se ha producido un error por favor actualice la página e intente nuevamente.";
                        ViewData["Estado"] = "";
                        logs.Add(string.Format("El usuarioapi no se logueo success:{0}", Session["Logueado"].ToString()));
                        logs = saveLogs(logs);
                    }
                }
                else
                {
                    ViewData["Validar"] = "Se ha producido un error por favor actualice la página e intente nuevamente.";
                    ViewData["Estado"] = "";
                    logs.Add(string.Format("El usuarioapi no se logueo session null"));
                    logs = saveLogs(logs);
                }

            }
            catch (Exception ex) {
                ViewData["Validar"] = "Por favor ingrese un Imei y Phone Code válido.";
                ViewData["Estado"] = "";
            }
            return View("Index");
        }