protected override async void OnNavigatedTo(NavigationEventArgs e) { // Remember which trip we came from, so we can perform a connected animation. defaultId = e.Parameter as string; // Clear any trip title. ApplicationView.GetForCurrentView().Title = String.Empty; // Generate a UserActivity that says that // the user is looking at the trips overview. var channel = UserActivityChannel.GetDefault(); string activityId = "home"; var activity = await channel.GetOrCreateUserActivityAsync(activityId); // Describe the activity. activity.ActivationUri = new Uri($"{App.ProtocolScheme}:{activityId}"); activity.VisualElements.DisplayText = "Trips Overview"; var card = new AdaptiveCard(); // Source: https://www.publicdomainpictures.net/en/view-image.php?image=248425 card.BackgroundImageString = "https://www.publicdomainpictures.net/pictures/250000/velka/passport-a-map-and-money.jpg"; card.Body.Add(new AdaptiveTextBlock("Trips Overview") { Size = AdaptiveTextSize.Large, Weight = AdaptiveTextWeight.Bolder }); card.Body.Add(new AdaptiveTextBlock("2 trips")); activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(card.ToJson()); // Save it to the channel. await activity.SaveAsync(); // Start a session. activitySession = activity.CreateSession(); }
public void TriggerRecordUserActivity() { if (_session == null) { _session = _actualUserActivity.CreateSession(); } }
private async Task AddTimelineItem(T newItem) { UserActivityChannel _userActivityChannel = UserActivityChannel.GetDefault(); UserActivity _userActivity = await _userActivityChannel.GetOrCreateUserActivityAsync("TDN"); // Fetch the adaptive card JSON var adaptiveCard = AdaptiveCards.AdaptiveHeaderDescription; // Replace the content. adaptiveCard = adaptiveCard.Replace("{backgroundImage}", ""); adaptiveCard = adaptiveCard.Replace("{name}", newItem.Name); adaptiveCard = adaptiveCard.Replace("{description}", newItem.Description); // Create the protocol, so when the clicks the Adaptive Card on the Timeline, it will directly launch to the correct image. //_userActivity.ActivationUri = new Uri($"my-timeline://details?{_galleryItem.ImageSource.Replace("ms-appx:///Assets/Images/", "")}"); // Set the display text to the User Activity(e.g. Pike Place market.) _userActivity.VisualElements.DisplayText = newItem.Name; // Assign the Adaptive Card to the user activity. _userActivity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(adaptiveCard); // Save the details user activity. await _userActivity.SaveAsync(); // Dispose of the session and create a new one ready for the next user activity. _userActivitySession?.Dispose(); _userActivitySession = _userActivity.CreateSession(); }
public async void GenerateActivityAsync(string websitePage, string title, string content, string backgroundPath) { // Get the default UserActivityChannel and query it for our UserActivity. If the activity doesn't exist, one is created. UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity userActivity = await channel.GetOrCreateUserActivityAsync("MainPage"); var uri = new Uri("moepicture://" + title + "?action=view"); // Populate required properties userActivity.VisualElements.DisplayText = "MoePicture"; userActivity.ActivationUri = uri; var folder = Package.Current.InstalledLocation; var file = await(await folder.GetFolderAsync("JskyUwpLibs")).GetFileAsync("Activities.json"); string cardJsonText = await FileIO.ReadTextAsync(file); dynamic card = JObject.Parse(cardJsonText); card.backgroundImage = backgroundPath; card.body[0].items[0].text = title; card.body[0].items[1].text = content; cardJsonText = JsonConvert.SerializeObject(card); // where jsonCardText is a JSON string that represents the card userActivity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(cardJsonText); //Save await userActivity.SaveAsync(); //save the new metadata // Dispose of any current UserActivitySession, and create a new one. currentActivity?.Dispose(); currentActivity = userActivity.CreateSession(); }
private async Task GenerateActivityAsync(VolItem volItem) { // Get the default UserActivityChannel and query it for our UserActivity. If the activity doesn't exist, one is created. UserActivityChannel channel = UserActivityChannel.GetDefault(); // The text here should be treated as a title for this activity and should be unique to this app. UserActivity userActivity = await channel.GetOrCreateUserActivityAsync("LuoVol." + volItem.Vol.VolNum); // Populate required properties: DisplayText and ActivationUri are required. userActivity.VisualElements.DisplayText = "Luoo-UWP Timeline activities"; // The name in the ActivationUri must match the name in the protocol setting in the manifest file (except for the "://" part). userActivity.ActivationUri = new Uri("luoo://?volnum=" + volItem.Vol.VolNum); // Build the adaptive card from a JSON string. userActivity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(apodTimelineCard.ToJson()); // Set the mime type of the user activity, in this case, an application. userActivity.ContentType = "application/octet-stream"; // Save the new metadata. await userActivity.SaveAsync(); // Dispose of any current UserActivitySession, and create a new one. _currentActivity?.Dispose(); _currentActivity = userActivity.CreateSession(); }
/// <summary> /// Finishes the activity session asynchronous. /// </summary> /// <param name="theActivitySession"> /// The activity session. /// </param> public static void FinishActivitySessionAsync(UserActivitySession theActivitySession) { if (!(theActivitySession is null)) { theActivitySession.Dispose(); } }
private async Task CreateUserActivityAsync() { // Get channel and create activity. UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity activity = await channel.GetOrCreateUserActivityAsync("Scenario2_AdvancedUserActivity"); // Set deep-link and properties. activity.ActivationUri = new Uri("sdkUserActivitySample:page?Scenario2_AdvancedUserActivity"); activity.VisualElements.DisplayText = "README.md"; // Add advanced properties. activity.ContentUri = new Uri("https://raw.githubusercontent.com/Microsoft/Windows-universal-samples/master/README.md"); activity.FallbackUri = new Uri("http://go.microsoft.com/fwlink/p/?LinkId=873257"); activity.VisualElements.Attribution = new UserActivityAttribution() { IconUri = new Uri("https://raw.githubusercontent.com/Microsoft/Windows-universal-samples/master/SharedContent/media/storelogo-sdk.png"), AlternateText = "Windows SDK Samples", AddImageQuery = false }; activity.VisualElements.BackgroundColor = Color.FromArgb(0xFF, 0x00, 0xb2, 0xf0); activity.VisualElements.Description = "https://raw.githubusercontent.com/Microsoft/Windows-universal-samples/master/README.md"; // Save to activity feed. await activity.SaveAsync(); // Create a session, which indicates that the user is engaged // in the activity. _currentSession = activity.CreateSession(); }
public async Task UpdateActivityAsync(ISource source, Media media, IEnumerable <Media> queue, string token, TimeSpan?timeSpan, bool isShuffled) { if (media.MediaType != MediaType.Track) { return; } var track = (Track)media; var activity = await _channel.GetOrCreateUserActivityAsync("last-playback"); activity.FallbackUri = new Uri("https://soundbytemedia.com/pages/remote-subsystem"); var continueText = @"Continue listening to " + track.Title.Replace('"', ' ') + " and " + queue.Count() + " other songs."; activity.VisualElements.DisplayText = track.Title.Replace('"', ' '); activity.VisualElements.Description = continueText; var json = @"{""$schema"":""http://adaptivecards.io/schemas/adaptive-card.json"",""type"":""AdaptiveCard"",""backgroundImage"":""" + track.ArtworkUrl + @""",""version"": ""1.0"",""body"":[{""type"":""Container"",""items"":[{""type"":""TextBlock"",""text"":""" + track.Title.Replace('"', ' ') + @""",""weight"":""bolder"",""size"":""large"",""wrap"":true,""maxLines"":3},{""type"":""TextBlock"",""text"":""" + continueText + @""",""size"":""default"",""wrap"":true,""maxLines"":3}]}]}"; activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(json); activity.ActivationUri = new Uri("https://soundbytemedia.com/pages/remote-subsystem"); await activity.SaveAsync(); // Session await DispatcherHelper.ExecuteOnUIThreadAsync(() => { _currentUserActivitySession?.Dispose(); _currentUserActivitySession = null; _currentUserActivitySession = activity.CreateSession(); }); }
private static async Task SaveAsync(UserActivity activity) { await activity.SaveAsync(); // Dispose of any current UserActivitySession, and create a new one. _currentUserActivitySession?.Dispose(); _currentUserActivitySession = activity.CreateSession(); }
public void TriggerEndUserActivity() { if (_session != null) { _session.Dispose(); _session = null; } }
public async void OnGetActivityClick(object sender, RoutedEventArgs e) { ActivityId = Guid.NewGuid().ToString(); // Get or Create a activity var activity = await UserActivityChannel.GetDefault().GetOrCreateUserActivityAsync(ActivityId); // if you want to use Adaptive card, reference: https://docs.microsoft.com/en-us/adaptive-cards/create/gettingstarted activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(@"{ ""$schema"": ""http://adaptivecards.io/schemas/adaptive-card.json"", ""type"": ""AdaptiveCard"", ""backgroundImage"": ""https://cdn2.ettoday.net/images/1376/d1376700.jpg"", ""version"": ""1.0"", ""body"" : [ { ""type"": ""Container"", ""items"": [ { ""type"": ""TextBlock"", ""text"": ""from adaptive card"", ""size"": ""large"", ""wrap"": ""true"", ""maxLines"": ""3"" } ] } ] }"); if (activity.State == UserActivityState.New) { // this is a new activity activity.VisualElements.DisplayText = "new activity"; activity.ActivationUri = new Uri($"testapp://mainPage?state=new&id={ActivityId}"); } else { // this is published activity activity.VisualElements.DisplayText = "published activity"; activity.ActivationUri = new Uri($"testapp://mainPage?state=published&id={ActivityId}"); } // set activity content info activity.ContentInfo = UserActivityContentInfo.FromJson(@"{ ""user_id"": ""pou"", ""email"": ""*****@*****.**"" }"); // FallbackUri is handled when System invoke ActivationUri failed. //activity.FallbackUri = new Uri("https://dotblogs.com.tw/pou"); activity.VisualElements.BackgroundColor = Color.FromArgb(0xFF, 0x88, 0x88, 0x88); await activity.SaveAsync(); // a activity match an session, need close other sessions. activitySesion?.Dispose(); activitySesion = activity.CreateSession(); }
public async Task InitializeUserSessionAsync() { UserActivityChannel channel = UserActivityChannel.GetDefault(); _activity = await channel.GetOrCreateUserActivityAsync(_sessionId); _activity.ActivationUri = new Uri($"quadrant-app:resume?{_sessionId}"); _activity.VisualElements.DisplayText = AppUtilities.GetString("AppName"); await _activity.SaveAsync(); _session = _activity.CreateSession(); }
private static async Task SaveAsync(UserActivity activity) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, async() => { await activity.SaveAsync(); // Dispose of any current UserActivitySession, and create a new one. _currentUserActivitySession?.Dispose(); _currentUserActivitySession = activity.CreateSession(); }); }
//时间线支持 public static async Task GenerateActivityAsync(string DisplayText, AdaptiveCard Card, Uri ActivationUri, string ActivityID) { UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity userActivity = await channel.GetOrCreateUserActivityAsync(ActivityID); userActivity.VisualElements.DisplayText = DisplayText; userActivity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(Card.ToJson()); userActivity.ActivationUri = ActivationUri; await userActivity.SaveAsync(); _currentActivity?.Dispose(); _currentActivity = userActivity.CreateSession(); }
private async Task AddActivity(ProjectPad.Business.ProjectViewModel project) { var channel = UserActivityChannel.GetDefault(); var activity = await channel.GetOrCreateUserActivityAsync("open:" + project.MetaData.Id); activity.ActivationUri = new Uri("useopsprjpad://projects/" + project.MetaData.Id); activity.IsRoamable = true; activity.VisualElements.DisplayText = project.MetaData.Name; activity.VisualElements.Description = LocalizationHelper.FormatActivityForProject(project); await activity.SaveAsync(); _editProjectSession = activity.CreateSession(); }
private async Task GenerateTimelineActivityAsync(MyTextItem item) { UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity userActivity = await channel.GetOrCreateUserActivityAsync(item.Id.ToString()); userActivity.VisualElements.DisplayText = item.Content; userActivity.VisualElements.Description = $"Last saved: {item.LastModified}"; userActivity.ActivationUri = new Uri($"mytext://editor?id={item.Id}"); await userActivity.SaveAsync(); this.currentActivity?.Dispose(); this.currentActivity = userActivity.CreateSession(); }
public async Task AddCardToTimeline(FileViewModel card) { UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity userActivity = await channel.GetOrCreateUserActivityAsync(Guid.NewGuid().ToString()); userActivity.VisualElements.DisplayText = "Card error: " + card.Name; userActivity.VisualElements.AttributionDisplayText = card.Name; userActivity.ActivationUri = new Uri("https://github.com/Microsoft/AdaptiveCards/blob/master/samples/" + card.Name + ".json"); userActivity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(card.Contents); await userActivity.SaveAsync(); _currentSession?.Dispose(); _currentSession = userActivity.CreateSession(); }
public async void Create(string json, string text) { string id = random.Next(1, 100000000).ToString(); UserActivity activity = await channel.GetOrCreateUserActivityAsync(id); activity.VisualElements.DisplayText = text; activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(json); activity.ActivationUri = new Uri(uri); activity.FallbackUri = new Uri(uri); await activity.SaveAsync(); UserActivitySession session = activity.CreateSession(); session?.Dispose(); }
private async Task <string> Create(string title, string body, Color background) { string id = random.Next(1, 100000000).ToString(); UserActivity activity = await _channel.GetOrCreateUserActivityAsync(id); activity.VisualElements.DisplayText = title; activity.ActivationUri = new Uri(timeline_uri); activity.FallbackUri = new Uri(timeline_uri); activity.VisualElements.BackgroundColor = background; activity.VisualElements.Description = body; await activity.SaveAsync(); UserActivitySession session = activity.CreateSession(); session?.Dispose(); return(id); }
private async Task CreateActivityAsync(AppContent target) { var channel = UserActivityChannel.TryGetForWebAccount(Account); var activity = await channel.GetOrCreateUserActivityAsync(target.Id); activity.ActivationUri = new Uri($"decodedemo:?id={target.Id}"); var card = target.ToAdaptiveCard(); activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(card.ToJson()); activity.VisualElements.DisplayText = target.Title; await activity.SaveAsync(); _currentActivity?.Dispose(); _currentActivity = activity.CreateSession(); }
async Task CreateUserActivityAsync() { // Get channel and create activity. UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity activity = await channel.GetOrCreateUserActivityAsync("SentEmail"); // Set deep-link and properties. activity.VisualElements.DisplayText = "Graph Demo - Email Sent!"; activity.ActivationUri = new Uri("ignitedemo://page?MainPage"); // Save to activity feed. await activity.SaveAsync(); // Create a session, which indicates that the user is engaged in the activity. _currentSession?.Dispose(); _currentSession = activity.CreateSession(); }
async Task CreateUserActivityAsync() { // Get channel and create activity. UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity activity = await channel.GetOrCreateUserActivityAsync("Scenario1_BasicUserActivity"); // Set deep-link and properties. activity.ActivationUri = new Uri("useractivitysdkcs:page?Scenario1_BasicUserActivity"); activity.VisualElements.DisplayText = "User Activity Sample Scenario 1"; // Save to activity feed. await activity.SaveAsync(); // Create a session, which indicates that the user is engaged // in the activity. _currentSession = activity.CreateSession(); }
private async void RenderResult_OnAction(RenderedAdaptiveCard sender, AdaptiveActionEventArgs e) { if (e.Action.ActionType == ActionType.OpenUrl) { _userActivity.ActivationUri = new Uri("adaptivecards://openLastPost"); _userActivity.VisualElements.DisplayText = "Windows AppConsult blog"; _userActivity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(json); await _userActivity.SaveAsync(); _userActivitySession?.Dispose(); _userActivitySession = _userActivity.CreateSession(); var action = e.Action as AdaptiveOpenUrlAction; await Launcher.LaunchUriAsync(action.Url); } }
public static async Task <UserActivitySession> AddToTimeLine(string area, ModelBase theModel, string bodyText) { UserActivitySession returnedFromUIThread = await MainThread.InvokeOnMainThreadAsync(async() => { UserActivitySession activitySession = null; try { // Record in the TimeLine UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity _ModelUserActivity = await channel.GetOrCreateUserActivityAsync(theModel.HLinkKey.Value); if (theModel.Valid) { _ModelUserActivity.VisualElements.DisplayText = area.ToUpper(); _ModelUserActivity.VisualElements.Description = bodyText; _ModelUserActivity.VisualElements.BackgroundColor = ColorExtensions.ToPlatformColor(theModel.ModelItemGlyph.SymbolColour); // _ModelUserActivity.VisualElements.Content = // AdaptiveCardBuilder.CreateAdaptiveCardFromJson(CreateAdaptiveCardForTimeline(area, // theModel, bodyText).ToJson()); _ModelUserActivity.ActivationUri = new Uri("gramps://" + area + @"/handle/" + theModel.HLinkKey); //Save await _ModelUserActivity.SaveAsync(); if (_ModelUserActivity != null) { activitySession = _ModelUserActivity.CreateSession(); } } } catch (Exception ex) { DataStore.Instance.CN.NotifyException("Timeline Add", ex); throw; } return(activitySession); }).ConfigureAwait(false); return(returnedFromUIThread); }
async Task CreateUserActivityAsync() { // Get channel and create activity. UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity activity = await channel.GetOrCreateUserActivityAsync("Coupon Reader"); // Set deep-link and properties. activity.VisualElements.DisplayText = "DevIntersection Demo - Coupon Scanned!"; activity.ActivationUri = new Uri("DevIntersectionDemo://page?MainPage"); // Save to activity feed. await activity.SaveAsync(); // Dispose prevsion session, Create a new session which indicates that the user is engaged in the activity. _currentSession?.Dispose(); _currentSession = activity.CreateSession(); }
public async Task StartActivityAsync(ISource <BaseTrack> source, BaseTrack track, IEnumerable <BaseTrack> playlist, string token) { // We do not support these items if (track.ServiceType == ServiceType.ITunesPodcast || track.ServiceType == ServiceType.Local || track.ServiceType == ServiceType.Unknown) { return; } var activity = await UpdateActivityAsync(source, track, playlist, token); await DispatcherHelper.ExecuteOnUIThreadAsync(() => { _currentUserActivitySession = activity.CreateSession(); }); }
public async Task AddToTimeline(Expense expense) { _userActivityChannel = UserActivityChannel.GetDefault(); _userActivity = await _userActivityChannel.GetOrCreateUserActivityAsync($"Expense-{expense.ExpenseId}"); _userActivity.ActivationUri = new Uri($"contosoexpenses://expense/{expense.ExpenseId}"); _userActivity.VisualElements.DisplayText = "Contoso Expenses"; string json = BuildAdaptiveCard(expense); _userActivity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(json); await _userActivity.SaveAsync(); _userActivitySession?.Dispose(); _userActivitySession = _userActivity.CreateSession(); }
private async void GenerateActivityAsync() { // Get the default UserActivityChannel and query it for our UserActivity. If the activity doesn't exist, one is created. UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity userActivity = await channel.GetOrCreateUserActivityAsync("ShowMerchants"); // Populate required properties userActivity.VisualElements.DisplayText = "Handelaars"; userActivity.VisualElements.Description = "Bekijk de handelaars"; userActivity.ActivationUri = new Uri("stapp://ShowMerchants"); //Save await userActivity.SaveAsync(); //save the new metadata // Dispose of any current UserActivitySession, and create a new one. _currentActivity?.Dispose(); _currentActivity = userActivity.CreateSession(); }
public async Task GenerateCharActivityAsync(CharHolder Char) { if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.ApplicationModel.UserActivities.UserActivityChannel")) { return; } UserActivityChannel channel = UserActivityChannel.GetDefault(); var name = Char.MakeName(false); UserActivity userActivity = await channel.GetOrCreateUserActivityAsync(name); userActivity.VisualElements.DisplayText = AppResources.PlayedWith + " " + name.Remove(name.Length - Constants.DATEIENDUNG_CHAR.Length); userActivity.ActivationUri = new Uri(Constants.PROTOCOL_CHAR + Char.FileInfo?.FullName); await userActivity.SaveAsync(); CurrentCharActivity?.Dispose(); ShadowRunHelper.Helper.PlatformHelper.ExecuteOnUIThreadAsync(() => CurrentCharActivity = userActivity.CreateSession()); }
private async Task GenerateActivityAsync() { // Get the default UserActivityChannel and query it for our UserActivity. If the activity doesn't exist, one is created. UserActivityChannel channel = UserActivityChannel.GetDefault(); UserActivity userActivity = await channel.GetOrCreateUserActivityAsync("MainPage"); // Populate required properties userActivity.VisualElements.DisplayText = "ProjectCityAppUWP Activity"; userActivity.VisualElements.Description = "You downloaded a discount PDF!"; userActivity.ActivationUri = new Uri("my-app://MainPage?action=edit"); //Save await userActivity.SaveAsync(); //save the new metadata // Dispose of any current UserActivitySession, and create a new one. _currentActivity?.Dispose(); _currentActivity = userActivity.CreateSession(); }