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

既知のフォルダーの同期状態が変更されたときに発生するイベント。

適用対象

こちらもご覧ください