miércoles, 23 de diciembre de 2015

orden especifico de listas

Lista de como deben ir los ids

 List<String> preferencias = new List<String> {"", "L", "K", "M", "J", "V", "S", "D", "T" };


Lista a ordenar

 resultado = resultado.OrderBy(item => preferencias.IndexOf(item.Codigo)).ToList();

viernes, 4 de diciembre de 2015

Obtener IP




 public static string obtenerIP()
        {
            string ip = null;
            string strHostName = null;
            IPHostEntry ipEntry = default(IPHostEntry);
            strHostName = System.Net.Dns.GetHostName();
         
            ipEntry = System.Net.Dns.GetHostEntry(strHostName);
            ip = "";

            try
            {

                if ((ipEntry.AddressList == null | ipEntry.AddressList.Count() == 0))
                {
                    ip = "No obtenida";
                }
                else
                {
                    ip = ipEntry.AddressList.Where(x => x.ToString().Contains(".")).FirstOrDefault().ToString();

                    if ((ip.Equals("")))
                    {

                        if ((ipEntry.AddressList.Count() > 2))
                        {
                            ip = ipEntry.AddressList[2].ToString();
                        }
                        else if ((ipEntry.AddressList.Count() <= 2))
                        {
                            ip = ipEntry.AddressList[1].ToString();
                        }
                    }
                }
            }
            catch (Exception)
            {
                ip = "No obtenida";
            }
            return ip;
        }


//Fuente no recordada.