Пример #1
0
        public void TestGetEncryptionState()
        {
            IAsset asset = JobTests.CreateSmoothAsset(_mediaContext, _filePaths, AssetCreationOptions.None);
            AssetDeliveryProtocol protocolsToSet = AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.Dash;
            Dictionary <AssetDeliveryPolicyConfigurationKey, string> configuration = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>()
            {
                { AssetDeliveryPolicyConfigurationKey.EnvelopeBaseKeyAcquisitionUrl, "https://www.test.com/" },
                { AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIVAsBase64, Convert.ToBase64String(ContentKeyTests.GetRandomBuffer(16)) }
            };
            IAssetDeliveryPolicy policy = _mediaContext.AssetDeliveryPolicies.Create("Test Policy", AssetDeliveryPolicyType.DynamicEnvelopeEncryption, protocolsToSet, configuration);
            IContentKey          key    = _mediaContext.ContentKeys.Create(Guid.NewGuid(), ContentKeyTests.GetRandomBuffer(16), "Test key", ContentKeyType.EnvelopeEncryption);

            asset.ContentKeys.Add(key);
            asset.DeliveryPolicies.Add(policy);

            AssetEncryptionState state = asset.GetEncryptionState(protocolsToSet);

            Assert.AreEqual(AssetEncryptionState.DynamicEnvelopeEncryption, state);

            state = asset.GetEncryptionState(AssetDeliveryProtocol.Dash | AssetDeliveryProtocol.Hds);
            Assert.AreEqual(AssetEncryptionState.NoSinglePolicyApplies, state);

            state = asset.GetEncryptionState(AssetDeliveryProtocol.Hds);
            Assert.AreEqual(AssetEncryptionState.BlockedByPolicy, state);

            CleanupAsset(asset);
        }
