public void RefreshStreamingEndpoints(CloudMediaContext context) { if (!_initialized) { return; } this.BeginInvoke(new Action(() => this.FindForm().Cursor = Cursors.WaitCursor)); _context = context; IEnumerable <StreamingEndpointEntry> endpointquery; streamingendpoints = context.StreamingEndpoints; _context = context; try { int c = streamingendpoints.Count(); } catch (Exception e) { MessageBox.Show("There is a problem when connecting to Azure Media Services. Application will close. " + e.Message); Environment.Exit(0); } endpointquery = from c in streamingendpoints select new StreamingEndpointEntry { Name = c.Name, Id = c.Id, Description = c.Description, CDN = c.CdnEnabled ? StreamingEndpointInformation.ReturnDisplayedProvider(c.CdnProvider) ?? "CDN" : string.Empty, ScaleUnits = StreamingEndpointInformation.ReturnTypeSE(c) != StreamingEndpointInformation.StreamEndpointType.Premium ? "" : ((int)c.ScaleUnits).ToString(), State = c.State, LastModified = c.LastModified.ToLocalTime(), Type = StreamingEndpointInformation.ReturnTypeSE(c) }; _MyObservStreamingEndpoints = new SortableBindingList <StreamingEndpointEntry>(endpointquery.ToList()); this.BeginInvoke(new Action(() => this.DataSource = _MyObservStreamingEndpoints)); _refreshedatleastonetime = true; this.BeginInvoke(new Action(() => this.FindForm().Cursor = Cursors.Default)); }
public async Task RefreshStreamingEndpointsAsync() { if (!_initialized) { return; } this.BeginInvoke(new Action(() => this.FindForm().Cursor = Cursors.WaitCursor)); IEnumerable <StreamingEndpointEntry> endpointquery; await _client.RefreshTokenIfNeededAsync(); streamingendpoints = await _client.AMSclient.StreamingEndpoints.ListAsync(_client.credentialsEntry.ResourceGroup, _client.credentialsEntry.AccountName); try { int c = streamingendpoints.Count(); } catch (Exception e) { MessageBox.Show("There is a problem when connecting to Azure Media Services. Application will close. " + e.Message); Environment.Exit(0); } endpointquery = from c in streamingendpoints select new StreamingEndpointEntry { Name = c.Name, Id = c.Id, Description = c.Description, CDN = (bool)c.CdnEnabled ? StreamingEndpointInformation.ReturnDisplayedProvider(c.CdnProvider) ?? "CDN" : string.Empty, ScaleUnits = StreamingEndpointInformation.ReturnTypeSE(c) != StreamingEndpointInformation.StreamEndpointType.Premium ? string.Empty : ((int)c.ScaleUnits).ToString(), State = (StreamingEndpointResourceState)c.ResourceState, LastModified = ((DateTime)c.LastModified).ToLocalTime(), Type = StreamingEndpointInformation.ReturnTypeSE(c) }; _MyObservStreamingEndpoints = new SortableBindingList <StreamingEndpointEntry>(endpointquery.ToList()); this.BeginInvoke(new Action(() => this.DataSource = _MyObservStreamingEndpoints)); this.BeginInvoke(new Action(() => this.FindForm().Cursor = Cursors.Default)); }
public void Init(CredentialsEntry credentials, CloudMediaContext context) { IEnumerable <StreamingEndpointEntry> originquery; _credentials = credentials; _context = context; originquery = from o in _context.StreamingEndpoints orderby o.LastModified descending select new StreamingEndpointEntry { Name = o.Name, Id = o.Id, Description = o.Description, CDN = o.CdnEnabled ? StreamingEndpointInformation.ReturnDisplayedProvider(o.CdnProvider) ?? "CDN" : string.Empty, ScaleUnits = StreamingEndpointInformation.ReturnTypeSE(o) != StreamingEndpointInformation.StreamEndpointType.Premium ? "" : ((int)o.ScaleUnits).ToString(), Type = StreamingEndpointInformation.ReturnTypeSE(o), State = o.State, LastModified = o.LastModified.ToLocalTime() }; SortableBindingList <StreamingEndpointEntry> MyObservOriginInPage = new SortableBindingList <StreamingEndpointEntry>(originquery.Take(0).ToList()); this.DataSource = MyObservOriginInPage; this.Columns["Id"].Visible = Properties.Settings.Default.DisplayOriginIDinGrid; this.Columns["Name"].Width = 300; this.Columns["State"].Width = 100; this.Columns["CDN"].Width = 120; this.Columns["Description"].Width = 230; this.Columns["ScaleUnits"].Width = 100; this.Columns["ScaleUnits"].HeaderText = "Streaming Units"; this.Columns["LastModified"].Width = 150; this.Columns["LastModified"].HeaderText = "Last modified"; WorkerRefreshStreamingEndpoints = new BackgroundWorker(); WorkerRefreshStreamingEndpoints.WorkerSupportsCancellation = true; WorkerRefreshStreamingEndpoints.DoWork += new System.ComponentModel.DoWorkEventHandler(this.WorkerRefreshStreamingEndpoints_DoWork); _initialized = true; }
public void Init(AMSClientV3 client) { IEnumerable <StreamingEndpointEntry> originquery; _client = client; _client.RefreshTokenIfNeeded(); originquery = _client.AMSclient.StreamingEndpoints.List(_client.credentialsEntry.ResourceGroup, _client.credentialsEntry.AccountName).Select(o => new StreamingEndpointEntry { Name = o.Name, Id = o.Id, Description = o.Description, CDN = ((bool)o.CdnEnabled) ? StreamingEndpointInformation.ReturnDisplayedProvider(o.CdnProvider) ?? "CDN" : string.Empty, ScaleUnits = StreamingEndpointInformation.ReturnTypeSE(o) != StreamingEndpointInformation.StreamEndpointType.Premium ? string.Empty : ((int)o.ScaleUnits).ToString(), Type = StreamingEndpointInformation.ReturnTypeSE(o), State = (StreamingEndpointResourceState)o.ResourceState, LastModified = ((DateTime)o.LastModified).ToLocalTime() }); SortableBindingList <StreamingEndpointEntry> MyObservOriginInPage = new SortableBindingList <StreamingEndpointEntry>(originquery.Take(0).ToList()); this.DataSource = MyObservOriginInPage; this.Columns["Name"].Width = 300; this.Columns["State"].Width = 100; this.Columns["CDN"].Width = 120; this.Columns["Description"].Width = 230; this.Columns["ScaleUnits"].Width = 100; this.Columns["ScaleUnits"].HeaderText = "Streaming Units"; this.Columns["LastModified"].Width = 150; this.Columns["LastModified"].HeaderText = "Last modified"; WorkerRefreshStreamingEndpoints = new BackgroundWorker(); WorkerRefreshStreamingEndpoints.WorkerSupportsCancellation = true; WorkerRefreshStreamingEndpoints.DoWork += new System.ComponentModel.DoWorkEventHandler(this.WorkerRefreshStreamingEndpoints_DoWork); _initialized = true; }
public void RefreshStreamingEndpoint(IStreamingEndpoint origin) { int index = -1; foreach (StreamingEndpointEntry CE in _MyObservStreamingEndpoints) // let's search for index { if (CE.Id == origin.Id) { index = _MyObservStreamingEndpoints.IndexOf(CE); break; } } if (index >= 0) // we found it { // we update the observation collection origin = _context.StreamingEndpoints.Where(o => o.Id == origin.Id).FirstOrDefault(); //refresh if (origin != null) { _MyObservStreamingEndpoints[index].State = origin.State; _MyObservStreamingEndpoints[index].Description = origin.Description; _MyObservStreamingEndpoints[index].LastModified = origin.LastModified.ToLocalTime(); _MyObservStreamingEndpoints[index].Type = StreamingEndpointInformation.ReturnTypeSE(origin); _MyObservStreamingEndpoints[index].CDN = origin.CdnEnabled ? StreamingEndpointInformation.ReturnDisplayedProvider(origin.CdnProvider) ?? "CDN" : string.Empty; _MyObservStreamingEndpoints[index].ScaleUnits = StreamingEndpointInformation.ReturnTypeSE(origin) != StreamingEndpointInformation.StreamEndpointType.Premium ? "" : ((int)origin.ScaleUnits).ToString(); this.Refresh(); } } }
public async Task RefreshStreamingEndpointAsync(StreamingEndpoint streamingEndpoint) { int index = -1; foreach (StreamingEndpointEntry CE in _MyObservStreamingEndpoints) // let's search for index { if (CE.Id == streamingEndpoint.Id) { index = _MyObservStreamingEndpoints.IndexOf(CE); break; } } if (index >= 0) // we found it { // we update the observation collection await _client.RefreshTokenIfNeededAsync(); streamingEndpoint = await _client.AMSclient.StreamingEndpoints.GetAsync(_client.credentialsEntry.ResourceGroup, _client.credentialsEntry.AccountName, streamingEndpoint.Name); //refresh if (streamingEndpoint != null) { _MyObservStreamingEndpoints[index].State = (StreamingEndpointResourceState)streamingEndpoint.ResourceState; _MyObservStreamingEndpoints[index].Description = streamingEndpoint.Description; _MyObservStreamingEndpoints[index].LastModified = ((DateTime)streamingEndpoint.LastModified).ToLocalTime(); _MyObservStreamingEndpoints[index].Type = StreamingEndpointInformation.ReturnTypeSE(streamingEndpoint); _MyObservStreamingEndpoints[index].CDN = ((bool)streamingEndpoint.CdnEnabled) ? StreamingEndpointInformation.ReturnDisplayedProvider(streamingEndpoint.CdnProvider) ?? "CDN" : string.Empty; _MyObservStreamingEndpoints[index].ScaleUnits = StreamingEndpointInformation.ReturnTypeSE(streamingEndpoint) != StreamingEndpointInformation.StreamEndpointType.Premium ? string.Empty : ((int)streamingEndpoint.ScaleUnits).ToString(); this.BeginInvoke(new Action(() => this.Refresh())); } } }