public async Task <WamsLocators> CreateLocatorsAsync(IAsset asset, WamsLocatorCategory category) { Logger.Debug("CreateLocatorsAsync() invoked for asset '{0}' with category '{1}'.", asset.Name, category); Task <WamsLocatorInfo> sasLocatorInfoTask = null; Task <WamsLocatorInfo> onDemandLocatorInfoTask = null; var primaryAssetFile = asset.AssetFiles.Where(assetFile => assetFile.IsPrimary).Single(); var isDynamicAsset = Settings.EnableDynamicPackaging && primaryAssetFile.Name.EndsWith(".ism", StringComparison.OrdinalIgnoreCase); try { sasLocatorInfoTask = CreateLocatorAsync(asset, String.Format("{0} {1} On-Demand Policy", asset.Id, category), LocatorType.Sas, Settings.AccessPolicyDuration); if (isDynamicAsset) { onDemandLocatorInfoTask = CreateLocatorAsync(asset, String.Format("{0} {1} On-Demand Policy", asset.Id, category), LocatorType.OnDemandOrigin, Settings.AccessPolicyDuration); } Logger.Information("Locators with category '{0}' were created for asset '{1}'.", category, asset.Name); return(new WamsLocators( await sasLocatorInfoTask.ConfigureAwait(continueOnCapturedContext: false), isDynamicAsset ? await onDemandLocatorInfoTask.ConfigureAwait(continueOnCapturedContext: false) : null, isDynamicAsset ? primaryAssetFile.Name : null)); } catch (Exception ex) { Logger.Error(ex, "Error while creating locators for asset '{0}'. Cleaning up any orphaned locators.", asset.Name); try { var wamsLocators = new WamsLocators( sasLocatorInfoTask != null ? sasLocatorInfoTask.Result : null, onDemandLocatorInfoTask != null ? onDemandLocatorInfoTask.Result : null, isDynamicAsset ? primaryAssetFile.Name : null); DeleteLocatorsAsync(asset, wamsLocators).Wait(); } catch (Exception iex) { Logger.Warning(iex, "Error while cleaning up orphaned locators."); } throw; } }
public async Task DeleteLocatorsAsync(IAsset asset, WamsLocators locators) { Logger.Debug("DeleteLocatorsAsync() invoked for asset '{0}'.", asset.Name); var locatorsToDelete = new List <ILocator>(); try { if (locators.SasLocator != null && !String.IsNullOrEmpty(locators.SasLocator.Id)) { locatorsToDelete.AddRange( from locator in Context.Locators where locator.Id == locators.SasLocator.Id select locator); } if (locators.OnDemandLocator != null && !String.IsNullOrEmpty(locators.OnDemandLocator.Id)) { locatorsToDelete.AddRange( from locator in Context.Locators where locator.Id == locators.OnDemandLocator.Id select locator); } var deleteTaskQuery = from locator in locatorsToDelete let accessPolicy = locator.AccessPolicy select locator.DeleteAsync().ContinueWith((previousTask) => accessPolicy.DeleteAsync()); if (deleteTaskQuery.Any()) { await Task.WhenAll(deleteTaskQuery).ConfigureAwait(continueOnCapturedContext: false); } Logger.Information("Locators were deleted for asset '{0}'.", asset.Name); } catch (Exception ex) { Logger.Error(ex, "Error while deleting locators for asset '{0}'.", asset.Name); throw; } }
public async Task DeleteLocatorsAsync(IAsset asset, WamsLocators locators) { Logger.Debug("DeleteLocatorsAsync() invoked for asset '{0}'.", asset.Name); var locatorsToDelete = new List<ILocator>(); try { if (locators.SasLocator != null && !String.IsNullOrEmpty(locators.SasLocator.Id)) locatorsToDelete.AddRange( from locator in Context.Locators where locator.Id == locators.SasLocator.Id select locator); if (locators.OnDemandLocator != null && !String.IsNullOrEmpty(locators.OnDemandLocator.Id)) locatorsToDelete.AddRange( from locator in Context.Locators where locator.Id == locators.OnDemandLocator.Id select locator); var deleteTaskQuery = from locator in locatorsToDelete let accessPolicy = locator.AccessPolicy select locator.DeleteAsync().ContinueWith((previousTask) => accessPolicy.DeleteAsync()); if (deleteTaskQuery.Any()) await Task.WhenAll(deleteTaskQuery).ConfigureAwait(continueOnCapturedContext: false); Logger.Information("Locators were deleted for asset '{0}'.", asset.Name); } catch (Exception ex) { Logger.Error(ex, "Error while deleting locators for asset '{0}'.", asset.Name); throw; } }
public async Task<WamsLocators> CreateLocatorsAsync(IAsset asset, WamsLocatorCategory category) { Logger.Debug("CreateLocatorsAsync() invoked for asset '{0}' with category '{1}'.", asset.Name, category); Task<WamsLocatorInfo> sasLocatorInfoTask = null; Task<WamsLocatorInfo> onDemandLocatorInfoTask = null; var primaryAssetFile = asset.AssetFiles.Where(assetFile => assetFile.IsPrimary).Single(); var isDynamicAsset = Settings.EnableDynamicPackaging && primaryAssetFile.Name.EndsWith(".ism", StringComparison.OrdinalIgnoreCase); try { sasLocatorInfoTask = CreateLocatorAsync(asset, String.Format("{0} {1} On-Demand Policy", asset.Id, category), LocatorType.Sas, Settings.AccessPolicyDuration); if (isDynamicAsset) onDemandLocatorInfoTask = CreateLocatorAsync(asset, String.Format("{0} {1} On-Demand Policy", asset.Id, category), LocatorType.OnDemandOrigin, Settings.AccessPolicyDuration); Logger.Information("Locators with category '{0}' were created for asset '{1}'.", category, asset.Name); return new WamsLocators( await sasLocatorInfoTask.ConfigureAwait(continueOnCapturedContext: false), isDynamicAsset ? await onDemandLocatorInfoTask.ConfigureAwait(continueOnCapturedContext: false) : null, isDynamicAsset ? primaryAssetFile.Name : null); } catch (Exception ex) { Logger.Error(ex, "Error while creating locators for asset '{0}'. Cleaning up any orphaned locators.", asset.Name); try { var wamsLocators = new WamsLocators( sasLocatorInfoTask != null ? sasLocatorInfoTask.Result : null, onDemandLocatorInfoTask != null ? onDemandLocatorInfoTask.Result : null, isDynamicAsset ? primaryAssetFile.Name : null); DeleteLocatorsAsync(asset, wamsLocators).Wait(); } catch (Exception iex) { Logger.Warning(iex, "Error while cleaning up orphaned locators."); } throw; } }