Inheritance: AddinRepository
Exemplo n.º 1
0
        /// <summary>
        /// Updates the add-in index of the provided repository
        /// </summary>
        /// <param name="statusMonitor">
        /// Progress monitor where to show progress status and log
        /// </param>
        /// <param name="url">
        /// URL of the repository
        /// </param>
        public void UpdateRepository(IProgressStatus statusMonitor, string url)
        {
            repoList = null;

            IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor(statusMonitor);

            monitor.BeginTask("Updating repositories", service.Configuration.Repositories.Count);
            try {
                int num = service.Configuration.Repositories.Count;
                for (int n = 0; n < num; n++)
                {
                    RepositoryRecord rr = (RepositoryRecord)service.Configuration.Repositories [n];
                    if (((url == null && rr.Enabled) || rr.Url == url) && !rr.IsReference)
                    {
                        UpdateRepository(monitor, new Uri(rr.Url), rr);
                    }
                    monitor.Step(1);
                }
            } catch (Exception ex) {
                statusMonitor.ReportError("Could not get information from repository", ex);
                return;
            } finally {
                monitor.EndTask();
            }

            PurgeUnusedRepositories();
            service.SaveConfiguration();
        }
Exemplo n.º 2
0
        void GetRepositoryTree(string url, ArrayList list)
        {
            RepositoryRecord rr = FindRepositoryRecord(url);

            if (rr == null)
            {
                return;
            }

            if (list.Contains(rr))
            {
                return;
            }

            list.Add(rr);
            Repository rep = rr.GetCachedRepository();

            if (rep == null)
            {
                return;
            }

            Uri absUri = new Uri(url);

            foreach (ReferenceRepositoryEntry re in rep.Repositories)
            {
                Uri refRepUri = new Uri(absUri, re.Url);
                GetRepositoryTree(refRepUri.ToString(), list);
            }
        }
        void UpdateRepository(IProgressMonitor monitor, Uri baseUri, RepositoryRecord rr)
        {
            Uri absUri = new Uri(baseUri, rr.Url);

            monitor.BeginTask("Updating from " + absUri.ToString(), 2);
            Repository newRep;

            try {
                newRep = (Repository)service.Store.DownloadObject(monitor, absUri.ToString(), typeof(Repository));
            } catch (Exception ex) {
                monitor.ReportError("Could not get information from repository" + ": " + absUri.ToString(), ex);
                return;
            }

            monitor.Step(1);

            foreach (ReferenceRepositoryEntry re in newRep.Repositories)
            {
                Uri              refRepUri = new Uri(absUri, re.Url);
                string           refRepUrl = refRepUri.ToString();
                RepositoryRecord refRep    = FindRepositoryRecord(refRepUrl);
                if (refRep == null)
                {
                    refRep = RegisterRepository(refRepUrl, true);
                }
                if (refRep.LastModified < re.LastModified)
                {
                    UpdateRepository(monitor, refRepUri, refRep);
                }
            }
            monitor.EndTask();
            rr.UpdateCachedRepository(newRep);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Subscribes to an on-line repository
        /// </summary>
        /// <param name="monitor">
        /// Progress monitor where to show progress status and log
        /// </param>
        /// <param name="url">
        /// URL of the repository
        /// </param>
        /// <param name="updateNow">
        /// When set to True, the repository index will be downloaded.
        /// </param>
        /// <returns>
        /// A repository reference
        /// </returns>
        public AddinRepository RegisterRepository(IProgressStatus monitor, string url, bool updateNow)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentException("Emtpy url");
            }

            if (!url.EndsWith(".mrep"))
            {
                if (url [url.Length - 1] != '/')
                {
                    url += "/";
                }
                url = url + "main.mrep";
            }

            RepositoryRecord rr = FindRepositoryRecord(url);

            if (rr != null)
            {
                return(rr);
            }

            rr = RegisterRepository(url, false);

            try
            {
                if (updateNow)
                {
                    UpdateRepository(monitor, url);
                    rr = FindRepositoryRecord(url);
                    Repository rep = rr.GetCachedRepository();
                    if (rep != null)
                    {
                        rr.Name = rep.Name;
                    }
                }
                service.SaveConfiguration();
                return(rr);
            }
            catch (Exception ex)
            {
                if (monitor != null)
                {
                    monitor.ReportError("The repository could not be registered", ex);
                }
                if (ContainsRepository(url))
                {
                    RemoveRepository(url);
                }
                return(null);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Removes an on-line repository subscription.
        /// </summary>
        /// <param name="url">
        /// URL of the repository.
        /// </param>
        public void RemoveRepository(string url)
        {
            RepositoryRecord rep = FindRepositoryRecord(url);

            if (rep == null)
            {
                return;                 // Nothing to do
            }
            rep.IsReference = true;
            PurgeUnusedRepositories();
            service.SaveConfiguration();
            repoList = null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Removes an on-line repository subscription.
        /// </summary>
        /// <param name="url">
        /// URL of the repository.
        /// </param>
        public void RemoveRepository(string url)
        {
            RepositoryRecord rep = FindRepositoryRecord(url);

            if (rep == null)
            {
                return;                 // Nothing to do
            }
            foreach (RepositoryRecord rr in service.Configuration.Repositories)
            {
                if (rr == rep)
                {
                    continue;
                }
                Repository newRep = rr.GetCachedRepository();
                if (newRep == null)
                {
                    continue;
                }
                foreach (ReferenceRepositoryEntry re in newRep.Repositories)
                {
                    if (re.Url == url)
                    {
                        // The repository can't be removed because there is another
                        // repository depending on it. Just mark it as a reference.
                        rep.IsReference = true;
                        return;
                    }
                }
            }

            // There are no other repositories referencing this one, so we can safely delete

            Repository delRep = rep.GetCachedRepository();

            service.Configuration.Repositories.Remove(rep);
            rep.ClearCachedRepository();

            if (delRep != null)
            {
                foreach (ReferenceRepositoryEntry re in delRep.Repositories)
                {
                    RemoveRepository(new Uri(new Uri(url), re.Url).ToString());
                }
            }

            service.SaveConfiguration();
            repoList = null;
        }
        public void RemoveRepository(string url)
        {
            RepositoryRecord rep = FindRepositoryRecord(url);

            if (rep == null)
            {
                throw new InstallException("The repository at url '" + url + "' is not registered");
            }

            foreach (RepositoryRecord rr in service.Configuration.Repositories)
            {
                if (rr == rep)
                {
                    continue;
                }
                Repository newRep = rr.GetCachedRepository();
                if (newRep == null)
                {
                    continue;
                }
                foreach (ReferenceRepositoryEntry re in newRep.Repositories)
                {
                    if (re.Url == url)
                    {
                        rep.IsReference = true;
                        return;
                    }
                }
            }

            // There are no other repositories referencing this one, so we can safely delete

            Repository delRep = rep.GetCachedRepository();

            service.Configuration.Repositories.Remove(rep);
            rep.ClearCachedRepository();

            if (delRep != null)
            {
                foreach (ReferenceRepositoryEntry re in delRep.Repositories)
                {
                    RemoveRepository(new Uri(new Uri(url), re.Url).ToString());
                }
            }

            service.SaveConfiguration();
            repoList = null;
        }
Exemplo n.º 8
0
        void UpdateRepository(IProgressMonitor monitor, Uri baseUri, RepositoryRecord rr)
        {
            Uri absUri = new Uri(baseUri, rr.Url);

            monitor.BeginTask("Updating from " + absUri.ToString(), 2);
            Repository newRep = null;
            Exception  error  = null;

            try
            {
                newRep = (Repository)service.Store.DownloadObject(monitor, absUri.ToString(), typeof(Repository));
            }
            catch (Exception ex)
            {
                error = ex;
            }

            if (newRep == null)
            {
                monitor.ReportError("Could not get information from repository" + ": " + absUri.ToString(), error);
                return;
            }

            monitor.Step(1);

            foreach (ReferenceRepositoryEntry re in newRep.Repositories)
            {
                Uri              refRepUri = new Uri(absUri, re.Url);
                string           refRepUrl = refRepUri.ToString();
                RepositoryRecord refRep    = FindRepositoryRecord(refRepUrl);
                if (refRep == null)
                {
                    refRep = RegisterRepository(refRepUrl, true);
                }
                refRep.Enabled = rr.Enabled;
                // Update the repo if the modified timestamp changes or if there is no timestamp info
                if (refRep.LastModified != re.LastModified || re.LastModified == DateTime.MinValue)
                {
                    refRep.LastModified = re.LastModified;
                    UpdateRepository(monitor, refRepUri, refRep);
                }
            }
            monitor.EndTask();
            rr.UpdateCachedRepository(newRep);
        }
Exemplo n.º 9
0
        internal RepositoryRecord RegisterRepository(string url, bool isReference, string providerId)
        {
            RepositoryRecord rr = FindRepositoryRecord(url);

            if (rr != null)
            {
                if (rr.IsReference && !isReference)
                {
                    rr.IsReference = false;
                }
                rr.ProviderId = providerId;
                service.SaveConfiguration();
                return(rr);
            }

            rr             = new RepositoryRecord();
            rr.Url         = url;
            rr.IsReference = isReference;
            rr.ProviderId  = providerId;

            string name = service.RepositoryCachePath;

            if (!Directory.Exists(name))
            {
                Directory.CreateDirectory(name);
            }
            string host = new Uri(url).Host;

            if (host.Length == 0)
            {
                host = "repo";
            }
            name    = Path.Combine(name, host);
            rr.File = name + "_" + service.Configuration.RepositoryIdCount + ".mrep";

            rr.Id = "rep" + service.Configuration.RepositoryIdCount;
            service.Configuration.Repositories.Add(rr);
            service.Configuration.RepositoryIdCount++;
            service.SaveConfiguration();
            repoList = null;
            return(rr);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Enables or disables a repository
        /// </summary>
        /// <param name='url'>
        /// URL of the repository
        /// </param>
        /// <param name='enabled'>
        /// 'true' if the repository has to be enabled.
        /// </param>
        /// <remarks>
        /// Disabled repositories are ignored when calling UpdateAllRepositories.
        /// </remarks>
        public void SetRepositoryEnabled(string url, bool enabled)
        {
            RepositoryRecord rep = FindRepositoryRecord(url);

            if (rep == null)
            {
                return;                 // Nothing to do
            }
            rep.Enabled = enabled;
            Repository crep = rep.GetCachedRepository();

            if (crep != null)
            {
                foreach (RepositoryEntry re in crep.Repositories)
                {
                    SetRepositoryEnabled(new Uri(new Uri(url), re.Url).ToString(), enabled);
                }
            }

            service.SaveConfiguration();
        }
        public AddinRepository RegisterRepository(IProgressStatus monitor, string url, bool updateNow)
        {
            if (!url.EndsWith(".mrep"))
            {
                url = url + "/main.mrep";
            }

            RepositoryRecord rr = FindRepositoryRecord(url);

            if (rr != null)
            {
                return(rr);
            }

            rr = RegisterRepository(url, false);

            try {
                if (updateNow)
                {
                    UpdateRepository(monitor, url);
                    rr = FindRepositoryRecord(url);
                    Repository rep = rr.GetCachedRepository();
                    rr.Name = rep.Name;
                }
                service.SaveConfiguration();
                return(rr);
            } catch (Exception ex) {
                if (monitor != null)
                {
                    monitor.ReportError("The repository could not be registered", ex);
                }
                if (ContainsRepository(url))
                {
                    RemoveRepository(url);
                }
                return(null);
            }
        }
        public void UpdateRepository(IProgressStatus statusMonitor, string url)
        {
            repoList = null;

            IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor(statusMonitor);

            monitor.BeginTask("Updating repositories", service.Configuration.Repositories.Count);
            try {
                int num = service.Configuration.Repositories.Count;
                for (int n = 0; n < num; n++)
                {
                    RepositoryRecord rr = (RepositoryRecord)service.Configuration.Repositories [n];
                    if ((url == null || rr.Url == url) && !rr.IsReference)
                    {
                        UpdateRepository(monitor, new Uri(rr.Url), rr);
                    }
                    monitor.Step(1);
                }
            } finally {
                monitor.EndTask();
            }
            service.SaveConfiguration();
        }
		internal RepositoryRecord RegisterRepository (string url, bool isReference)
		{
			RepositoryRecord rr = FindRepositoryRecord (url);
			if (rr != null) {
				if (rr.IsReference && !isReference) {
					rr.IsReference = false;
					service.SaveConfiguration ();
				}
				return rr;
			}
			
			rr = new RepositoryRecord ();
			rr.Url = url;
			rr.IsReference = isReference;
			
			string name = service.RepositoryCachePath;
			if (!Directory.Exists (name))
				Directory.CreateDirectory (name);
			string host = new Uri (url).Host;
			if (host.Length == 0)
				host = "repo";
			name = Path.Combine (name, host);
			rr.File = name + "_" + service.Configuration.RepositoryIdCount + ".mrep";
			
			rr.Id = "rep" + service.Configuration.RepositoryIdCount;
			service.Configuration.Repositories.Add (rr);
			service.Configuration.RepositoryIdCount++;
			service.SaveConfiguration ();
			repoList = null;
			return rr;
		}
		void UpdateRepository (IProgressMonitor monitor, Uri baseUri, RepositoryRecord rr)
		{
			Uri absUri = new Uri (baseUri, rr.Url);
			monitor.BeginTask ("Updating from " + absUri.ToString (), 2);
			Repository newRep;
			try {
				newRep = (Repository) service.Store.DownloadObject (monitor, absUri.ToString (), typeof(Repository));
			} catch (Exception ex) {
				monitor.ReportError ("Could not get information from repository" + ": " + absUri.ToString (), ex);
				return;
			}
			
			monitor.Step (1);
			
			foreach (ReferenceRepositoryEntry re in newRep.Repositories) {
				Uri refRepUri = new Uri (absUri, re.Url);
				string refRepUrl = refRepUri.ToString ();
				RepositoryRecord refRep = FindRepositoryRecord (refRepUrl);
				if (refRep == null)
					refRep = RegisterRepository (refRepUrl, true);
				if (refRep.LastModified < re.LastModified) {
					UpdateRepository (monitor, refRepUri, refRep);
				}
			}
			monitor.EndTask ();
			rr.UpdateCachedRepository (newRep);
		}
Exemplo n.º 15
0
		void UpdateRepository (IProgressMonitor monitor, Uri baseUri, RepositoryRecord rr)
		{
			Uri absUri = new Uri (baseUri, rr.Url);
			monitor.BeginTask ("Updating from " + absUri.ToString (), 2);
			Repository newRep = null;
			Exception error = null;
			
			try {
				newRep = (Repository) service.Store.DownloadObject (monitor, absUri.ToString (), typeof(Repository));
			} catch (Exception ex) {
				error = ex;
			}
			
			if (newRep == null) {
				monitor.ReportError ("Could not get information from repository" + ": " + absUri.ToString (), error);
				return;
			}
			
			monitor.Step (1);
			
			foreach (ReferenceRepositoryEntry re in newRep.Repositories) {
				Uri refRepUri = new Uri (absUri, re.Url);
				string refRepUrl = refRepUri.ToString ();
				RepositoryRecord refRep = FindRepositoryRecord (refRepUrl);
				if (refRep == null)
					refRep = RegisterRepository (refRepUrl, true);
				refRep.Enabled = rr.Enabled;
				// Update the repo if the modified timestamp changes or if there is no timestamp info
				if (refRep.LastModified != re.LastModified || re.LastModified == DateTime.MinValue) {
					refRep.LastModified = re.LastModified;
					UpdateRepository (monitor, refRepUri, refRep);
				}
			}
			monitor.EndTask ();
			rr.UpdateCachedRepository (newRep);
		}