docs.unity3d.com
    Show / Hide Table of Contents

    Class AnnotationRepository

    Represents a local cache of topics for a specific scene. Allows CRUD operations and monitoring.

    Inheritance
    Object
    AnnotationRepository
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Cloud.Annotation
    Syntax
    public class AnnotationRepository : IAnnotationRepository, IDisposable
    Examples
    AnnotationRepository m_AnnotationRepository;
    
    void InitializeRepository(IScene scene)
    {
        // Get and create dependencies for repository creation.
        var serviceHostResolver = UnityRuntimeServiceHostResolverFactory.Create();
        var playerSettings = UnityCloudPlayerSettings.Instance;
        var httpClient = new UnityHttpClient();
    
        var compositeAuthenticatorSettings = new CompositeAuthenticatorSettingsBuilder(httpClient, PlatformSupportFactory.GetAuthenticationPlatformSupport(), serviceHostResolver)
            .AddDefaultBrowserAuthenticatedAccessTokenProvider(playerSettings)
            .AddDefaultPersonalAccessTokenProvider()
            .AddDefaultPkceAuthenticator(playerSettings)
            .Build();
    
        var compositeAuthenticator = new CompositeAuthenticator(compositeAuthenticatorSettings);
    
        var serviceHttpClient = new ServiceHttpClient(httpClient,
        compositeAuthenticator,
        playerSettings);
    
        // Create a new repository for the given scene.
        m_AnnotationRepository = new AnnotationRepository(scene,
            serviceHttpClient,
            serviceHostResolver);
    }
    
    void Shutdown()
    {
        m_AnnotationRepository?.Dispose();
    }

    Constructors

    AnnotationRepository(IAnnotationDataSource)

    Initializes and returns an instance of AnnotationRepository.

    Declaration
    public AnnotationRepository(IAnnotationDataSource annotationDataSource)
    Parameters
    Type Name Description
    IAnnotationDataSource annotationDataSource

    The data source the repository uses to convert source data.

    AnnotationRepository(IScene, IServiceHttpClient, IServiceHostResolver)

    Initializes and returns an instance of AnnotationRepository.

    Declaration
    public AnnotationRepository(IScene scene, IServiceHttpClient serviceHttpClient, IServiceHostResolver serviceHostResolver)
    Parameters
    Type Name Description
    IScene scene

    The scene used to get the annotation from.

    IServiceHttpClient serviceHttpClient

    The IServiceHttpClient used to fetch the data.

    IServiceHostResolver serviceHostResolver

    The service host resolver object.

    Examples
    void ConstructRepository(IScene scene)
    {
        // Get and create dependencies for repository creation.
        var serviceHostResolver = UnityRuntimeServiceHostResolverFactory.Create();
        var playerSettings = UnityCloudPlayerSettings.Instance;
        var httpClient = new UnityHttpClient();
    
        var compositeAuthenticatorSettings = new CompositeAuthenticatorSettingsBuilder(httpClient, PlatformSupportFactory.GetAuthenticationPlatformSupport(), serviceHostResolver)
            .AddDefaultBrowserAuthenticatedAccessTokenProvider(playerSettings)
            .AddDefaultPersonalAccessTokenProvider()
            .AddDefaultPkceAuthenticator(playerSettings)
            .Build();
    
        var compositeAuthenticator = new CompositeAuthenticator(compositeAuthenticatorSettings);
    
        var serviceHttpClient = new ServiceHttpClient(httpClient,
        compositeAuthenticator,
        playerSettings);
    
        // Create a new repository for the given scene.
        m_AnnotationRepository = new AnnotationRepository(scene,
            serviceHttpClient,
            serviceHostResolver);
    }

    Methods

    CreateTopicAsync(ITopicCreation)

    Creates and adds an ITopic to the repository.

    Declaration
    public async Task<ITopic> CreateTopicAsync(ITopicCreation topicCreation)
    Parameters
    Type Name Description
    ITopicCreation topicCreation

    The ITopicCreation object that contains the necessary information to create the new topic.

    Returns
    Type Description
    Task<ITopic>

    A task whose result is the created topic.

    Implements
    IAnnotationRepository.CreateTopicAsync(ITopicCreation)
    Examples
    async Task<ITopic> CreateTopic(string title, string description)
    {
        // Creates and populates a TopicCreation request object.
        var topicCreation = new TopicCreation()
        {
            // Populate all desired fields.
            Title = title,
            Description = description
        };
    
        // Sends the request to the repository and waits for the created topic.
        var createdTopic = await m_AnnotationRepository.CreateTopicAsync(topicCreation);
        return createdTopic;
    }

    DeleteTopicAsync(Guid)

    Removes an ITopic from the repository.

    Declaration
    public async Task DeleteTopicAsync(Guid topicId)
    Parameters
    Type Name Description
    Guid topicId

    The ID of the topic you want to delete.

    Returns
    Type Description
    Task

    A task with no result.

    Implements
    IAnnotationRepository.DeleteTopicAsync(Guid)
    Examples
    async Task DeleteTopic(Guid topicId)
    {
        // Delete a specific topic in the repository.
        await m_AnnotationRepository.DeleteTopicAsync(topicId);
    }

    Dispose()

    Performs tasks related to disposing of associated resources.

    Declaration
    public void Dispose()
    Implements
    IDisposable.Dispose()
    Examples
    void DisposeRepository()
    {
        m_AnnotationRepository?.Dispose();
    }

    Dispose(Boolean)

    Performs tasks related to the disposing of associated resources.

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    Boolean disposing

    Whether to dispose of the cache or not.

    GetTopicAsync(Guid)

    Returns the ITopic for the specific ID from the repository. Returns null if the ITopic does not exist.

    Declaration
    public async Task<ITopic> GetTopicAsync(Guid topicId)
    Parameters
    Type Name Description
    Guid topicId

    The ID of the topic to get.

    Returns
    Type Description
    Task<ITopic>

    A task whose result is the fetched topic.

    Implements
    IAnnotationRepository.GetTopicAsync(Guid)
    Examples
    async Task<ITopic> GetTopic(Guid topicId)
    {
        // Retrieve and return a specific topic by an ID in the repository.
        var topic = await m_AnnotationRepository.GetTopicAsync(topicId);
        return topic;
    }

    GetTopicsAsync()

    Returns the collection of ITopics from the repository.

    Declaration
    public async Task<IEnumerable<ITopic>> GetTopicsAsync()
    Returns
    Type Description
    Task<IEnumerable<ITopic>>

    A task whose result is the collection of fetched topics.

    Implements
    IAnnotationRepository.GetTopicsAsync()
    Examples
    async Task<IEnumerable<ITopic>> GetTopics()
    {
        // Retrieve and return all topics in repository.
        var topics =  await m_AnnotationRepository.GetTopicsAsync();
        return topics;
    }

    UpdateTopicAsync(ITopicUpdate)

    Updates an ITopic in the repository.

    Declaration
    public async Task<ITopic> UpdateTopicAsync(ITopicUpdate topicUpdate)
    Parameters
    Type Name Description
    ITopicUpdate topicUpdate

    The ITopicUpdate object that contains the necessary information to update the topic.

    Returns
    Type Description
    Task<ITopic>

    A task whose result is the updated topic.

    Implements
    IAnnotationRepository.UpdateTopicAsync(ITopicUpdate)
    Examples
    async Task<ITopic> UpdateTopic(ITopic topicToUpdate, string title, string description)
    {
        // Creates and populates a TopicUpdate request object.
        var topicUpdate = new TopicUpdate(topicToUpdate)
        {
            // Populate all fields to update.
            Title = title,
            Description = description
        };
    
        // Sends the request to the repository and waits for the updated topic.
        var updatedTopic = await m_AnnotationRepository.UpdateTopicAsync(topicUpdate);
        return updatedTopic;
    }

    Events

    TopicCreated

    Calls the methods in its invocation list when you create an ITopic in the repository.

    Declaration
    public event Action<ITopic> TopicCreated
    Event Type
    Type Description
    Action<ITopic>
    Implements
    IAnnotationRepository.TopicCreated

    TopicRemoved

    Calls the methods in its invocation list when you remove an ITopic in the repository.

    Declaration
    public event Action<ITopic> TopicRemoved
    Event Type
    Type Description
    Action<ITopic>
    Implements
    IAnnotationRepository.TopicRemoved

    TopicUpdated

    Calls the methods in its invocation list when you update an ITopic in the repository.

    Declaration
    public event Action<ITopic> TopicUpdated
    Event Type
    Type Description
    Action<ITopic>
    Implements
    IAnnotationRepository.TopicUpdated
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023