Exemplo n.º 1
0
 private void SetButtonStates()
 {
     _useUSBButton.Enabled = new CloneFromUsb().GetHaveOneOrMoreUsbDrives();
     _useInternetButton.Enabled = NetworkInterface.GetIsNetworkAvailable();
     var client = new ChorusHubClient();
     var server = client.FindServer();
     _useChorusHubButton.Enabled = ((server != null) && (server.ServerIsCompatibleWithThisClient));
 }
Exemplo n.º 2
0
 public void GetRepostoryNames_EmptyHubFolder_EmptyList()
 {
     using (var testRoot = new TemporaryFolder("ChorusHubCloneTest"))
     using (var chorusHubSourceFolder = new TemporaryFolder(testRoot, "ChorusHub"))
        {
         var client = new ChorusHubClient();
         Assert.IsNull(client.FindServer());
         //normally we shouldn't call this if none was found
         Assert.Throws<ApplicationException>(()=>
             {
                 Assert.AreEqual(0, client.GetRepositoryInformation(string.Empty).Count());
             });
     }
 }
Exemplo n.º 3
0
        void OnChorusHubInfo_DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.CurrentThread.Name = "GetRepositoryInformation";
            var client = new ChorusHubClient();
            var server = client.FindServer();

            if (server == null || !server.ServerIsCompatibleWithThisClient)
            {
                e.Result = null;
            }
            else
            {
                var results = new object[2];
                results[0] = client;
                results[1] = client.GetRepositoryInformation(_model.ProjectFilter);
                e.Result = results;
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var parameters = new ChorusHubParameters();
            if(Parser.ParseHelp(args))
            {
                MessageBox.Show(Parser.ArgumentsUsage(parameters.GetType()),"Chorus Hub Command Line Parameters");
                return;
            }
            if (!Parser.ParseArguments(args, parameters, ShowCommandLineError))
            {
                return;
            }

            string parentOfRoot = Path.GetDirectoryName(parameters.RootDirectory);
            if(!Path.IsPathRooted(parameters.RootDirectory))
            {
                ErrorReport.NotifyUserOfProblem("You supplied '{0}' for the root directory, but that doesn't have a drive letter.",
                                                                    parameters.RootDirectory);
                return;
            }
            if(!Directory.Exists(parentOfRoot))
            {
                ErrorReport.NotifyUserOfProblem("In order to use '{0}', '{1}' must already exist",
                                                                    parameters.RootDirectory, parentOfRoot);
                return;
            }
            var server = new ChorusHubClient().FindServer();
            if (server != null)
            {
                ErrorReport.NotifyUserOfProblem("Only one ChorusHub can be run on a network but there is already one running on {0}",
                                                server.HostName);
                return;
            }

            SetupErrorHandling(parameters);
            SetUpReporting();

            Application.Run(mainForm: new ChorusHubWindow(parameters));
        }
Exemplo n.º 5
0
        public void MakeClone(IProgress progress)
        {
            var client = new ChorusHubClient();
            var server = client.FindServer();
            if (server == null)
            {
                progress.WriteError("The Chorus Server is not available.");
                CloneSucceeded = false;
                return;
            }
            if (!server.ServerIsCompatibleWithThisClient)
            {
                progress.WriteError("The Chorus Server is not compatible with ths client.");
                CloneSucceeded = false;
                return;
            }

            var targetFolder = Path.Combine(_baseFolder, RepositoryName);
            try
            {
                NewlyClonedFolder= HgRepository.Clone(new HttpRepositoryPath(RepositoryName, client.GetUrl(RepositoryName), false), targetFolder, progress);
                CloneSucceeded = true;
            }
            catch (Exception)
            {
                NewlyClonedFolder = null;
                CloneSucceeded = false;
                throw;
            }
        }
