Exemplo n.º 1
0
        public IEnumerable <RepositoryInformation> GetRepositoryInformation(string queryString)
        {
            if (_repositoryNames != null)
            {
                return(_repositoryNames);                //for now, there's no way to get an updated list except by making a new client
            }
            const string genericUrl = "scheme://path?";
            var          finalUrl   = string.IsNullOrEmpty(queryString)
                                                           ? queryString
                                                           : genericUrl + queryString;
            var binding = new NetTcpBinding
            {
                Security = { Mode = SecurityMode.None }
            };

            var factory = new ChannelFactory <IChorusHubService>(binding, _chorusHubServerInfo.ServiceUri);

            var channel = factory.CreateChannel();

            try
            {
                var jsonStrings = channel.GetRepositoryInformation(finalUrl);
                _repositoryNames = ImitationHubJSONService.ParseJsonStringsToChorusHubRepoInfos(jsonStrings);
            }
            finally
            {
                var comChannel = (ICommunicationObject)channel;
                if (comChannel.State != CommunicationState.Faulted)
                {
                    comChannel.Close();
                }
            }
            return(_repositoryNames);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <returns>true if client should wait for hg to notice</returns>
        public bool PrepareToReceiveRepository(string name, string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                var jsonStrings = GetRepositoryInformation(string.Empty);
                var hubInfo     = ImitationHubJSONService.ParseJsonStringsToChorusHubRepoInfos(jsonStrings);
                if (hubInfo.Any(info => info.RepoID == id))
                {
                    return(false);
                }
            }

            // since the repository doesn't exist, create it
            var directory = Path.Combine(ChorusHubOptions.RootDirectory, name);
            var uniqueDir = DirectoryUtilities.GetUniqueFolderPath(directory);

            //EventLog.WriteEntry("Application", string.Format("PrepareToReceiveRepository() is preparing a place for '{0}'.", name), EventLogEntryType.Information);
            if (uniqueDir != directory)
            {
                //EventLog.WriteEntry("Application", string.Format("{0} already exists! Creating repository for {1} at {2}.", directory, name, uniqueDir), EventLogEntryType.Warning);
            }
            Directory.CreateDirectory(uniqueDir);
            HgRepository.CreateRepositoryInExistingDir(uniqueDir, new ConsoleProgress());
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns information about the Hg repositories that the ChorusHub knows about.
        ///
        /// Similar to GetRepositoryInformation except the value of the id field is the id
        /// of the tip revision of the repository.
        ///
        /// For the returned tip to be accurate, clients using this method have to call
        /// PutFile(IChorusHubService.tipIdFolder, projectName, tipId) after doing a push.
        /// </summary>
        public string GetRepositoryInformationWithTipIds(string searchUrl)
        {
            List <RepositoryInformation> results = new List <RepositoryInformation>();

            foreach (RepositoryInformation repoInfo in
                     ImitationHubJSONService.ParseJsonStringsToChorusHubRepoInfos(GetRepositoryInformation(searchUrl, false)))
            {
                string tipId = GetFileAsText(TipIdFolder, repoInfo.RepoName);
                if (tipId == null)
                {
                    tipId = GetTipId(repoInfo.RepoName);
                    PutFileFromText(TipIdFolder, repoInfo.RepoName, tipId);
                }
                results.Add(new RepositoryInformation(repoInfo.RepoName, tipId));
            }

            return(string.Join("/", results.Select(r => ImitationHubJSONService.MakeJsonString(r.RepoName, r.RepoID))));
        }
Exemplo n.º 4
0
        private static bool HasRepo(string dirName, out string jsonRepoInfo)
        {
            jsonRepoInfo = null;
            var hgDir = Path.Combine(dirName, HgFolder);

            if (!Directory.Exists(hgDir))
            {
                return(false);
            }
            var repo = HgRepository.CreateOrUseExisting(dirName, new ConsoleProgress());
            var id   = repo.Identifier;
            var name = Path.GetFileName(dirName);

            if (id == null)
            {
                id = RepositoryInformation.NEW_REPO;
            }
            jsonRepoInfo = ImitationHubJSONService.MakeJsonString(name, id);
            return(true);
        }