private Task <IMediaDataServiceResponse> CreateStreamingEndpointAsync(StreamingEndpointCreationOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (string.IsNullOrEmpty(options.Name))
            {
                throw new ArgumentException(Resources.ErrorEmptyStreamingEndpointName);
            }

            var streamingEndpoint = new StreamingEndpointData
            {
                Name                    = options.Name,
                Description             = options.Description,
                ScaleUnits              = options.ScaleUnits,
                CrossSiteAccessPolicies = options.CrossSiteAccessPolicies
            };

            if (options.CustomHostNames != null)
            {
                streamingEndpoint.CustomHostNames = (options.CustomHostNames as IList <string>) ??
                                                    options.CustomHostNames.ToList();
            }

            ((IStreamingEndpoint)streamingEndpoint).AccessControl = options.AccessControl;
            ((IStreamingEndpoint)streamingEndpoint).CacheControl  = options.CacheControl;

            streamingEndpoint.ValidateSettings();

            streamingEndpoint.SetMediaContext(MediaContext);

            IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext();

            dataContext.AddObject(StreamingEndpointSet, streamingEndpoint);

            MediaRetryPolicy retryPolicy = MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter);

            return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(streamingEndpoint)));
        }
        private Task <IMediaDataServiceResponse> CreateStreamingEndpointAsync(StreamingEndpointCreationOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (string.IsNullOrEmpty(options.Name))
            {
                throw new ArgumentException(Resources.ErrorEmptyStreamingEndpointName);
            }

            var streamingEndpoint = new StreamingEndpointData(options);

            streamingEndpoint.SetMediaContext(MediaContext);

            IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext();

            dataContext.AddObject(StreamingEndpointSet, streamingEndpoint);

            MediaRetryPolicy retryPolicy = MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter);

            return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(streamingEndpoint)));
        }