/// <summary> /// Registers sync root. /// </summary> /// <param name="syncRootId">ID of the sync root.</param> /// <param name="path">A root folder of your user file system. Your file system tree will be located under this folder.</param> /// <param name="displayName">Human readable display name.</param> /// <param name="iconPath">Path to the drive ico file.</param> /// <remarks>Call this method during application installation.</remarks> public static async Task RegisterAsync(string syncRootId, string path, string displayName, string iconPath) { StorageProviderSyncRootInfo storageInfo = new StorageProviderSyncRootInfo(); storageInfo.Path = await StorageFolder.GetFolderFromPathAsync(path); storageInfo.Id = syncRootId; storageInfo.DisplayNameResource = displayName; storageInfo.IconResource = iconPath; storageInfo.Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); storageInfo.RecycleBinUri = new Uri("https://userfilesystem.com/recyclebin"); storageInfo.Context = CryptographicBuffer.ConvertStringToBinary(path, BinaryStringEncoding.Utf8); storageInfo.HydrationPolicy = StorageProviderHydrationPolicy.Progressive; storageInfo.HydrationPolicyModifier = StorageProviderHydrationPolicyModifier.AutoDehydrationAllowed; //| StorageProviderHydrationPolicyModifier.ValidationRequired; // To implement folders on-demand placeholders population set the // StorageProviderSyncRootInfo.PopulationPolicy to StorageProviderPopulationPolicy.Full. storageInfo.PopulationPolicy = StorageProviderPopulationPolicy.Full; // Set to Full to list folder content immediately on program start. // The read-only attribute is used to indicate that the item is being locked by another user. Do NOT include it into InSyncPolicy. storageInfo.InSyncPolicy = //StorageProviderInSyncPolicy.FileCreationTime | StorageProviderInSyncPolicy.DirectoryCreationTime | //StorageProviderInSyncPolicy.FileLastWriteTime | StorageProviderInSyncPolicy.DirectoryLastWriteTime | //StorageProviderInSyncPolicy.FileHiddenAttribute | StorageProviderInSyncPolicy.DirectoryHiddenAttribute | //StorageProviderInSyncPolicy.FileSystemAttribute | StorageProviderInSyncPolicy.DirectorySystemAttribute | //StorageProviderInSyncPolicy.FileReadOnlyAttribute | StorageProviderInSyncPolicy.DirectoryReadOnlyAttribute | StorageProviderInSyncPolicy.Default; //storageInfo.ShowSiblingsAsGroup = false; //storageInfo.HardlinkPolicy = StorageProviderHardlinkPolicy.None; // Adds columns to Windows File Manager. // Show/hide columns in the "More..." context menu on the columns header. var proDefinitions = storageInfo.StorageProviderItemPropertyDefinitions; proDefinitions.Add(new StorageProviderItemPropertyDefinition { DisplayNameResource = "Lock Owner", Id = (int)CustomColumnIds.LockOwnerIcon }); proDefinitions.Add(new StorageProviderItemPropertyDefinition { DisplayNameResource = "Lock Scope", Id = (int)CustomColumnIds.LockScope }); proDefinitions.Add(new StorageProviderItemPropertyDefinition { DisplayNameResource = "Lock Expires", Id = (int)CustomColumnIds.LockExpirationDate }); proDefinitions.Add(new StorageProviderItemPropertyDefinition { DisplayNameResource = "ETag", Id = (int)CustomColumnIds.ETag }); ValidateStorageProviderSyncRootInfo(storageInfo); StorageProviderSyncRootManager.Register(storageInfo); }
public async void Register() { string folderRoot = GetRootPath(); if (!Directory.Exists(folderRoot)) { Directory.CreateDirectory(folderRoot); } StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(folderRoot); StorageProviderSyncRootInfo info = new StorageProviderSyncRootInfo(); info.Id = syncRootId; info.Path = folder; info.DisplayNameResource = ProviderName; info.AllowPinning = true; info.IconResource = "%SystemRoot%\\system32\\charmap.exe,0"; info.HydrationPolicy = StorageProviderHydrationPolicy.Progressive; info.HydrationPolicyModifier = StorageProviderHydrationPolicyModifier.StreamingAllowed; info.PopulationPolicy = StorageProviderPopulationPolicy.AlwaysFull; info.InSyncPolicy = StorageProviderInSyncPolicy.FileCreationTime | StorageProviderInSyncPolicy.DirectoryCreationTime; info.Version = "1.0.0"; info.ShowSiblingsAsGroup = false; info.HardlinkPolicy = StorageProviderHardlinkPolicy.None; info.Context = CryptographicBuffer.ConvertStringToBinary(folderRoot, BinaryStringEncoding.Utf8); var customStates = info.StorageProviderItemPropertyDefinitions; customStates.Add(new StorageProviderItemPropertyDefinition() { Id = 1, DisplayNameResource = "CustomStateName1" }); customStates.Add(new StorageProviderItemPropertyDefinition() { Id = 2, DisplayNameResource = "CustomStateName2" }); customStates.Add(new StorageProviderItemPropertyDefinition() { Id = 3, DisplayNameResource = "CustomStateName3" }); StorageProviderSyncRootManager.Register(info); System.Threading.Thread.Sleep(1000); }
/// <summary> /// Ensures that minimum required properties for <see cref="StorageProviderSyncRootInfo"/> are set. /// </summary> private static void ValidateStorageProviderSyncRootInfo(StorageProviderSyncRootInfo info) { if (info == null) { throw new ArgumentNullException("info"); } string message = "Property not set."; // DisplayNameResource is required. if (string.IsNullOrEmpty(info.Id)) { throw new ArgumentException(message, "StorageProviderSyncRootInfo.Id"); } // Version is required. Otherwise StorageProviderSyncRootManager.Register() call hangs. if (string.IsNullOrEmpty(info.Version)) { throw new ArgumentException(message, "StorageProviderSyncRootInfo.Version"); } // DisplayNameResource is required. if (string.IsNullOrEmpty(info.DisplayNameResource)) { throw new ArgumentException(message, "StorageProviderSyncRootInfo.DisplayNameResource"); } // IconResource is required. if (string.IsNullOrEmpty(info.IconResource)) { throw new ArgumentException(message, "StorageProviderSyncRootInfo.IconResource"); } // RecycleBinUri is required. if (info.RecycleBinUri == null) { throw new ArgumentException(message, "StorageProviderSyncRootInfo.RecycleBinUri"); } // Context is required. if (info.Context == null) { throw new ArgumentException(message, "StorageProviderSyncRootInfo.Context"); } }
/// <summary> /// Registers sync root. /// </summary> /// <param name="syncRootId">ID of the sync root.</param> /// <param name="path">A root folder of your user file system. Your file system tree will be located under this folder.</param> /// <param name="displayName">Human readable display name.</param> /// <remarks>Call this method during application installation.</remarks> public static async Task RegisterAsync(string syncRootId, string path, string displayName) { StorageProviderSyncRootInfo storageInfo = new StorageProviderSyncRootInfo(); storageInfo.Path = await StorageFolder.GetFolderFromPathAsync(path); storageInfo.Id = syncRootId; storageInfo.DisplayNameResource = displayName; storageInfo.IconResource = "%SystemRoot%\\system32\\charmap.exe,0"; storageInfo.Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); storageInfo.RecycleBinUri = new Uri("https://userfilesystem.com/recyclebin"); storageInfo.Context = CryptographicBuffer.ConvertStringToBinary(path, BinaryStringEncoding.Utf8); storageInfo.HydrationPolicy = StorageProviderHydrationPolicy.Progressive; storageInfo.HydrationPolicyModifier = StorageProviderHydrationPolicyModifier.AutoDehydrationAllowed | StorageProviderHydrationPolicyModifier.ValidationRequired; // To implement folders on-demand placeholders population set the StorageProviderSyncRootInfo.PopulationPolicy to StorageProviderPopulationPolicy.Full. storageInfo.PopulationPolicy = StorageProviderPopulationPolicy.Full; // Set to Full to list folder content immediately on program start. storageInfo.InSyncPolicy = StorageProviderInSyncPolicy.FileLastWriteTime | StorageProviderInSyncPolicy.FileCreationTime | StorageProviderInSyncPolicy.FileHiddenAttribute | StorageProviderInSyncPolicy.FileReadOnlyAttribute | StorageProviderInSyncPolicy.FileSystemAttribute | StorageProviderInSyncPolicy.DirectoryLastWriteTime | StorageProviderInSyncPolicy.DirectoryCreationTime | StorageProviderInSyncPolicy.DirectoryHiddenAttribute | StorageProviderInSyncPolicy.DirectoryReadOnlyAttribute | StorageProviderInSyncPolicy.DirectorySystemAttribute; //storageInfo.ShowSiblingsAsGroup = false; //storageInfo.HardlinkPolicy = StorageProviderHardlinkPolicy.None; /* * var proDefinitions = storageInfo.StorageProviderItemPropertyDefinitions; * proDefinitions.Add(new StorageProviderItemPropertyDefinition { DisplayNameResource = "Test0", Id = 0, }); * proDefinitions.Add(new StorageProviderItemPropertyDefinition { DisplayNameResource = "Test1", Id = 1, }); * proDefinitions.Add(new StorageProviderItemPropertyDefinition { DisplayNameResource = "Test2", Id = 2, }); */ ValidateStorageProviderSyncRootInfo(storageInfo); StorageProviderSyncRootManager.Register(storageInfo); }
public static async Task RegisterWithShell() { try { var info = new StorageProviderSyncRootInfo(); info.Id = GetSyncRootId(); info.Path = await StorageFolder.GetFolderFromPathAsync(ProviderFolderLocations.GetClientFolder()); info.DisplayNameResource = "TestStorageProviderDisplayName"; // This icon is just for the sample. You should provide your own branded icon here info.IconResource = "%SystemRoot%\\system32\\charmap.exe,0"; info.HydrationPolicy = StorageProviderHydrationPolicy.Full; info.HydrationPolicyModifier = StorageProviderHydrationPolicyModifier.None; info.PopulationPolicy = StorageProviderPopulationPolicy.AlwaysFull; info.InSyncPolicy = StorageProviderInSyncPolicy.FileCreationTime | StorageProviderInSyncPolicy.DirectoryCreationTime; info.Version = "1.0.0"; info.ShowSiblingsAsGroup = false; info.HardlinkPolicy = StorageProviderHardlinkPolicy.None; info.RecycleBinUri = new Uri("http://cloudmirror.example.com/recyclebin"); // Context var syncRootIdentity = ProviderFolderLocations.GetServerFolder() + "->" + ProviderFolderLocations.GetClientFolder(); //var contextString = "TestProviderContextString"; var contextBuffer = CryptographicBuffer.ConvertStringToBinary(syncRootIdentity, BinaryStringEncoding.Utf8); info.Context = contextBuffer; var customStates = info.StorageProviderItemPropertyDefinitions; AddCustomState(customStates, "CustomStateName1", 1); AddCustomState(customStates, "CustomStateName2", 2); AddCustomState(customStates, "CustomStateName3", 3); StorageProviderSyncRootManager.Register(info); // Give the cache some time to invalidate Sleep(1000); } catch (Exception ex) { // to_hresult() will eat the exception if it is a result of check_hresult, otherwise the exception will get rethrown and // this method will crash out as it should Console.Write("Could not register the sync root, hr {0:X8}\n", ex.HResult); throw; } }