Наследование: GitCommands.Repository.RepositoryCategory
Пример #1
0
        public static void DeserializeHistoryFromXml(string xml)
        {
            if (string.IsNullOrEmpty(xml))
            {
                return;
            }

            try
            {
                var serializer = new XmlSerializer(typeof(RepositoryHistory));
                using (var stringReader = new StringReader(xml))
                    using (var xmlReader = new XmlTextReader(stringReader))
                    {
                        var obj = serializer.Deserialize(xmlReader) as RepositoryHistory;
                        if (obj != null)
                        {
                            RepositoryHistory = obj;
                            RepositoryHistory.SetIcon();
                        }
                    }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Пример #2
0
 public static void AddMostRecentRepository(string repo)
 {
     if (Repository.PathIsUrl(repo))
     {
         RemoteRepositoryHistory.AddMostRecentRepository(repo);
     }
     else
     {
         RepositoryHistory.AddMostRecentRepository(repo);
         AssignRepositoryHistoryFromCategories(repo);
     }
 }
Пример #3
0
 private static void AssignRepositoryHistoryFromCategories(RepositoryHistory repositoryHistory, string path)
 {
     foreach (Repository repo in repositoryHistory.Repositories)
     {
         if (path == null || path.Equals(repo.Path, StringComparison.CurrentCultureIgnoreCase))
         {
             Repository catRepo = FindFirstCategoryRepository(repo.Path);
             if (catRepo != null)
             {
                 repo.Assign(catRepo);
             }
         }
     }
 }
Пример #4
0
 private static string SerializeHistoryIntoXml(RepositoryHistory history)
 {
     try
     {
         var sw         = new StringWriter();
         var serializer = new XmlSerializer(typeof(RepositoryHistory));
         serializer.Serialize(sw, history);
         return(sw.ToString());
     }
     catch
     {
         return(null);
     }
 }
Пример #5
0
        private static RepositoryHistory DeserializeHistoryFromXml(string xml)
        {
            if (string.IsNullOrEmpty(xml))
            {
                return(null);
            }

            RepositoryHistory history = null;

            try
            {
                var          serializer   = new XmlSerializer(typeof(RepositoryHistory));
                StringReader stringReader = null;
                try
                {
                    stringReader = new StringReader(xml);
                    using (var xmlReader = new XmlTextReader(stringReader))
                    {
                        stringReader = null;
                        var obj = serializer.Deserialize(xmlReader) as RepositoryHistory;
                        if (obj != null)
                        {
                            history = obj;
                            history.SetIcon();
                        }
                    }
                }
                finally
                {
                    if (stringReader != null)
                    {
                        stringReader.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            return(history);
        }
Пример #6
0
        private static RepositoryHistory LoadRepositoryHistory()
        {
            int    size    = AppSettings.RecentRepositoriesHistorySize;
            object setting = AppSettings.GetString("history", null);

            if (setting == null)
            {
                return(new RepositoryHistory(size));
            }

            RepositoryHistory repositoryHistory = DeserializeHistoryFromXml(setting.ToString());

            if (repositoryHistory == null)
            {
                return(new RepositoryHistory(size));
            }

            repositoryHistory.MaxCount = size;
            AssignRepositoryHistoryFromCategories(repositoryHistory, null);

            // migration from old version (move URL history to _remoteRepositoryHistory)
            if (AppSettings.GetString("history remote", null) == null)
            {
                _remoteRepositoryHistory = new RepositoryHistory(size);
                foreach (Repository repo in repositoryHistory.Repositories)
                {
                    if (repo.IsRemote)
                    {
                        repo.Path = repo.Path.ToPosixPath();
                        _remoteRepositoryHistory.AddRepository(repo);
                    }
                }

                foreach (Repository repo in _remoteRepositoryHistory.Repositories)
                {
                    repositoryHistory.RemoveRepository(repo);
                }
            }

            return(repositoryHistory);
        }
Пример #7
0
 public static void DeserializeHistoryFromXml(string xml)
 {
     try
     {
         var serializer = new XmlSerializer(typeof (RepositoryHistory));
         using (var stringReader = new StringReader(xml))
         using (var xmlReader = new XmlTextReader(stringReader))
         {
             var obj = serializer.Deserialize(xmlReader) as RepositoryHistory;
             if (obj != null)
             {
                 RepositoryHistory = obj;
                 RepositoryHistory.SetIcon();
             }
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.Message);
     }
 }
Пример #8
0
        private static RepositoryHistory LoadRepositoryHistory()
        {
            var    repositoryHistory = new RepositoryHistory();
            object setting           = Settings.GetString("history", null);

            if (setting == null)
            {
                repositoryHistory = new RepositoryHistory();
                return(repositoryHistory);
            }

            repositoryHistory = DeserializeHistoryFromXml(setting.ToString());
            if (repositoryHistory != null)
            {
                AssignRepositoryHistoryFromCategories(repositoryHistory, null);

                // migration from old version (move URL history to _remoteRepositoryHistory)
                if (Settings.GetString("history remote", null) == null)
                {
                    _remoteRepositoryHistory = new RepositoryHistory();
                    foreach (Repository repo in repositoryHistory.Repositories)
                    {
                        if (repo.IsRemote)
                        {
                            repo.Path = repo.Path.Replace('\\', '/');
                            _remoteRepositoryHistory.AddRepository(repo);
                        }
                    }
                    foreach (Repository repo in _remoteRepositoryHistory.Repositories)
                    {
                        repositoryHistory.RemoveRepository(repo);
                    }
                }
            }

            return(repositoryHistory ?? new RepositoryHistory());
        }
Пример #9
0
        private static RepositoryHistory LoadRepositoryHistory()
        {
            int size = AppSettings.GetInt("history size", DefaultRepositoriesCount);
            object setting = AppSettings.GetString("history", null);
            if (setting == null)
            {
                return new RepositoryHistory(size);
            }

            RepositoryHistory repositoryHistory = DeserializeHistoryFromXml(setting.ToString());
            if (repositoryHistory == null)
                return new RepositoryHistory(size);

            repositoryHistory.MaxCount = size;
            AssignRepositoryHistoryFromCategories(repositoryHistory, null);

            // migration from old version (move URL history to _remoteRepositoryHistory)
            if (AppSettings.GetString("history remote", null) == null)
            {
                _remoteRepositoryHistory = new RepositoryHistory(size);
                foreach (Repository repo in repositoryHistory.Repositories)
                {
                    if (repo.IsRemote)
                    {
                        repo.Path = repo.Path.Replace('\\', '/');
                        _remoteRepositoryHistory.AddRepository(repo);
                    }
                }
                foreach (Repository repo in _remoteRepositoryHistory.Repositories)
                {
                    repositoryHistory.RemoveRepository(repo);
                }
            }

            return repositoryHistory;
        }
Пример #10
0
 private static string SerializeHistoryIntoXml(RepositoryHistory history)
 {
     try
     {
         var sw = new StringWriter();
         var serializer = new XmlSerializer(typeof(RepositoryHistory));
         serializer.Serialize(sw, history);
         return sw.ToString();
     }
     catch
     {
         return null;
     }
 }
Пример #11
0
        private static RepositoryHistory LoadRepositoryHistory()
        {
            var repositoryHistory = new RepositoryHistory();
            object setting = Settings.GetValue<string>("history", null);
            if (setting == null)
            {
                repositoryHistory = new RepositoryHistory();
                return repositoryHistory;
            }

            repositoryHistory = DeserializeHistoryFromXml(setting.ToString());
            if (repositoryHistory != null)
            {
                AssignRepositoryHistoryFromCategories(repositoryHistory, null);

                // migration from old version (move URL history to _remoteRepositoryHistory)
                if (Settings.GetValue<string>("history remote", null) == null)
                {
                    _remoteRepositoryHistory = new RepositoryHistory();
                    foreach (Repository repo in repositoryHistory.Repositories)
                    {
                        if (repo.IsRemote)
                        {
                            repo.Path = repo.Path.Replace('\\', '/');
                            _remoteRepositoryHistory.AddRepository(repo);
                        }
                    }
                    foreach (Repository repo in _remoteRepositoryHistory.Repositories)
                    {
                        repositoryHistory.RemoveRepository(repo);
                    }
                }
            }

            return repositoryHistory ?? new RepositoryHistory();
        }
Пример #12
0
 private static void AssignRepositoryHistoryFromCategories(RepositoryHistory repositoryHistory, string path)
 {
     foreach (Repository repo in repositoryHistory.Repositories)
     {
         if (path == null || path.Equals(repo.Path, StringComparison.CurrentCultureIgnoreCase))
         {
             Repository catRepo = FindFirstCategoryRepository(repo.Path);
             if (catRepo != null)
                 repo.Assign(catRepo);
         }
     }
 }