/// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Request the creative service from the service client factory.
            CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService(
                DfaService.v1_19.CreativeRemoteService);

            long creativeId = long.Parse(_T("INSERT_IN_STREAM_VIDEO_CREATIVE_ID_HERE"));

            try {
                // Fetch the In-Stream video creative which contains the asset to modify.
                CreativeBase rawCreative = creativeService.getCreative(creativeId);

                if (!(rawCreative is InStreamVideoCreative))
                {
                    Console.WriteLine("Unable to update creative with ID \"{0}\": not an In-Stream video "
                                      + "creative.", creativeId);
                }
                else
                {
                    InStreamVideoCreative inStreamVideoCreative = (InStreamVideoCreative)rawCreative;

                    // Modify the media files, companion ads, and/or non-linear ads.
                    if (inStreamVideoCreative.mediaFiles != null)
                    {
                        foreach (InStreamMediaFile mediaFile in inStreamVideoCreative.mediaFiles)
                        {
                            mediaFile.pickedToServe = !mediaFile.pickedToServe;
                        }
                    }

                    if (inStreamVideoCreative.companionAds != null)
                    {
                        foreach (InStreamCompanionAd companionAd in inStreamVideoCreative.companionAds)
                        {
                            companionAd.altText = companionAd.altText + " Updated.";
                        }
                    }

                    if (inStreamVideoCreative.nonLinearAds != null)
                    {
                        foreach (InStreamNonLinearAd nonLinearAd in inStreamVideoCreative.nonLinearAds)
                        {
                            nonLinearAd.scalable = !nonLinearAd.scalable;
                        }
                    }

                    CreativeSaveResult creativeSaveResult =
                        creativeService.saveCreative(inStreamVideoCreative, 0);

                    Console.WriteLine("Updated the In-Stream assets of In-Stream video creative with ID "
                                      + "\"{0}\".", creativeSaveResult.id);
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to update in-stream assets of in-stream video creative. " +
                                  "Exception says \"{0}\"", ex.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Request the creative service from the service client factory.
            CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService(
                DfaService.v1_20.CreativeRemoteService);

            long   advertiserId    = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
            long   campaignId      = 0;
            float  videoDuration   = float.Parse(_T("INSERT_VIDEO_DURATION_HERE"));
            string adId            = _T("INSERT_VAST_AD_ID_HERE");
            string surveyUrl       = _T("INSERT_VAST_SURVEY_URL_HERE");
            string clickThroughUrl = _T("INSERT_VAST_CLICK_THROUGH_URL_HERE");

            // Create the In-Stream video creative.
            InStreamVideoCreative inStreamVideoCreative = new InStreamVideoCreative();

            inStreamVideoCreative.advertiserId  = advertiserId;
            inStreamVideoCreative.name          = "In-Stream Video Creative #" + GetTimeStamp();
            inStreamVideoCreative.videoDuration = videoDuration;
            // In-Stream video creatives have to be created inactive. One can only be
            // set active after at least one media file has been added to it or the API
            // will return an error message.
            inStreamVideoCreative.active = false;

            // Set the video details based on the Video Ad Serving Template (VAST)
            // specification.
            inStreamVideoCreative.adId            = adId;
            inStreamVideoCreative.description     = "You are viewing an In-Stream Video Creative";
            inStreamVideoCreative.surveyUrl       = surveyUrl;
            inStreamVideoCreative.clickThroughUrl = clickThroughUrl;

            try {
                // Save the In-Stream video creative.
                CreativeSaveResult creativeSaveResult = creativeService.saveCreative(inStreamVideoCreative,
                                                                                     campaignId);

                // Display the new creative ID.
                Console.WriteLine("In-Stream video creative with ID \"{0}\" was created.",
                                  creativeSaveResult.id);
            } catch (Exception ex) {
                Console.WriteLine("Failed to create in-stream video creative. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Request the creative service from the service client factory.
            CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService(
                DfaService.v1_20.CreativeRemoteService);

            string assetName      = _T("INSERT_ASSET_NAME_HERE");
            string pathToFile     = _T("INSERT_PATH_TO_FILE_HERE");
            long   creativeId     = long.Parse(_T("INSERT_IN_STREAM_VIDEO_CREATIVE_ID_HERE"));
            string assetToReplace = _T("INSERT_ASSET_TO_REPLACE_HERE");

            // Create the In-Stream creative asset.
            CreativeAsset inStreamVideoAsset = new CreativeAsset();

            inStreamVideoAsset.name    = assetName;
            inStreamVideoAsset.content = MediaUtilities.GetAssetDataFromUrl(
                new Uri(pathToFile).AbsoluteUri);

            // Create an upload request to make this asset a companion ad file for an
            // existing In-Stream video creative.
            InStreamAssetUploadRequest inStreamAssetUploadRequest = new InStreamAssetUploadRequest();

            inStreamAssetUploadRequest.companion     = true;
            inStreamAssetUploadRequest.inStreamAsset = inStreamVideoAsset;
            inStreamAssetUploadRequest.creativeId    = creativeId;

            try {
                // Replace the existing asset with a newly uploaded asset.
                InStreamVideoCreative inStreamVideoCreative =
                    creativeService.replaceInStreamAsset(assetToReplace, inStreamAssetUploadRequest);

                // Display a success message.
                Console.WriteLine("Replaced companion ad asset \"{0}\" in In-Stream video creative "
                                  + "with ID \"{1}\".%n", assetToReplace, inStreamVideoCreative.id);
            } catch (Exception ex) {
                Console.WriteLine("Failed to replace companion ad asset in in-stream video creative. " +
                                  "Exception says \"{0}\"", ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Request the creative service from the service client factory.
            CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService(
                DfaService.v1_19.CreativeRemoteService);

            string assetName  = _T("INSERT_ASSET_NAME_HERE");
            string pathToFile = _T("INSERT_PATH_TO_FILE_HERE");
            long   creativeId = long.Parse(_T("INSERT_IN_STREAM_VIDEO_CREATIVE_ID_HERE"));

            // Create the In-Stream video creative asset.
            CreativeAsset inStreamVideoAsset = new CreativeAsset();

            inStreamVideoAsset.name    = assetName;
            inStreamVideoAsset.content = MediaUtilities.GetAssetDataFromUrl(
                new Uri(pathToFile).AbsolutePath);

            // Create an upload request to make this asset a media file for an existing
            // In-Stream creative.
            InStreamAssetUploadRequest inStreamAssetUploadRequest = new InStreamAssetUploadRequest();

            inStreamAssetUploadRequest.mediaFile     = true;
            inStreamAssetUploadRequest.inStreamAsset = inStreamVideoAsset;
            inStreamAssetUploadRequest.creativeId    = creativeId;

            try {
                // Save the media file.
                InStreamVideoCreative inStreamVideoCreative =
                    creativeService.uploadInStreamAsset(inStreamAssetUploadRequest);

                // Display a success message.
                Console.WriteLine("Added a media file to In-Stream video creative with ID \"{0}\".",
                                  inStreamVideoCreative.id);
            } catch (Exception ex) {
                Console.WriteLine("Failed to add a media file to in-stream video creative. " +
                                  "Exception says \"{0}\"", ex.Message);
            }
        }