Пример #2
0
        private void ExportAssetExcel(IAsset asset, Excel.Worksheet xlWorkSheet, int row, bool detailed, bool localtime)
        {
            xlWorkSheet.Cells[row, 1] = asset.Name;
            xlWorkSheet.Cells[row, 2] = asset.Id;
            xlWorkSheet.Cells[row, 3] = localtime ? asset.LastModified.ToLocalTime() : asset.LastModified;
            xlWorkSheet.Cells[row, 4] = AssetInfo.GetAssetType(asset);
            xlWorkSheet.Cells[row, 5] = AssetInfo.GetSize(asset);
            var url = AssetInfo.GetValidOnDemandURI(asset);

            xlWorkSheet.Cells[row, 6] = url != null?url.ToString() : string.Empty;

            if (localtime)
            {
                xlWorkSheet.Cells[row, 7] = asset.Locators.Any() ? (DateTime?)asset.Locators.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
            }
            else
            {
                xlWorkSheet.Cells[row, 7] = asset.Locators.Any() ? (DateTime?)asset.Locators.Max(l => l.ExpirationDateTime) : null;
            }

            if (detailed)
            {
                xlWorkSheet.Cells[row, 8] = asset.AlternateId;
                xlWorkSheet.Cells[row, 9] = asset.StorageAccount.Name;
                var streamingloc = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);
                xlWorkSheet.Cells[row, 10] = streamingloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, 11] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, 12] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, 11] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, 12] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime) : null;
                }

                var sasloc = asset.Locators.Where(l => l.Type == LocatorType.Sas);
                xlWorkSheet.Cells[row, 13] = sasloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, 14] = sasloc.Any() ? (DateTime?)sasloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, 15] = sasloc.Any() ? (DateTime?)sasloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, 14] = sasloc.Any() ? (DateTime?)sasloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, 15] = sasloc.Any() ? (DateTime?)sasloc.Max(l => l.ExpirationDateTime) : null;
                }

                xlWorkSheet.Cells[row, 16] = asset.GetEncryptionState(AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash).ToString();
            }
        }
        private void ExportAssetExcel(IAsset asset, Excel.Worksheet xlWorkSheet, int row, bool detailed, bool localtime)
        {
            int index = 1;
            xlWorkSheet.Cells[row, index++] = asset.Name;
            xlWorkSheet.Cells[row, index++] = asset.Id;
            xlWorkSheet.Cells[row, index++] = localtime ? asset.LastModified.ToLocalTime() : asset.LastModified;
            xlWorkSheet.Cells[row, index++] = AssetInfo.GetAssetType(asset);
            xlWorkSheet.Cells[row, index++] = AssetInfo.GetSize(asset);
            int backindex = index;
            var urls = AssetInfo.GetURIs(asset);
            if (urls!=null)
            {
                foreach (var url in urls)
                {
                    xlWorkSheet.Cells[row, index++] = url != null ? url.ToString() : string.Empty;
                }

            }
            index = backindex + _context.StreamingEndpoints.Count();
            if (localtime)
            {
                xlWorkSheet.Cells[row, index++] = asset.Locators.Any() ? (DateTime?)asset.Locators.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
            }
            else
            {
                xlWorkSheet.Cells[row, index++] = asset.Locators.Any() ? (DateTime?)asset.Locators.Max(l => l.ExpirationDateTime) : null;
            }

            if (detailed)
            {
                xlWorkSheet.Cells[row, index++] = asset.AlternateId;
                xlWorkSheet.Cells[row, index++] = asset.StorageAccount.Name;
                var streamingloc = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);
                xlWorkSheet.Cells[row, index++] = streamingloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime) : null;
                }

                var sasloc = asset.Locators.Where(l => l.Type == LocatorType.Sas);
                xlWorkSheet.Cells[row, index++] = sasloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = sasloc.Any() ? (DateTime?)sasloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, index++] = sasloc.Any() ? (DateTime?)sasloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = sasloc.Any() ? (DateTime?)sasloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, index++] = sasloc.Any() ? (DateTime?)sasloc.Max(l => l.ExpirationDateTime) : null;
                }

                xlWorkSheet.Cells[row, index++] = asset.GetEncryptionState(AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash).ToString();
                xlWorkSheet.Cells[row, index++] = asset.AssetFilters.Count().ToString();

            }
        }
        public void RunAllGetEffectiveDeliveryPolicyTestCases()
        {
            string testCaseDataFilePath = WindowsAzureMediaServicesTestConfiguration.GetVideoSampleFilePath(TestContext, c_TestCaseDataFile);

            string[] testCases = File.ReadAllLines(testCaseDataFilePath);
            Assert.IsNotNull(testCases);
            Assert.AreEqual(401, testCases.Length); // ensure we have the expected number of cases

            int failureCount = 0;

            StringBuilder builder = new StringBuilder();

            builder.Append(testCases[0]);
            builder.Append(",ActualAssetType,ActualIsStreamable,ActualEffectiveEncryptionState");
            builder.AppendLine();

            for (int i = 1; i < testCases.Length; i++)
            {
                string[]                parameters              = testCases[i].Split(',');
                AssetCreationOptions    options                 = (AssetCreationOptions)Enum.Parse(typeof(AssetCreationOptions), parameters[0]);
                AssetType               assetType               = (AssetType)Enum.Parse(typeof(AssetType), parameters[1]);
                AssetDeliveryProtocol   assetDeliveryProtocol   = (AssetDeliveryProtocol)Enum.Parse(typeof(AssetDeliveryProtocol), parameters[2]);
                AssetDeliveryPolicyType assetDeliveryPolicyType = (AssetDeliveryPolicyType)Enum.Parse(typeof(AssetDeliveryPolicyType), parameters[3]);
                AssetEncryptionState    expectedEncryptionState = (AssetEncryptionState)Enum.Parse(typeof(AssetEncryptionState), parameters[4]);
                bool      expectedIsStreamable = bool.Parse(parameters[5]);
                AssetType expectedAssetType    = (AssetType)Enum.Parse(typeof(AssetType), parameters[6]);

                IAsset asset = GetTestAsset(options, assetType, assetDeliveryProtocol, assetDeliveryPolicyType);

                AssetEncryptionState actualEncryptionState = asset.GetEncryptionState(assetDeliveryProtocol);

                if (false == ((expectedAssetType == asset.AssetType) &&
                              (expectedIsStreamable == asset.IsStreamable) &&
                              (expectedEncryptionState == actualEncryptionState)
                              )
                    )
                {
                    // We had a failure so increase our failed count and then save the details of the test case and where it failed
                    failureCount++;

                    builder.Append(testCases[i]);
                    builder.Append(",");
                    builder.Append(asset.AssetType.ToString());
                    builder.Append(",");
                    builder.Append(asset.IsStreamable.ToString());
                    builder.Append(",");
                    builder.Append(actualEncryptionState.ToString());
                    builder.AppendLine();
                }
            }

            if (failureCount > 0)
            {
                Assert.Fail("Some RunAllGetEffectiveDeliveryPolicyTestCases failed");

                // If there are a lot of failures the best way to debug then is to dump
                // failed test case input and output data to a csv file for more detailed
                // analysis
                //File.WriteAllText("output.csv", builder.ToString());
            }
        }
