Exemplo n.º 1
0
 public static JObject SetContext(JObject document, MediaAccount mediaAccount, string assetId)
 {
     document["accountId"]       = mediaAccount.Id;
     document["accountDomain"]   = mediaAccount.DomainName;
     document["accountEndpoint"] = mediaAccount.EndpointUrl;
     document["clientId"]        = mediaAccount.ClientId;
     document["clientKey"]       = mediaAccount.ClientKey;
     document["assetId"]         = assetId;
     return(document);
 }
Exemplo n.º 2
0
        private MediaAccount GetMediaAccount()
        {
            MediaAccount mediaAccount = new MediaAccount()
            {
                Id          = GetMediaAccountId(),
                DomainName  = GetMediaAccountDomainName(),
                EndpointUrl = GetMediaAccountEndpointUrl(),
                ClientId    = GetMediaAccountClientId(),
                ClientKey   = GetMediaAccountClientKey(),
                IndexerKey  = GetMediaAccountIndexerKey()
            };

            return(mediaAccount);
        }
Exemplo n.º 3
0
        internal MediaStorage(MediaAccount mediaAccount, MediaStorageAccount storageAccount) : base(storageAccount.Type, storageAccount.Id)
        {
            ServiceClientCredentials clientCredentials = ApplicationTokenProvider.LoginSilentAsync(mediaAccount.DirectoryTenantId, mediaAccount.ServicePrincipalId, mediaAccount.ServicePrincipalKey).Result;
            StorageManagementClient  storageClient     = new StorageManagementClient(clientCredentials)
            {
                SubscriptionId = mediaAccount.SubscriptionId
            };

            _storageAccountName = Path.GetFileName(storageAccount.Id);
            IEnumerable <StorageAccount> storageAccounts = storageClient.StorageAccounts.List();

            storageAccounts = storageAccounts.Where(s => s.Name.Equals(_storageAccountName, StringComparison.OrdinalIgnoreCase));
            _storageAccount = storageAccounts.SingleOrDefault();
        }
Exemplo n.º 4
0
        public static Task <AuthenticationResult> AcquireToken(MediaAccount mediaAccount)
        {
            string settingKey   = Constant.AppSettingKey.DirectoryAuthorityUrl;
            string authorityUrl = AppSetting.GetValue(settingKey);

            authorityUrl = string.Format(authorityUrl, mediaAccount.DirectoryTenantId);

            string           redirectUri      = Constant.AuthIntegration.RedirectUri;
            ClientCredential clientCredential = new ClientCredential(mediaAccount.ServicePrincipalKey);
            ConfidentialClientApplication clientApplication = new ConfidentialClientApplication(mediaAccount.ServicePrincipalId, authorityUrl, redirectUri, clientCredential, null, null);

            settingKey = Constant.AppSettingKey.AzureResourceManagementTokenScope;
            string tokenScope = AppSetting.GetValue(settingKey);

            string[] tokenScopes = new string[] { tokenScope };
            return(clientApplication.AcquireTokenForClientAsync(tokenScopes));
        }
Exemplo n.º 5
0
        public static CloudStorageAccount GetStorageAccount(MediaAccount mediaAccount, string accountName)
        {
            CloudStorageAccount storageAccount;

            if (mediaAccount == null)
            {
                string settingKey    = Constant.AppSettingKey.AzureStorage;
                string systemStorage = AppSetting.GetValue(settingKey);
                storageAccount = CloudStorageAccount.Parse(systemStorage);
            }
            else
            {
                string             accountKey         = mediaAccount.StorageAccounts[accountName];
                StorageCredentials storageCredentials = new StorageCredentials(accountName, accountKey);
                storageAccount = new CloudStorageAccount(storageCredentials, true);
            }
            return(storageAccount);
        }
Exemplo n.º 6
0
        public MediaClient(string authToken, MediaAccount mediaAccount = null)
        {
            if (!string.IsNullOrEmpty(authToken))
            {
                User userProfile = new User(authToken);
                mediaAccount = userProfile.MediaAccount;
            }
            MediaAccount = mediaAccount;
            string settingKey = Constant.AppSettingKey.AzureResourceManagementServiceUrl;
            string serviceUrl = AppSetting.GetValue(settingKey);
            MediaClientCredentials clientCredentials = new MediaClientCredentials(mediaAccount);

            _media = new AzureMediaServicesClient(new Uri(serviceUrl), clientCredentials)
            {
                SubscriptionId = mediaAccount.SubscriptionId
            };
            if (!string.IsNullOrEmpty(MediaAccount.VideoIndexerRegion) &&
                !string.IsNullOrEmpty(MediaAccount.VideoIndexerKey))
            {
                IndexerSetAccountContext();
            }
        }
Exemplo n.º 7
0
        public static void SetMediaSubscription(MediaAccount mediaAccount)
        {
            ServiceClientCredentials  clientCredentials = ApplicationTokenProvider.LoginSilentAsync(mediaAccount.DirectoryTenantId, mediaAccount.ServicePrincipalId, mediaAccount.ServicePrincipalKey).Result;
            EventGridManagementClient eventGridClient   = new EventGridManagementClient(clientCredentials)
            {
                SubscriptionId = mediaAccount.SubscriptionId
            };

            string settingKey           = Constant.AppSettingKey.EventGridLiveEventUrl;
            string jobOutputProgressUrl = AppSetting.GetValue(settingKey);

            settingKey = Constant.AppSettingKey.EventGridJobStateFinalUrl;
            string jobStateFinalUrl = AppSetting.GetValue(settingKey);

            settingKey = Constant.AppSettingKey.EventGridLiveEventUrl;
            string liveEventUrl = AppSetting.GetValue(settingKey);

            string eventScope = mediaAccount.ResourceId;

            SetEventSubscription(eventGridClient, eventScope, Constant.EventGrid.JobOutputProgressSubscriptionName, jobOutputProgressUrl, Constant.EventGrid.JobOutputProgressSubscriptionEvents);
            SetEventSubscription(eventGridClient, eventScope, Constant.EventGrid.JobStateFinalSubscriptionName, jobStateFinalUrl, Constant.EventGrid.JobStateFinalSubscriptionEvents);
            SetEventSubscription(eventGridClient, eventScope, Constant.EventGrid.LiveEventSubscriptionName, liveEventUrl, Constant.EventGrid.LiveEventSubscriptionEvents);
        }
