IStorageProviderKnownFolderSyncInfoSource 接口
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
云提供商实现的接口,用于提供有关已知文件夹的同步状态的信息。
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 |
已知文件夹的同步状态更改时引发的事件。 |