Пример #5
0
        private void ExportAssetExcel(IAsset asset, Excel.Worksheet xlWorkSheet, int row, bool detailed, bool localtime)
        {
            int index = 1;
            xlWorkSheet.Cells[row, index++] = asset.Name;
            xlWorkSheet.Cells[row, index++] = asset.Id;
            xlWorkSheet.Cells[row, index++] = localtime ? asset.LastModified.ToLocalTime() : asset.LastModified;
            xlWorkSheet.Cells[row, index++] = AssetInfo.GetAssetType(asset);
            xlWorkSheet.Cells[row, index++] = AssetInfo.GetSize(asset);
            int backindex = index;
            var urls = AssetInfo.GetURIs(asset);
            if (urls != null)
            {
                foreach (var url in urls)
                {
                    xlWorkSheet.Cells[row, index++] = url != null ? url.ToString() : string.Empty;
                }

            }
            index = backindex + _context.StreamingEndpoints.Count();
            var streamlocators = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);
            if (streamlocators.Any())
            {
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = (DateTime?)streamlocators.Max(l => l.ExpirationDateTime).ToLocalTime();
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = (DateTime?)streamlocators.Max(l => l.ExpirationDateTime);
                }
            }
            else
            {
                xlWorkSheet.Cells[row, index++] = string.Empty;
            }

            // SAS locator
            var saslocators = asset.Locators.Where(l => l.Type == LocatorType.Sas);
            var saslocator = saslocators.ToList().OrderByDescending(l => l.ExpirationDateTime).FirstOrDefault();
            if (saslocator != null && asset.AssetFiles.Count() > 0)
            {
                var ProgressiveDownloadUri = asset.AssetFiles.ToList().OrderByDescending(af => af.ContentFileSize).FirstOrDefault().GetSasUri(saslocator);
                xlWorkSheet.Cells[row, index++] = ProgressiveDownloadUri.AbsoluteUri;
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = saslocator.ExpirationDateTime.ToLocalTime();
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = saslocator.ExpirationDateTime;
                }
            }
            else
            {
                xlWorkSheet.Cells[row, index++] = string.Empty;
                xlWorkSheet.Cells[row, index++] = string.Empty;
            }

            if (detailed)
            {
                xlWorkSheet.Cells[row, index++] = asset.AlternateId;
                xlWorkSheet.Cells[row, index++] = asset.StorageAccount.Name;
                xlWorkSheet.Cells[row, index++] = asset.Uri == null ? string.Empty : asset.Uri.ToString();
                var streamingloc = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);
                xlWorkSheet.Cells[row, index++] = streamingloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime) : null;
                }

                // SAS
                xlWorkSheet.Cells[row, index++] = saslocators.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = saslocators.Any() ? (DateTime?)saslocators.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, index++] = saslocators.Any() ? (DateTime?)saslocators.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = saslocators.Any() ? (DateTime?)saslocators.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, index++] = saslocators.Any() ? (DateTime?)saslocators.Max(l => l.ExpirationDateTime) : null;
                }

                xlWorkSheet.Cells[row, index++] = asset.GetEncryptionState(AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash).ToString();
                xlWorkSheet.Cells[row, index++] = asset.AssetFilters.Count().ToString();

            }
        }
        private void ExportAssetExcel(IAsset asset, Excel.Worksheet xlWorkSheet, int row, bool detailed, bool localtime)
        {
            int index = 1;

            xlWorkSheet.Cells[row, index++] = asset.Name;
            xlWorkSheet.Cells[row, index++] = asset.Id;
            xlWorkSheet.Cells[row, index++] = localtime ? asset.LastModified.ToLocalTime() : asset.LastModified;
            xlWorkSheet.Cells[row, index++] = AssetInfo.GetAssetType(asset);
            xlWorkSheet.Cells[row, index++] = AssetInfo.GetSize(asset);
            int backindex = index;
            var urls      = AssetInfo.GetURIs(asset);

            if (urls != null)
            {
                foreach (var url in urls)
                {
                    xlWorkSheet.Cells[row, index++] = url != null?url.ToString() : string.Empty;
                }
            }
            index = backindex + _context.StreamingEndpoints.Count();
            var streamlocators = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);

            if (streamlocators.Any())
            {
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = (DateTime?)streamlocators.Max(l => l.ExpirationDateTime).ToLocalTime();
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = (DateTime?)streamlocators.Max(l => l.ExpirationDateTime);
                }
            }
            else
            {
                xlWorkSheet.Cells[row, index++] = string.Empty;
            }


            // SAS locator
            var saslocators = asset.Locators.Where(l => l.Type == LocatorType.Sas);
            var saslocator  = saslocators.ToList().OrderByDescending(l => l.ExpirationDateTime).FirstOrDefault();

            if (saslocator != null && asset.AssetFiles.Count() > 0)
            {
                if (asset.AssetFiles.Count() == 1)
                {
                    var ProgressiveDownloadUri = asset.AssetFiles.FirstOrDefault().GetSasUri(saslocator);
                    xlWorkSheet.Cells[row, index++] = ProgressiveDownloadUri.AbsoluteUri;
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = saslocator.Path;
                }

                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = saslocator.ExpirationDateTime.ToLocalTime();
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = saslocator.ExpirationDateTime;
                }
            }
            else
            {
                xlWorkSheet.Cells[row, index++] = string.Empty;
                xlWorkSheet.Cells[row, index++] = string.Empty;
            }


            if (detailed)
            {
                xlWorkSheet.Cells[row, index++] = asset.AlternateId;
                xlWorkSheet.Cells[row, index++] = asset.StorageAccount.Name;
                xlWorkSheet.Cells[row, index++] = asset.Uri == null ? string.Empty : asset.Uri.ToString();
                var streamingloc = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);
                xlWorkSheet.Cells[row, index++] = streamingloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime) : null;
                }

                // SAS
                xlWorkSheet.Cells[row, index++] = saslocators.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = saslocators.Any() ? (DateTime?)saslocators.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, index++] = saslocators.Any() ? (DateTime?)saslocators.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = saslocators.Any() ? (DateTime?)saslocators.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, index++] = saslocators.Any() ? (DateTime?)saslocators.Max(l => l.ExpirationDateTime) : null;
                }

                xlWorkSheet.Cells[row, index++] = asset.GetEncryptionState(AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash).ToString();
                xlWorkSheet.Cells[row, index++] = asset.AssetFilters.Count().ToString();
            }
        }
        private string ExportAssetCSVLine(IAsset asset, bool detailed, bool localtime)
        {
            List <string> linec = new List <string>();

            linec.Add(asset.Name);
            linec.Add(asset.Id);
            linec.Add(localtime ? asset.LastModified.ToLocalTime().ToString() : asset.LastModified.ToString());
            linec.Add(AssetInfo.GetAssetType(asset));
            linec.Add(AssetInfo.GetSize(asset).ToString());
            var urls = AssetInfo.GetURIs(asset);

            if (urls != null && urls.Count() > 0)
            {
                foreach (var url in urls)
                {
                    linec.Add(url != null ? url.ToString() : string.Empty);
                }
            }
            else
            {
                for (int i = 0; i < _context.StreamingEndpoints.Count(); i++)
                {
                    linec.Add(string.Empty);
                }
            }

            var streamlocators = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);

            if (streamlocators.Any())
            {
                if (localtime)
                {
                    linec.Add(streamlocators.Max(l => l.ExpirationDateTime).ToLocalTime().ToString());
                }
                else
                {
                    linec.Add(streamlocators.Max(l => l.ExpirationDateTime).ToString());
                }
            }
            else
            {
                linec.Add(string.Empty);
            }


            // SAS locator
            var saslocators = asset.Locators.Where(l => l.Type == LocatorType.Sas);
            var saslocator  = saslocators.ToList().OrderByDescending(l => l.ExpirationDateTime).FirstOrDefault();

            if (saslocator != null && asset.AssetFiles.Count() > 0)
            {
                if (asset.AssetFiles.Count() == 1)
                {
                    var ProgressiveDownloadUri = asset.AssetFiles.FirstOrDefault().GetSasUri(saslocator);
                    linec.Add(ProgressiveDownloadUri.AbsoluteUri);
                }
                else
                {
                    linec.Add(saslocator.Path);
                }

                if (localtime)
                {
                    linec.Add(saslocator.ExpirationDateTime.ToLocalTime().ToString());
                }
                else
                {
                    linec.Add(saslocator.ExpirationDateTime.ToString());
                }
            }
            else
            {
                linec.Add(string.Empty);
                linec.Add(string.Empty);
            }


            if (detailed)
            {
                linec.Add(asset.AlternateId);
                linec.Add(asset.StorageAccount.Name);
                linec.Add(asset.Uri == null ? string.Empty : asset.Uri.ToString());
                var streamingloc = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);
                linec.Add(streamingloc.Count().ToString());
                if (localtime)
                {
                    linec.Add(streamingloc.Any() ? streamingloc.Min(l => l.ExpirationDateTime).ToLocalTime().ToString() : null);
                    linec.Add(streamingloc.Any() ? streamingloc.Max(l => l.ExpirationDateTime).ToLocalTime().ToString() : null);
                }
                else
                {
                    linec.Add(streamingloc.Any() ? streamingloc.Min(l => l.ExpirationDateTime).ToString() : null);
                    linec.Add(streamingloc.Any() ? streamingloc.Max(l => l.ExpirationDateTime).ToString() : null);
                }

                // SAS
                linec.Add(saslocators.Count().ToString());
                if (localtime)
                {
                    linec.Add(saslocators.Any() ? saslocators.Min(l => l.ExpirationDateTime).ToLocalTime().ToString() : null);
                    linec.Add(saslocators.Any() ? saslocators.Max(l => l.ExpirationDateTime).ToLocalTime().ToString() : null);
                }
                else
                {
                    linec.Add(saslocators.Any() ? saslocators.Min(l => l.ExpirationDateTime).ToString() : null);
                    linec.Add(saslocators.Any() ? saslocators.Max(l => l.ExpirationDateTime).ToString() : null);
                }

                linec.Add(asset.GetEncryptionState(AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash).ToString());
                linec.Add(asset.AssetFilters.Count().ToString());
            }

            return(convertCSVLine(linec));
        }
        private static AssetBitmapAndText BuildBitmapDynEncryption(IAsset asset)
        {
            AssetBitmapAndText ABT = new AssetBitmapAndText();
            AssetEncryptionState assetEncryptionState = asset.GetEncryptionState(AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash);

            switch (assetEncryptionState)
            {
                case AssetEncryptionState.DynamicCommonEncryption:
                    ABT.bitmap = commonencryptedimage;
                    ABT.MouseOverDesc = "Dynamic Common Encryption (CENC)";
                    break;

                case AssetEncryptionState.DynamicEnvelopeEncryption:
                    ABT.bitmap = envelopeencryptedimage;
                    ABT.MouseOverDesc = "Dynamic Envelope Encryption (AES)";
                    break;

                case AssetEncryptionState.NoDynamicEncryption:
                    ABT.bitmap = storagedecryptedimage;
                    ABT.MouseOverDesc = "No Dynamic Encryption";
                    break;

                case AssetEncryptionState.NoSinglePolicyApplies:
                    AssetEncryptionState assetEncryptionStateHLS = asset.GetEncryptionState(AssetDeliveryProtocol.HLS);
                    AssetEncryptionState assetEncryptionStateSmooth = asset.GetEncryptionState(AssetDeliveryProtocol.SmoothStreaming);
                    AssetEncryptionState assetEncryptionStateDash = asset.GetEncryptionState(AssetDeliveryProtocol.Dash);
                    bool CENCEnable = (assetEncryptionStateHLS == AssetEncryptionState.DynamicCommonEncryption || assetEncryptionStateSmooth == AssetEncryptionState.DynamicCommonEncryption || assetEncryptionStateDash == AssetEncryptionState.DynamicCommonEncryption);
                    bool EnvelopeEnable = (assetEncryptionStateHLS == AssetEncryptionState.DynamicEnvelopeEncryption || assetEncryptionStateSmooth == AssetEncryptionState.DynamicEnvelopeEncryption || assetEncryptionStateDash == AssetEncryptionState.DynamicEnvelopeEncryption);
                    if (CENCEnable && EnvelopeEnable)
                    {
                        ABT.bitmap = new Bitmap((envelopeencryptedimage.Width + commonencryptedimage.Width), envelopeencryptedimage.Height);
                        using (Graphics graphicsObject = Graphics.FromImage(ABT.bitmap))
                        {
                            graphicsObject.DrawImage(envelopeencryptedimage, new Point(0, 0));
                            graphicsObject.DrawImage(commonencryptedimage, new Point(envelopeencryptedimage.Width, 0));
                        }
                    }
                    else
                    {
                        ABT.bitmap = CENCEnable ? commonencryptedimage : envelopeencryptedimage;
                    }
                    ABT.MouseOverDesc = "Multiple policies";
                    break;

                default:
                    break;
            }
            return ABT;
        }
        private void ValidateAssetEncryptionState(IAsset asset, AssetDeliveryProtocol protocolsToTest, AssetEncryptionState expectedState)
        {
            AssetEncryptionState actualState = asset.GetEncryptionState(protocolsToTest);

            Assert.AreEqual(expectedState, actualState);
        }
