コード例 #1
0
        private void StartProcessing(List <string> folders)
        {
            if (folders != null)
            {
                foreach (string folder in folders)
                {
                    //Each folder will generate one CSV file to highlight the asset information
                    StringBuilder assetInfo         = new StringBuilder();
                    string        currentFolderPath = (string)folder;
                    string        assetInfoFileName = Guid.NewGuid().ToString() + ".csv";

                    FIO.IoHelper ioHelper = new FIO.IoHelper();

                    List <string> vttMp4Files = ioHelper.FindFiles(currentFolderPath, new List <string>()
                    {
                        ".mp4", ".vtt"
                    });
                    foreach (string file in vttMp4Files)
                    {
                        string fileName       = Path.GetFileNameWithoutExtension(file);
                        string outputFileName = ValidityCheck.FormatFileName(fileName);

                        //If changed file name to a valid file name, rename the file with new file name
                        if (outputFileName != fileName)
                        {
                            string newFile = file.Replace(fileName, outputFileName);
                            if (File.Exists(newFile))
                            {
                                File.Delete(newFile);
                            }

                            File.Move(file, newFile);
                        }
                    }

                    //Files count that handled successfully
                    int totalCount = 0;
                    if (!userChoice_HandleVTT)
                    {
                        List <string> mp4Files = ioHelper.FindFiles(currentFolderPath, new List <string>()
                        {
                            ".mp4"
                        });
                        foreach (var mp4File in mp4Files)
                        {
                            totalCount++;

                            // Get the Asset File Name
                            assetInfo.AppendLine();

                            //Updating Status Message
                            UpdateMessageInStatusLabel($"Uploading {mp4File}");

                            var videoAsset = MediaHelper.CreateAssetAndUploadSingleFile(mp4File, Microsoft.WindowsAzure.MediaServices.Client.AssetCreationOptions.None);
                            assetInfo.Append(videoAsset.Name);

                            //Encoding Status Message
                            UpdateMessageInStatusLabel($"Encoding {mp4File}");

                            var encodedAsset = MediaHelper.EncodeToAdaptiveBitrateMP4s(videoAsset, Microsoft.WindowsAzure.MediaServices.Client.AssetCreationOptions.None);

                            //Publishing Status Message
                            UpdateMessageInStatusLabel($"Publishing {mp4File}");

                            List <string> mp4URLs   = null;
                            string        playerUrl = MediaHelper.PublishAssetAndGetURLs(encodedAsset, out mp4URLs);

                            if (mp4URLs.Count > 0)
                            {
                                assetInfo.Append("," + encodedAsset.Name);
                                foreach (var mp4Url in mp4URLs)
                                {
                                    assetInfo.Append("," + mp4Url);
                                }
                            }
                        }
                    }
                    else
                    {
                        List <string> vttFiles = ioHelper.FindFiles(currentFolderPath, new List <string>()
                        {
                            ".vtt"
                        });
                        foreach (var vttFile in vttFiles)
                        {
                            totalCount++;
                            assetInfo.AppendLine();

                            //Updating Status Message
                            UpdateMessageInStatusLabel($"Uploading {vttFile}");

                            var vttAsset = MediaHelper.CreateAssetAndUploadSingleFile(vttFile, Microsoft.WindowsAzure.MediaServices.Client.AssetCreationOptions.None);
                            assetInfo.Append(vttAsset.Name);

                            //publishing status message
                            UpdateMessageInStatusLabel($"Publishing {vttFile}");
                            List <string> vttURLs   = null;
                            string        playerUrl = MediaHelper.PublishAssetAndGetURLs(vttAsset, out vttURLs);

                            if (vttURLs.Count > 0)
                            {
                                assetInfo.Append($",{vttAsset.Name}");
                                foreach (var vttUrl in vttURLs)
                                {
                                    assetInfo.Append($",{vttUrl}");
                                }
                            }
                        }
                    }

                    string assetInfoFilePath = Path.Combine(currentFolderPath, assetInfoFileName);
                    //File.Create(resultFilepath);
                    using (StreamWriter writer = new StreamWriter(assetInfoFilePath))
                    {
                        writer.WriteLine(assetInfo.ToString());
                        writer.Flush();
                    }

                    string message = $"Complete {totalCount} Files uploading in {currentFolderPath}";
                    UpdateMessageInListBox(message);
                }
            }
        }