MobileCache m_mobileCache1; m_mobileCache1 = new MobileCache(@C:\user\MobileCache); m_mobileCache1.Open(); Map mMap = new Map(); mMap.MapLayers.AddRange(m_mobileCache1); if (m_mobileCache1.CacheExists) { m_mobileCache1.Close(); m_mobileCache1.DeleteCache(); } MobileServiceConnection con = new MobileServiceConnection(); con.Url = @"http://server/arcgis/services/Test_Mobile_Services/Radiation_Data_V1_B11/MapServer/Mobileserver"; con.CreateCache(m_mobileCache1); m_mobileCache1.Open(); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(m_mobileCache1); agent.MapDocumentConnection = con; agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); mMap.MapLayers.AddRange(m_mobileCache1);
MobileCache mobileCache1 = new MobileCache(); Map map1 = new Map(); MapControl mapControl1 = new MapControl(); MobileServiceConnection mobileServiceConnection1 = new MobileServiceConnection(); //mobileServiceConnection1.CreateCache("Rad_Data"); try { mobileCache1.StoragePath = @C:\Akhil\ArcGIS_Mobile_Projects\P_Radiation_Data_V3_B1\Radiation_Data; //Uncomment these lines if you are using your own service mobileCache1.DeleteCache(); mobileServiceConnection1.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data/MapServer/MobileServer"; MobileCacheSyncAgent mobileSync = new MobileCacheSyncAgent(mobileCache1, mobileServiceConnection1); MobileCacheSyncResults mobileResults = new MobileCacheSyncResults(); //get the schema to determine list of layers mobileServiceConnection1.CreateCache(mobileCache1); mobileCache1.Open(); mobileSync.Synchronize(); //map1.DataSources.Add(mobileCache1); <-- THIS DOES NOT WORK //mapControl1.Map.Content = (mobileCache1); <-- THIS DOES NOT WORK } catch { MessageBox.Show("Cannot open map cache"); }
mapControl.Map.MapLayers.AddRange(mobileCache1);
MobileApplication.Current.Map.MapLayers.AddRange(mobileCache1);
MobileApplication.Current.Map........????
public static void Download_Data() { ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog("This is where the automatic download of data occurs!"); // Create an instance of MobileCache, and set StoragePath MobileCache mobileCache = new MobileCache(); mobileCache.StoragePath = @C:\Akhil\ArcGIS_Mobile_Projects\P_Radiation_Data_V1_B1\Radiation_Data_V1; try { if (mobileCache.CacheExists) { mobileCache.Close(); } mobileCache.Open(); MobileServiceConnection con = new MobileServiceConnection(); con.Url = "http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/MobileServer"; FeatureLayerSyncAgent agent0 = new FeatureLayerSyncAgent(mobileCache.FeatureLayers[0]); agent0.MapDocumentConnection = con; agent0.StateChanged += new EventHandler(agent_StateChanged); agent0.Synchronize(); FeatureLayerSyncAgent agent1 = new FeatureLayerSyncAgent(mobileCache.FeatureLayers[1]); agent1.MapDocumentConnection = con; //agent1.StateChanged += new EventHandler(agent_StateChanged); agent1.StateChanged += new EventHandler(agent_StateChanged); agent1.Synchronize(); FeatureLayerSyncAgent agent2 = new FeatureLayerSyncAgent(mobileCache.FeatureLayers[2]); agent2.MapDocumentConnection = con; agent2.StateChanged += new EventHandler(agent_StateChanged); agent2.Synchronize(); catch (Exception exception) { if (mobileCache.CacheExists) { if (mobileCache.IsOpen) { mobileCache.Close(); } } }
public static void Download_Data() { MobileCache m_mobileCache1; m_mobileCache1 = new MobileCache(@C:\Akhil\MobileCache); MessageBox.Show("before opening mobile cache"); m_mobileCache1.Open(); Map mMap = new Map(); MessageBox.Show("new map"); //mMap.MapLayers.AddRange(m_mobileCache1); // Delete the above line since your doing this at the end of your code if (m_mobileCache1.CacheExists) { m_mobileCache1.Close(); m_mobileCache1.DeleteCache(); MessageBox.Show("deletes cache"); } else { //You did a m_mobileCache1.Open(); twice if cache does not exist // Once above and once below. You need to close it here since you are opening it below m_mobileCache1.Close(); MessageBox.Show("closes cache"); } MessageBox.Show("creating mobile connection"); MobileServiceConnection con = new MobileServiceConnection(); MessageBox.Show("after creating mobile connection"); con.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/Mobileserver"; MessageBox.Show("sets the URL"); con.CreateCache(m_mobileCache1.StoragePath); // Per ESRI sample m_mobileCache1.Open(); MessageBox.Show("opens cache"); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(m_mobileCache1, con); agent.MapDocumentConnection = con; //agent.Synchronize(); // See if Synchronize works instead of line below agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); MessageBox.Show("after synch"); mMap.MapLayers.AddRange(m_mobileCache1); MessageBox.Show("adds to map"); //LoadData(); //mMap.Refresh(); mMap.Invalidate(); }
mapControl1.MapLayers.AddRange(m_mobileCache1);
using ESRI.ArcGIS.Mobile.WPF; ESRI.ArcGIS.Mobile.WPF.Map mMap = new ESRI.ArcGIS.Mobile.WPF.Map(); mMap.MapLayers.AddRange(m_mobileCache1);
public static void Download_Data() { ViewMapTask viewMapTask = (ViewMapTask)MobileApplication.Current.Project.Tasks.GetFirstExtensionOfType(typeof(ViewMapTask)); ViewMapPage viewMapPage = viewMapTask.ViewMapPage; MapControl mMap = viewMapTask.ViewMapPage.MapControl; MobileCache m_mobileCache1; m_mobileCache1 = new MobileCache(@C:\Akhil\ArcGIS_Mobile_Projects\P_Radiation_Data_V1_B8\Radiation_Data_V1); m_mobileCache1.Open(); if (m_mobileCache1.CacheExists) { m_mobileCache1.Close(); try { m_mobileCache1.DeleteCache(); } catch (Exception ex) { MessageBox.Show("FIRST ERROR " + Convert.ToString(ex)); } } else { m_mobileCache1.Close(); } MobileServiceConnection con = new MobileServiceConnection(); con.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/Mobileserver"; con.CreateCache(m_mobileCache1.StoragePath); // Per ESRI sample m_mobileCache1.Open(); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(m_mobileCache1, con); agent.MapDocumentConnection = con; //agent.Synchronize(); // See if Synchronize works instead of line below agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); try { mMap.Map.MapLayers.AddRange(m_mobileCache1); } catch (Exception ex) { MessageBox.Show("Second ERROR " + ex.ToString()); } }
1) The first problem is the first try and catch section, the catch is always triggered because the cache is in use. The error is "cache is in use by another process", fortunately aslong as a messagebox appears the code will continue, and works as expected.I modified your first try catch. I notice that I don't actually need to open and close a cache to delete it.2) If I comment out the first catch messagebox, the second try and catch section is triggered. The error states "object reference is invalid". As long as we can solve the first problem then hopefully the second try and catch will work without problems.See code below, I think you added an extra reference to the Map that I do not see in ESRI samples.public static void Download_Data() { ViewMapTask viewMapTask = (ViewMapTask)MobileApplication.Current.Project.Tasks.GetFirstExtensionOfType(typeof(ViewMapTask)); ViewMapPage viewMapPage = viewMapTask.ViewMapPage; MapControl mMap = viewMapTask.ViewMapPage.MapControl; MobileCache m_mobileCache1; m_mobileCache1 = new MobileCache(@C:\Akhil\ArcGIS_Mobile_Projects\P_Radiation_Data_V1_B8\Radiation_Data_V1); if (m_mobileCache1.CacheExists) { try { m_mobileCache1.DeleteCache(); } catch (Exception ex) { MessageBox.Show("FIRST ERROR " + Convert.ToString(ex)); } } MobileServiceConnection con = new MobileServiceConnection(); con.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/Mobileserver"; con.CreateCache(m_mobileCache1.StoragePath); // Per ESRI sample m_mobileCache1.Open(); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(m_mobileCache1, con); agent.MapDocumentConnection = con; //agent.Synchronize(); // See if Synchronize works instead of line below agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); try { // mMap.Map.MapLayers.AddRange(m_mobileCache1); This line should be as follows: mMap.MapLayers.AddRange(m_mobileCache1); } catch (Exception ex) { MessageBox.Show("Second ERROR " + ex.ToString()); } }
public static void Download_Data() { ViewMapTask viewMapTask = (ViewMapTask)MobileApplication.Current.Project.Tasks.GetFirstExtensionOfType(typeof(ViewMapTask)); ViewMapPage viewMapPage = viewMapTask.ViewMapPage; MapControl mMap = viewMapTask.ViewMapPage.MapControl; MobileCache m_mobileCache1; m_mobileCache1 = new MobileCache(@C:\Akhil\ArcGIS_Mobile_Projects\P_Radiation_Data_V1_B8\Radiation_Data_V1); if (m_mobileCache1.CacheExists) { try { m_mobileCache1.DeleteCache(); } catch (Exception ex) { MessageBox.Show("FIRST ERROR " + Convert.ToString(ex)); } } MobileServiceConnection con = new MobileServiceConnection(); con.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/Mobileserver"; con.CreateCache(m_mobileCache1.StoragePath); // Per ESRI sample m_mobileCache1.Open(); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(m_mobileCache1, con); agent.MapDocumentConnection = con; //agent.Synchronize(); // See if Synchronize works instead of line below agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); try { // mMap.Map.MapLayers.AddRange(m_mobileCache1); This line should be as follows: mMap.MapLayers.AddRange(m_mobileCache1); } catch (Exception ex) { MessageBox.Show("Second ERROR " + ex.ToString()); } }
public static void Download_DataAkhil() { ViewMapTask viewMapTask = (ViewMapTask)MobileApplication.Current.Project.Tasks.GetFirstExtensionOfType(typeof(ViewMapTask)); ViewMapPage viewMapPage = viewMapTask.ViewMapPage; MapControl mMap = viewMapTask.ViewMapPage.MapControl; ESRI.ArcGIS.Mobile.WPF.Map MyMap = mMap.Map; MobileCache m_mobileCache1; m_mobileCache1 = new MobileCache(@C:\Akhil\ArcGIS_Mobile_Projects\P_Radiation_Data_V1_B8\Radiation_Data_V1); if (m_mobileCache1.CacheExists) { try { m_mobileCache1.DeleteCache(); } catch (Exception ex) { MessageBox.Show(Convert.ToString(ex)); //Still gives error } } else { m_mobileCache1.Close(); } MobileServiceConnection con = new MobileServiceConnection(); con.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/Mobileserver"; con.CreateCache(m_mobileCache1.StoragePath); // Per ESRI sample m_mobileCache1.Open(); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(m_mobileCache1, con); agent.MapDocumentConnection = con; //agent.Synchronize(); // See if Synchronize works instead of line below agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); try { //mMap.Map.MapLayers.AddRange(m_mobileCache1); MyMap.MapLayers.AddRange(m_mobileCache1); //Gives error now, stating null reference } catch (Exception ex) { MessageBox.Show("This is second ERROR " + ex.ToString()); } }
public static void Download_DataAkhil() { ESRI.ArcGIS.Mobile.WPF.Map nMap = MobileApplication.Current.Map; //ViewMapTask viewMapTask = (ViewMapTask)MobileApplication.Current.Project.Tasks.GetFirstExtensionOfType(typeof(ViewMapTask)); //ViewMapPage viewMapPage = viewMapTask.ViewMapPage; //MapControl mMap = viewMapTask.ViewMapPage.MapControl; //ESRI.ArcGIS.Mobile.WPF.Map MyMap = mMap.Map; MobileCache m_mobileCache1; m_mobileCache1 = new MobileCache(@C:\Akhil\ArcGIS_Mobile_Projects\P_Radiation_Data_V1_B8\Radiation_Data_V1); //if (m_mobileCache1.CacheExists) //not needed // m_mobileCache1.Close(); //not needed MobileServiceConnection con = new MobileServiceConnection(); con.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/Mobileserver"; con.CreateCache(m_mobileCache1.StoragePath); // Per ESRI sample m_mobileCache1.Open(); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(m_mobileCache1, con); agent.MapDocumentConnection = con; agent.Synchronize(); // See if Synchronize works instead of line below //agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); nMap.MapLayers.AddRange(m_mobileCache1); }
public static void Download_DataAkhil() { ESRI.ArcGIS.Mobile.WPF.Map nMap = MobileApplication.Current.Map; //ViewMapTask viewMapTask = (ViewMapTask)MobileApplication.Current.Project.Tasks.GetFirstExtensionOfType(typeof(ViewMapTask)); //ViewMapPage viewMapPage = viewMapTask.ViewMapPage; //MapControl mMap = viewMapTask.ViewMapPage.MapControl; //ESRI.ArcGIS.Mobile.WPF.Map MyMap = mMap.Map; MobileCache m_mobileCache1; m_mobileCache1 = new MobileCache(@C:\Akhil\ArcGIS_Mobile_Projects\P_Radiation_Data_V1_B8\Radiation_Data_V1); //if (m_mobileCache1.CacheExists) //not needed // m_mobileCache1.Close(); //not needed MobileServiceConnection con = new MobileServiceConnection(); con.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/Mobileserver"; con.CreateCache(m_mobileCache1.StoragePath); // Per ESRI sample m_mobileCache1.Open(); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(m_mobileCache1, con); agent.MapDocumentConnection = con; agent.Synchronize(); // See if Synchronize works instead of line below //agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); nMap.MapLayers.AddRange(m_mobileCache1); }Thanks Buddha and Angel for helping me out, now everyone can enjoy this. 🙂Akhil P.
public static void Download_DataAkhil2() { try { ESRI.ArcGIS.Mobile.WPF.Map nMap = MobileApplication.Current.Map; MobileCache m_mobileCache1; m_mobileCache1 = new MobileCache(@C:\Akhil\ArcGIS_Mobile_Projects\P_Radiation_Data_V1_B8\Radiation_Data_V1); MobileServiceConnection con = new MobileServiceConnection(); con.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/Mobileserver"; con.CreateCache(m_mobileCache1.StoragePath); // Per ESRI sample m_mobileCache1.Open(); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(m_mobileCache1, con); agent.MapDocumentConnection = con; agent.Synchronize(); // See if Synchronize works instead of line below //agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); nMap.MapLayers.AddRange(m_mobileCache1); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
using System.Net.NetworkInformation; using System.Text; Private bool PingGISServer() { try { Ping pingSender = new Ping(); PingOptions options = new PingOptions(); options.DontFragment = true; // Create a buffer of data to be transmitted. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 120; //First check if Intranetserver is available PingReply reply = pingSender.Send("severNameHere", timeout, buffer, options); if (reply.Status == IPStatus.Success) { return true; } else { return false; } } catch (Exception ex) { return false; } if (PingGISServer()) { If true do something like upload & download data }
using System.Net.NetworkInformation; public bool isNetWorkAvailable = NetworkInterface.GetIsNetworkAvailable(); if(isNetWorkAvailable) { If true do something }...
nMap.MapLayers.AddRange(mobileCache); //refreshes the map, should use Map.Refresh or Map.Invalidate instead
public static bool PingGISServer() { try { Ping pingSender = new Ping(); PingOptions options = new PingOptions(); options.DontFragment = true; // Create a buffer of data to be transmitted. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 2000; //First check if Intranetserver is available PingReply reply = pingSender.Send("emapappdev", timeout, buffer, options); if (reply.Status == IPStatus.Success) { return true; } else { return false; } } catch (Exception ex) { return false; } } public static void Download_DataAkhil2() { if (PingGISServer() == true) { try { ESRI.ArcGIS.Mobile.WPF.Map nMap = MobileApplication.Current.Map; // instance of the Map (does not really work, but does work) string appName = MobileApplication.Current.ApplicationTitle; //gets the name of the application title to be used in cache storage path appName = appName.Remove(0, 16); //removes the first 16 characters from the application title MobileCache mobileCache = new MobileCache(@C:\NEPRD\Mobile Radiation Applications\P_ + appName + "\\Radiation_Data_V1"); MobileServiceConnection con = new MobileServiceConnection(); //connection to mobile service con.Url = @"http://emapappdev/arcgis/services/Test_Mobile_Services/Radiation_Data_V1/MapServer/Mobileserver"; con.CreateCache(mobileCache.StoragePath); // creates the cache in the storage path mobileCache.Open(); MobileCacheSyncAgent agent = new MobileCacheSyncAgent(mobileCache, con); //create an agent to the mobile cache and service agent.MapDocumentConnection = con; //sets the map document connection agent.Synchronize(); //agent.DownloadExtent(m_mobileCache1.GetExtent(), 0, 0); - alternative for downloading and synchronizing nMap.MapLayers.AddRange(mobileCache); //refreshes the map, should use Map.Refresh or Map.Invalidate instead } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } //else //{ // MessageBox.Show("Ping Failed!"); //} }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.