Skip to content

Commit

Permalink
ArcGIS Pro 2.2 SDK for .NET
Browse files Browse the repository at this point in the history
  • Loading branch information
UmaHarano committed Jun 26, 2018
1 parent a5f7311 commit b76a662
Show file tree
Hide file tree
Showing 1,507 changed files with 11,576 additions and 2,678 deletions.
21 changes: 10 additions & 11 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
*.gdb
*.zip
*.7z
*.sqlite

# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
Expand Down Expand Up @@ -41,13 +42,19 @@ x64/
*.vspscc
*.vssscc
.builds
.tmp_proj
*.tmp_proj

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

# Visual Studio profiler
*.psess
Expand Down Expand Up @@ -111,14 +118,6 @@ Generated_Code #added for RIA/Silverlight projects
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
/Workflow/WorkflowManagerConfigSample/.vs/WorkflowManagerConfigSample/v15/Server/sqlite3
/.vs/Samples/v15/Server/sqlite3
/Content/PortalInfoListAllFedServers/.vs/ListAllFedServers/v15/Server/sqlite3
/Framework/ModifyProUIWithDAML/.vs/ModifyProUIWithDAML/v15/Server/sqlite3
/Raster/CustomRasterIdentify/.vs/CustomRasterIdentify/v15/Server/sqlite3
/Raster/LockToSelectedRasters/.vs/LockToSelectedRasters/v15/Server/sqlite3
/Raster/ScientificDataStatisticalAnalysis/.vs/ScientificDataStatisticalAnalysis/v15/Server/sqlite3
/Sharing/LivingAtlasOfTheWorld/.vs/LivingAtlasOfTheWorld/v15/Server/sqlite3
/Sharing/UploadItem/.vs/UploadItem/v15/Server/sqlite3
/Framework/QAReviewTool/.vs
/Content/ContentFileExplorer/.vs/ContentFileExplorer/v15/Server/sqlite3
/.vs
.vs
*.ide
214 changes: 214 additions & 0 deletions Content/AddInInfoManager/AddIn.cs
@@ -0,0 +1,214 @@
/*
Copyright 2018 Esri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Xml;

namespace AddInInfoManager
{
/// <summary>
/// Encapsulated AddIn metadata
/// </summary>
public class AddIn
{
public string Name { get; set; }
public string Version { get; set; }
public string DesktopVersion { get; set; }
public string AddInPath { get; set; }
public string Id { get; set; }
public string Image { get; set; }
public BitmapImage Thumbnail { get; set; }
public string AddInDate { get; set; }

/// <summary>
/// Get the current add-in module's daml / AddInInfo Id tag (which is the same as the Assembly GUID)
/// </summary>
/// <returns></returns>
public static string GetAddInId()
{
// Module.Id is internal, but we can still get the ID from the assembly
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
var fileName = Path.Combine($@"{{{attribute.Value.ToString()}}}", $@"{assembly.FullName.Split(',')[0]}.esriAddInX");
return fileName;
}

/// <summary>
/// returns a tuple with version and desktopVersion using the given addin file path
/// </summary>
/// <param name="fileName">file path (partial) of esriAddinX package</param>
/// <returns>tuple: version, desktopVersion</returns>
public static AddIn GetConfigDamlAddInInfo(string fileName)
{
var esriAddInX = new AddIn();
XmlDocument xDoc = new XmlDocument();
var esriAddInXPath = FindEsriAddInXPath(fileName);
try
{
esriAddInX.AddInPath = esriAddInXPath;
using (ZipArchive zip = ZipFile.OpenRead(esriAddInXPath))
{
ZipArchiveEntry zipEntry = zip.GetEntry("Config.daml");
MemoryStream ms = new MemoryStream();
string daml = string.Empty;
using (Stream stmZip = zipEntry.Open())
{
StreamReader streamReader = new StreamReader(stmZip);
daml = streamReader.ReadToEnd();
xDoc.LoadXml(daml); // @"<?xml version=""1.0"" encoding=""utf - 8""?>" +
}
}
XmlNodeList items = xDoc.GetElementsByTagName("AddInInfo");
foreach (XmlNode xItem in items)
{
esriAddInX.Version = xItem.Attributes["version"].Value;
esriAddInX.DesktopVersion = xItem.Attributes["desktopVersion"].Value;
esriAddInX.Id = xItem.Attributes["id"].Value;
esriAddInX.Name = "N/A";
esriAddInX.AddInDate = "N/A";
foreach (XmlNode xChild in xItem.ChildNodes)
{
switch (xChild.Name)
{
case "Name":
esriAddInX.Name = xChild.InnerText;
break;
case "Image":
esriAddInX.Image = xChild.InnerText;
break;
case "Date":
esriAddInX.AddInDate = xChild.InnerText;
break;
}
}
}
if (esriAddInX.Image != null) {
using (ZipArchive zip = ZipFile.OpenRead(esriAddInXPath))
{
esriAddInX.Thumbnail = new BitmapImage();
ZipArchiveEntry zipEntry = zip.GetEntryOrdinalIgnoreCase(esriAddInX.Image);
if (zipEntry != null)
{
MemoryStream ms = new MemoryStream();
using (Stream stmZip = zipEntry.Open())
{
stmZip.CopyTo(ms);
}
esriAddInX.Thumbnail.BeginInit();
esriAddInX.Thumbnail.StreamSource = ms;
esriAddInX.Thumbnail.EndInit();

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(esriAddInX.Thumbnail));
using (var filestream = new FileStream(@"c:\temp\test.png", FileMode.Create))
{
encoder.Save(filestream);
}
}
}
}
}
catch (Exception ex)
{
throw new Exception($@"Unable to parse config.daml {esriAddInXPath}: {ex.Message}");
}
return esriAddInX;
}

private static readonly string AddInSubFolderPath = @"ArcGIS\AddIns\ArcGISPro";
private static string FindEsriAddInXPath(string fileName)
{
string defaultAddInPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), AddInSubFolderPath);
string thePath = Path.Combine(defaultAddInPath, fileName);
if (File.Exists(thePath)) return thePath;
foreach (var addinPath in GetAddInFolders())
{
thePath = Path.Combine(addinPath, fileName);
if (File.Exists(thePath)) return thePath;
}
throw new FileNotFoundException($@"esriAddInX file for {fileName} was not found");
}

/// <summary>
/// Returns the list of all Addins
/// </summary>
/// <returns></returns>
public static List<AddIn> GetAddIns()
{
List<AddIn> addIns = new List<AddIn>();
List<string> lstPaths = GetAddInFolders();
string defaultAddInPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), AddInSubFolderPath);
lstPaths.Insert(0, defaultAddInPath);
foreach (var addinPath in lstPaths)
{
foreach (var addinDirs in Directory.GetDirectories (addinPath))
{
foreach (var addinFile in Directory.GetFiles (addinDirs, "*.esriAddinX"))
{
addIns.Add (GetConfigDamlAddInInfo(addinFile));
}
}
}
return addIns;
}

/// <summary>
/// Gets the well-known Add-in folders on the machine
/// </summary>
/// <returns>List of all well-known add-in folders</returns>
public static List<string> GetAddInFolders()
{
List<string> myAddInPathKeys = new List<string>();
string regPath = string.Format(@"Software\ESRI\ArcGISPro\Settings\Add-In Folders");
//string path = "";
string err1 = "This is an error";
try
{
Microsoft.Win32.RegistryKey localKey = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);
Microsoft.Win32.RegistryKey esriKey = localKey.OpenSubKey(regPath);
if (esriKey == null)
{
localKey = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, Microsoft.Win32.RegistryView.Registry64);
esriKey = localKey.OpenSubKey(regPath);
}
if (esriKey != null)
myAddInPathKeys.AddRange(esriKey.GetValueNames().Select(key => key.ToString()));
}
catch (InvalidOperationException ie)
{
//this is ours
throw ie;
}
catch (Exception ex)
{
throw new System.Exception(err1, ex);
}
return myAddInPathKeys;
}

}
}
@@ -1,21 +1,21 @@
## CoreHostGDB
## AddInInfoManager

<!-- TODO: Write a brief abstract explaining this sample -->
WPF application that implements a generic File GDB reader
This sample illustrates how to retrieve Add-In metadata information similar to the 'Add-in Manager' available out-of-box in the ArcGIS Pro backstage.



<a href="http://pro.arcgis.com/en/pro-app/sdk/" target="_blank">View it live</a>

<!-- TODO: Fill this section below with metadata about this sample-->
```
Language: C# 6.0
Subject: Console
Language: C#
Subject: Content
Contributor: ArcGIS Pro SDK Team <arcgisprosdk@esri.com>
Organization: Esri, http://www.esri.com
Date: 11/8/2017
ArcGIS Pro: 2.1
Visual Studio: 2015, 2017
Date: 6/11/2018
ArcGIS Pro: 2.2
Visual Studio: 2017
.NET Target Framework: 4.6.1
```

Expand All @@ -41,14 +41,13 @@ Visual Studio: 2015, 2017

## How to use the sample
<!-- TODO: Explain how this sample can be used. To use images in this section, create the image file in your sample project's screenshots folder. Use relative url to link to this image using this syntax: ![My sample Image](FacePage/SampleImage.png) -->
1. Open this solution in Visual Studio
1. Click the build menu and select Build Solution.
1. Click the Start button to run the WPF app.
1. Specify a valid path to a file geodatabase path in the 'Open a GDB' input field and click the 'Open' button.
1. The 'Open a Dataset' dropdown is filled with all available datasets.
1. Select a dataset on the 'Open a Dataset' dropdown and click the 'Read' button.
1. View the table showing the dataset's content.
![UI](Screenshots/Screen.png)
1. In Visual studio click the Build menu. Then select Build Solution.
1. Click Start button to open ArcGIS Pro.
1. ArcGIS Pro will open, select any project
1. Open the Add-in tab and click the "Show AddIn Info Manager" button to open "AddIn List" dockpane.
![UI](Screenshots/screenshot1.png)

1. Click on any of the Add-ins in "AddIn List" to delete the selected add-in.



Expand Down

0 comments on commit b76a662

Please sign in to comment.