public static async Task <Boolean> CheckModuleExists(string moduleName, AutomationManagementClient automationManagementClient, string resourceGroupName, string accountName, string version) { try { CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(TIMEOUT_MS); ModuleGetResponse response = await automationManagementClient.Modules.GetAsync(resourceGroupName, accountName, moduleName, cts.Token); // If the cloud module is greater or equal to local module then return false so that it gets imported. if ((response.Module.Properties.Version != null && response.Module.Properties.Version.CompareTo(version) < 0) || !(String.IsNullOrEmpty(response.Module.Properties.Error.Message))) { return(false); } } catch (Exception ex) { // Module not found. if (ex.HResult == -2146233088) { return(false); } else { throw ex; } } // Module exists and is the same or newer version return(true); }
public static async Task <Module> GetModule(string moduleName, AutomationManagementClient automationManagementClient, string resourceGroupName, string accountName) { CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(TIMEOUT_MS); ModuleGetResponse response = await automationManagementClient.Modules.GetAsync(resourceGroupName, accountName, moduleName, cts.Token); return(response.Module); }