private void DoCreateLocator(List<IAsset> SelectedAssets) { string labelAssetName; if (SelectedAssets.Count > 0) { labelAssetName = "A locator will be created for Asset '" + SelectedAssets.FirstOrDefault().Name + "'."; if (SelectedAssets.Count > 1) { labelAssetName = "A locator will be created for the " + SelectedAssets.Count.ToString() + " selected assets."; } CreateLocator form = new CreateLocator() { LocatorStartDate = DateTime.UtcNow.AddMinutes(-5), LocatorEndDate = DateTime.UtcNow.AddDays(Properties.Settings.Default.DefaultLocatorDurationDaysNew), LocAssetName = labelAssetName, LocatorHasStartDate = false, LocWarning = _context.StreamingEndpoints.Where(o => o.ScaleUnits > 0).ToList().Count > 0 ? string.Empty : "Dynamic packaging will not work as there is no scale unit streaming endpoint in this account." }; if (form.ShowDialog() == DialogResult.OK) { // The permissions for the locator's access policy. AccessPermissions accessPolicyPermissions = AccessPermissions.Read; // The duration for the locator's access policy. TimeSpan accessPolicyDuration = form.LocatorEndDate.Subtract(DateTime.UtcNow); if (form.LocatorStartDate != null) { accessPolicyDuration = form.LocatorEndDate.Subtract((DateTime)form.LocatorStartDate); } sbuilder.Clear(); try { Task.Factory.StartNew(() => ProcessCreateLocator(form.LocatorType, SelectedAssets, accessPolicyPermissions, accessPolicyDuration, form.LocatorStartDate, form.ForceLocatorGuid)); } catch (Exception e) { // Add useful information to the exception TextBoxLogWriteLine("There is a problem when creating a locator", true); TextBoxLogWriteLine(e); } } } }
private async Task DoRefreshStreamingLocators() { IList<IAsset> SelectedAssets = ReturnSelectedAssets(); if (SelectedAssets.Count > 0) { string labelAssetName = "Streaming locators will be updated for Asset '" + SelectedAssets.FirstOrDefault().Name + "'."; if (SelectedAssets.Count > 1) { labelAssetName = "Streaming locators will be updated for the " + SelectedAssets.Count.ToString() + " selected assets."; } CreateLocator form = new CreateLocator(true) { LocatorStartDate = DateTime.Now.ToLocalTime(), LocatorEndDate = DateTime.Now.ToLocalTime().AddDays(Properties.Settings.Default.DefaultLocatorDurationDaysNew), LocAssetName = labelAssetName, LocatorHasStartDate = false, LocWarning = _context.StreamingEndpoints.Where(o => o.ScaleUnits > 0).ToList().Count > 0 ? string.Empty : "Dynamic packaging will not work as there is no scale unit streaming endpoint in this account." }; if (form.ShowDialog() == DialogResult.OK) { try { foreach (var asset in SelectedAssets) { var tasks = asset .Locators .Where(locator => locator.Type == form.LocatorType) .Select(locator => UpdateLocatorExpirationDate(locator, form.LocatorEndDate)); await Task.WhenAll(tasks); } } finally { dataGridViewAssetsV.PurgeCacheAssets(SelectedAssets.ToList()); dataGridViewAssetsV.AnalyzeItemsInBackground(); } } } }