private async Task <List <ContentKeyPolicy> > ReturnSelectedCKPoliciessAsync()
        {
            List <ContentKeyPolicy> SelectedCKPolicies = new List <ContentKeyPolicy>();
            await _amsClient.RefreshTokenIfNeededAsync();

            Microsoft.Rest.Azure.IPage <ContentKeyPolicy> ckPolicies = await _amsClient.AMSclient.ContentKeyPolicies.ListAsync(_amsClient.credentialsEntry.ResourceGroup, _amsClient.credentialsEntry.AccountName);

            foreach (DataGridViewRow Row in dataGridViewCKPolicies.SelectedRows)
            {
                string           ckpolName = Row.Cells[dataGridViewFilters.Columns["Name"].Index].Value.ToString();
                ContentKeyPolicy myPolicy  = ckPolicies.Where(f => f.Name == ckpolName).FirstOrDefault();
                if (myPolicy != null)
                {
                    SelectedCKPolicies.Add(myPolicy);
                }
            }

            return(SelectedCKPolicies);
        }
Exemple #2
0
        private async void ChooseStreamingEndpoint_Load(object sender, EventArgs e)
        {
            DpiUtils.InitPerMonitorDpi(this);

            label.Text = string.Format(label.Text, _asset.Name);

            // SE List
            await _amsClient.RefreshTokenIfNeededAsync();

            // StreamingEndpoint BestSE = Task.Run(async () => await AssetInfo.GetBestStreamingEndpointAsync(_client)).Result;
            StreamingEndpoint BestSE = await AssetInfo.GetBestStreamingEndpointAsync(_amsClient);

            var myStreamingEndpoints = Task.Run(() => _amsClient.AMSclient.StreamingEndpoints.ListAsync(_amsClient.credentialsEntry.ResourceGroup, _amsClient.credentialsEntry.AccountName)).GetAwaiter().GetResult();

            foreach (StreamingEndpoint se in myStreamingEndpoints)
            {
                listBoxSE.Items.Add(new Item(string.Format(AMSExplorer.Properties.Resources.AssetInformation_AssetInformation_Load_012ScaleUnit, se.Name, se.ResourceState, StreamingEndpointInformation.ReturnTypeSE(se)), se.Name + "|" + se.HostName));
                if (se.Id == BestSE.Id)
                {
                    listBoxSE.SelectedIndex = listBoxSE.Items.Count - 1;
                }

                foreach (string custom in se.CustomHostNames)
                {
                    listBoxSE.Items.Add(new Item(string.Format(AMSExplorer.Properties.Resources.AssetInformation_AssetInformation_Load_012ScaleUnitCustomHostname3, se.Name, se.ResourceState, StreamingEndpointInformation.ReturnTypeSE(se), custom), se.Name + "|" + custom));
                }
            }


            // Filters

            // asset filters
            Microsoft.Rest.Azure.IPage <AssetFilter> assetFilters = await _amsClient.AMSclient.AssetFilters.ListAsync(_amsClient.credentialsEntry.ResourceGroup, _amsClient.credentialsEntry.AccountName, _asset.Name);

            List <string> afiltersnames = assetFilters.Select(a => a.Name).ToList();

            listViewFilters.BeginUpdate();
            assetFilters.ToList().ForEach(f =>
            {
                ListViewItem lvitem = new ListViewItem(new string[] { AMSExplorer.Properties.Resources.ChooseStreamingEndpoint_ChooseStreamingEndpoint_Load_AssetFilter + f.Name, f.Name });
                if (_filter != null && f.Name == _filter)
                {
                    lvitem.Checked = true;
                }
                listViewFilters.Items.Add(lvitem);
            }
                                          );

            // account filters
            IPage <AccountFilter> acctFilters = await _amsClient.AMSclient.AccountFilters.ListAsync(_amsClient.credentialsEntry.ResourceGroup, _amsClient.credentialsEntry.AccountName);

            acctFilters.ToList().ForEach(f =>
            {
                ListViewItem lvitem = new ListViewItem(new string[] { AMSExplorer.Properties.Resources.ChooseStreamingEndpoint_ChooseStreamingEndpoint_Load_GlobalFilter + f.Name, f.Name });
                if (_filter != null && f.Name == _filter && listViewFilters.CheckedItems.Count == 0) // only if not already selected (asset filter priority > account filter)
                {
                    lvitem.Checked = true;
                }
                if (afiltersnames.Contains(f.Name)) // global filter with same name than asset filter
                {
                    lvitem.ForeColor = Color.Gray;
                }
                listViewFilters.Items.Add(lvitem);
            }
                                         );
            listViewFilters.EndUpdate();


            if (_playertype == PlayerType.DASHIFRefPlayer)
            {
                radioButtonDASHCSF.Checked = true;
            }

            comboBoxBrowser.Items.Add(new Item(AMSExplorer.Properties.Resources.ChooseStreamingEndpoint_ChooseStreamingEndpoint_Load_DefaultBrowser, string.Empty));
            if (_displayBrowserSelection)
            { // let's add the browser options to lplayback the content (IE, Edge, Chrome...)
                if (IsWindows10())
                {
                    comboBoxBrowser.Items.Add(new Item(Constants.BrowserEdge[0], Constants.BrowserEdge[1]));
                }

                comboBoxBrowser.Items.Add(new Item(Constants.BrowserIE[0], Constants.BrowserIE[1]));
                comboBoxBrowser.Items.Add(new Item(Constants.BrowserChrome[0], Constants.BrowserChrome[1]));
                comboBoxBrowser.SelectedIndex = 0;
            }
            comboBoxBrowser.Visible = _displayBrowserSelection;

            UpdatePreviewUrl();

            FillLocatorComboInPolicyTab();
        }
        private void backgroundWorkerCSV_DoWork(object sender, DoWorkEventArgs e)
        {
            _amsClient.RefreshTokenIfNeeded();

            int  numberMaxLocators = 0;
            var  csvheader         = new StringBuilder();
            var  csv      = new StringBuilder();
            bool detailed = radioButtonDetailledMode.Checked;

            try
            {
                // Streaming endpoints
                Microsoft.Rest.Azure.IPage <StreamingEndpoint> streamingEndpoints = _amsClient.AMSclient.StreamingEndpoints.List(_amsClient.credentialsEntry.ResourceGroup, _amsClient.credentialsEntry.AccountName);
                var selist = streamingEndpoints.ToList();

                // Asset lines
                int index = 1;

                if (radioButtonAllAssets.Checked)
                {
                    IPage <Asset> currentPage = null;
                    currentPage = _amsClient.AMSclient.Assets.List(_amsClient.credentialsEntry.ResourceGroup, _amsClient.credentialsEntry.AccountName);

                    while (true)
                    {
                        foreach (Asset asset in currentPage)
                        {
                            var res = Task.Run(async() => await ExportAssetCSVLineAsync(asset, detailed, checkBoxLocalTime.Checked, selist)).Result;
                            csv.AppendLine(res.line);
                            if (res.locatorCount != null)
                            {
                                numberMaxLocators = Math.Max(numberMaxLocators, (int)res.locatorCount);
                            }

                            backgroundWorkerCSV.ReportProgress(index, DateTime.Now); //notify progress to main thread. We also pass time information in UserState to cover this property in the example.
                                                                                     //if cancellation is pending, cancel work.
                            if (backgroundWorkerCSV.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }
                            index++;
                        }

                        if (currentPage.NextPageLink != null)
                        {
                            currentPage = _amsClient.AMSclient.Assets.ListNext(currentPage.NextPageLink);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else // Selected assets
                {
                    int total = _selassets.Count();

                    foreach (Asset asset in _selassets)
                    {
                        var res = Task.Run(async() => await ExportAssetCSVLineAsync(asset, detailed, checkBoxLocalTime.Checked, selist)).Result;
                        csv.AppendLine(res.line);
                        if (res.locatorCount != null)
                        {
                            numberMaxLocators = Math.Max(numberMaxLocators, (int)res.locatorCount);
                        }

                        backgroundWorkerCSV.ReportProgress(100 * index / total, DateTime.Now); //notify progress to main thread. We also pass time information in UserState to cover this property in the example.
                                                                                               //if cancellation is pending, cancel work.
                        if (backgroundWorkerCSV.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }
                        index++;
                    }
                }

                // Header
                if (radioButtonAllAssets.Checked)
                {
                    csvheader.AppendLine(checkStringForCSV(string.Format(AMSExplorer.Properties.Resources.ExportToExcel_backgroundWorker1_DoWork_AllAssetsInformationMediaAccount0, _amsClient.credentialsEntry.AccountName)));
                }
                else
                {
                    csvheader.AppendLine(checkStringForCSV(string.Format(AMSExplorer.Properties.Resources.ExportToExcel_backgroundWorker1_DoWork_SelectedAssetsInformationMediaAccount0, _amsClient.credentialsEntry.AccountName)));
                }

                csvheader.AppendLine(checkStringForCSV(string.Format("Exported with Azure Media Services Explorer v{0} on {1}. Dates are {2}.",
                                                                     Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                                                                     checkBoxLocalTime.Checked ? DateTime.Now.ToString() : DateTime.UtcNow.ToString(),
                                                                     checkBoxLocalTime.Checked ? "local" : "UTC based"
                                                                     )));

                List <string> linec = new List <string>();
                linec.Add("Asset name");
                linec.Add("Description");
                linec.Add("Alternate Id");
                linec.Add("Asset Id");
                linec.Add("Created time");
                linec.Add("Last modified time");
                linec.Add("Storage account");
                linec.Add("Storage container");

                if (detailed)
                {
                    linec.Add("Asset type");
                    linec.Add("Size");
                }

                linec.Add("Streaming locators count");

                if (detailed)
                {
                    for (int iloc = 0; iloc < numberMaxLocators; iloc++)
                    {
                        linec.Add(string.Format("Locator name #{0}", iloc + 1));
                        linec.Add("Created time");
                        linec.Add("Start time");
                        linec.Add("End time");
                        foreach (var se in selist)
                        {
                            linec.Add(string.Format("Streaming Urls with streaming endpoint #{0}", selist.IndexOf(se)));
                        }
                    }
                }

                csvheader.AppendLine(convertToCSVLine(linec));
                csvheader.Append(csv);

                try
                {
                    File.WriteAllText(filename, csvheader.ToString());
                }
                catch
                {
                    MessageBox.Show(AMSExplorer.Properties.Resources.ExportToExcel_backgroundWorker1_DoWork_ErrorWhenSavingTheExcelFile, AMSExplorer.Properties.Resources.AMSLogin_buttonExport_Click_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (checkBoxOpenFileAfterExport.Checked)
                {
                    System.Diagnostics.Process.Start(filename);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(AMSExplorer.Properties.Resources.ExportToExcel_backgroundWorker1_DoWork_Error + ex.Message);
            }
        }
        private void backgroundWorkerExcel_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                _amsClient.RefreshTokenIfNeeded();

                // Streaming endpoints
                Microsoft.Rest.Azure.IPage <StreamingEndpoint> streamingEndpoints = _amsClient.AMSclient.StreamingEndpoints.List(_amsClient.credentialsEntry.ResourceGroup, _amsClient.credentialsEntry.AccountName);
                var selist = streamingEndpoints.ToList();

                int  numberMaxLocators = 0;
                var  csvheader         = new StringBuilder();
                var  csv                = new StringBuilder();
                bool detailed           = radioButtonDetailledMode.Checked;
                Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

                if (xlApp == null)
                {
                    MessageBox.Show("Excel is not properly installed!!");
                    return;
                }

                Excel.Workbook  xlWorkBook;
                Excel.Worksheet xlWorkSheet;
                object          misValue = System.Reflection.Missing.Value;

                xlWorkBook  = xlApp.Workbooks.Add(misValue);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                xlWorkSheet.get_Range("a1", "f1").Merge(false);
                Excel.Range chartRange = xlWorkSheet.get_Range("a1", "f1");
                if (radioButtonAllAssets.Checked)
                {
                    chartRange.FormulaR1C1 = string.Format(AMSExplorer.Properties.Resources.ExportToExcel_backgroundWorker1_DoWork_AllAssetsInformationMediaAccount0, _amsClient.credentialsEntry.AccountName);
                }
                else
                {
                    chartRange.FormulaR1C1 = string.Format(AMSExplorer.Properties.Resources.ExportToExcel_backgroundWorker1_DoWork_SelectedAssetsInformationMediaAccount0, _amsClient.credentialsEntry.AccountName);
                }
                chartRange.VerticalAlignment = 3;
                chartRange.Font.Color        = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.DarkBlue);
                chartRange.Font.Size         = 20;

                xlWorkSheet.get_Range("a2", "f2").Merge(false);
                Excel.Range chartRange2 = xlWorkSheet.get_Range("a2", "f2");
                chartRange2.FormulaR1C1 = string.Format("Exported with Azure Media Services Explorer v{0} on {1}. Dates are {2}.",
                                                        Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                                                        checkBoxLocalTime.Checked ? DateTime.Now.ToString() : DateTime.UtcNow.ToString(),
                                                        checkBoxLocalTime.Checked ? "local" : "UTC based"
                                                        );
                chartRange2.VerticalAlignment = 3;
                chartRange2.Font.Color        = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.DarkBlue);
                chartRange2.Font.Size         = 12;


                Excel.Range formatRange;
                formatRange = xlWorkSheet.get_Range("a4");
                formatRange.EntireRow.Font.Bold      = true;
                formatRange.EntireRow.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightBlue);

                int row   = 5;
                int index = 1;

                if (radioButtonAllAssets.Checked)
                {
                    IPage <Asset> currentPage = null;
                    currentPage = _amsClient.AMSclient.Assets.List(_amsClient.credentialsEntry.ResourceGroup, _amsClient.credentialsEntry.AccountName);

                    while (true)
                    {
                        foreach (Asset asset in currentPage)
                        {
                            var locatorCount = Task.Run(async() => await ExportAssetExcelAsync(asset, xlWorkSheet, row, detailed, checkBoxLocalTime.Checked, selist)).Result;
                            if (locatorCount != null)
                            {
                                numberMaxLocators = Math.Max(numberMaxLocators, (int)locatorCount);
                            }

                            backgroundWorkerCSV.ReportProgress(index, DateTime.Now); //notify progress to main thread. We also pass time information in UserState to cover this property in the example.
                                                                                     //if cancellation is pending, cancel work.
                            if (backgroundWorkerExcel.CancellationPending)
                            {
                                xlApp.DisplayAlerts = false;
                                xlWorkBook.Close();
                                xlApp.Quit();
                                releaseObject(xlWorkSheet);
                                releaseObject(xlWorkBook);
                                releaseObject(xlApp);
                                e.Cancel = true;
                                return;
                            }
                            index++;
                            row++;
                        }

                        if (currentPage.NextPageLink != null)
                        {
                            currentPage = _amsClient.AMSclient.Assets.ListNext(currentPage.NextPageLink);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else // Selected assets
                {
                    int total = _selassets.Count();

                    foreach (Asset asset in _selassets)
                    {
                        var locatorCount = Task.Run(async() => await ExportAssetExcelAsync(asset, xlWorkSheet, row, detailed, checkBoxLocalTime.Checked, selist)).Result;
                        if (locatorCount != null)
                        {
                            numberMaxLocators = Math.Max(numberMaxLocators, (int)locatorCount);
                        }

                        backgroundWorkerCSV.ReportProgress(100 * index / total, DateTime.Now); //notify progress to main thread. We also pass time information in UserState to cover this property in the example.
                                                                                               //if cancellation is pending, cancel work.
                        if (backgroundWorkerExcel.CancellationPending)
                        {
                            xlApp.DisplayAlerts = false;
                            xlWorkBook.Close();
                            xlApp.Quit();
                            releaseObject(xlWorkSheet);
                            releaseObject(xlWorkBook);
                            releaseObject(xlApp);
                            e.Cancel = true;
                            return;
                        }
                        index++;
                        row++;
                    }
                }

                // Header
                row   = 4;
                index = 1;
                xlWorkSheet.Cells[row, index++] = "Asset name";
                xlWorkSheet.Cells[row, index++] = "Description";
                xlWorkSheet.Cells[row, index++] = "Alternate Id";
                xlWorkSheet.Cells[row, index++] = "Asset Id";
                xlWorkSheet.Cells[row, index++] = "Created time";
                xlWorkSheet.Cells[row, index++] = "Last modified time";
                xlWorkSheet.Cells[row, index++] = "Storage account";
                xlWorkSheet.Cells[row, index++] = "Storage container";

                if (detailed)
                {
                    xlWorkSheet.Cells[row, index++] = "Asset type";
                    xlWorkSheet.Cells[row, index++] = "Size";
                }

                xlWorkSheet.Cells[row, index++] = "Streaming locators count";

                if (detailed)
                {
                    for (int iloc = 0; iloc < numberMaxLocators; iloc++)
                    {
                        xlWorkSheet.Cells[row, index++] = string.Format("Locator name #{0}", iloc + 1);
                        xlWorkSheet.Cells[row, index++] = "Created time";
                        xlWorkSheet.Cells[row, index++] = "Start time";
                        xlWorkSheet.Cells[row, index++] = "End time";
                        foreach (var se in selist)
                        {
                            xlWorkSheet.Cells[row, index++] = string.Format("Streaming Urls with streaming endpoint #{0}", selist.IndexOf(se));
                        }
                    }
                }

                // Set the range to fill.
                var aRange = xlWorkSheet.get_Range("A4", "Z100");
                aRange.EntireColumn.AutoFit();

                try
                {
                    xlWorkBook.SaveAs(filename, Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                    xlWorkBook.Close(true, misValue, misValue);
                    xlApp.Quit();
                    releaseObject(xlWorkSheet);
                    releaseObject(xlWorkBook);
                    releaseObject(xlApp);
                }
                catch
                {
                    MessageBox.Show(AMSExplorer.Properties.Resources.ExportToExcel_backgroundWorker1_DoWork_ErrorWhenSavingTheExcelFile, AMSExplorer.Properties.Resources.AMSLogin_buttonExport_Click_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (checkBoxOpenFileAfterExport.Checked)
                {
                    System.Diagnostics.Process.Start(filename);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(AMSExplorer.Properties.Resources.ExportToExcel_backgroundWorker1_DoWork_Error + ex.Message);
            }
        }