Exemplo n.º 1
0
        public void GetPathForContentUri(string contentUri, StorageProviderGetPathForContentUriResult result)
        {
            result.Status = StorageProviderUriSourceStatus.FileNotFound;

            const string prefix = "http://cloudmirror.example.com/contentUri/";
            var          uri    = contentUri;

            if (uri.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
            {
                var localPath = ProviderFolderLocations.GetClientFolder() + "\\" + uri[prefix.Length..uri.IndexOf('?')];
Exemplo n.º 2
0
 static void InitDirectoryWatcher()
 {
     // Set up a Directory Watcher on the client side to handle user's changing things there
     try
     {
         s_directoryWatcher.Initalize(ProviderFolderLocations.GetClientFolder(), OnSyncRootFileChanges);
     }
     catch
     {
         Console.Write("Could not init directory watcher.\n");
         throw;
     }
 }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        public static async Task <bool> Start(string serverFolder = "", string clientFolder = "")
        {
            var result = false;

            if (ProviderFolderLocations.Init(serverFolder, clientFolder))
            {
                // Stage 1: Setup
                //--------------------------------------------------------------------------------------------
                // The client folder (syncroot) must be indexed in order for states to properly display
                Utilities.AddFolderToSearchIndexer(ProviderFolderLocations.GetClientFolder());
                // Start up the task that registers and hosts the services for the shell (such as custom states, menus, etc)
                ShellServices.InitAndStartServiceTask();
                // Register the provider with the shell so that the Sync Root shows up in File Explorer
                await CloudProviderRegistrar.RegisterWithShell();

                // Hook up callback methods (in this class) for transferring files between client and server
                ConnectSyncRootTransferCallbacks();
                // Create the placeholders in the client folder so the user sees something
                Placeholders.Create(ProviderFolderLocations.GetServerFolder(), "", ProviderFolderLocations.GetClientFolder());

                // Stage 2: Running
                //--------------------------------------------------------------------------------------------
                // The file watcher loop for this sample will run until the user presses Ctrl-C.
                // The file watcher will look for any changes on the files in the client (syncroot) in order
                // to let the cloud know.
                CloudProviderSyncRootWatcher.WatchAndWait();

                // Stage 3: Done Running-- caused by CTRL-C
                //--------------------------------------------------------------------------------------------
                // Unhook up those callback methods
                DisconnectSyncRootTransferCallbacks();

                // A real sync engine should NOT unregister the sync root upon exit.
                // This is just to demonstrate the use of StorageProviderSyncRootManager.Unregister.
                CloudProviderRegistrar.Unregister();

                // And if we got here, then this was a normally run test versus crash-o-rama
                result = true;
            }

            return(result);
        }
Exemplo n.º 5
0
 static void ConnectSyncRootTransferCallbacks()
 {
     try
     {
         // Connect to the sync root using Cloud File API
         CfConnectSyncRoot(ProviderFolderLocations.GetClientFolder(), s_MirrorCallbackTable, default,