public AjaxDictionary<string, object> Get_CatUrl()
        {
            AjaxDictionary<string, object> result = new AjaxDictionary<string, object>();
            try
            {
                using (var entity = new db_SeguimientoProtocolo_r2Entities())
                {
                    //entity.wappSpAttemptLogUser("", "", true).ToList();
                    List<spGetHashablePuntoMedicion_Result> res = entity.spGetHashablePuntoMedicion().ToList();

                    int i = 0;
                    (from s in entity.CAT_LINKS
                     where s.IsActive == true
                     select s).ToList().ForEach(row =>
                     {
                         AjaxDictionary<string, object> item = new AjaxDictionary<string, object>();
                         item.Add("idUrl", row.IdLink);
                         item.Add("Url", row.LinkUrl);
                         item.Add("IsActive", row.IsActive);
                         item.Add("DescriptionUrl", row.LinkName);
                         result.Add("Result" + i.ToString(),item);
                         i++;
                     });
                }
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }
            return result;
        }
    public void AddTest()
    {
        var myTest = new AjaxDictionary <int, string>();

        myTest.Add(1, "test");
        Assert.AreEqual(1, myTest.GetList().Count);
    }
 public AjaxDictionary<string, object> GetNivelLluvia()
 {
     AjaxDictionary<string, object> res = new AjaxDictionary<string, object>();
     try
     {
         using (var entity=new db_SeguimientoProtocolo_r2Entities())
         {
             (from s in entity.CAT_NIVEL_LLUVIA
              where s.IsActive == true
              select s).ToList().ForEach(i =>
              {
                  AjaxDictionary<string, object> tmp = new AjaxDictionary<string, object>();
                  tmp.Add("idNivel", i.IdNivelLluvia);
                  tmp.Add("rangoMax", i.RangMax);
                  tmp.Add("rangoMin", i.RangoMin);
                  tmp.Add("intensidadName", i.IntensidadName);
                  tmp.Add("imagen", i.Imagen);
                  res.Add("N" + i.RangoMin + "_" + i.RangMax, tmp);
              });
         }
     }
     catch (Exception ex)
     {
     }
     return res;
 }
        public void GetHashableGraficaPuntoMedicionTest()
        {
            HashableDataRepository r = new HashableDataRepository();
            AjaxDictionary<string, object> tipo = new AjaxDictionary<string, object>();

            tipo = r.GetHashableGraficaLumbreras(201405151704);
            tipo = new AjaxDictionary<string, object>(); ;
            //r.GetHashableGraficaPuntoMedicion(1002, 201406111219);
        }
    public void GetListTest()
    {
        var myTest = new AjaxDictionary <int, string>();

        myTest.Add(1, "one");
        myTest.Add(2, "two");
        var myResult = myTest.GetList().FirstOrDefault();

        Assert.AreEqual("1 - one", myResult);
    }
        public void Download_HashablePuntosMedicionOrderZonaTest()
        {
            AjaxDictionary<string, object> tipos = null;
            try
            {
                tipos = (new HashableDataRepository()).GetPuntosMedicionOrdenZona();
            }
            catch (Exception ex)
            {

                tipos = new AjaxDictionary<string, object>();
                tipos.Add("Error", (object)ex.InnerException);
            }
        }
        public AjaxDictionary<string, object> GetHashableGraficaLumbreras(long FechaNumerica)
        {
            AjaxDictionary<string, object> tipo = new AjaxDictionary<string, object>();
            AjaxDictionary<string, object> punto = new AjaxDictionary<string, object>();
            AjaxDictionary<string, object> datos = new AjaxDictionary<string, object>();
            long IdPuntoMedicion = -1;
            try
            {
                using (var entity=new db_SeguimientoProtocolo_r2Entities())
                {
                    List<spGetHashableGraficaLumbreras_Result> items = entity.spGetHashableGraficaLumbreras(FechaNumerica).ToList();
                    try
                    {
                        if (items != null && items.Count > 0)
                        {
                            foreach (spGetHashableGraficaLumbreras_Result i in items)
                            {
                                bool x = false;
                                if (IdPuntoMedicion != i.IdPuntoMedicion)
                                {
                                    IdPuntoMedicion = i.IdPuntoMedicion;
                                    punto.Add(toStrIdPm(i.IdPuntoMedicion), new AjaxDictionary<string, object>());
                                    x = true;
                                }
                                if (x)
                                {
                                    datos = new AjaxDictionary<string, object>();
                                }
                                datos.Add("F" + i.FechaNumerica, i.Valor);
                                punto[toStrIdPm(i.IdPuntoMedicion)] = datos;
                            }
                            tipo.Add("t1", punto);
                        }
                    }
                    catch (Exception)
                    {
                        ;
                    }
                }
            }
            catch (Exception)
            {

            }
            return tipo;
        }
    public void AddTest_Duplicate()
    {
        var myTest = new AjaxDictionary <int, string>();

        myTest.Add(1, "test");
        myTest[2] = "test";
        myTest.Add(3, "initial");

        var tempDic = new Dictionary <int, string>();

        tempDic.Add(3, "test3");
        tempDic.Add(4, "test4");
        myTest.Add(tempDic);

        myTest.Add(1, "test1");
        myTest[2] = "test2";

        Assert.AreEqual("test1", myTest[1]);
        Assert.AreEqual("test2", myTest[2]);
        Assert.AreEqual("test3", myTest[3]);
        Assert.AreEqual("test4", myTest[4]);
    }
        public AjaxDictionary<string, object> GetCatRegion()
        {
            AjaxDictionary<string, object> result = new AjaxDictionary<string, object>();
            try
            {
                using (var entity=new db_SeguimientoProtocolo_r2Entities())
                {
                    (from s in entity.CAT_REGION
                     select s).ToList().ForEach(row =>
                     {
                         AjaxDictionary<string, object> item = new AjaxDictionary<string, object>();
                         item.Add("idRegion", row.IdRegion);
                         item.Add("RegionName", row.RegionName);
                         item.Add("fileName", row.FileName);
                         result.Add("R" + row.IdRegion, item);
                     });
                }
            }
            catch (Exception)
            {

            }
            return result;
        }
        public AjaxDictionary<string, object> Download_IsopFiles_5min(long FechaNumerica)
        {
            AjaxDictionary<string, object> dictionaryFiles = new AjaxDictionary<string, object>();
            try
            {
                string rootDirectory = this.GetHostedRootDirectory5min();
                HashableDataRepository repository = new HashableDataRepository();
                dictionaryFiles = repository.GetIsopFileList_5min(FechaNumerica, rootDirectory);
            }
            catch (Exception ex)
            {
                ServerSQLLogger.Instance.log(ex, "Download_IsopFiles_5min (c1)");
                //throw ex;
            }

            return dictionaryFiles;
        }
        public AjaxDictionary<string, object> Download_HashablePuntosMedicionOrderZona()
        {
            AjaxDictionary<string, object> tipos = null;
            try
            {
                tipos = (new HashableDataRepository()).GetPuntosMedicionOrdenZona();
            }
            catch (Exception ex)
            {

                tipos = new AjaxDictionary<string,object>();
                tipos.Add("Error", (object)ex.Message);
            }

            return tipos;
        }
 public AjaxDictionary<string, object> Download_Get_CatUrls()
 {
     AjaxDictionary<string, object> res = new AjaxDictionary<string, object>();
     try
     {
         using (var repository = new CatUrlRepository())
         {
             res = repository.Get_CatUrl();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("IMC_ERR_MSG:", ex);
     }
     return res;
 }
        //AjaxDictionary<string, List<HashableGraficaPuntoMedicionModel>>
        public AjaxDictionary<string, object> Download_GetHashableGraficaPuntoMedicion(long IdPuntoMedicion, long FechaNumerica)
        {
            AjaxDictionary<string, object> tipos = new AjaxDictionary<string, object>();
            AjaxDictionary<string, List<HashableGraficaPuntoMedicionModel>> res = new AjaxDictionary<string, List<HashableGraficaPuntoMedicionModel>>();
            AjaxDictionary<string, HashableGraficaPuntoMedicionModel[]> array = new AjaxDictionary<string, HashableGraficaPuntoMedicionModel[]>();
            //try
            //{

            //    HashableDataRepository repository = new HashableDataRepository();
            //    //tipos.Add(IdPuntoMedicion.ToString(), FechaNumerica);
            //    array = repository.GetHashableGraficaPuntoMedicion(IdPuntoMedicion, FechaNumerica);//(new HashableDataRepository()).GetHashableGraficaPuntoMedicion((long)IdPuntoMedicion, (long)FechaNumerica);
            //}
            //catch (Exception ex)
            //{
            //    tipos.Add("Download", ex.Message);
            //}
            try
            {
                //array.Add("res", new HashableGraficaPuntoMedicionModel[] { new HashableGraficaPuntoMedicionModel() { FechaNumerica = 1, Valor = 1 } });
                HashableDataRepository repository = new HashableDataRepository();
                tipos = repository.GetHstTableGraficaPuntoMedicion(IdPuntoMedicion, FechaNumerica);
            }
            catch (Exception ex)
            {
                tipos.Add("Download", ex.Message);
            }

            return tipos;
        }
 public AjaxDictionary<string, object> Download_GetHashableGraficaPromedioPesado(long FechaNumerica)
 {
     AjaxDictionary<string, object> tipos = new AjaxDictionary<string, object>();
     try
     {
         HashableDataRepository repository = new HashableDataRepository();
         tipos = repository.GetHshableGraficaPromedioPesado(FechaNumerica);
     }
     catch (Exception ex)
     {
         var error = ex.Message;
     }
     return tipos;
 }
        public AjaxDictionary<string, object> GetPuntosMedicionOrdenZona()
        {
            AjaxDictionary<string, object> tipos = null;
            long tipopmSentinel = -1;

            using (var entity = new db_SeguimientoProtocolo_r2Entities())
            {
                List<spGetHashablePuntoMedicionOrderZonaTipo_Result1> res = entity.spGetHashablePuntoMedicionOrderZonaTipoS().ToList();

                if (res != null && res.Count > 0)
                {
                    tipos = new AjaxDictionary<string, object>();
                    foreach (spGetHashablePuntoMedicionOrderZonaTipo_Result1 r in res)
                    {
                        if (tipopmSentinel != r.IdTipoPuntoMedicion)
                        {
                            tipopmSentinel = (long)r.IdTipoPuntoMedicion;
                            tipos.Add(this.toStrIdTipoPm(tipopmSentinel), new AjaxDictionary<string, object>());
                        }

                        AjaxDictionary<string, object> attrs = new AjaxDictionary<string, object>();
                        string ultAct = r.ultimaActualización.ToString();
                        if (ultAct.Length >= 12)
                        {
                            ultAct = ultAct.Substring(0, 12);
                        }

                        attrs.Add("puntoMedicionName", r.PuntoMedicionName);
                        attrs.Add("lat", r.latiitud);
                        attrs.Add("long", r.longitud);
                        attrs.Add("idTipoPm", r.IdTipoPuntoMedicion);
                        attrs.Add("idPm", r.IdPuntoMedicion);
                        attrs.Add("dependencias", r.dependencias);
                        attrs.Add("parametroMed", r.ParametroMedicion);
                        attrs.Add("unidadMedida", r.UnidadMedidaName);
                        attrs.Add("unidadMedidaShort", r.UnidadMedidaShort);
                        attrs.Add("sistema", r.SistemaName);
                        attrs.Add("ultimaActualizacion", ultAct);
                        attrs.Add("ultimaCond", r.UltimaCondicion);
                        attrs.Add("IdZona", r.IdZona);

                        this.toDictio(tipos, tipopmSentinel).Add(toStrIdPm(r.IdPuntoMedicion), attrs);

                    }//endforeach
                }//endif
            }//endusing

            return tipos;
        }
        public AjaxDictionary<string, object> GetIsopFileListV1(long FechaNumerica, string rootDirectory)
        {
            DateTime fecha=this.ConvertFechaNumericaToDatetime(FechaNumerica); //convertir la fecha numerica a dateitme
            int minutesThreshold=this.GetIsopMinutesThresholdSetting(); //obtener el setting
            DateTime fechaMin = fecha.AddMinutes(-1 * minutesThreshold); //En base al setting generar la fecha minima
            AjaxDictionary<string, object> dictioFiles = new AjaxDictionary<string, object>(); //diccionario de retorno de la funcion

            if(!String.IsNullOrEmpty(rootDirectory))
            {
                long longFechaMin=this.ConvertDatetimeToFechaNumerica(fechaMin);

                ServerSQLLogger.Instance.log("Rango de tiempo : " + longFechaMin.ToString(), "GetIsopFileList(0)");

                ServerSQLLogger.Instance.log("Isoyetas path : " + Path.Combine(rootDirectory, ISOP_DIRECTORY).ToString(), "GetIsopFileList(1)");

                //TODO: Optimizar para que solo se obtengan los archivos que estén en el rango de fechas
                List<string> list= Directory.GetFiles(Path.Combine(rootDirectory, ISOP_DIRECTORY), "isop*.kml").ToList<string>();

                ServerSQLLogger.Instance.log("Archivos en directory "+list.Count().ToString(), "GetIsopFileList(2)");

                string [] filesArray = (from o in list
                                      where Int64.Parse(o.Split('_')[1]) >= longFechaMin && Int64.Parse(o.Split('_')[1]) <= FechaNumerica
                                      select o).ToArray<string>();

                if(filesArray.Length==0)
                {
                    dictioFiles.Add("t0", "0");
                    return dictioFiles;
                }

                Array.Sort(filesArray);

                ServerSQLLogger.Instance.log("Array despues de filtro : " + filesArray.Length.ToString(), "GetIsopFileList(4)");

                /*
                long dictioEntrySentinel = this.GetFechaNumericaFromFileName(filesArray.First());
                //AjaxDictionary<string, string> fileNamesByLevel = new AjaxDictionary<string,string>();
                foreach(string s in filesArray)
                {
                    long fileDate = Int64.Parse( s.Split('_')[1] );

                    if(dictioEntrySentinel!=fileDate)
                    {
                        dictioFiles.Add("t" + fileDate.ToString(), fileNamesByLevel);
                        fileNamesByLevel = new AjaxDictionary<string, string>();
                    }
                    else
                    {
                        string level = this.GetLevelFromFileName(s);
                        fileNamesByLevel.Add("l" + level, s);
                    }
                }//endforeach
                */

                //metodo2:
                AjaxDictionary<string, object> fileNamesByLevel = new AjaxDictionary<string, object>();
                DateTime filesMinDate= this.ConvertFechaNumericaToDatetime(  this.GetFechaNumericaFromFileName(filesArray.First())  ) ;
                while(filesMinDate<fecha)
                {
                    //obtener los archivos que correspondan a esta fecha
                    var res = (from o in filesArray
                               where Int64.Parse(o.Split('_')[1]) == this.ConvertDatetimeToFechaNumerica(filesMinDate)
                               select o).ToArray<string>();

                    if(res!=null && res.Length>0)
                    {
                        Array.Sort(res);
                        fileNamesByLevel = new AjaxDictionary<string, object>();

                        //Recorrer para agregar entradas
                        foreach (string s in res)
                        {
                            string level = this.GetLevelFromFileName(s);
                            fileNamesByLevel.Add("l" + level, s.Split('\\').Last());
                            ServerSQLLogger.Instance.log("Archivo : " + s, "GetIsopFileList(5)");
                        }
                    }//endif
                    else
                    {
                        //Si es nulo quiere decir que no hay archivo para ese minuto, se tomará el anterior
                    }

                    //Agregar al diccionario
                    dictioFiles.Add("t" + this.ConvertDatetimeToFechaNumerica(filesMinDate).ToString(), fileNamesByLevel);

                    filesMinDate=filesMinDate.AddMinutes(1);
                }//endwhile

            }
            else
            {
                throw new Exception("IMC_ERROR: [GetIsopFileList] La ruta rootDirectory no puede estar vacia");
            }

            return dictioFiles;
        }
        public AjaxDictionary<string, object> GetIsopFileList_5min(long FechaNumerica, string rootDirectory)
        {
            //Control de tiempo
            DateTime iniDate = DateTime.Now;
            DateTime endDate = DateTime.Now;
            TimeSpan diff = endDate - iniDate;

            int minutesThreshold = this.GetIsopMinutesThresholdSetting5min(); //obtener el setting

            DateTime fecha = this.ConvertFechaNumericaToDatetime(FechaNumerica); //convertir la fecha numerica a dateitme
            DateTime fechaMin = fecha.AddMinutes(-1 * minutesThreshold); //En base al setting generar la fecha minima (restando minutos

            AjaxDictionary<string, object> levelByFn = new AjaxDictionary<string, object>(); //valor de retorno

            if (!String.IsNullOrEmpty(rootDirectory))//Si existe el folder...
            {
                long longFechaMin = this.ConvertDatetimeToFechaNumerica(fechaMin);

                ServerSQLLogger.Instance.log("Rango de tiempo : " + longFechaMin.ToString(), "GetIsopFileList_5min(0)");
                ServerSQLLogger.Instance.log("Isoyetas path : " + Path.Combine(rootDirectory, ISOP_DIRECTORY5min).ToString(), "GetIsopFileList_5min(1)");

                //TODO: Optimizar para que solo se obtengan los archivos que estén en el rango de fechas
                List<string> isopFiles = Directory.GetFiles(Path.Combine(rootDirectory, ISOP_DIRECTORY5min), "iso5*.kml").ToList<string>();

                ServerSQLLogger.Instance.log("Archivos en directory " + isopFiles.Count().ToString(), "GetIsopFileList_5min(2)");

                AjaxDictionary<string, object> isopFileByLevel = new AjaxDictionary<string, object>();
                Dictionary<string, string[]> arraysByLevel = new Dictionary<string, string[]>();

                List<string> ranges = new List<string>() { "8", "15", "30", "1000" };

                //Llenar subarrays por nivel
                string strFechaNumericaNew = String.Format("{0:yyyyMMddHHmm}", fecha);
                string strFechaNumericaOld = String.Format("{0:yyyyMMddHHmm}", fechaMin);
                string[] tmpStrArray;
                foreach (string range in ranges)
                {
                    this.GetLastIsopFile(
                        strFechaNumericaNew
                        , strFechaNumericaOld
                        , range
                        , isopFiles
                        , out tmpStrArray
                    );

                    arraysByLevel.Add(range, tmpStrArray); //agregar al diccionario
                }//endFech

                //Iniciar ciclo para cada uno de los minutos entre los rangos
                DateTime loopDate = fechaMin;
                while (loopDate <= fecha)
                {
                    isopFileByLevel = new AjaxDictionary<string, object>();
                    foreach (string range in ranges)//para cada uno de los rangos
                    {
                        string[] tmp = arraysByLevel[range];
                        if (tmp != null)
                        {
                            string tmpIsopLastFile = this.GetLastIsopFile(String.Format("{0:yyyyMMddHHmm}", loopDate), range, arraysByLevel[range].ToList<string>());
                            if (!String.IsNullOrEmpty(tmpIsopLastFile))
                            {
                                isopFileByLevel.Add("l" + range, tmpIsopLastFile.Split('\\').Last());
                            }
                            else
                            {
                                isopFileByLevel.Add("l" + range, "");
                            }

                        }
                        else
                        {
                            isopFileByLevel.Add("l" + range, "");
                        }
                    }//endFech

                    levelByFn.Add("t" + String.Format("{0:yyyyMMddHHmm}", loopDate), isopFileByLevel);

                    loopDate = loopDate.AddMinutes(1);
                }//endWhile

                endDate = DateTime.Now;
                diff = endDate - iniDate;
                System.Diagnostics.Debug.Write("Subarrays method resList : " + diff.Minutes.ToString() + "." + diff.Seconds.ToString());
            }//endIf
            else
            {
                throw new Exception("IMC_ERROR: [GetIsopFileList] La ruta rootDirectory no puede estar vacia");
            }//endElse

            return levelByFn;
        }
 public AjaxDictionary<string, object> toDictio(AjaxDictionary<string,object> dictio, long sentinel)
 {
     return ((AjaxDictionary<string, object>)dictio[this.toStrIdTipoPm(sentinel)]);
 }
        public AjaxDictionary<string, object> GetUltimaMedicon(long fecha)
        {
            AjaxDictionary<string, object> tipos = null;
            long tipopmSentinel = -1;

            using (var entity = new db_SeguimientoProtocolo_r2Entities())
            {

                List<spGetHashableUltimaMedicion_Result> res = entity.spGetHashableUltimaMedicion( (long?)(fecha)).ToList();

                if (res != null && res.Count > 0)
                {
                    tipos = new AjaxDictionary<string, object>();
                    foreach (spGetHashableUltimaMedicion_Result r in res)
                    {
                        if (tipopmSentinel != r.IdTipoPuntoMedicion)
                        {
                            tipopmSentinel = (long)r.IdTipoPuntoMedicion;
                            tipos.Add(this.toStrIdTipoPm(tipopmSentinel), new AjaxDictionary<string, object>());
                        }

                        //Llenar atributos
                        AjaxDictionary<string, object> attrs = new AjaxDictionary<string, object>();
                        attrs.Add("fechaNumerica", r.FechaNumerica);
                        attrs.Add("idCond", r.IdCondicion);
                        attrs.Add("condName", r.CondicionName);
                        attrs.Add("medicion", r.Valor);

                        this.toDictio(tipos, tipopmSentinel).Add(toStrIdPm(r.IdPuntoMedicion), attrs);

                    }//endforeach
                }//endif
            }//endusing

            return tipos;
        }
        public AjaxDictionary<string, object> Download_IsoyetaRango()
        {
            AjaxDictionary<string, object> isoyetaRango = new AjaxDictionary<string, object>();

            try
            {
                HashableDataRepository repository = new HashableDataRepository();
                isoyetaRango = repository.GetIsoyetaRange();
            }
            catch (Exception ex)
            {
                throw new Exception("IMC_ERR_MSG: No se pudieron obtener los rangos de isoyetas", ex);
            }

            return isoyetaRango;
        }
        public AjaxDictionary<string, object> GetHstTableGraficaPromedio( long FechaNumerica)
        {
            AjaxDictionary<string, object> tipo = new AjaxDictionary<string, object>();
            AjaxDictionary<string, object> punto = new AjaxDictionary<string, object>();
            AjaxDictionary<string, object> datos = new AjaxDictionary<string, object>();
            try
            {
                using (var entity = new db_SeguimientoProtocolo_r2Entities())
                {

                        List<spGetHashableGraficaPromedio_Result> atributos = entity.spGetHashableGraficaPromedio(FechaNumerica).ToList();
                        if (atributos != null && atributos.Count > 0)
                        {
                            foreach (spGetHashableGraficaPromedio_Result item in atributos)
                            {
                                datos.Add("F" + item.FechaNumerica, item.Valor);
                            }
                            punto.Add("promedio", datos);

                        }

                }
            }
            catch (Exception)
            {

            }
            return punto;
        }
        public AjaxDictionary<string, object> GetHstTableGraficaPuntoMedicion(long IdPuntoMedicion,long FechaNumerica)
        {
            AjaxDictionary<string, object> tipo = new AjaxDictionary<string, object>();
            AjaxDictionary<string, object> punto = new AjaxDictionary<string, object>();
            AjaxDictionary<string, object> datos = new AjaxDictionary<string, object>();

            try
            {
                using (var entity=new db_SeguimientoProtocolo_r2Entities())
                {
                    spGetHashablePuntoMedicionAttributes_Result res = entity.spGetHashablePuntoMedicionAttributes(IdPuntoMedicion).FirstOrDefault();
                    if (res != null)
                    {
                        List<spGetHashableGraficaPuntoMedicion_Result> atributos = entity.spGetHashableGraficaPuntoMedicion(IdPuntoMedicion, FechaNumerica).ToList();
                        if (atributos != null && atributos.Count > 0)
                        {
                            foreach (spGetHashableGraficaPuntoMedicion_Result item in atributos)
                            {
                                datos.Add("F" + item.FechaNumerica, item.Valor);
                            }
                            punto.Add("p" + IdPuntoMedicion, datos);
                            tipo.Add("t" + res.IdTipoPuntoMedicion, punto);
                        }
                    }
                }
            }
            catch (Exception)
            {

            }
            return tipo;
        }
 public AjaxDictionary<string, object> Download_GetHashableGraficaPromedio(long FechaNumerica)
 {
     AjaxDictionary<string, object> tipos = new AjaxDictionary<string, object>();
     try
     {
         HashableDataRepository repository = new HashableDataRepository();
         tipos = repository.GetHstTableGraficaPromedio(FechaNumerica);
     }
     catch (Exception)
     {
         ;
     }
     return tipos;
 }
    public void AjaxDictionaryTest1()
    {
        var myTest = new AjaxDictionary <int, string>();

        Assert.AreNotEqual(null, myTest);
    }
        public AjaxDictionary<string, object> GetIsoyetaRange()
        {
            AjaxDictionary<string, object> isoyetaRango = new AjaxDictionary<string, object>();
            isoyetaRango.Add("nodata", "0");

            using (var entity = new db_SeguimientoProtocolo_r2Entities())
            {
                List<spGetHashableIsoyetaRangosLabels_Result> res = entity.spGetHashableIsoyetaRangosLabels().ToList<spGetHashableIsoyetaRangosLabels_Result>();

                if(res!= null && res.Count>0)
                {
                    foreach(spGetHashableIsoyetaRangosLabels_Result item in res)
                    {
                        AjaxDictionary<string, object> temp =  new AjaxDictionary<string, object>();
                        temp.Add("etiqueta",item.Etiqueta);
                        temp.Add("colorHex",item.ColorHex);
                        isoyetaRango.Add("l" + item.Nivel.ToString(), temp);
                    }
                }
            }
            return isoyetaRango;
        }
        // http://localhost:20557/Search/Test/SearchManager.svc/%E5%91%98%E5%B7%A5/?exp=Id%20=%20100000
        protected virtual List<AjaxDictionary<string, object>> OnGetItems(string winTabName)
        {
            var r = InternalGetItems(winTabName, WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters);
            if (r == null)
                return null;

            var ret = new List<AjaxDictionary<string, object>>();
            foreach (Dictionary<string, object> j in r)
            {
                var l = new AjaxDictionary<string, object>();
                foreach (var kvp in j)
                {
                    l.Add(kvp.Key, kvp.Value);
                }
                ret.Add(l);
            }

            return ret;
        }
 public AjaxDictionary<string, object> Download_CatNivelLluvia()
 {
     AjaxDictionary<string, object> res = new AjaxDictionary<string, object>();
     try
     {
         using (var repository=new CatNivelLluviaRepository())
         {
             res = repository.GetNivelLluvia();
         }
     }
     catch (Exception ex)
     {
         ;
     }
     return res;
 }
        public void GetLastIsopFileTest()
        {
            HashableDataRepository r = new HashableDataRepository();
            /*
            List<string> isopFiles = new List<string>(){
                "isop_201406102015_8.kml","isop_201406102201_8.kml","isop_201406101944_8.kml",
                "isop_201406101730_15.kml","isop_201406101939_15.kml","isop_201406102301_15.kml",
                "isop_201406101830_30.kml","isop_201406101939_30.kml","isop_201406102201_30.kml"
            };
             * */

            //Control de tiempo
            DateTime iniDate = DateTime.Now;
            DateTime endDate = DateTime.Now;
            //Prueba con array de
            List<string> isopFiles = new List<string>();
            DateTime initDateTime=new DateTime(2014,8,1,0,0,0);
            for (int i = 0; i <= (8640*3); i++)
            {
                if (i == 8630)
                {
                    Console.WriteLine(i);
                }
                DateTime dt = initDateTime.AddMinutes( (i * 5) * -1);

                isopFiles.Add("isop_" + String.Format("{0:yyyyMMddHHmm}", dt) + "_8.kml");
                isopFiles.Add("isop_" + String.Format("{0:yyyyMMddHHmm}", dt) + "_15.kml");
                isopFiles.Add("isop_" + String.Format("{0:yyyyMMddHHmm}", dt) + "_30.kml");
                isopFiles.Add("isop_" + String.Format("{0:yyyyMMddHHmm}", dt) + "_1000.kml");
            }
            endDate = DateTime.Now;
            TimeSpan diff = endDate - iniDate;
            Console.WriteLine("Fill array : " + diff.Minutes.ToString() + "." + diff.Seconds.ToString());
            System.Diagnostics.Debug.Write("Fill array : " + diff.Minutes.ToString() + "." + diff.Seconds.ToString());

            /*
            //Obtener en base a un rango de 3 horas
            iniDate = DateTime.Now;
            DateTime rangeInitTime = new DateTime(2014, 7, 5, 15, 5, 0);
            int totalMinutes = 120;
            List<string> resList=new List<string>();

            for (int i = 0; i < totalMinutes; i++)
            {
                DateTime dt=rangeInitTime.AddMinutes(i * -1);

                resList.Add(r.GetLastIsopFile(String.Format("{0:yyyyMMddHHmm}", dt), "8", isopFiles));
                resList.Add(r.GetLastIsopFile(String.Format("{0:yyyyMMddHHmm}", dt), "15", isopFiles));
                resList.Add(r.GetLastIsopFile(String.Format("{0:yyyyMMddHHmm}", dt), "30", isopFiles));
                resList.Add(r.GetLastIsopFile(String.Format("{0:yyyyMMddHHmm}", dt), "1000", isopFiles));
            }
            endDate = DateTime.Now;
            diff = endDate - iniDate;
            System.Diagnostics.Debug.Write("Gill resList : " + diff.Minutes.ToString() + "." + diff.Seconds.ToString());
            */

            //Metodo 2: Utilizar sub arrays
            //Fechas de inicio y calculo de fecha fin
            iniDate = DateTime.Now;
            DateTime rangeInitTime = new DateTime(2014, 5, 3, 0, 0, 0);
            int totalMinutes = 120;
            DateTime rangeOldDate = rangeInitTime.AddMinutes(totalMinutes * -1);
            string strFechaNumericaNew = String.Format("{0:yyyyMMddHHmm}", rangeInitTime);
            string strFechaNumericaOld = String.Format("{0:yyyyMMddHHmm}", rangeOldDate);

            //Diccionarios para obtener los datos
            AjaxDictionary<string, object> isopFileByLevel = new AjaxDictionary<string, object>();
            AjaxDictionary<string, object> levelByFn = new AjaxDictionary<string, object>();
            Dictionary<string, string[]> arraysByLevel = new Dictionary<string, string[]>();

            List<string> ranges = new List<string>() { "8", "15", "30", "1000" };

            //Ciclo para llenar el subarray
            string[] tmpStrArray;
            foreach(string range in ranges)
            {
                r.GetLastIsopFile(
                    strFechaNumericaNew
                    ,strFechaNumericaOld
                    ,range
                    ,isopFiles
                    , out tmpStrArray
                );

                //Guardar el arreglo
                arraysByLevel.Add(range, tmpStrArray);
            }//endFech

            //Iniciar ciclo para cada uno de los minutos entre los rangos
            DateTime loopDate = rangeOldDate;
            while(loopDate<=rangeInitTime)
            {
                isopFileByLevel = null;
                foreach (string range in ranges)//para cada uno de los rangos
                {
                    string[] tmp = arraysByLevel[range];
                    isopFileByLevel = new AjaxDictionary<string, object>();
                    if(tmp!=null)
                    {
                        string tmpIsopLastFile = r.GetLastIsopFile(String.Format("{0:yyyyMMddHHmm}", loopDate), range, arraysByLevel[range].ToList<string>());
                        isopFileByLevel.Add(range, tmpIsopLastFile);
                    }
                    else
                    {
                        isopFileByLevel.Add(range, "");
                    }
                }//endFech

                levelByFn.Add(String.Format("{0:yyyyMMddHHmm}", loopDate), isopFileByLevel);

                loopDate=loopDate.AddMinutes(1);
            }//endWhile

            endDate = DateTime.Now;
            diff = endDate - iniDate;
            System.Diagnostics.Debug.Write("Subarrays method resList : " + diff.Minutes.ToString() + "." + diff.Seconds.ToString());
        }
        public AjaxDictionary<string, HashableGraficaPuntoMedicionModel[]> GetHashableGraficaPuntoMedicion(long IdPuntoMedicion, long FechaNumerica)
        {
            AjaxDictionary<string, object> tipos = new AjaxDictionary<string,object>();
            AjaxDictionary<string, List<HashableGraficaPuntoMedicionModel>> atrr = new AjaxDictionary<string, List<HashableGraficaPuntoMedicionModel>>();
            AjaxDictionary<string, HashableGraficaPuntoMedicionModel[]> array = new AjaxDictionary<string, HashableGraficaPuntoMedicionModel[]>();

            long tipopmSentinel = -1;
            string seccion = "";
            try
            {
                using (var entity = new db_SeguimientoProtocolo_r2Entities())
                {
                    spGetHashablePuntoMedicionAttributes_Result res = entity.spGetHashablePuntoMedicionAttributes(IdPuntoMedicion).FirstOrDefault();
                    if (res != null)
                    {
                        //List<spGetHashableGraficaPuntoMedicion_Result> atributos = entity.spGetHashableGraficaPuntoMedicion(IdPuntoMedicion, FechaNumerica).ToList();
                        List<HashableGraficaPuntoMedicionModel> atributos = new List<HashableGraficaPuntoMedicionModel>();
                        entity.spGetHashableGraficaPuntoMedicion(IdPuntoMedicion,FechaNumerica).ToList().ForEach(row => {
                            atributos.Add(new HashableGraficaPuntoMedicionModel()
                            {
                                FechaNumerica=row.FechaNumerica,
                                Valor=row.Valor
                            });
                        });
                        if (atributos != null && atributos.Count > 0)
                        {
                            tipos = new AjaxDictionary<string, object>();
                            //string valor = "";
                           //valor = new JavaScriptSerializer().Serialize(atributos);
                            array.Add(this.toStrIdPm(IdPuntoMedicion), atributos.ToArray());
                            //tipos.Add(this.toStrIdTipoPm(res.IdTipoPuntoMedicion), atrr);
                            //tipos.Add(this.toStrIdTipoPm(res.IdTipoPuntoMedicion), (new AjaxDictionary<string, string>().Add("", "")));
                            //this.toDictio(tipos, res.IdTipoPuntoMedicion).Add(this.toStrIdPm(IdPuntoMedicion),valor);
                        }
                    }
                }//endusing
            }
            catch (Exception ex)
            {
                tipos.Add(seccion, ex.Message);
            }
            return array;
        }