public void MakeClone(IProgress progress)
        {
            var chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();

            if (chorusHubServerInfo == null)
            {
                progress.WriteError(LocalizationManager.GetString("Messages.ChorusServerNA", "The Chorus Server is not available."));
                CloneSucceeded = false;
                return;
            }
            if (!chorusHubServerInfo.ServerIsCompatibleWithThisClient)
            {
                progress.WriteError(LocalizationManager.GetString("Messages.ChorusServerIncompatible", "The Chorus Server is not compatible with ths client."));
                CloneSucceeded = false;
                return;
            }

            var targetFolder = Path.Combine(_baseFolder, RepositoryName);

            try
            {
                var client = new ChorusHubClient(chorusHubServerInfo);
                NewlyClonedFolder = HgRepository.Clone(new ChorusHubRepositorySource(RepositoryName, client.GetUrl(RepositoryName), false, HubRepositoryInformation), targetFolder, progress);
                CloneSucceeded    = true;
            }
            catch (Exception)
            {
                NewlyClonedFolder = null;
                CloneSucceeded    = false;
                throw;
            }
        }
Beispiel #2
0
        private void SetButtonStates()
        {
            _useUSBButton.Enabled      = new CloneFromUsb().GetHaveOneOrMoreUsbDrives();
            _useInternetButton.Enabled = NetworkInterface.GetIsNetworkAvailable();
            var chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();

            _useChorusHubButton.Enabled = ((chorusHubServerInfo != null) && (chorusHubServerInfo.ServerIsCompatibleWithThisClient));
        }
Beispiel #3
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)
                    {
                        _chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();
                        if (_chorusHubServerInfo != null)
                        {
                            _chorusHubClient = new ChorusHubClient(_chorusHubServerInfo);
                        }
                    }
                }
                catch (Exception)
                {
                    //not worth complaining about
#if DEBUG
                    throw;
#endif
                }
            }
            if (_chorusHubServerInfo == null)
            {
                message = LocalizationManager.GetString("GetChorusHubStatus.NoChorusHubFound", "No Chorus Hub found on local network.");
            }
            else if (!_chorusHubServerInfo.ServerIsCompatibleWithThisClient)
            {
                message = string.Format(LocalizationManager.GetString("GetChorusHubStatus.FoundButNotCompatible",
                                                                      "Found Chorus Hub, but it is not compatible with this version of {0}."), Application.ProductName);
            }
            else
            {
                isReady = true;
                message = string.Format(LocalizationManager.GetString("GetChorusHubStatus.FoundChorusHubAt", "Found Chorus Hub at {0}"),
                                        _chorusHubServerInfo.HostName);
                tooltip = _chorusHubServerInfo.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);
                Invoke(callback, new object[] { isReady, message, tooltip, diagnostics });
            }
            Monitor.Exit(this);
        }
Beispiel #4
0
 /// <summary>
 /// Since this might not be a real "server", its ip address could be assigned dynamically,
 /// and could change each time someone "wakes up the server laptop" each morning
 /// </summary>
 private void UpdateAdvertisementBasedOnCurrentIpAddress()
 {
     if (_currentIpAddress != GetLocalIpAddress())
     {
         _currentIpAddress = GetLocalIpAddress();
         var serverInfo = new ChorusHubServerInfo(_currentIpAddress, ChorusHubOptions.MercurialPort.ToString(CultureInfo.InvariantCulture),
                                                  Environment.MachineName, ChorusHubServerInfo.VersionOfThisCode);
         _sendBytes = Encoding.ASCII.GetBytes(serverInfo.ToString());
         //EventLog.WriteEntry("Application", "Serving at http://" + _currentIpAddress + ":" + ChorusHubOptions.MercurialPort, EventLogEntryType.Information);
     }
 }
Beispiel #5
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_" + Guid.NewGuid()))
                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

                                    ChorusHubOptions.RootDirectory = chorusHubSourceFolder.Path;
                                    using (var service = new ChorusHubServer())
                                    {
                                        Assert.IsTrue(service.Start(true));

                                        var chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();
                                        Assert.NotNull(chorusHubServerInfo);
                                        // Make sure all repos are there first
                                        var client1     = new ChorusHubClient(chorusHubServerInfo);
                                        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
                                        chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();
                                        Assert.NotNull(ChorusHubServerInfo.FindServerInformation());
                                        var client2  = new ChorusHubClient(chorusHubServerInfo);
                                        var repoInfo = client2.GetRepositoryInformation(queryString);
                                        Assert.AreEqual(1, repoInfo.Count());
                                        var info = repoInfo.First();
                                        Assert.IsTrue(info.RepoName == "repo1");
                                    }
                                }
        }
