uncheck concurrent extensions when program closes

135
1
10-02-2020 01:26 PM
MarkJohnson11
New Contributor

Having done in Desktop, using C#  I used the ESRI.ArcGIS.esriSystem .dll and there was a protected override void OnStartup() and OnShutdown method I could use.

In Pro I think the best I can use is ArcGIS.Core.Licensing.LicensingInformation.CheckinLicense(LicenseCodes.'extension') method. I cannot find or think up a way to check if the extensions have been used without the ArcGIS.esriSystem .dll.  I also cannot seem to find similar OnStartup() and OnShutdown() methods for the knowing when to run the CheckinLicense() methods. 

Has anyone come across something similar to this? I am worried that even with the concurrent extensions, many of my co-workers might just check on the extensions and then never close the program, we have many more employees than extensions.

Thanks

0 Kudos
1 Reply
PascalVezina
Occasional Contributor

Good day Mark,

I am doing something similar. I use the Expiration date to know if it's in use.  

I use the Close Project event instead of the ArcGIS Pro.

 

public static bool IsCheckedOutProDataReviewer()
{
try
{
DateTime origin = new DateTime();
DateTime expire = new DateTime();
if (LicenseInformation.GetExpirationDate(LicenseCodes.DataReviewer) != null)
expire = (DateTime)LicenseInformation.GetExpirationDate(LicenseCodes.DataReviewer);
if (expire.CompareTo(origin) != 0)
return true;
else
return false;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return false;
}

 

In the Module1.cs, I added this code... (Make sure that the autoLoad="true" in the insertModule in your Config.daml)

 

protected override bool Initialize()
{
try
{
ProjectClosedEvent.Subscribe(OnProjectClose);

}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return base.Initialize();

}

private void OnProjectClose(ProjectEventArgs obj)
{
try
{
ExecuteShutdownReviewExtension();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}


private void ExecuteShutdownReviewExtension()
{

try
{
if (ClassHelperReviewer.IsCheckedOutProDataReviewer())
    ClassHelperReviewer.DisableProDataReviewer();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

protected override void Uninitialize()
{
try
{
ProjectClosedEvent.Unsubscribe(OnProjectClose); //unsubscribe
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return;
}

 

 

0 Kudos