コード例 #1
0
        public static bool Start(string serverFolder = "", string clientFolder = "")
        {
            var result = false;

            if (ProviderFolderLocations.Init(serverFolder, clientFolder))
            {
                try
                {
                    // Stage 1: Setup
                    //--------------------------------------------------------------------------------------------
                    // The client folder (syncroot) must be indexed in order for states to properly display
                    Utilities.AddFolderToSearchIndexer(ProviderFolderLocations.ClientFolder);
                    // 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
                    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.ServerFolder, "", ProviderFolderLocations.ClientFolder);

                    // 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();

                    // And if we got here, then this was a normally run test versus crash-o-rama
                    result = true;
                }
                finally
                {
                    // 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();
                }
            }

            return(result);
        }
コード例 #2
0
        static int Main(string[] args)
        {
            Console.Write("Press ctrl-C to stop gracefully\n");
            Console.Write("-------------------------------\n");

            var returnCode = 0;

            try
            {
                if (FakeCloudProvider.Start(args.Length > 0 ? args[0] : null, args.Length > 1 ? args[1] : null).Result)
                {
                    returnCode = 1;
                }
            }
            catch
            {
                CloudProviderSyncRootWatcher.Stop(0);                 // Param is unused
            }

            return(returnCode);
        }