IStorageProviderKnownFolderSyncInfoSource 介面

定義

雲端提供者實作的介面,以提供已知資料夾同步處理狀態的相關資訊。

public interface class IStorageProviderKnownFolderSyncInfoSource
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Storage.Provider.CloudFilesContract, 458752)]
/// [Windows.Foundation.Metadata.Guid(1362465602, 63424, 21456, 187, 182, 28, 220, 9, 142, 189, 169)]
struct IStorageProviderKnownFolderSyncInfoSource
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Storage.Provider.CloudFilesContract), 458752)]
[Windows.Foundation.Metadata.Guid(1362465602, 63424, 21456, 187, 182, 28, 220, 9, 142, 189, 169)]
public interface IStorageProviderKnownFolderSyncInfoSource
Public Interface IStorageProviderKnownFolderSyncInfoSource
屬性

Windows 需求

裝置系列
Windows 11 Insider Preview (已於 10.0.23504.0 引進)
API contract
Windows.Storage.Provider.CloudFilesContract (已於 v7.0 引進)

範例

下列範例示範儲存體提供者的 IStorageProviderKnownFolderSyncInfoSource 實作:

namespace winrt::CloudMirror::implementation
{
    struct MyKnownFolderInfoSource : implements<MyKnownFolderInfoSource,
            winrt::CloudMirror::IStorageProviderKnownFolderSyncInfoSource>
    {
        MyKnownFolderInfoSource();

        StorageProviderKnownFolderSyncInfo GetKnownFolderSyncInfo();

        winrt::event_token KnownFolderSyncInfoChanged(
            winrt::Windows::Foundation::TypedEventHandler<IStorageProviderKnownFolderSyncInfoSource,
            winrt::Windows::Foundation::IInspectable> const& handler);
        void KnownFolderSyncInfoChanged(winrt::event_token const& token) noexcept;

    private:
        winrt::hstring GetProviderDisplayName();
        winrt::Uri GetAvailableIcon();
        winrt::Uri GetEnrollingIcon();
        void NotifyStateChanged();

    winrt::event<winrt::TypedEventHandler<IStorageProviderKnownFolderSyncInfoSource, IInspectable>> m_changedEvent;
        std::vector<StorageProviderKnownFolderEntry> m_knownFolderEntries;
    };
}

...

using namespace winrt::Windows::Storage::Provider;

namespace winrt::CloudMirror::implementation
{
    MyKnownFolderInfoSource::MyKnownFolderInfoSource()
    {
        // The cloud provider would assess its current state and use it to
        // inform File Explorer. In this example, Documents is available for
        // backup, Pictures is currently enrolling, and Downloads is already
        // backed up (enrolled).
        winrt::StorageProviderKnownFolderEntry documents{};
        documents.KnownFolderId(FOLDERID_Documents);
        documents.Status(StorageProviderKnownFolderSyncStatus::Available);
        m_knownFolderState.push_back(documents);

        winrt::StorageProviderKnownFolderEntry pictures{};
        pictures.KnownFolderId(FOLDERID_Pictures);
        pictures.Status(StorageProviderKnownFolderSyncStatus::Enrolling);
        m_knownFolderState.push_back(pictures);

        winrt::StorageProviderKnownFolderEntry downloads{};
        downloads.KnownFolderId(FOLDERID_Downloads);
        downloads.Status(StorageProviderKnownFolderSyncStatus::Enrolled);
        m_knownFolderState.push_back(downloads);
    }

    // GetKnownFolderSyncInfo is called by File Explorer whenever it needs to get the
    // latest known folder sync status from the cloud provider. Once returned, the
    // StorageProviderKnownFolderSyncInfo is considered immutable.
    //
    // A SyncRequested handler must be set on the returned object to be considered valid
    // and to be displayed in File Explorer.
    StorageProviderKnownFolderSyncInfo MyKnownFolderInfoSource::GetKnownFolderSyncInfo()
    {
        winrt::StorageProviderKnownFolderSyncInfo info{};
        info.ProviderDisplayName(GetProviderDisplayName());
        // Setting a SyncRequested handler to respond to user action.
        auto syncRequestHandler = [](
            winrt::CloudMirror::StorageProviderKnownFolderSyncRequestArgs const& args)
        {
            // The user wants to sync some known folders with our cloud provider.
            // We can show some UI to sign in, confirm their choice, etc.
            MyStorageProviderSyncManager::ShowFolderEnrollmentUI(args.KnownFolders(), args.Source());

            // Or we can immediately start syncing the requested folders.
            MyStorageProviderSyncManager::StartSyncingFolders(args.KnownFolders(), args.Source());
        };

        info.SyncRequested(syncRequestHandler);
        info.KnownFolderEntries().ReplaceAll(m_knownFolderEntries);
        return info;
    }
}

備註

檔案總管呼叫GetKnownFolderSyncInfoSource,以取得指定提供者的IStorageProviderKnownFolderSyncInfoSource實例。

此介面會提供 KnownFolderSyncInfoChanged 事件,應用程式會在任何屬性或資料夾狀態變更時引發,包括顯示名稱。 雲端提供者不應該預期在引發事件之後立即呼叫 GetKnownFolderSyncInfoSource 。 檔案總管只會視需要要求新的 物件。

方法

GetKnownFolderSyncInfo()

每當需要從雲端提供者取得最新的已知資料夾同步狀態時,就會呼叫GetKnownFolderSyncInfo檔案總管。

事件

KnownFolderSyncInfoChanged

已知資料夾的同步處理狀態變更時所引發的事件。

適用於

另請參閱