Exemplo n.º 6
0
        public void GetRepostoryNames_TwoItemsInHubFolder_GetNoneForProjectFilter()
        {
            // only accept folders containing a file with the name "randomName.ext1"
            // but there aren't any.
            const string queryString = "filePattern=*.ext1";

            using (var testRoot = new TemporaryFolder("ChorusHubCloneTest"))
            using (var chorusHubSourceFolder = new TemporaryFolder(testRoot, "ChorusHub"))
            using (var repo1 = new TemporaryFolder(chorusHubSourceFolder, "repo1"))
            using (var tempFile1 = TempFile.WithExtension("other"))
            using (var repo2 = new TemporaryFolder(chorusHubSourceFolder, "repo2"))
            using (var tempFile2 = TempFile.WithExtension("unwanted"))
            {
                tempFile1.MoveTo(Path.Combine(repo1.Path, Path.GetFileName(tempFile1.Path)));
                using (var writer = new StreamWriter(tempFile1.Path))
                    writer.Write("Some random text.");
                // Does it work if the file is empty?
                tempFile2.MoveTo(Path.Combine(repo2.Path, Path.GetFileName(tempFile2.Path)));
                RepositorySetup.MakeRepositoryForTest(repo1.Path, "bob", new ConsoleProgress());
                RepositorySetup.MakeRepositoryForTest(repo2.Path, "bob", new ConsoleProgress());
                var r1 = HgRepository.CreateOrUseExisting(repo1.Path, new ConsoleProgress());
                r1.AddAndCheckinFile(tempFile1.Path); // need this to create store/data/files
                var r2 = HgRepository.CreateOrUseExisting(repo2.Path, new ConsoleProgress());
                r2.AddAndCheckinFile(tempFile2.Path); // need this to create store/data/files
                using (var service = new ChorusHubService(new ChorusHubParameters() { RootDirectory = chorusHubSourceFolder.Path }))
                {
                    service.Start(true);

                    // Make sure filter works
                    var client = new ChorusHubClient();
                    Assert.NotNull(client.FindServer());
                    var repositoryInfo = client.GetRepositoryInformation(queryString);
                    Assert.AreEqual(0, repositoryInfo.Count());
                }
            }
        }
Exemplo n.º 7
0
 public void FindServer_NoServerFound_Null()
 {
     var client = new ChorusHubClient();
     Assert.IsNull(client.FindServer());
 }
Exemplo n.º 8
0
        public void GetRepostoryNames_TwoItemsInHubFolder_GetTwoItems()
        {
            using (var testRoot = new TemporaryFolder("ChorusHubCloneTest"))
            using (var chorusHubSourceFolder = new TemporaryFolder(testRoot, "ChorusHub"))
            using (var repo1 = new TemporaryFolder(chorusHubSourceFolder, "repo1"))
            using (var tempFile1 = TempFile.WithExtension("ext1"))
            using (var repo2 = new TemporaryFolder(chorusHubSourceFolder, "repo2"))
            using (var tempFile2 = TempFile.WithExtension("ext2"))
            {
                tempFile1.MoveTo(Path.Combine(repo1.Path, Path.GetFileName(tempFile1.Path)));
                tempFile2.MoveTo(Path.Combine(repo2.Path, Path.GetFileName(tempFile2.Path)));
                RepositorySetup.MakeRepositoryForTest(repo1.Path, "bob", new ConsoleProgress());
                RepositorySetup.MakeRepositoryForTest(repo2.Path, "bob", new ConsoleProgress());

                var r1 = HgRepository.CreateOrUseExisting(repo1.Path, new ConsoleProgress());
                r1.AddAndCheckinFile(tempFile1.Path); // need this to create store/data/files
                var r2 = HgRepository.CreateOrUseExisting(repo2.Path, new ConsoleProgress());
                r2.AddAndCheckinFile(tempFile2.Path); // need this to create store/data/files

                using (var service = new ChorusHubService(new ChorusHubParameters() { RootDirectory = chorusHubSourceFolder.Path }))
                {
                    // hg server side is now involved in deciding what repos are available
                    service.Start(true);
                    var client = new ChorusHubClient();
                    Assert.NotNull(client.FindServer());
                    var repoInfo = client.GetRepositoryInformation(string.Empty);
                    Assert.AreEqual(2, repoInfo.Count());
                    var info1 = repoInfo.First();
                    var info2 = repoInfo.Last();
                    Assert.IsTrue(info1.RepoName == "repo1");
                    Assert.IsTrue(info2.RepoName == "repo2");
                }
            }
        }
