// </Snippet2> private async Task InitializeExperiment() { // Get the current cached variation assignment for the experiment. // <Snippet3> var result = await StoreServicesExperimentVariation.GetCachedVariationAsync(projectId); variation = result.ExperimentVariation; // </Snippet3> // Refresh the cached variation assignment if necessary. // <Snippet4> if (result.ErrorCode != StoreServicesEngagementErrorCode.None || result.ExperimentVariation.IsStale) { result = await StoreServicesExperimentVariation.GetRefreshedVariationAsync(projectId); if (result.ErrorCode == StoreServicesEngagementErrorCode.None) { variation = result.ExperimentVariation; } } // </Snippet4> // Get the remote variable named "buttonText" and assign the value // to the button. // <Snippet5> var buttonText = variation.GetString("buttonText", "Grey Button"); // </Snippet5> // <Snippet6> await button.Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, () => { button.Content = buttonText; }); // </Snippet6> // Log the view event named "userViewedButton" to Dev Center. // <Snippet7> if (logger == null) { logger = StoreServicesCustomEventLogger.GetDefault(); } logger.LogForVariation(variation, "userViewedButton"); // </Snippet7> }
private async Task InitializeExperiment() { // Get the current cached variation assignment for the experiment. var result = await StoreServicesExperimentVariation.GetCachedVariationAsync(projectId); variation = result.ExperimentVariation; // Check whether the cached variation assignment needs to be refreshed. // If so, then refresh it. if (result.ErrorCode != StoreServicesEngagementErrorCode.None || result.ExperimentVariation.IsStale) { result = await StoreServicesExperimentVariation.GetRefreshedVariationAsync(projectId); // If the call succeeds, use the new result. Otherwise, use the cached value. if (result.ErrorCode == StoreServicesEngagementErrorCode.None) { variation = result.ExperimentVariation; } } // Get remote variables named "buttonText", "r", "g", and "b" from the variation // assignment. If no variation assignment is available, the variables default // to "Grey button" for the button text and grey RGB value for the button color. var buttonText = variation.GetString("buttonText", "Grey Button"); var r = (byte)variation.GetInt32("r", 128); var g = (byte)variation.GetInt32("g", 128); var b = (byte)variation.GetInt32("b", 128); // Assign button text and color. await button.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { button.Background = new SolidColorBrush(Color.FromArgb(255, r, g, b)); button.Content = buttonText; button.Visibility = Visibility.Visible; }); // Log the view event named "userViewedButton" to Dev Center. if (logger == null) { logger = StoreServicesCustomEventLogger.GetDefault(); } logger.LogForVariation(variation, "userViewedButton"); }
public async Task InitializeExperiment() { // 取得現在 cache 中的實驗參數 var result = await StoreServicesExperimentVariation.GetCachedVariationAsync(ProjectId); variation = result.ExperimentVariation; // 檢查如果有錯誤訊息或是否有新的參數 if (result.ErrorCode != StoreServicesEngagementErrorCode.None || result.ExperimentVariation.IsStale) { result = await StoreServicesExperimentVariation.GetRefreshedVariationAsync(ProjectId); if (result.ErrorCode == StoreServicesEngagementErrorCode.None) { variation = result.ExperimentVariation; } } //// Get the remote variable named "buttonText" and assign the value //// to the button. //var buttonText = variation.GetString("buttonText", "Grey Button"); //await button.Dispatcher.RunAsync( // Windows.UI.Core.CoreDispatcherPriority.Normal, // () => // { // button.Content = buttonText; // }); //// Log the view event named "userViewedButton" to Dev Center. //if (logger == null) //{ // logger = StoreServicesCustomEventLogger.GetDefault(); //} //logger.LogForVariation(variation, "userViewedButton"); }