/// <summary> /// Asynchronously creates new StreamingFilter. /// </summary> /// <param name="name">filter name</param> /// <param name="timeRange">filter boundaries</param> /// <param name="trackConditions">filter track conditions</param> /// <returns>The task to create the filter.</returns> public Task <IStreamingAssetFilter> CreateAsync(string name, PresentationTimeRange timeRange, IList <FilterTrackSelectStatement> trackConditions) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } AssetFilterData filter = new AssetFilterData(_parentAsset.Id, name, timeRange, trackConditions); filter.SetMediaContext(MediaContext); IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AddObject(AssetFilterSet, filter); MediaRetryPolicy retryPolicy = MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(filter)) .ContinueWith <IStreamingAssetFilter>( t => { t.ThrowIfFaulted(); return (AssetFilterData)t.Result.AsyncState; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Creates new Filter /// </summary> /// <param name="name">filter name</param> /// <param name="timeRange">streaming time range</param> /// <param name="trackConditions">filter track conditions</param> /// <param name="firstQuality">first quality</param> /// <returns>The created filter.</returns> public IStreamingAssetFilter Create( string name, PresentationTimeRange timeRange, IList <FilterTrackSelectStatement> trackConditions, FirstQuality firstQuality = null) { return(AsyncHelper.Wait(CreateAsync(name, timeRange, trackConditions, firstQuality))); }
public AssetFilterData( string parentAssetId, string name, PresentationTimeRange timeRange, IList <FilterTrackSelectStatement> trackConditions) : base(name, timeRange, trackConditions) { ParentAssetId = parentAssetId; Id = String.Empty; ResourceSetName = AssetFilterBaseCollection.AssetFilterSet; }
public AssetFilterData( string parentAssetId, string name, PresentationTimeRange timeRange, IList<FilterTrackSelectStatement> trackConditions) : base(name, timeRange, trackConditions) { ParentAssetId = parentAssetId; Id = String.Empty; ResourceSetName = AssetFilterBaseCollection.AssetFilterSet; }
public StreamingFilterData(string name, PresentationTimeRange timeRange, IList <FilterTrackSelectStatement> trackConditions) { Name = name; PresentationTimeRange = timeRange != null ? new PresentationTimeRangeData(timeRange) : new PresentationTimeRangeData(); Tracks = trackConditions != null ? trackConditions.Select(track => new FilterTrackSelectStatementData(track)).ToList() : new List <FilterTrackSelectStatementData>(); ResourceSetName = StreamingFilterBaseCollection.FilterSet; }
public PresentationTimeRangeData(PresentationTimeRange range) { if (range == null) { throw new ArgumentNullException("range"); } Timescale = (Int64)(range.Timescale ?? PresentationTimeRange.TimescaleHns); StartTimestamp = (Int64) (range.StartTimestamp ?? 0); EndTimestamp = (Int64) (range.EndTimestamp ?? Int64.MaxValue); PresentationWindowDuration = range.PresentationWindowDuration.HasValue && range.PresentationWindowDuration.Value != TimeSpan.MaxValue ? (Int64)range.PresentationWindowDuration.Value.TotalMilliseconds * (Timescale / 1000) : Int64.MaxValue; LiveBackoffDuration = range.LiveBackoffDuration.HasValue && range.LiveBackoffDuration.Value != TimeSpan.MaxValue ? (Int64)range.LiveBackoffDuration.Value.TotalMilliseconds * (Timescale / 1000) : 0; }
public PresentationTimeRangeData(PresentationTimeRange range) { if (range == null) { throw new ArgumentNullException("range"); } Timescale = (Int64)(range.Timescale ?? PresentationTimeRange.TimescaleHns); StartTimestamp = (Int64)(range.StartTimestamp ?? 0); EndTimestamp = (Int64)(range.EndTimestamp ?? Int64.MaxValue); PresentationWindowDuration = range.PresentationWindowDuration.HasValue && range.PresentationWindowDuration.Value != TimeSpan.MaxValue ? (Int64)range.PresentationWindowDuration.Value.TotalMilliseconds * (Timescale / 1000) : Int64.MaxValue; LiveBackoffDuration = range.LiveBackoffDuration.HasValue && range.LiveBackoffDuration.Value != TimeSpan.MaxValue ? (Int64)range.LiveBackoffDuration.Value.TotalMilliseconds * (Timescale / 1000) : 0; }
private async void ProcessCloneProgramToAnotherAMSAccount(CredentialsEntry DestinationCredentialsEntry, string DestinationStorageAccount, IProgram sourceProgram, bool CopyDynEnc, bool RewriteLAURL, bool CloneLocators, bool CloneAssetFilters) { TextBoxLogWriteLine("Starting the program cloning process."); CloudMediaContext DestinationContext = Program.ConnectAndGetNewContext(DestinationCredentialsEntry); // let's check that target channel exists IChannel clonedchannel = DestinationContext.Channels.Where(c => c.Name == sourceProgram.Channel.Name).FirstOrDefault(); if (clonedchannel == null) { TextBoxLogWriteLine(string.Format("Cloned channel '{0}' not found in destination account!", sourceProgram.Channel.Name), true); return; } // let's check that a program with same name does not already exist for the channel if (DestinationContext.Programs.Where(p => p.Name == sourceProgram.Name && p.ChannelId == clonedchannel.Id).FirstOrDefault() != null) { TextBoxLogWriteLine(string.Format("A program '{0}' has been already found in destination account for channel '{1}'. A new one cannot be created.", sourceProgram.Name, clonedchannel.Name), true); return; } // Cloned asset creation IAsset clonedAsset = DestinationContext.Assets.Create(sourceProgram.Asset.Name, DestinationStorageAccount, AssetCreationOptions.None); TextBoxLogWriteLine(string.Format("Cloned asset {0} created.", sourceProgram.Asset.Name)); if (CopyDynEnc) { TextBoxLogWriteLine("Dynamic encryption settings copy..."); try { await DynamicEncryption.CopyDynamicEncryption(sourceProgram.Asset, clonedAsset, RewriteLAURL); TextBoxLogWriteLine("Dynamic encryption settings copied."); } catch (Exception ex) { TextBoxLogWriteLine("Error when copying Dynamic encryption", true); TextBoxLogWriteLine(ex); } } if (CloneLocators) { try { TextBoxLogWriteLine("Creating locator for cloned asset '{0}'", sourceProgram.Asset.Name); foreach (var streamlocator in sourceProgram.Asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin)) { IAccessPolicy policy = DestinationContext.AccessPolicies.Create("AP:" + sourceProgram.Asset.Name, (streamlocator.ExpirationDateTime - DateTime.UtcNow), AccessPermissions.Read); DestinationContext.Locators.CreateLocator(streamlocator.Id, LocatorType.OnDemandOrigin, clonedAsset, policy, streamlocator.StartTime); TextBoxLogWriteLine(string.Format("Cloned locator {0} created.", streamlocator.Id)); } } catch (Exception ex) { // Add useful information to the exception TextBoxLogWriteLine("There is a problem when creating the locator for the asset '{0}'.", clonedAsset.Name, true); TextBoxLogWriteLine(ex); } } if (CloneAssetFilters && sourceProgram.Asset.AssetFilters.Count() > 0) { try { TextBoxLogWriteLine("Copying filter(s) to cloned asset '{0}'", sourceProgram.Asset.Name); foreach (var filter in sourceProgram.Asset.AssetFilters) { // let's remove start and end time var PTR = new PresentationTimeRange(filter.PresentationTimeRange.Timescale, null, null, filter.PresentationTimeRange.PresentationWindowDuration, filter.PresentationTimeRange.LiveBackoffDuration); clonedAsset.AssetFilters.Create(filter.Name, PTR, filter.Tracks); TextBoxLogWriteLine(string.Format("Cloned filter {0} created.", filter.Name)); } } catch (Exception ex) { // Add useful information to the exception TextBoxLogWriteLine("There is a problem when copying filter(s) to the asset '{0}'.", clonedAsset.Name, true); TextBoxLogWriteLine(ex); } } var options = new ProgramCreationOptions() { Name = sourceProgram.Name, Description = sourceProgram.Description, ArchiveWindowLength = sourceProgram.ArchiveWindowLength, AssetId = clonedAsset.Id, ManifestName = sourceProgram.ManifestName }; var STask = ProgramExecuteAsync( () => clonedchannel.Programs.CreateAsync(options), sourceProgram.Name, "created"); await STask; TextBoxLogWriteLine(string.Format("Cloned program {0} created.", sourceProgram.Name)); }
private void DynManifestFilter_Load(object sender, EventArgs e) { _parentassetmanifestdata = new ManifestTimingData(); tabControl1.TabPages.Remove(tabPageTRRaw); FillComboBoxImportFilters(_parentAsset); timeControlDVR.TotalDuration = TimeSpan.FromHours(24); timeControlDVR.Max = TimeSpan.FromHours(24); ///////////////////////////////////////////// // New Global Filter ///////////////////////////////////////////// if (_filterToDisplay == null && _parentAsset == null) { newfilter = true; isGlobalFilter = true; tabControl1.TabPages.Remove(tabPageInformation); _filter_presentationtimerange = new PresentationTimeRange(); // _filter_tracks = new List<FilterTrackSelectStatement>(); filtertracks = new List<ExFilterTrack>(); timeControlStart.DisplayTrackBar = timeControlEnd.DisplayTrackBar = timeControlDVR.DisplayTrackBar = false; _timescale = timeControlStart.TimeScale = timeControlEnd.TimeScale = timeControlDVR.TimeScale = _filter_presentationtimerange.Timescale; textBoxFilterTimeScale.Text = (_filter_presentationtimerange.Timescale == null) ? "(default)" : _filter_presentationtimerange.Timescale.ToString(); } ///////////////////////////////////////////// // Existing Global Filter ///////////////////////////////////////////// else if (_filterToDisplay != null && _parentAsset == null) { newfilter = false; isGlobalFilter = true; DisplayFilterInfo(); _filter_name = _filterToDisplay.Name; _filter_presentationtimerange = _filterToDisplay.PresentationTimeRange; //_filter_tracks = new List<FilterTrackSelectStatement>(); filtertracks = ConvertFilterTracksToInternalVar(_filterToDisplay.Tracks); _timescale = _filterToDisplay.PresentationTimeRange.Timescale; timeControlStart.TimeScale = timeControlEnd.TimeScale = timeControlDVR.TimeScale = _timescale; buttonOk.Text = "Update Filter"; buttonOk.Enabled = true; // we can enable the button toolTip1.SetToolTip(this.buttonOk, "It can take up to 2 minutes for streaming endpoint to refresh the rules"); textBoxFilterName.Enabled = false; // no way to change the filter name textBoxFilterName.Text = _filter_name; timeControlStart.DisplayTrackBar = timeControlEnd.DisplayTrackBar = timeControlDVR.DisplayTrackBar = false; checkBoxStartTime.Checked = _filter_presentationtimerange.StartTimestamp != null; checkBoxEndTime.Checked = _filter_presentationtimerange.EndTimestamp != null; checkBoxDVRWindow.Checked = _filter_presentationtimerange.PresentationWindowDuration != null; checkBoxLiveBackoff.Checked = _filter_presentationtimerange.LiveBackoffDuration != null; timeControlStart.SetScaledTimeStamp(_filter_presentationtimerange.StartTimestamp); timeControlEnd.SetScaledTimeStamp(_filter_presentationtimerange.EndTimestamp); timeControlDVR.SetTimeStamp(_filter_presentationtimerange.PresentationWindowDuration ?? TimeSpan.FromMinutes(2)); // we don't want to pass the max value to the control (overflow) TimeSpan backoff = _filter_presentationtimerange.LiveBackoffDuration ?? new TimeSpan(0); numericUpDownBackoffSeconds.Value = Convert.ToDecimal(backoff.TotalSeconds); } ///////////////////////////////////////////// // New Asset Filter ///////////////////////////////////////////// else if (_filterToDisplay == null && _parentAsset != null) { newfilter = true; isGlobalFilter = false; tabControl1.TabPages.Remove(tabPageInformation); _filter_presentationtimerange = new PresentationTimeRange(); //_filter_tracks = new List<FilterTrackSelectStatement>(); filtertracks = new List<ExFilterTrack>(); labelFilterTitle.Text = "Asset Filter"; textBoxAssetName.Visible = true; labelassetname.Visible = true; textBoxAssetName.Text = _parentAsset != null ? _parentAsset.Name : string.Empty; // let's try to read asset timing _parentassetmanifestdata = AssetInfo.GetManifestTimingData(_parentAsset); if (!_parentassetmanifestdata.Error) // we were able to read asset timings and not live { // timescale _timescale = timeControlStart.TimeScale = timeControlEnd.TimeScale = timeControlDVR.TimeScale = _parentassetmanifestdata.TimeScale; timeControlStart.ScaledFirstTimestampOffset = timeControlEnd.ScaledFirstTimestampOffset = _parentassetmanifestdata.TimestampOffset; textBoxOffset.Text = _parentassetmanifestdata.TimestampOffset.ToString(); labelOffset.Visible = textBoxOffset.Visible = true; // let's disable trackbars if this is live (duration is not fixed) timeControlStart.DisplayTrackBar = timeControlEnd.DisplayTrackBar = timeControlDVR.DisplayTrackBar = !_parentassetmanifestdata.IsLive; TimeSpan duration = _parentassetmanifestdata.AssetDuration; textBoxAssetDuration.Text = duration.ToString(@"d\.hh\:mm\:ss"); labelassetduration.Visible = textBoxAssetDuration.Visible = true; textBoxFilterName.Text = "filter" + new Random().Next(9999).ToString(); if (!_parentassetmanifestdata.IsLive) // Not a live content { // let set duration and active track bat timeControlStart.TotalDuration = timeControlEnd.TotalDuration = timeControlDVR.TotalDuration = _parentassetmanifestdata.AssetDuration; timeControlDVR.TotalDuration = TimeSpan.FromHours(24); timeControlStart.Max = timeControlEnd.Max = duration; timeControlEnd.SetTimeStamp(timeControlEnd.Max); } else { textBoxAssetDuration.Text += " (LIVE)"; } if (_subclipconfig != null && _subclipconfig.Trimming) // user used the subclip UI before and timings are passed { timeControlStart.SetTimeStamp(_subclipconfig.StartTimeForAssetFilter - timeControlStart.GetOffSetAsTimeSpan()); timeControlEnd.SetTimeStamp(_subclipconfig.EndTimeForAssetFilter - timeControlStart.GetOffSetAsTimeSpan()); checkBoxStartTime.Checked = checkBoxEndTime.Checked = true; textBoxFilterName.Text = "subclip" + new Random().Next(9999).ToString(); } } else // not able to read asset timings { timeControlStart.DisplayTrackBar = timeControlEnd.DisplayTrackBar = timeControlDVR.DisplayTrackBar = false; timeControlStart.TimeScale = timeControlEnd.TimeScale = timeControlDVR.TimeScale = _timescale; timeControlStart.Max = timeControlEnd.Max = timeControlDVR.Max = TimeSpan.MaxValue; timeControlEnd.SetTimeStamp(timeControlEnd.Max); labelassetduration.Visible = textBoxAssetDuration.Visible = false; } } ///////////////////////////////////////////// // Existing Asset Filter ///////////////////////////////////////////// else if (_filterToDisplay != null && _parentAsset != null) { newfilter = false; isGlobalFilter = false; DisplayFilterInfo(); _filter_name = _filterToDisplay.Name; _filter_presentationtimerange = _filterToDisplay.PresentationTimeRange; //_filter_tracks = _filterToDisplay.Tracks; filtertracks = ConvertFilterTracksToInternalVar(_filterToDisplay.Tracks); _timescale = _filterToDisplay.PresentationTimeRange.Timescale; buttonOk.Text = "Update Filter"; buttonOk.Enabled = true; // we can enable the button toolTip1.SetToolTip(this.buttonOk, "It can take up to 2 minutes for streaming endpoint to refresh the rules"); labelFilterTitle.Text = "Asset Filter"; textBoxAssetName.Visible = true; labelassetname.Visible = true; textBoxAssetName.Text = _parentAsset != null ? _parentAsset.Name : string.Empty; textBoxFilterName.Enabled = false; // no way to change the filter name textBoxFilterName.Text = _filter_name; // let's try to read asset timing _parentassetmanifestdata = AssetInfo.GetManifestTimingData(_parentAsset); _timescale = timeControlStart.TimeScale = timeControlEnd.TimeScale = timeControlDVR.TimeScale = _filterToDisplay.PresentationTimeRange.Timescale; if (!_parentassetmanifestdata.Error && _timescale == _parentassetmanifestdata.TimeScale) // we were able to read asset timings and timescale between manifest and existing asset match { // let's disable trackbars if this is live (duration is not fixed) timeControlStart.DisplayTrackBar = timeControlEnd.DisplayTrackBar = timeControlDVR.DisplayTrackBar = !_parentassetmanifestdata.IsLive; timeControlStart.ScaledFirstTimestampOffset = timeControlEnd.ScaledFirstTimestampOffset = _parentassetmanifestdata.TimestampOffset; textBoxOffset.Text = _parentassetmanifestdata.TimestampOffset.ToString(); labelOffset.Visible = textBoxOffset.Visible = true; TimeSpan duration = _parentassetmanifestdata.AssetDuration; textBoxAssetDuration.Text = duration.ToString(@"d\.hh\:mm\:ss"); labelassetduration.Visible = textBoxAssetDuration.Visible = true; if (!_parentassetmanifestdata.IsLive) { timeControlStart.Max = timeControlEnd.Max = duration; // let set duration and active track bat timeControlStart.TotalDuration = timeControlEnd.TotalDuration = duration; } else { textBoxAssetDuration.Text += " (LIVE)"; } } else // not able to read asset timings or mismatch in timescale { timeControlStart.DisplayTrackBar = timeControlEnd.DisplayTrackBar = timeControlDVR.DisplayTrackBar = false; timeControlStart.Max = timeControlEnd.Max = TimeSpan.MaxValue; //timeControlEnd.SetTimeStamp(timeControlEnd.Max); labelassetduration.Visible = textBoxAssetDuration.Visible = false; } checkBoxStartTime.Checked = _filter_presentationtimerange.StartTimestamp != null; checkBoxEndTime.Checked = _filter_presentationtimerange.EndTimestamp != null; checkBoxDVRWindow.Checked = _filter_presentationtimerange.PresentationWindowDuration != null; checkBoxLiveBackoff.Checked = _filter_presentationtimerange.LiveBackoffDuration != null; timeControlStart.SetScaledTimeStamp(_filter_presentationtimerange.StartTimestamp); timeControlEnd.SetScaledTimeStamp(_filter_presentationtimerange.EndTimestamp); // we don't want to pass the max value to the control (overflow) timeControlDVR.SetTimeStamp(_filter_presentationtimerange.PresentationWindowDuration ?? TimeSpan.FromMinutes(2)); // we don't want to pass the max value to the control (overflow) TimeSpan backoff = _filter_presentationtimerange.LiveBackoffDuration ?? new TimeSpan(0); numericUpDownBackoffSeconds.Value = Convert.ToDecimal(backoff.TotalSeconds); } // Common code textBoxFilterTimeScale.Text = (_timescale == null) ? "(default)" : _timescale.ToString(); // dataPropertyType dataPropertyType = new DataTable(); dataPropertyType.Columns.Add(new DataColumn("Value", typeof(string))); dataPropertyType.Columns.Add(new DataColumn("Description", typeof(string))); dataPropertyType.Rows.Add(FilterTrackType.Audio.ToString(), FilterTrackType.Audio.ToString()); dataPropertyType.Rows.Add(FilterTrackType.Video.ToString(), FilterTrackType.Video.ToString()); dataPropertyType.Rows.Add(FilterTrackType.Text.ToString(), FilterTrackType.Text.ToString()); // FilterPropertyFourCCValue dataPropertyFourCC = new DataTable(); dataPropertyFourCC.Columns.Add(new DataColumn("Value", typeof(string))); dataPropertyFourCC.Columns.Add(new DataColumn("Description", typeof(string))); dataPropertyFourCC.Rows.Add(FilterPropertyFourCCValue.avc1, FilterPropertyFourCCValue.avc1); dataPropertyFourCC.Rows.Add(FilterPropertyFourCCValue.ec3, FilterPropertyFourCCValue.ec3); dataPropertyFourCC.Rows.Add(FilterPropertyFourCCValue.mp4a, FilterPropertyFourCCValue.mp4a); dataPropertyFourCC.Rows.Add(FilterPropertyFourCCValue.mp4v, FilterPropertyFourCCValue.mp4v); // dataProperty dataProperty = new DataTable(); dataProperty.Columns.Add(new DataColumn("Property", typeof(string))); dataProperty.Columns.Add(new DataColumn("Description", typeof(string))); dataProperty.Rows.Add(FilterProperty.Type, FilterProperty.Type); dataProperty.Rows.Add(FilterProperty.Bitrate, FilterProperty.Bitrate); dataProperty.Rows.Add(FilterProperty.FourCC, FilterProperty.FourCC); dataProperty.Rows.Add(FilterProperty.Language, FilterProperty.Language); dataProperty.Rows.Add(FilterProperty.Name, FilterProperty.Name); // dataOperator dataOperator = new DataTable(); dataOperator.Columns.Add(new DataColumn("Operator", typeof(string))); dataOperator.Columns.Add(new DataColumn("Description", typeof(string))); dataOperator.Rows.Add(FilterTrackCompareOperator.Equal.ToString(), FilterTrackCompareOperator.Equal.ToString()); dataOperator.Rows.Add(FilterTrackCompareOperator.NotEqual.ToString(), FilterTrackCompareOperator.NotEqual.ToString()); var columnProperty = new DataGridViewComboBoxColumn(); columnProperty.DataSource = dataProperty; columnProperty.ValueMember = "Property"; columnProperty.DisplayMember = "Description"; dataGridViewTracks.Columns.Add(columnProperty); var columnOperator = new DataGridViewComboBoxColumn(); columnOperator.DataSource = dataOperator; columnOperator.ValueMember = "Operator"; columnOperator.DisplayMember = "Description"; dataGridViewTracks.Columns.Add(columnOperator); var columnValue = new DataGridViewTextBoxColumn(); dataGridViewTracks.Columns.Add(columnValue); moreinfoprofilelink.Links.Add(new LinkLabel.Link(0, moreinfoprofilelink.Text.Length, Constants.LinkHowIMoreInfoDynamicManifest)); RefreshTracks(); CheckIfErrorTimeControls(); UpdateDurationText(); }
/// <summary> /// Creates new Filter /// </summary> /// <param name="name">filter name</param> /// <param name="timeRange">streaming time range</param> /// <param name="trackConditions">filter track conditions</param> /// <returns>The created filter.</returns> public IStreamingFilter Create(string name, PresentationTimeRange timeRange, IList <FilterTrackSelectStatement> trackConditions) { return(AsyncHelper.Wait(CreateAsync(name, timeRange, trackConditions))); }