Exemplo n.º 9
0
        public void GetRepostoryNames_TwoItemsInHubFolder_GetOneItemWithProjectFilter()
        {
            // only accept folders containing a file with the name "randomName.someExt"
            const string queryString = "filePattern=*.someExt";

            using (var testRoot = new TemporaryFolder("ChorusHubCloneTest"))
            using (var chorusHubSourceFolder = new TemporaryFolder(testRoot, "ChorusHub"))
            using (var repo1 = new TemporaryFolder(chorusHubSourceFolder, "repo1"))
            using (var tempFile = TempFile.WithExtension("someExt"))
            using (var repo2 = new TemporaryFolder(chorusHubSourceFolder, "repo2"))
            using (var tempFile2 = TempFile.WithExtension("someOtherExt"))
            {
                tempFile.MoveTo(Path.Combine(repo1.Path, Path.GetFileName(tempFile.Path)));
                using (var writer = new StreamWriter(tempFile.Path))
                    writer.Write("Some random text.");
                tempFile2.MoveTo(Path.Combine(repo2.Path, Path.GetFileName(tempFile2.Path)));

                RepositorySetup.MakeRepositoryForTest(repo1.Path, "bob", new ConsoleProgress());
                RepositorySetup.MakeRepositoryForTest(repo2.Path, "bob", new ConsoleProgress());

                var r1 = HgRepository.CreateOrUseExisting(repo1.Path, new ConsoleProgress());
                r1.AddAndCheckinFile(tempFile.Path); // need this to create store/data/files
                var r2 = HgRepository.CreateOrUseExisting(repo2.Path, new ConsoleProgress());
                r2.AddAndCheckinFile(tempFile2.Path); // need this to create store/data/files

                using (var service = new ChorusHubService(new ChorusHubParameters() { RootDirectory = chorusHubSourceFolder.Path }))
                {
                    service.Start(true);

                    // Make sure all repos are there first
                    var client1 = new ChorusHubClient();
                    Assert.NotNull(client1.FindServer());
                    var allRepoInfo = client1.GetRepositoryInformation(string.Empty);
                    Assert.AreEqual(2, allRepoInfo.Count());
                    Assert.IsTrue(allRepoInfo.Select(ri => ri.RepoName.Contains("repo2")).Any());

                    // Make sure filter works
                    // In order to have a hope of getting a different result to GetRepositoryInformation
                    // we have to start over with a new client
                    var client2 = new ChorusHubClient();
                    Assert.NotNull(client2.FindServer());
                    var repoInfo = client2.GetRepositoryInformation(queryString);
                    Assert.AreEqual(1, repoInfo.Count());
                    var info = repoInfo.First();
                    Assert.IsTrue(info.RepoName == "repo1");
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Called by our worker thread to avoid inordinate pauses in the UI while checking the
        /// Shared Network Folder to determine its status.
        /// </summary>
        private void CheckNetworkStatusAndUpdateUI()
        {
            // Check network Shared Folder status
            string message, tooltip, diagnostics;
            message = tooltip = diagnostics = "";
            bool isReady=false;
            _lanMode = LANMode.ChorusHub;

            if (Properties.Settings.Default.ShowChorusHubInSendReceive)
            {
                try
                {
                    if (_chorusHubClient == null)
                    {
                        _chorusHubClient = new ChorusHub.ChorusHubClient();
                    }
                    _chorusHubInfo = _chorusHubClient.FindServer();
                }
                catch (Exception)
                {
                    //not worth complaining about
            #if DEBUG
                    throw;
            #endif
                }
            }
            if(_chorusHubInfo==null)
            {
                message = "No Chorus Hub found on local network.";
            }
            else if (!_chorusHubInfo.ServerIsCompatibleWithThisClient)
            {
                message = "Found Chorus Hub but it is not compatible with this version of "+Application.ProductName;
            }
            else
            {
                isReady = true;
                message = string.Format("Found Chorus Hub at {0}", _chorusHubInfo.HostName);
                tooltip = _chorusHubInfo.GetHgHttpUri(Path.GetFileName(_repository.PathToRepo));
            }

            Monitor.Enter(this);
            // Using a callback and Invoke ensures that we avoid cross-threading updates.
            if (!_exiting)
            {
                var callback = new UpdateNetworkUICallback(UpdateNetworkUI);
                this.Invoke(callback, new object[] { isReady, message, tooltip, diagnostics });
            }
            Monitor.Exit(this);
        }