Пример #1
0
        public Dictionary <Param, IList <HisValue> > readNewDataSiteJson(Site apiSite, string json)
        {
            var paramValues = new Dictionary <Param, IList <HisValue> >();

            json = json.Substring(0, json.IndexOf('\0'));  // ETS remove strange character at end '\0\0+��\0\'

            // get data from string
            var deserialized = JsonConvert.DeserializeObject <JsonResponseMqttEaseEGIotModel>(json);


            // get site variables
            foreach (var param in apiSite.Params)
            {
                IParamAttributRepository paramAttributRepo = new ParamAttributReposiroty();
                IAttributRepository      attributRepo      = new AttributRepository();

                Attribut      attribut      = attributRepo.FindByName("Adresse Api");
                ParamAttribut paramAttribut = paramAttributRepo.FindWithParamAttribut(param.Id, attribut.Id);

                // get from "adresse api" attribut
                var hisValues = new List <HisValue>();
                var hisValue  = deserialized.GetHisValueFromLabel(paramAttribut.Valeur, param.Id);
                if (hisValue != null)
                {
                    hisValues.Add(hisValue);
                    paramValues.Add(param, hisValues);
                }
            }// rof params


            return(paramValues);
        }
Пример #2
0
        public IDictionary <Param, IList <HisValue> > readDataSite(DateTime startDate, DateTime enDate, Site sites)
        {
            var url = Url + "&dateDebutDju={0}&dateFinDju={1}&codeStationMeteo={2}";


            // renvoi une liste de tous les params du site contenant un attribut (ref_attribut) au nom : "Adresse Api"
            var paramList = getVariables(sites);

            mapParamListValue = new Dictionary <Param, IList <HisValue> >(); // objet his_value contenant des données horodatés dateTime et une valeur double

            foreach (var par in paramList)
            {
                var Result = "";
                // On récupère la valeur des attributs de ParamAttribut correspondant à à l'id_param et à l'id_attribut
                IParamAttributRepository paramAttributRepo = new ParamAttributReposiroty();
                IAttributRepository      attributRepo      = new AttributRepository();

                Attribut      attribut      = attributRepo.FindByName("Adresse Api");
                ParamAttribut paramAttribut = paramAttributRepo.FindWithParamAttribut(par.Id, attribut.Id);

                // if (attribut != null)
                {
                    WebRequest request = WebRequest.Create(string.Format(url, startDate.ToString("yyyyMMdd"), enDate.ToString("yyyyMMdd"), sites.CodeExterne)); //TODO ajouter get getData pour tous les param du site contenant un attribut "adresse api"

                    request.Credentials = CredentialCache.DefaultCredentials;
                    request.Method      = "GET";
                    request.Timeout     = 60000;// System.Threading.Timeout.Infinite;

                    try
                    {
                        WebResponse response = request.GetResponse();

                        // Get the stream containing content returned by the server.
                        Stream dataStream = response.GetResponseStream();

                        // Open the stream using a StreamReader for easy access.
                        StreamReader reader = new StreamReader(dataStream);

                        // Read the content.
                        string responseFromServer = reader.ReadToEnd();

                        Result = responseFromServer;//.Replace(",", "\r\n");
                        reader.Close();
                        response.Close();
                        JsonResponseMeteoIdexModel valueList = JsonConvert.DeserializeObject <JsonResponseMeteoIdexModel>(Result);
                        mapParamListValue.Add(par, valueList.toHisValues(par.Id, paramAttribut != null ? paramAttribut.Valeur : ""));
                    }
                    catch (Exception ex)
                    {
                        Result = ex.Message;
                    }
                }
            }
            return(mapParamListValue);
        }
Пример #3
0
        IDictionary <Param, IList <HisValue> > IApiProtocol.readDataSite(DateTime startDate, DateTime enDate, Site sites)
        {
            var token = sites.Ligne.apiToken;
            var url   = Url + "getdatatounits?siteID={0}&channelID={1}&token={2}&startDate={3}&endDate={4}&units=3";
            //var channel = "D1a";

            // renvoi une liste de tous les params du site contenant un attribut (ref_attribut) au nom : "Adresse Api"
            var paramList = getVariables(sites);

            mapParamListValue = new Dictionary <Param, IList <HisValue> >(); // objet his_value contenant des données horodatés dateTime et une valeur double

            foreach (var par in paramList)
            {
                var Result = "";
                // On récupère la valeur des attributs de ParamAttribut correspondant à à l'id_param et à l'id_attribut
                IParamAttributRepository paramAttributRepo = new ParamAttributReposiroty();
                IAttributRepository      attributRepo      = new AttributRepository();

                Attribut      attribut      = attributRepo.FindByName("Adresse Api");
                ParamAttribut paramAttribut = paramAttributRepo.FindWithParamAttribut(par.Id, attribut.Id);

                if (attribut != null)
                {
                    WebRequest request = WebRequest.Create(string.Format(url, sites.Mnemonique, paramAttribut.Valeur, token, startDate.ToString("MM/dd/yyyy"), enDate.ToString("MM/dd/yyyy"))); //TODO ajouter get getData pour tous les param du site contenant un attribut "adresse api"

                    request.Credentials = CredentialCache.DefaultCredentials;
                    request.Method      = "GET";
                    request.Timeout     = 60000;// System.Threading.Timeout.Infinite;

                    try
                    {
                        WebResponse response = request.GetResponse();

                        // Get the stream containing content returned by the server.
                        Stream dataStream = response.GetResponseStream();

                        // Open the stream using a StreamReader for easy access.
                        StreamReader reader = new StreamReader(dataStream);

                        // Read the content.
                        string responseFromServer = reader.ReadToEnd();

                        // Clean up the streams and the response.

                        Result = responseFromServer;//.Replace(",", "\r\n");
                        reader.Close();
                        response.Close();
                        JSonReponseXilogModel valueList = JsonConvert.DeserializeObject <JSonReponseXilogModel>(Result);
                        if (mapParamListValue.ContainsKey(par) == false)
                        {
                            mapParamListValue.Add(par, valueList.toHisValues(par.Id, paramAttribut.Valeur));
                        }
                    }
                    catch (Exception ex)
                    {
                        Result = ex.Message;
                    }
                }
            }
            return(mapParamListValue);
        }