Esempio n. 1
0
        public IActionResult TestConnection(string url, string username, string password)
        {
            if (url.Length > 1)
            {
                if (url.Substring(url.Length - 1) != "/")
                {
                    url = url + "/";
                }
            }

            string api    = url + "api/dataElements?format=json&paging=true&pageSize=1";
            string result = HTTPFactory.HTTPGet(api, username, password);

            if (result != "")
            {
                return(Json(new { success = true, msg = "Successful connection" }));
            }
            else
            {
                return(Json(new { success = false, msg = "Connection failed" }));
            }
        }
Esempio n. 2
0
        public IActionResult LoadData(string id, string type, string serverId)
        {
            JObject server = DataFactory.GetServer(serverId, directory);

            string url = server.GetValue("url").ToString();

            if (url.Length > 1)
            {
                if (url.Substring(url.Length - 1) != "/")
                {
                    url = url + "/";
                }
            }

            string username = server.GetValue("user").ToString();
            string password = server.GetValue("password").ToString();


            string api    = url + "api/analytics.json?skipMeta=false&paging=false&dimension=pe:LAST_5_YEARS&dimension=dx:" + id;
            string result = HTTPFactory.HTTPGet(api, username, password);

            return(Json(result.ToString()));
        }
Esempio n. 3
0
        public IActionResult SyncServer(string id)
        {
            JObject server = DataFactory.GetServer(id, directory);

            string url = server.GetValue("url").ToString();

            if (url.Length > 1)
            {
                if (url.Substring(url.Length - 1) != "/")
                {
                    url = url + "/";
                }
            }

            string username = server.GetValue("user").ToString();
            string password = server.GetValue("password").ToString();



            //Get data

            string api    = url + Configuration["api:dataElements"];
            string result = HTTPFactory.HTTPGet(api, username, password);

            if (result == "")
            {
                return(Json(new { success = false, msg = "Unable to complete Data Elements sync, please try again" }));
            }

            WriteToFile(result, id + "-DE", XferFactory.FileType.Meta);

            api    = url + Configuration["api:indicators"];
            result = HTTPFactory.HTTPGet(api, username, password);
            if (result == "")
            {
                return(Json(new { success = false, msg = "Unable to complete Indicator sync, please try again" }));
            }
            WriteToFile(result, id + "-IND", XferFactory.FileType.Meta);

            api    = url + Configuration["api:programIndicators"];
            result = HTTPFactory.HTTPGet(api, username, password);
            if (result == "")
            {
                return(Json(new { success = false, msg = "Unable to complete Program Indicator sync, please try again" }));
            }
            WriteToFile(result, id + "-PRG", XferFactory.FileType.Meta);

            //Get Organisation Units
            api    = url + Configuration["api:organisationUnits"];
            result = HTTPFactory.HTTPGet(api, username, password);
            if (result == "")
            {
                return(Json(new { success = false, msg = "Unable to complete Organisation Unit sync, please try again" }));
            }
            WriteToFile(result, id, XferFactory.FileType.OrgUnits);

            //Get Organisation Unit Groups
            api    = url + Configuration["api:organisationUnitGroups"];
            result = HTTPFactory.HTTPGet(api, username, password);
            if (result == "")
            {
                return(Json(new { success = false, msg = "Unable to complete Organisation Unit Group sync, please try again" }));
            }
            WriteToFile(result, id, XferFactory.FileType.OrgUnitGroup);

            //Get Organisation Unit Levels
            api = url + Configuration["api:organisationUnitLevels"];

            result = HTTPFactory.HTTPGet(api, username, password);
            JObject levels = new JObject();

            if (result != "")
            {
                levels["orgUnitLevels"] = JArray.Parse(result);
                FileFactory.WriteFile(levels, id, XferFactory.FileType.OrgUnitLevels, directory);
            }

            //Get Category Combos
            api = url + Configuration["api:categoryCombo"];

            result = HTTPFactory.HTTPGet(api, username, password);
            if (result == "")
            {
                return(Json(new { success = false, msg = "Unable to complete Category Combo sync, please try again" }));
            }
            WriteToFile(result, id, XferFactory.FileType.CategoryCombo);

            //Get Category Option Combos
            api = url + Configuration["api:categoryOptionCombo"];

            result = HTTPFactory.HTTPGet(api, username, password);
            if (result == "")
            {
                return(Json(new { success = false, msg = "Unable to complete Category Combo Option sync, please try again" }));
            }
            WriteToFile(result, id, XferFactory.FileType.CategoryOptionCombo);

            //Add the sync time
            server["lastSync"] = DateTime.Now;
            FileFactory.WriteFile(server, id, XferFactory.FileType.Server, directory);

            return(Json(new { success = true, result = DateTime.Now }));
        }