From 2e61bf992a9ff2edc4f031b8706d52f975a8e68d Mon Sep 17 00:00:00 2001 From: Adam Nagy Date: Sat, 21 Sep 2019 17:45:14 +0100 Subject: [PATCH] Update to Inventor 2019 and VS 2017 --- GetUserIdProject/GetUserIdProject.csproj | 12 ++-- GetUserIdProject/GetUserIdProject.csproj.user | 2 +- GetUserIdProject/StandardAddInServer.cs | 32 +++++---- GetUserIdProject/WebServicesUtils.cs | 65 ------------------- 4 files changed, 30 insertions(+), 81 deletions(-) delete mode 100644 GetUserIdProject/WebServicesUtils.cs diff --git a/GetUserIdProject/GetUserIdProject.csproj b/GetUserIdProject/GetUserIdProject.csproj index 271e971..99d6466 100644 --- a/GetUserIdProject/GetUserIdProject.csproj +++ b/GetUserIdProject/GetUserIdProject.csproj @@ -30,7 +30,7 @@ v4.5 - bin\debug\ + C:\ProgramData\Autodesk\Inventor 2019\Addins\ false 285212672 false @@ -78,6 +78,9 @@ AllRules.ruleset + + C:\Program Files\Autodesk\Inventor 2020\Bin\AddinNETFramework.AdWebServicesWrapper.dll + False False @@ -95,13 +98,14 @@ Code - - + + PreserveNewest + @@ -110,7 +114,7 @@ - call "%25VS110COMNTOOLS%25vsvars32" + call "%25VS150COMNTOOLS%25VsDevCmd" mt.exe -manifest "$(ProjectDir)GetUserIdProject.X.manifest" -outputresource:"$(TargetPath)";#2 \ No newline at end of file diff --git a/GetUserIdProject/GetUserIdProject.csproj.user b/GetUserIdProject/GetUserIdProject.csproj.user index 8224e33..5ca4c31 100644 --- a/GetUserIdProject/GetUserIdProject.csproj.user +++ b/GetUserIdProject/GetUserIdProject.csproj.user @@ -2,6 +2,6 @@ Program - C:\Program Files\Autodesk\Inventor 2016\Bin\Inventor.exe + C:\Program Files\Autodesk\Inventor 2019\Bin\Inventor.exe \ No newline at end of file diff --git a/GetUserIdProject/StandardAddInServer.cs b/GetUserIdProject/StandardAddInServer.cs index 0b31e01..28f3ca4 100644 --- a/GetUserIdProject/StandardAddInServer.cs +++ b/GetUserIdProject/StandardAddInServer.cs @@ -1,8 +1,9 @@ using System; using System.Runtime.InteropServices; +using Autodesk.WebServices; using Inventor; using Microsoft.Win32; -using MsgBox = System.Windows.Forms.MessageBox; +using MsgBox = System.Windows.Forms.MessageBox; namespace GetUserIdProject { @@ -35,18 +36,27 @@ public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTi // TODO: Add ApplicationAddInServer.Activate implementation. // e.g. event initialization, command creation etc. - try - { - string userName; - string userId = WebServicesUtils.GetUserId(out userName); - MsgBox.Show( - "User ID = '" + userId + "\n" + - "User Name = '" + userName + "'"); - } - catch (Exception ex) + CWebServicesManager mgr = new CWebServicesManager(); + bool isInitialized = mgr.Initialize(); + + if (isInitialized) { - MsgBox.Show(ex.Message); + try + { + string userId = ""; + mgr.GetUserId(ref userId); + string userName = ""; + mgr.GetLoginUserName(ref userName); + MsgBox.Show( + "User ID = '" + userId + "\n" + + "User Name = '" + userName + "'"); + } + catch (Exception ex) + { + MsgBox.Show(ex.Message); + } } + } public void Deactivate() diff --git a/GetUserIdProject/WebServicesUtils.cs b/GetUserIdProject/WebServicesUtils.cs deleted file mode 100644 index 2d7c1a6..0000000 --- a/GetUserIdProject/WebServicesUtils.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Text; - -namespace GetUserIdProject -{ - class WebServicesUtils - { - [DllImport("AdWebServices", EntryPoint = "GetUserId", CharSet = CharSet.Unicode)] - private static extern int AdGetUserId(StringBuilder userid, int buffersize); - - [DllImport("AdWebServices", EntryPoint = "IsWebServicesInitialized")] - private static extern bool AdIsWebServicesInitialized(); - - [DllImport("AdWebServices", EntryPoint = "InitializeWebServices")] - private static extern void AdInitializeWebServices(); - - [DllImport("AdWebServices", EntryPoint = "IsLoggedIn")] - private static extern bool AdIsLoggedIn(); - - [DllImport("AdWebServices", EntryPoint = "GetLoginUserName", CharSet = CharSet.Unicode)] - private static extern int AdGetLoginUserName(StringBuilder username, int buffersize); - - internal static string _GetUserId() - { - int buffersize = 128; //should be long enough for userid - StringBuilder sb = new StringBuilder(buffersize); - int len = AdGetUserId(sb, buffersize); - sb.Length = len; - - return sb.ToString(); - } - - internal static string _GetUserName() - { - int buffersize = 128; //should be long enough for username - StringBuilder sb = new StringBuilder(buffersize); - int len = AdGetLoginUserName(sb, buffersize); - sb.Length = len; - - return sb.ToString(); - } - - public static string GetUserId(out string userName) - { - AdInitializeWebServices(); - - if (!AdIsWebServicesInitialized()) - throw new Exception("Could not initialize the web services component."); - - if (!AdIsLoggedIn()) - throw new Exception("User is not logged in."); - - string userId = _GetUserId(); - if (userId == "") - throw new Exception("Could not get user id."); - - userName = _GetUserName(); - if (userName == "") - throw new Exception("Could not get user name."); - - return userId; - } - } -}