internal static async void BrowseToProject(bool bProjects = true) { try { var dlg = new OpenItemDialog(); var myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var initFolder = Path.Combine(System.IO.Path.Combine(myDocs, "ArcGIS"), "Projects"); if (!bProjects) { initFolder = @"C:\Program Files\ArcGIS\Pro\Resources\ProjectTemplates"; } if (!Directory.Exists(initFolder)) { initFolder = myDocs; } dlg.Title = "Open Project"; dlg.InitialLocation = initFolder; dlg.Filter = bProjects ? ItemFilters.projects : ItemFilters.project_templates; if (!(dlg.ShowDialog() ?? false)) { return; } var item = dlg.Items.FirstOrDefault(); if (item == null) { return; } if (bProjects) { await Project.OpenAsync(item.Path); } else { var ps = new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(item.Name), LocationPath = ConfigWithStartWizardModule.DefaultFolder(), TemplatePath = item.Path }; await Project.CreateAsync(ps); } } catch (Exception ex) { MessageBox.Show($@"Error in open project: {ex}"); } }
protected internal async virtual void ExecuteItemAction(string id) { _selectedResult = _results.FirstOrDefault(ri => ri.Id == id); if (_selectedResult == null) { return; } //Either we open a project and then create the item or //we download the item and then create a project from it. //MapPackage is a special case. We download it, create //a project and then add the map package to it. VisibleList = Visibility.Collapsed; VisibleText = Visibility.Visible; StatusTitle = $@"{_selectedResult.LinkText}: {_selectedResult.Title}"; switch (_selectedResult.PortalItemType) { case PortalItemType.WebMap: { await Project.CreateAsync(new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_selectedResult.Name) }); var currentItem = ItemFactory.Instance.Create(_selectedResult.Id, ItemFactory.ItemType.PortalItem); if (MapFactory.Instance.CanCreateMapFrom(currentItem)) { await QueuedTask.Run(() => { var newMap = MapFactory.Instance.CreateMapFromItem(currentItem); FrameworkApplication.Panes.CreateMapPaneAsync(newMap); }); } } break; case PortalItemType.Layer: { var ps = new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_selectedResult.Name), LocationPath = ConfigWithStartWizardModule.DefaultFolder(), TemplateType = TemplateType.GlobalScene }; _eventToken = ArcGIS.Desktop.Mapping.Events.MapViewInitializedEvent.Subscribe((args) => { Item currentItem = ItemFactory.Instance.Create(_selectedResult.Id, ItemFactory.ItemType.PortalItem); if (LayerFactory.Instance.CanCreateLayerFrom(currentItem)) { var lyrParams = new LayerCreationParams(currentItem); QueuedTask.Run(() => LayerFactory.Instance.CreateLayer <FeatureLayer>(lyrParams, args.MapView.Map)); } ArcGIS.Desktop.Mapping.Events.MapViewInitializedEvent.Unsubscribe(_eventToken); _eventToken = null; }); try { await Project.CreateAsync(ps); } catch (Exception ex) { Status = $@"Error occurred: {ex.ToString()}"; System.Diagnostics.Debug.WriteLine(ex.ToString()); } } break; default: var query = new OnlineQuery(_activePortalUri); query.ConfigureData("", _selectedResult.Id, _selectedResult.Name); Status = "Downloading"; await new SubmitQuery().DownloadFileAsync(query); Status = "Opening"; //Project package if (_selectedResult.PortalItemType == PortalItemType.ProjectPackage) { await Project.OpenAsync(query.DownloadFileName); } //Project Template else if (_selectedResult.PortalItemType == PortalItemType.MapTemplate) { var ps = new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_selectedResult.Name), LocationPath = ConfigWithStartWizardModule.DefaultFolder(), TemplatePath = query.DownloadFileName }; try { await Project.CreateAsync(ps); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); Status = $@"Error occurred: {ex.ToString()}"; } } //Map Package else if (_selectedResult.PortalItemType == PortalItemType.MapPackage) { await Project.CreateAsync(new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_selectedResult.Name) }); try { var mapPackage = ItemFactory.Instance.Create(query.DownloadFileName); MapFactory.Instance.CreateMapFromItem(mapPackage); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); Status = $@"Error occurred: {ex.ToString()}"; } } break; } }
protected internal async virtual void ExecuteItemAction(string url) { _result = _results.FirstOrDefault(ri => ri.Id == url); if (_result == null) { return; } //Either we open a project and then create the item or //we download the item and then create a project from it. //MapPackage is a special case. We download it, create //a project and then add the map package to it. switch (_result.OnlineItemType) { case OnlineItemType.WebMap: { await Project.CreateAsync(new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_result.Name) }); var currentItem = ItemFactory.Create(_result.Id, ItemFactory.ItemType.PortalItem); if (MapFactory.CanCreateMapFrom(currentItem)) { var newMap = await MapFactory.CreateMapAsync(currentItem); await FrameworkApplication.Panes.CreateMapPaneAsync(newMap); } } break; case OnlineItemType.Layer: { var ps = new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_result.Name), LocationPath = ConfigWithStartWizardModule.DefaultFolder(), TemplatePath = ConfigWithStartWizardModule.GetDefaultTemplates()[0] //Scene }; _eventToken = ArcGIS.Desktop.Mapping.Events.MapViewInitializedEvent.Subscribe((args) => { Item currentItem = ItemFactory.Create(_result.Id, ItemFactory.ItemType.PortalItem); if (LayerFactory.CanCreateLayerFrom(currentItem)) { QueuedTask.Run(() => LayerFactory.CreateLayer(currentItem, args.MapView.Map)); } ArcGIS.Desktop.Mapping.Events.MapViewInitializedEvent.Unsubscribe(_eventToken); _eventToken = null; }); try { await Project.CreateAsync(ps); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } break; default: var query = new OnlineQuery(_activePortalUri); query.ConfigureData("", _result.Id, _result.Name); await new SubmitQuery().DownloadFileAsync(query); //Project package if (_result.OnlineItemType == OnlineItemType.ProjectPackage) { Project.OpenAsync(query.DownloadFileName); } //Project Template else if (_result.OnlineItemType == OnlineItemType.Template) { var ps = new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_result.Name), LocationPath = ConfigWithStartWizardModule.DefaultFolder(), TemplatePath = query.DownloadFileName }; try { await Project.CreateAsync(ps); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } //Map Package else if (_result.OnlineItemType == OnlineItemType.MapPackage) { await Project.CreateAsync(new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_result.Name) }); try { var mapPackage = ItemFactory.Create(query.DownloadFileName); await Project.Current.AddAsync(mapPackage); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } break; } }