/// <summary>
        /// Calling the rest end points for the GP
        /// </summary>
        /// <param name="myConfigToDownload"></param>
        private void DownloadDataGP(OsmConfig myConfigToDownload)
        {
            WebClient client = new WebClient();

            // This assumes is port 80
            string sGpUrl = "http://" + Request.Url.Host + "/" + System.Configuration.ConfigurationManager.AppSettings["ArcGISInstance"].ToString()
                            + "/rest/services/OSM_on_AGS/GPServer/Download%20OSM%20Data%20Serverside";

            ESRI.ArcGIS.Client.Tasks.Geoprocessor geoprocessorTask = new
                                                                     ESRI.ArcGIS.Client.Tasks.Geoprocessor(sGpUrl);

            List <ESRI.ArcGIS.Client.Tasks.GPParameter> parameters = new List <ESRI.ArcGIS.Client.Tasks.GPParameter>();

            string[] myExtent = myConfigToDownload.Extent.Split(',');

            ESRI.ArcGIS.Client.Geometry.PointCollection pointCollect = new ESRI.ArcGIS.Client.Geometry.PointCollection();

            // X1 Y1
            pointCollect.Add(new
                             ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[0])),
                                                                  WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[1]))));
            // X2 Y1
            pointCollect.Add(new
                             ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[2])),
                                                                  WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[1]))));
            // X2 Y2
            pointCollect.Add(new
                             ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[2])),
                                                                  WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[3]))));
            // X1 Y2
            pointCollect.Add(new
                             ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[0])),
                                                                  WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[3]))));
            // X1 Y1
            pointCollect.Add(new
                             ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[0])),
                                                                  WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[1]))));

            ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon();
            polygon.Rings.Add(pointCollect);
            polygon.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326);

            parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer("Feature_Set", polygon));
            parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPString("Name_of_OSM_Dataset", myConfigToDownload.FeatureDataSet));

            AppLogs logs = new AppLogs();

            ESRI.ArcGIS.Client.Tasks.JobInfo info = null;

            try
            {
                info = geoprocessorTask.SubmitJob(parameters);
            }
            catch (Exception e)
            {
                logs.AddLog("DOWNLOADLOGS", "Exception " + e.Message);
                if (info != null)
                {
                    for (int i = 0; i < info.Messages.Count; i++)
                    {
                        logs.AddLog("DOWNLOADLOGS", "Exception: DownloadDataGP messages " + info.Messages[i].Description);
                    }
                }
            }

            while (info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobSucceeded &&
                   info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed)
            {
                Thread.Sleep(2000);
                info = geoprocessorTask.CheckJobStatus(info.JobId);
            }

            if (info.JobStatus == ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed)
            {
                for (int i = 0; i < info.Messages.Count; i++)
                {
                    logs.AddLog("DOWNLOADLOGS", "JobFailed: DownloadDataGP messages " + info.Messages[i].Description);
                }
                throw new ApplicationException("JobFailed: Please view logs for details");
            }
        }
        private void SyncDataGP(OsmConfig myConfigToDownload)
        {
            string sGpUrl = "";

            if (Request != null)
            {
                sGpUrl = "http://" + Request.Url.Host + "/" + System.Configuration.ConfigurationManager.AppSettings["ArcGISInstance"].ToString() +
                         "/rest/services/OSM_on_AGS/GPServer/Sync%20OSM%20Data%20Serverside";
            }
            else
            {
                string smyHost = myConfigToDownload.FeatureService.Substring(0, myConfigToDownload.FeatureService.ToLower().IndexOf("/arcgis/rest"));

                sGpUrl = smyHost + "/" + System.Configuration.ConfigurationManager.AppSettings["ArcGISInstance"].ToString() +
                         "/rest/services/OSM_on_AGS/GPServer/Sync%20OSM%20Data%20Serverside";
            }

            ESRI.ArcGIS.Client.Tasks.Geoprocessor geoprocessorTask = new
                                                                     ESRI.ArcGIS.Client.Tasks.Geoprocessor(sGpUrl);

            List <ESRI.ArcGIS.Client.Tasks.GPParameter> parameters = new List <ESRI.ArcGIS.Client.Tasks.GPParameter>();

            parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPString("Start_Time_for_Diff_Files", ""));
            parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPBoolean("Load_updates_only_inside_current_AOI", true));
            parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPString("Name_of_Sync_Feature_Dataset", myConfigToDownload.FeatureDataSet));

            AppLogs logs = new AppLogs();

            ESRI.ArcGIS.Client.Tasks.JobInfo info = null;

            try
            {
                info = geoprocessorTask.SubmitJob(parameters);
            }
            catch (Exception e)
            {
                logs.AddLog("DOWNLOADLOGS", "SyncDataGP Exception " + e.Message);
                if (info != null)
                {
                    for (int i = 0; i < info.Messages.Count; i++)
                    {
                        logs.AddLog("DOWNLOADLOGS", "Exception: SyncDataGP messages " + info.Messages[i].Description);
                    }
                }
            }

            while (info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobSucceeded &&
                   info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed)
            {
                Thread.Sleep(2000);
                info = geoprocessorTask.CheckJobStatus(info.JobId);
            }

            if (info.JobStatus == ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed)
            {
                for (int i = 0; i < info.Messages.Count; i++)
                {
                    logs.AddLog("DOWNLOADLOGS", "JobFailed: SyncDataGP messages " + info.Messages[i].Description);
                }
                throw new ApplicationException("JobFailed: Please view logs for details");
            }
        }
        /// <summary>
        /// Do upload using the ArcGIS GP
        /// </summary>
        /// <param name="sUsername"></param>
        /// <param name="sPassword"></param>
        /// <param name="sFeatureDataSet"></param>
        public void DoUploadGP(string sUsername, string sPassword, string sFeatureDataSet, OsmConfig myConfigToDownload)
        {
            string sGpUrl;

            if (Request != null)
            {
                sGpUrl = "http://" + Request.Url.Host + "/" + System.Configuration.ConfigurationManager.AppSettings["ArcGISInstance"].ToString() +
                         "/rest/services/OSM_on_AGS/GPServer/Upload%20OSM%20Data%20Serverside";
            }
            else if (myConfigToDownload != null)
            {
                string smyHost = myConfigToDownload.FeatureService.Substring(0, myConfigToDownload.FeatureService.ToLower().IndexOf("/arcgis/rest"));
                sGpUrl = smyHost + "/" + System.Configuration.ConfigurationManager.AppSettings["ArcGISInstance"].ToString() +
                         "/rest/services/OSM_on_AGS/GPServer/Upload%20OSM%20Data%20Serverside";
            }
            else
            {
                sGpUrl = "http://localhost/ArcGIS/rest/services/OSM_on_AGS/GPServer/Upload%20OSM%20Data%20Serverside";
            }


            ESRI.ArcGIS.Client.Tasks.Geoprocessor geoprocessorTask = new
                                                                     ESRI.ArcGIS.Client.Tasks.Geoprocessor(sGpUrl);

            List <ESRI.ArcGIS.Client.Tasks.GPParameter> parameters = new List <ESRI.ArcGIS.Client.Tasks.GPParameter>();

            string sCredentials = OSMWeb.Utils.StringManipulation.EncodeTo64(sUsername + ":" + sPassword);

            parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPString("OSM_login_credentials", sCredentials));
            parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPString("Name_of_Upload_Feature_Dataset", sFeatureDataSet));
            parameters.Add(new
                           ESRI.ArcGIS.Client.Tasks.GPString("Comment_describing_the_upload_content",
                                                             System.Configuration.ConfigurationManager.AppSettings["UploadComment"].ToString() +
                                                             sFeatureDataSet + " at " + DateTime.Now.ToString()));

            AppLogs logs = new AppLogs();

            ESRI.ArcGIS.Client.Tasks.JobInfo info = null;

            try
            {
                info = geoprocessorTask.SubmitJob(parameters);
            }
            catch (Exception e)
            {
                logs.AddLog("DOWNLOADLOGS", "DoUploadGP Exception " + e.Message);
                if (info != null)
                {
                    for (int i = 0; i < info.Messages.Count; i++)
                    {
                        logs.AddLog("DOWNLOADLOGS", "Exception: DoUploadGP messages " + info.Messages[i].Description);
                    }
                }
            }

            while (info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobSucceeded &&
                   info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed)
            {
                Thread.Sleep(2000);
                info = geoprocessorTask.CheckJobStatus(info.JobId);
            }

            if (info.JobStatus == ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed)
            {
                for (int i = 0; i < info.Messages.Count; i++)
                {
                    logs.AddLog("DOWNLOADLOGS", "JobFailed: DoUploadGP messages " + info.Messages[i].Description);
                }
                throw new ApplicationException("JobFailed: Please view logs for details");
            }
        }