Example #1
0
        private static List <SensorEvent> GetSensorEventsHelper(HttpClient i_Client, int i_SensorId, int i_PageId, out int i_PagesCount)
        {
            var httpRequest = new HttpRequestMessage(HttpMethod.Get, Settings.ApiVersionEndpoint +
                                                     "events?sensorId=" + i_SensorId.ToString() + "&page=" + i_PageId.ToString());


            Task <HttpResponseMessage> result   = i_Client.SendAsync(httpRequest);
            HttpResponseMessage        response = result.Result;
            JObject responseJsonObject          = GetHttpResponseBody(response);

            i_PagesCount = int.Parse(responseJsonObject["pages"].ToString());
            InnoviApiService.RefreshAccessToken(response);
            List <SensorEvent> events = JsonConvert.DeserializeObject <List <SensorEvent> >(responseJsonObject["list"].ToString());

            verifyCodeZero(responseJsonObject);
            InnoviApiService.RefreshAccessToken(response);
            //    List<SensorEvent> sortedEvents = events.OrderByDescending(x => x.StartTime).ToList();
            //   sortedEvents.Reverse();

            if (events.Count == 0)
            {
                events = null;
            }
            else
            {
                AddSensorNamesToEventsList(events);
            }

            return(events);
        }
Example #2
0
        private static List <Folder> GetFoldersHelper(HttpClient i_Client, int i_FolderId, int i_PageId, out int i_PagesCount)
        {
            var httpRequest = new HttpRequestMessage(HttpMethod.Get, Settings.ApiVersionEndpoint +
                                                     "folders/" + i_FolderId.ToString() + "/folders" + "?page=" + i_PageId.ToString() + "&sort=name+");


            Task <HttpResponseMessage> result   = i_Client.SendAsync(httpRequest);
            HttpResponseMessage        response = result.Result;
            JObject responseJsonObject          = GetHttpResponseBody(response);

            i_PagesCount = int.Parse(responseJsonObject["pages"].ToString());

            List <Folder> folders = JsonConvert.DeserializeObject <List <Folder> >(responseJsonObject["list"].ToString());

            verifyCodeZero(responseJsonObject);
            InnoviApiService.RefreshAccessToken(response);

            //   List<Folder> sortedFolders = folders.OrderByDescending(x => x.Name).ToList();
            //    sortedFolders.Reverse();

            if (folders.Count == 0)
            {
                folders = null;
            }

            return(folders);
        }
Example #3
0
        internal static List <Sensor.Health> GetSensorHealthArray(int i_SensorId)
        {
            verifyLoggedInStatus();
            HttpClient client = BaseHttpClient();

            client.DefaultRequestHeaders.TryAddWithoutValidation("X-ACCESS-TOKEN", InnoviApiService.AccessToken);

            var httpRequest = new HttpRequestMessage(HttpMethod.Get, Settings.ApiVersionEndpoint +
                                                     "sensors/" + i_SensorId.ToString() + "/status/overtime");

            Task <HttpResponseMessage> result   = client.SendAsync(httpRequest);
            HttpResponseMessage        response = result.Result;
            JObject responseJsonObject          = GetHttpResponseBody(response);

            List <Sensor.Health> HealthArray = JsonConvert.DeserializeObject <List <Sensor.Health> >(responseJsonObject["entity"]["data"].ToString());

            verifyCodeZero(responseJsonObject);
            InnoviApiService.RefreshAccessToken(response);

            if (HealthArray.Count == 0)
            {
                HealthArray = null;
            }

            return(HealthArray);
        }
Example #4
0
        internal static bool SwitchAccount(int i_AccountId)
        {
            bool isSuccessful = false;

            verifyLoggedInStatus();
            HttpClient client = BaseHttpClient();

            client.DefaultRequestHeaders.TryAddWithoutValidation("X-ACCESS-TOKEN", InnoviApiService.AccessToken);
            var httpRequest = new HttpRequestMessage(HttpMethod.Get, Settings.ApiVersionEndpoint + "user/switch-account");

            Dictionary <string, string> jsonBuilder = new Dictionary <string, string>();

            jsonBuilder.Add("accountId", i_AccountId.ToString());
            string requestBody = JsonConvert.SerializeObject(jsonBuilder);

            httpRequest.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");
            Task <HttpResponseMessage> result   = client.SendAsync(httpRequest);
            HttpResponseMessage        response = result.Result;
            JObject responseJsonObject          = GetHttpResponseBody(response);

            verifyCodeZero(responseJsonObject);
            InnoviApiService.RefreshAccessToken(response);
            isSuccessful = responseJsonObject["code"].ToString() == "0";

            return(isSuccessful);
        }
Example #5
0
        internal static void UpdateSensorNamesCache(List <int> i_SensorIds)
        {
            verifyLoggedInStatus();

            if (i_SensorIds.Count < 1)
            {
                throw new ArgumentException("List must contain at least one value");
            }

            HttpClient client = BaseHttpClient();

            client.DefaultRequestHeaders.TryAddWithoutValidation("X-ACCESS-TOKEN", InnoviApiService.AccessToken);
            string        baseUri           = Settings.ApiVersionEndpoint + "sensors/list?";
            var           httpRequest       = new HttpRequestMessage(HttpMethod.Get, baseUri);
            StringBuilder requestUriBuilder = new StringBuilder();

            requestUriBuilder.Append(baseUri);
            int sensorCount = 0;
            Dictionary <int, int> addedSensors = new Dictionary <int, int>();

            Cache cache = Cache.Fetch();

            foreach (int SensorId in i_SensorIds)
            {
                if (!addedSensors.ContainsKey(SensorId))
                {
                    addedSensors.Add(SensorId, 0);

                    if (sensorCount++ > 0)
                    {
                        requestUriBuilder.Append("&");
                    }

                    requestUriBuilder.Append("id=" + SensorId.ToString());
                }
            }

            httpRequest.RequestUri = new Uri(requestUriBuilder.ToString(), UriKind.Relative);

            Task <HttpResponseMessage> result   = client.SendAsync(httpRequest);
            HttpResponseMessage        response = result.Result;
            JObject responseJsonObject          = GetHttpResponseBody(response);

            verifyCodeZero(responseJsonObject);
            InnoviApiService.RefreshAccessToken(response);
            List <Sensor> sensors = JsonConvert.DeserializeObject <List <Sensor> >(responseJsonObject["list"].ToString());



            List <string> sensorNames = new List <string>();

            foreach (Sensor sensor in sensors)
            {
                cache.AddToSensorCache(sensor.sensorId, sensor.Name);
            }
        }
Example #6
0
        internal static Sensor GetSensorByID(int i_SensorId)
        {
            verifyLoggedInStatus();

            HttpClient client = BaseHttpClient();

            client.DefaultRequestHeaders.TryAddWithoutValidation("X-ACCESS-TOKEN", InnoviApiService.AccessToken);
            var httpRequest = new HttpRequestMessage(HttpMethod.Get, Settings.ApiVersionEndpoint +
                                                     "sensors/" + i_SensorId.ToString());
            Task <HttpResponseMessage> result   = client.SendAsync(httpRequest);
            HttpResponseMessage        response = result.Result;
            JObject responseJsonObject          = GetHttpResponseBody(response);

            verifyCodeZero(responseJsonObject);
            InnoviApiService.RefreshAccessToken(response);
            Sensor sensor = JsonConvert.DeserializeObject <Sensor>(responseJsonObject["entity"].ToString());

            return(sensor);
        }