Пример #10
0
        private void ExportAssetExcel(IAsset asset, Excel.Worksheet xlWorkSheet, int row, bool detailed, bool localtime)
        {
            int index = 1;

            xlWorkSheet.Cells[row, index++] = asset.Name;
            xlWorkSheet.Cells[row, index++] = asset.Id;
            xlWorkSheet.Cells[row, index++] = localtime ? asset.LastModified.ToLocalTime() : asset.LastModified;
            xlWorkSheet.Cells[row, index++] = AssetInfo.GetAssetType(asset);
            xlWorkSheet.Cells[row, index++] = AssetInfo.GetSize(asset);
            int backindex = index;
            var urls      = AssetInfo.GetURIs(asset);

            if (urls != null)
            {
                foreach (var url in urls)
                {
                    xlWorkSheet.Cells[row, index++] = url != null?url.ToString() : string.Empty;
                }
            }
            index = backindex + _context.StreamingEndpoints.Count();
            if (localtime)
            {
                xlWorkSheet.Cells[row, index++] = asset.Locators.Any() ? (DateTime?)asset.Locators.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
            }
            else
            {
                xlWorkSheet.Cells[row, index++] = asset.Locators.Any() ? (DateTime?)asset.Locators.Max(l => l.ExpirationDateTime) : null;
            }

            if (detailed)
            {
                xlWorkSheet.Cells[row, index++] = asset.AlternateId;
                xlWorkSheet.Cells[row, index++] = asset.StorageAccount.Name;
                xlWorkSheet.Cells[row, index++] = asset.Uri == null ? string.Empty : asset.Uri.ToString();
                var streamingloc = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);
                xlWorkSheet.Cells[row, index++] = streamingloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, index++] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime) : null;
                }

                var sasloc = asset.Locators.Where(l => l.Type == LocatorType.Sas);
                xlWorkSheet.Cells[row, index++] = sasloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, index++] = sasloc.Any() ? (DateTime?)sasloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, index++] = sasloc.Any() ? (DateTime?)sasloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, index++] = sasloc.Any() ? (DateTime?)sasloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, index++] = sasloc.Any() ? (DateTime?)sasloc.Max(l => l.ExpirationDateTime) : null;
                }

                xlWorkSheet.Cells[row, index++] = asset.GetEncryptionState(AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash).ToString();
                xlWorkSheet.Cells[row, index++] = asset.AssetFilters.Count().ToString();
            }
        }
        private void ExportAssetExcel(IAsset asset, Excel.Worksheet xlWorkSheet, int row, bool detailed, bool localtime)
        {
            xlWorkSheet.Cells[row, 1] = asset.Name;
            xlWorkSheet.Cells[row, 2] = asset.Id;
            xlWorkSheet.Cells[row, 3] = localtime ? asset.LastModified.ToLocalTime() : asset.LastModified;
            xlWorkSheet.Cells[row, 4] = AssetInfo.GetAssetType(asset);
            xlWorkSheet.Cells[row, 5] = AssetInfo.GetSize(asset);
            var url = AssetInfo.GetValidOnDemandURI(asset);
            xlWorkSheet.Cells[row, 6] = url != null ? url.ToString() : string.Empty;

            if (localtime)
            {
                xlWorkSheet.Cells[row, 7] = asset.Locators.Any() ? (DateTime?)asset.Locators.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
            }
            else
            {
                xlWorkSheet.Cells[row, 7] = asset.Locators.Any() ? (DateTime?)asset.Locators.Max(l => l.ExpirationDateTime) : null;
            }

            if (detailed)
            {
                xlWorkSheet.Cells[row, 8] = asset.AlternateId;
                xlWorkSheet.Cells[row, 9] = asset.StorageAccount.Name;
                var streamingloc = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin);
                xlWorkSheet.Cells[row, 10] = streamingloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, 11] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, 12] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, 11] = streamingloc.Any() ? (DateTime?)streamingloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, 12] = streamingloc.Any() ? (DateTime?)streamingloc.Max(l => l.ExpirationDateTime) : null;
                }

                var sasloc = asset.Locators.Where(l => l.Type == LocatorType.Sas);
                xlWorkSheet.Cells[row, 13] = sasloc.Count();
                if (localtime)
                {
                    xlWorkSheet.Cells[row, 14] = sasloc.Any() ? (DateTime?)sasloc.Min(l => l.ExpirationDateTime).ToLocalTime() : null;
                    xlWorkSheet.Cells[row, 15] = sasloc.Any() ? (DateTime?)sasloc.Max(l => l.ExpirationDateTime).ToLocalTime() : null;
                }
                else
                {
                    xlWorkSheet.Cells[row, 14] = sasloc.Any() ? (DateTime?)sasloc.Min(l => l.ExpirationDateTime) : null;
                    xlWorkSheet.Cells[row, 15] = sasloc.Any() ? (DateTime?)sasloc.Max(l => l.ExpirationDateTime) : null;
                }

                xlWorkSheet.Cells[row, 16] = asset.GetEncryptionState(AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash).ToString();
            }
        }
Пример #12
0
        private void ValidateAssetEncryptionState(IAsset asset, AssetDeliveryProtocol protocolsToTest, AssetEncryptionState expectedState)
        {
            AssetEncryptionState actualState = asset.GetEncryptionState(protocolsToTest);

            Assert.AreEqual(expectedState, actualState);
        }