public async Task <AppContent> CreateNewAsync(string title) { CheckInitialized(); var item = new AppContent { Id = Guid.NewGuid().ToString(), Title = title }; Items.Add(item); await CreateActivityAsync(item); await SaveItemsAsync(); return(item.Clone()); }
public static AdaptiveCard ToAdaptiveCard(this AppContent self) => new AdaptiveCard { Version = "1.0", Body = { new AdaptiveColumnSet { Columns = { new AdaptiveColumn { Width = "auto", Items = { new AdaptiveImage { Url = new Uri("https://user-images.githubusercontent.com/79868/40269931-ed9022be-5bbf-11e8-83b9-e8cba533e405.jpg"), Style = AdaptiveImageStyle.Person, Size = AdaptiveImageSize.Small, } } }, new AdaptiveColumn { Width = "stretch", Items = { new AdaptiveTextBlock { Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Large, Wrap = false, MaxLines = 1, Text = self.Title ?? "", }, } } } }, new AdaptiveTextBlock { Weight = AdaptiveTextWeight.Default, Size = AdaptiveTextSize.Default, Wrap = true, MaxLines = 3, Text = self.Content ?? "", } } };
protected override async void OnNavigatedTo(NavigationEventArgs e) { void backToMainPage() { var ignore = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { if (Frame.CanGoBack) { Frame.GoBack(); } else { Frame.Navigate(typeof(MainPage)); } }); } base.OnNavigatedTo(e); if (DocumentManager.Account == null) { await DocumentManager.LoadAccountAsync(); if (DocumentManager.Account != null) { await DocumentManager.LoadItemsAsync(); } if (DocumentManager.Account == null || DocumentManager.Items == null) { backToMainPage(); return; } } var id = e.Parameter as string; AppContent = await DocumentManager.GetItemByIdAsync(id); if (AppContent == null) { backToMainPage(); return; } }
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(); Debug.WriteLine(card.ToJson()); activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(card.ToJson()); activity.VisualElements.DisplayText = target.Title; await activity.SaveAsync(); _currentActivity?.Dispose(); _currentActivity = activity.CreateSession(); }
public async Task AddOrUpdateDocumentAsync(AppContent appContent) { CheckInitialized(); var target = Items.FirstOrDefault(x => x.Id == appContent.Id); if (target != null) { target.Title = appContent.Title; target.Content = appContent.Content; } else { target = appContent; target.Id = Guid.NewGuid().ToString(); } await CreateActivityAsync(target); await SaveItemsAsync(); }