// GET: /Editor/
        public ActionResult Index(string FeatureService)
        {
            ViewBag.FeatureService = FeatureService;

            OsmConfig myConfigToDownload = null;

            foreach (OsmConfig config in context.OsmConfigs.ToList())
            {
                if (config.FeatureService == FeatureService)
                {
                    myConfigToDownload = config;
                    if (config.RefreshInterval > 0)
                    {
                        // We going to need it soon
                        ViewBag.ConfigID = config.ID;
                    }
                    break;
                }
            }

            if (myConfigToDownload != null)
            {
                // Setting up the name of the FeatureDataSet for the view.
                if (myConfigToDownload.RefreshInterval == 0)
                {
                    ViewBag.FeatureDataSet = myConfigToDownload.FeatureDataSet;
                }
            }

            return(View());
        }
        // GET: /Download/
        public string JustDownload(OsmConfig myConfigToDownload)
        {
            string dbName      = ConfigurationManager.AppSettings["DatabaseConnection"];
            string datasetName = System.IO.Path.Combine(dbName, myConfigToDownload.FeatureDataSet);

            AppLogs logs = new AppLogs();

            logs.AddLog("DOWNLOADLOGS", "Start Downloading");

            try
            {
                if (SyncState.CanSyncDataset(datasetName))
                {
                    SyncDataGP(myConfigToDownload);
                }
                else
                {
                    DownloadDataGP(myConfigToDownload);
                }
                return(null);
            }
            catch (Exception e)
            {
                logs.AddLog("DOWNLOADLOGS", "ERROR: Just Download raised exception " + e.Message);
                return("ERROR: Just Download raised exception " + e.Message);
            }


            logs.AddLog("DOWNLOADLOGS", "Finished Downloading");
        }
        public ActionResult DeleteConfirmed(string id)
        {
            OsmConfig osmconfig = context.OsmConfigs.Single(x => x.ID == id);

            if (osmconfig.FeatureService != null)
            {
                ServicePublisher.Services service = new ServicePublisher.Services();
                try
                {
                    service.DeleteService(Request.Url.Host,
                                          ConfigurationManager.AppSettings["ArcGISInstance"],
                                          osmconfig.ID,
                                          osmconfig.FeatureDataSet,
                                          osmconfig.FeatureService,
                                          ConfigurationManager.AppSettings["MxdOutput"],
                                          ConfigurationManager.AppSettings["DatabaseConnection"],
                                          ConfigurationManager.AppSettings["AgsAdminUser"],
                                          ConfigurationManager.AppSettings["AgsAdminPwd"],
                                          ConfigurationManager.AppSettings["PythonScriptDir"]);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            context.OsmConfigs.Remove(osmconfig);
            context.SaveChanges();


            return(RedirectToAction("Index"));
        }
        private string SetTargetDatasetParamGP(OsmConfig myConfigToDownload)
        {
            string DatabaseConnectionConfig = ConfigurationManager.AppSettings["DatabaseConnection"];

            if (DatabaseConnectionConfig.ToLower().Contains(".gdb"))
            {
                bUseSDE = false;
            }

            // Check the database exist
            if (System.IO.File.Exists(DatabaseConnectionConfig) == false)
            {
                if (System.IO.Directory.Exists(DatabaseConnectionConfig) == false)
                {
                    ViewBag.TitleReturn = "The download cannot be completed";
                    ViewBag.Result      = "Connection to the database does not exist";
                    return(null);
                }
            }

            if (DatabaseConnectionConfig.ToLower().Contains(".sde") == true)
            {
                DatabaseConnectionConfig += "\\";
            }

            return(DatabaseConnectionConfig + myConfigToDownload.FeatureDataSet);
        }
        public ActionResult DeleteConfirmed(string id)
        {
            OsmConfig osmconfig = context.OsmConfigs.Single(x => x.ID == id);

            context.OsmConfigs.Remove(osmconfig);
            context.SaveChanges();


            return(RedirectToAction("Index"));
        }
        public ActionResult EditFeatures(string id)
        {
            OsmConfig osmconfig = context.OsmConfigs.Single(x => x.ID == id);

            ServicePublisher.Services service = new ServicePublisher.Services();

            return(RedirectToAction("Index",
                                    new RouteValueDictionary(
                                        new { controller = "Editor", action = "Index", FeatureService = osmconfig.FeatureService })));
        }
Esempio n. 7
0
        private void RunOneSync(OsmConfig config)
        {
            try
            {
                // This Upload controller will also do a download
                Controllers.UploadController upload = new Controllers.UploadController();
                upload.Index(config.ID);
            }
            catch { }

            config.LastTimeRunned = RunnerLog.lastRun = DateTime.Now;
        }
        //
        // GET: /OsmConfigs/Delete/5
        public ActionResult Delete(string id)
        {
            OsmConfig osmconfig = context.OsmConfigs.Single(x => x.ID == id);

            ServicePublisher.Services service = new ServicePublisher.Services();
            try { service.DeleteService(Request.Url.Host,
                                        osmconfig.ID,
                                        osmconfig.FeatureDataSet,
                                        osmconfig.FeatureService,
                                        ConfigurationManager.AppSettings["MxdOutput"],
                                        ConfigurationManager.AppSettings["DatabaseConnection"]); }
            catch { }

            return(View(osmconfig));
        }
        public ActionResult Create(OsmConfig osmconfig)
        {
            // Check if the first character is a number
            Regex  regex = new Regex("[0-9]");
            string sFirstDataSetCharacter = osmconfig.FeatureDataSet.Substring(0, 1);

            if (regex.IsMatch(sFirstDataSetCharacter) == true)
            {
                ViewBag.mxdList     = OSMWeb.Utils.Config.GetListFromConfig("MxdList");
                ViewBag.refreshList = OSMWeb.Utils.Config.GetListFromConfig("RefreshInterval");

                ViewBag.AlphaCheck = "DataSet name cannot begin with a number";
                return(View(osmconfig));
            }

            if (osmconfig.Password == null)
            {
                osmconfig.Password = "";
            }
            if (osmconfig.Username == null)
            {
                osmconfig.Username = "";
            }

            osmconfig.LastTimeRunned = DateTime.Now;

            if (ModelState.IsValid)
            {
                osmconfig.ID = Guid.NewGuid().ToString();
                context.OsmConfigs.Add(osmconfig);
                context.SaveChanges();

                // Download the database
                return(RedirectToAction("Index",
                                        new RouteValueDictionary(
                                            new { controller = "Download", action = "Index", DataBaseObjectID = osmconfig.ID })));
            }
            else
            {
                osmconfig.ID = Guid.NewGuid().ToString();
            }

            return(View(osmconfig));
        }
        //
        // GET: /OsmConfigs/Delete/5
        public ActionResult Delete(string id)
        {
            OsmConfig osmconfig = context.OsmConfigs.Single(x => x.ID == id);

            //ServicePublisher.Services service = new ServicePublisher.Services();
            //try { service.DeleteService(Request.Url.Host,
            //                            ConfigurationManager.AppSettings["ArcGISInstance"],
            //                            osmconfig.ID,
            //                            osmconfig.FeatureDataSet,
            //                            osmconfig.FeatureService,
            //                            ConfigurationManager.AppSettings["MxdOutput"],
            //                            ConfigurationManager.AppSettings["DatabaseConnection"],
            //                            ConfigurationManager.AppSettings["AgsAdminUser"],
            //                            ConfigurationManager.AppSettings["AgsAdminPwd"],
            //                            ConfigurationManager.AppSettings["PythonScriptDir"]);
            //}
            //catch { }

            return(View(osmconfig));
        }
        // GET: /Upload/
        public ActionResult Index(string DataBaseObjectID)
        {
            OsmConfig myConfigToDownload = null;

            foreach (OsmConfig config in context.OsmConfigs.ToList())
            {
                if (config.ID == DataBaseObjectID)
                {
                    myConfigToDownload = config;
                    break;
                }
            }

            DoUploadGP(myConfigToDownload.Username, myConfigToDownload.Password, myConfigToDownload.FeatureDataSet, myConfigToDownload);

            // Download again the same extent
            DownloadController download = new DownloadController();

            download.JustDownload(myConfigToDownload);

            return(View());
        }
        public ActionResult Edit(OsmConfig osmconfig)
        {
            if (ModelState.IsValid)
            {
                if (osmconfig.ID.Contains("test") == true)
                {
                    context.OsmConfigs.Add(osmconfig);
                    context.SaveChanges();

                    return(RedirectToAction("Index",
                                            new RouteValueDictionary(
                                                new { controller = "Download", action = "Index", DataBaseObjectID = osmconfig.ID })));
                }
                else
                {
                    context.Entry(osmconfig).State = EntityState.Modified;
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            return(View(osmconfig));
        }
Esempio n. 13
0
        // GET: /Upload/
        public ActionResult Index(string DataBaseObjectID)
        {
            OsmConfig myConfigToDownload = null;

            foreach (OsmConfig config in context.OsmConfigs.ToList())
            {
                if (config.ID == DataBaseObjectID)
                {
                    myConfigToDownload = config;
                    break;
                }
            }

            AppLogs logs = new AppLogs();

            try
            {
                logs.AddLog("DOWNLOADLOGS", "Start Uploading");
                DoUploadGP(myConfigToDownload.Username, myConfigToDownload.Password, myConfigToDownload.FeatureDataSet, myConfigToDownload);
            }
            catch
            {
                // Exceptions logged in DoUploadGP
            }
            finally
            {
                logs.AddLog("DOWNLOADLOGS", "Finished Uploading");
            }

            // Download again the same extent
            DownloadController download = new DownloadController();

            download.JustDownload(myConfigToDownload);

            return(View());
        }
        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");
            }
        }
        //
        // GET: /OsmConfigs/Details/5
        public ViewResult Details(string id)
        {
            OsmConfig osmconfig = context.OsmConfigs.Single(x => x.ID == id);

            return(View(osmconfig));
        }
        /// <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");
            }
        }
        /// <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");
            }
        }
        public ActionResult Index(string DataBaseObjectID)
        {
            // Check if OSM is up
            //http://www.openstreetmap.org/api/0.6/map?bbox=-117.32410,33.89612,-117.32147,33.89794
            WebClient client = new WebClient();

            try
            {
                client.DownloadString("http://www.openstreetmap.org/api/0.6/map?bbox=-117.32410,33.89612,-117.32147,33.89794");
            }
            catch
            {
                ViewBag.Success = "OpenStreetMap is down, please try later";
                return(View());
            }

            if (DataBaseObjectID != null)
            {
                // Get the configuration to download
                OsmConfig myConfigToDownload = null;
                foreach (OsmConfig config in context.OsmConfigs.ToList())
                {
                    if (config.ID == DataBaseObjectID)
                    {
                        myConfigToDownload = config;
                        break;
                    }
                }

                if (myConfigToDownload == null)
                {
                    ViewBag.Result = "Cannot find the configuration, aborted.";

                    return(View());
                }

                // Download the configuration
                string results = JustDownload(myConfigToDownload);
                if (!(string.IsNullOrEmpty(results)))
                {
                    ViewBag.Result = results;

                    return(View());
                }

                // publish
                ServicePublisher.Services publisher = new ServicePublisher.Services();

                // Make sure to publish the correct host
                string sHostRequest = Request.Url.Host;

                // Pass the arguments to create a map service.
                myConfigToDownload.FeatureService = publisher.CreateService(SetTargetDatasetParamGP(myConfigToDownload),
                                                                            sHostRequest,
                                                                            DataBaseObjectID,
                                                                            myConfigToDownload.MxdTemplate,
                                                                            bUseSDE,
                                                                            ConfigurationManager.AppSettings["MxdOutput"]);

                if (ConfigurationManager.AppSettings["HostAddress"] != null)
                {
                    if (ConfigurationManager.AppSettings["HostAddress"].ToString().Length > 0)
                    {
                        sHostRequest = ConfigurationManager.AppSettings["HostAddress"].ToString();
                    }

                    myConfigToDownload.FeatureService = myConfigToDownload.FeatureService.Replace(Request.Url.Host, sHostRequest);
                }

                //Override the instance of the server if needed
                if (ConfigurationManager.AppSettings["ArcGISServerInstanceName"] != null)
                {
                    if (ConfigurationManager.AppSettings["ArcGISServerInstanceName"].ToString().Length > 0)
                    {
                        myConfigToDownload.FeatureService = myConfigToDownload.FeatureService.Replace("/arcgis/", "/" + ConfigurationManager.AppSettings["ArcGISServerInstanceName"].ToString() + "/");
                    }
                }

                context.Entry(myConfigToDownload).State = System.Data.EntityState.Modified;
                context.SaveChanges();

                ViewBag.Result          = myConfigToDownload.FeatureService;
                ViewBag.ResultMapServer = myConfigToDownload.FeatureService.Replace("/FeatureServer", "/MapServer");
                ViewBag.TitleReturn     = "Download Complete";

                ViewBag.EditingUrl = Url.Content("~/Editor?FeatureService=" + myConfigToDownload.FeatureService);

                ViewBag.ArcGIS_Com = "http://arcgis.com/home/webmap/viewer.html?url=" + myConfigToDownload.FeatureService;
            }

            ViewBag.Success = "Successfully created the Feature Service by downloading the requested data from OpenStreetMap.";

            return(View());
        }