Beispiel #6
0
        public void GetRepostoryNames_ThreeItemsInHubFolder_GetTwoItemsWithProjectFilter()
        {
            // only accept folders containing a file with the name "randomName.ext1" or "randomName.Ext2"
            const string queryString = @"filePattern=*.ext1|*.Ext2";

            using (var testRoot = new TemporaryFolder("ChorusHubCloneTest_" + Guid.NewGuid()))
                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("unwanted"))
                                    using (var repo3 = new TemporaryFolder(chorusHubSourceFolder, "repo3"))
                                        using (var tempFile3 = TempFile.WithExtension("Ext2"))
                                        {
                                            tempFile1.MoveTo(Path.Combine(repo1.Path, Path.GetFileName(tempFile1.Path)));
                                            using (var writer = new StreamWriter(tempFile1.Path))
                                                writer.Write("Some random text.");

                                            tempFile2.MoveTo(Path.Combine(repo2.Path, Path.GetFileName(tempFile2.Path)));
                                            tempFile3.MoveTo(Path.Combine(repo3.Path, Path.GetFileName(tempFile3.Path)));

                                            RepositorySetup.MakeRepositoryForTest(repo1.Path, "bob", new ConsoleProgress());
                                            RepositorySetup.MakeRepositoryForTest(repo2.Path, "bob", new ConsoleProgress());
                                            RepositorySetup.MakeRepositoryForTest(repo3.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
                                            var r3 = HgRepository.CreateOrUseExisting(repo3.Path, new ConsoleProgress());
                                            r3.AddAndCheckinFile(tempFile3.Path); // need this to create store/data/files

                                            ChorusHubOptions.RootDirectory = chorusHubSourceFolder.Path;
                                            using (var service = new ChorusHubServer())
                                            {
                                                Assert.IsTrue(service.Start(true));

                                                // Make sure filter works
                                                var chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();
                                                Assert.NotNull(chorusHubServerInfo);
                                                var client   = new ChorusHubClient(chorusHubServerInfo);
                                                var repoInfo = client.GetRepositoryInformation(queryString);
                                                Assert.AreEqual(2, repoInfo.Count());
                                                var info1 = repoInfo.First();
                                                var info2 = repoInfo.Last();
                                                Assert.IsTrue(info1.RepoName == "repo1");
                                                Assert.IsTrue(info2.RepoName == "repo3");
                                            }
                                        }
        }
        void OnChorusHubInfo_DoWork(object sender, DoWorkEventArgs e)
        {
#if !MONO // See https://bugzilla.xamarin.com/show_bug.cgi?id=4269. Remove #if when using mono that fixes this.
            Thread.CurrentThread.Name = @"GetRepositoryInformation";
#endif
            var chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();

            if (chorusHubServerInfo == null || !chorusHubServerInfo.ServerIsCompatibleWithThisClient)
            {
                e.Result = null;
            }
            else
            {
                var results = new object[2];
                var client  = new ChorusHubClient(chorusHubServerInfo);
                results[0] = client;
                results[1] = client.GetRepositoryInformation(_model.ProjectFilter);
                e.Result   = results;
            }
        }
Beispiel #8
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_" + Guid.NewGuid()))
                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
                                    ChorusHubOptions.RootDirectory = chorusHubSourceFolder.Path;
                                    using (var service = new ChorusHubServer())
                                    {
                                        Assert.That(service.Start(true), Is.True);

                                        // Make sure filter works
                                        var chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();
                                        Assert.NotNull(chorusHubServerInfo);
                                        var client         = new ChorusHubClient(chorusHubServerInfo);
                                        var repositoryInfo = client.GetRepositoryInformation(queryString);
                                        Assert.AreEqual(0, repositoryInfo.Count());
                                    }
                                }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            var parentOfRoot = Path.GetDirectoryName(ChorusHubOptions.RootDirectory);

            if (!Directory.Exists(parentOfRoot))
            {
                ErrorReport.NotifyUserOfProblem("In order to use '{0}', '{1}' must already exist", ChorusHubOptions.RootDirectory, parentOfRoot);
                return;
            }
            var chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();

            if (chorusHubServerInfo != null)
            {
                ErrorReport.NotifyUserOfProblem("Only one ChorusHub can be run on a network but there is already one running on {0}",
                                                chorusHubServerInfo.HostName);
                return;
            }

            SetupErrorHandling();
            SetUpReporting();

            Application.Run(new ChorusHubWindow());
        }
Beispiel #10
0
 protected override void OnStart(string[] args)
 {
     if (!_running)
     {
         var chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();
         if (chorusHubServerInfo != null)
         {
             EventLog.WriteEntry(string.Format("Only one ChorusHub can be run on a network but there is already one running on {0}", chorusHubServerInfo.HostName), EventLogEntryType.Error);
             Stop();
             return;
         }
         _chorusHubServer = new ChorusHubServer();
         EventLog.WriteEntry("Chorus Hub Service is starting....", EventLogEntryType.Information);
         _running      = _chorusHubServer.Start(true);
         _serviceTimer = new Timer
         {
             Interval = 500, Enabled = true
         };
         _serviceTimer.Elapsed += ServiceTimerOnElapsed;
         _serviceTimer.Start();
     }
     EventLog.WriteEntry("Chorus Hub Service started.", EventLogEntryType.Information);
 }
Beispiel #11
0
        public void GetRepostoryNames_TwoItemsInHubFolder_GetTwoItems()
        {
            using (var testRoot = new TemporaryFolder("ChorusHubCloneTest_" + Guid.NewGuid()))
                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

                                    ChorusHubOptions.RootDirectory = chorusHubSourceFolder.Path;
                                    using (var service = new ChorusHubServer())
                                    {
                                        // hg server side is now involved in deciding what repos are available
                                        Assert.IsTrue(service.Start(true));
                                        var chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation();
                                        Assert.NotNull(chorusHubServerInfo);
                                        var client   = new ChorusHubClient(chorusHubServerInfo);
                                        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");
                                    }
                                }
        }
Beispiel #12
0
 public void FindServer_NoServerFound_Null()
 {
     Assert.IsNull(ChorusHubServerInfo.FindServerInformation());
 }
Beispiel #13
0
 public void Setup()
 {
     _originalPath = ChorusHubOptions.RootDirectory;
     ChorusHubServerInfo.ClearServerInfoForTests();
 }
Beispiel #14
0
        public ChorusHubClient(ChorusHubServerInfo chorusHubServerInfo)
        {
            Guard.AgainstNull(chorusHubServerInfo, "chorusHubServerInfo");

            _chorusHubServerInfo = chorusHubServerInfo;
        }
Beispiel #15
0
 public void FindServer_NoServerFound_Null()
 {
     Assert.That(ChorusHubServerInfo.FindServerInformation(), Is.Null);
 }