Bagikan melalui


IStorageProviderKnownFolderSyncInfoSource Antarmuka

Definisi

Antarmuka yang diterapkan penyedia cloud untuk memberikan informasi tentang status sinkronisasi folder yang diketahui.

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
Atribut

Persyaratan Windows

Rangkaian perangkat
Windows 11 Insider Preview (diperkenalkan dalam 10.0.23504.0)
API contract
Windows.Storage.Provider.CloudFilesContract (diperkenalkan dalam v7.0)

Contoh

Contoh berikut menunjukkan implementasi penyedia penyimpanan 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;
    }
}

Keterangan

File Explorer mendapatkan instans IStorageProviderKnownFolderSyncInfoSource untuk penyedia tertentu dengan memanggil GetKnownFolderSyncInfoSource.

Antarmuka ini menyediakan peristiwa KnownFolderSyncInfoChanged , yang dinaikkan aplikasi saat status properti atau folder berubah, termasuk nama tampilan. Penyedia cloud seharusnya tidak mengharapkan GetKnownFolderSyncInfoSource dipanggil segera setelah menaikkan peristiwa. File Explorer hanya akan meminta objek baru sesuai kebutuhan.

Metode

GetKnownFolderSyncInfo()

GetKnownFolderSyncInfo dipanggil oleh File Explorer setiap kali perlu mendapatkan status sinkronisasi folder terbaru yang diketahui dari penyedia cloud.

Acara

KnownFolderSyncInfoChanged

Peristiwa yang dinaikkan saat status sinkronisasi folder yang diketahui berubah.

Berlaku untuk

Lihat juga