/// <inheritdoc/>
 protected override Style SelectStyleCore(object item, DependencyObject container)
 {
     return(item switch
     {
         CodeLibraryEntry _ => DefaultContainerStyle,
         CodeLibrarySection _ => PlaceholderContainerStyle,
         _ => ThrowHelper.ThrowArgumentNullException <Style>(nameof(item), "The input item can't be null")
     });
Ejemplo n.º 2
0
        public async Task LogOrUpdateActivityAsync(IFile file)
        {
            using (await TimelineMutex.LockAsync())
            {
                // Load the template, if needed
                if (_Template is null)
                {
                    StorageFile templateFile = await StorageFile.GetFileFromApplicationUriAsync(TemplateUri);

                    _Template = await FileIO.ReadTextAsync(templateFile);
                }

                // Get a unique id for the file
                uint numericId = (uint)HashCode <char> .Combine(file.Path.AsSpan());

                string
                    textId     = numericId.ToString(),
                    preview    = await CodeLibraryEntry.LoadCodePreviewAsync(file),
                    background = BackgroundImages[(int)(numericId % BackgroundImages.Count)];

                // Create the model to represent the current activity
                AdaptiveCard model = new AdaptiveCard(file.DisplayName, preview, background);

                // Render the adaptive card
                string adaptiveCard = await StaticStubbleRenderer.Instance.RenderAsync(_Template, model);

                // Get the default channel and create the activity
                UserActivity activity = await UserActivityChannel.GetDefault().GetOrCreateUserActivityAsync(textId);

                // Set the deep-link and the title
                activity.ActivationUri = new Uri($"brainf-ck:///file?path={file.Path}");
                activity.VisualElements.DisplayText = file.DisplayName;
                activity.VisualElements.Content     = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(adaptiveCard);
                activity.IsRoamable = false;

                // Save to activity feed.
                await activity.SaveAsync();

                // Update the activity currently in use
                _Session?.Dispose();
                _Session = activity.CreateSession();
            }
        }
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            Guard.IsNotNull(item, nameof(item));

            DataTemplate?template = item switch
            {
                CodeLibraryEntry entry when entry.File.IsReadOnly => SampleTemplate,
                CodeLibraryEntry _ => RecentItemTemplate,
                        CodeLibrarySection.Favorites => FavoritePlaceholderTemplate,
                        CodeLibrarySection.Recent => RecentPlaceholderTemplate,
                        _ => ThrowHelper.ThrowArgumentException <DataTemplate>("Invalid item type")
            };

            if (template is null)
            {
                ThrowHelper.ThrowInvalidOperationException("The requested template is null");
            }

            return(template);
        }
    }