示例#1
0
        /// <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);
        }
示例#2
0
 public static void Unregister()
 {
     try
     {
         StorageProviderSyncRootManager.Unregister(GetSyncRootId());
     }
     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 unregister the sync root, hr {0:X8}\n", ex.HResult);
     }
 }
示例#3
0
        /// <summary>
        /// Determins if the syn root is registered for specified folder.
        /// </summary>
        /// <param name="path"></param>
        /// <returns>True if the sync root is registered, false otherwise.</returns>
        public static async Task <bool> IsRegisteredAsync(string path)
        {
            StorageFolder storageFolder = await StorageFolder.GetFolderFromPathAsync(path);

            try
            {
                StorageProviderSyncRootManager.GetSyncRootInformationForFolder(storageFolder);
                return(true);
            }
            catch
            {
            }

            return(false);
        }
示例#4
0
        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);
        }
示例#5
0
        /// <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);
        }
示例#6
0
        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;
            }
        }
示例#7
0
        /// <summary>
        /// Unregisters sync root.
        /// </summary>
        /// <param name="syncRootId">ID of the sync root.</param>
        /// <remarks>
        /// Call this method during application ununstall.
        /// All file and folder placeholders are converted into regular files/folders during this call.
        /// </remarks>
        public static async Task UnregisterAsync(string syncRootId)
        {
            StorageProviderSyncRootManager.Unregister(syncRootId);

            Directory.Delete(Program.Settings.ServerDataFolderPath, true);
        }
示例#8
0
 /// <summary>
 /// Unregisters sync root.
 /// </summary>
 /// <param name="syncRootId">ID of the sync root.</param>
 /// <remarks>
 /// Call this method during application ununstall.
 /// All file and folder placeholders are converted into regular files/folders during this call.
 /// </remarks>
 public static async Task UnregisterAsync(string syncRootId)
 {
     StorageProviderSyncRootManager.Unregister(syncRootId);
 }
示例#9
0
 public void Unregister()
 {
     StorageProviderSyncRootManager.Unregister(syncRootId);
 }
示例#10
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     bool result = StorageProviderSyncRootManager.IsSupported();
 }