Exemplo n.º 8
0
        public static void PurgePublishInsight(TableClient tableClient)
        {
            DocumentClient documentClient = new DocumentClient();
            string         collectionId   = Constant.Database.Collection.ContentInsight;

            JObject[] documents = documentClient.GetDocuments(collectionId);
            foreach (JObject document in documents)
            {
                if (document["accountId"] != null)
                {
                    MediaAccount mediaAccount = new MediaAccount()
                    {
                        Id          = document["accountId"].ToString(),
                        DomainName  = document["accountDomain"].ToString(),
                        EndpointUrl = document["accountEndpoint"].ToString(),
                        ClientId    = document["clientId"].ToString(),
                        ClientKey   = document["clientKey"].ToString()
                    };
                    string assetId = document["assetId"].ToString();

                    MediaClient mediaClient = new MediaClient(mediaAccount);
                    IAsset      asset       = mediaClient.GetEntityById(MediaEntity.Asset, assetId) as IAsset;
                    if (asset == null)
                    {
                        string documentId = document["id"].ToString();
                        documentClient.DeleteDocument(collectionId, documentId);

                        string       tableName      = Constant.Storage.Table.InsightPublish;
                        MediaPublish insightPublish = tableClient.GetEntity <MediaPublish>(tableName, mediaAccount.Id, documentId);
                        if (insightPublish != null)
                        {
                            tableClient.DeleteEntity(tableName, insightPublish);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        public User(string authToken)
        {
            _authToken = authToken;

            string[] accountNames       = AuthToken.GetClaimValues(_authToken, Constant.UserAttribute.MediaAccountName);
            string[] resourceGroupNames = AuthToken.GetClaimValues(_authToken, Constant.UserAttribute.MediaAccountResourceGroupName);
            string   subscriptionId     = AuthToken.GetClaimValue(_authToken, Constant.UserAttribute.MediaAccountSubscriptionId);
            string   directoryTenantId  = AuthToken.GetClaimValue(_authToken, Constant.UserAttribute.MediaAccountDirectoryTenantId);

            string[] servicePrincipalIds  = AuthToken.GetClaimValues(_authToken, Constant.UserAttribute.MediaAccountServicePrincipalId);
            string[] servicePrincipalKeys = AuthToken.GetClaimValues(_authToken, Constant.UserAttribute.MediaAccountServicePrincipalKey);
            string[] videoIndexerIds      = AuthToken.GetClaimValues(_authToken, Constant.UserAttribute.MediaAccountVideoIndexerId);
            string[] videoIndexerKeys     = AuthToken.GetClaimValues(_authToken, Constant.UserAttribute.MediaAccountVideoIndexerKey);
            string[] videoIndexerRegions  = AuthToken.GetClaimValues(_authToken, Constant.UserAttribute.MediaAccountVideoIndexerRegion);

            List <MediaAccount> mediaAccounts = new List <MediaAccount>();

            for (int i = 0; i < accountNames.Length; i++)
            {
                MediaAccount mediaAccount = new MediaAccount()
                {
                    Name = accountNames[i],
                    ResourceGroupName   = resourceGroupNames[i],
                    SubscriptionId      = subscriptionId,
                    DirectoryTenantId   = directoryTenantId,
                    ServicePrincipalId  = servicePrincipalIds[i],
                    ServicePrincipalKey = servicePrincipalKeys[i],
                    VideoIndexerId      = videoIndexerIds == null || i >= videoIndexerIds.Length ? null : videoIndexerIds[i],
                    VideoIndexerKey     = videoIndexerKeys == null || i >= videoIndexerKeys.Length ? null : videoIndexerKeys[i],
                    VideoIndexerRegion  = videoIndexerRegions == null || i >= videoIndexerRegions.Length ? null : videoIndexerRegions[i],
                    StorageAccounts     = GetStorageAccounts(i)
                };
                mediaAccounts.Add(mediaAccount);
            }
            _mediaAccounts = mediaAccounts.ToArray();
        }
Exemplo n.º 10
0
 public User(string authToken)
 {
     _authToken    = authToken;
     _mediaAccount = GetMediaAccount();
 }
Exemplo n.º 11
0
        public StorageBlobClient(MediaAccount mediaAccount, string accountName)
        {
            CloudStorageAccount storageAccount = Account.GetStorageAccount(mediaAccount, accountName);

            _blobClient = storageAccount.CreateCloudBlobClient();
        }
Exemplo n.º 12
0
 public MediaClientCredentials(MediaAccount mediaAccount)
 {
     _mediaAccount = mediaAccount;
 }
Exemplo n.º 13
0
 public MediaClient(MediaAccount mediaAccount, UserAccount userAccount)
 {
     MediaAccount = mediaAccount;
     UserAccount  = userAccount;
     BindContext();
 }