Exemplo n.º 1
0
        /// <summary>
        /// Registers a new <see cref="StackRepo"/> or updates its <see cref="GitRepositoryKey.IsPublic"/> configuration.
        /// This is exposed as a command by <see cref="UserHost.EnsureStackRepository"/> in order for Stack repository manipulations
        /// (that are NOT world: it's meta) to appear in "Home/" command namespace instead of "World/".
        /// </summary>
        /// <param name="m">The monitor to use.</param>
        /// <param name="url">The repository url. Must not be numm or empty.</param>
        /// <param name="isPublic">Whether this repository contains public (Open Source) worlds.</param>
        public void EnsureStackRepository(IActivityMonitor m, string url, bool isPublic)
        {
            if (DisableRepositoryAndStacksCommands)
            {
                throw new InvalidOperationException(nameof(DisableRepositoryAndStacksCommands));
            }
            if (String.IsNullOrWhiteSpace(url) || !Uri.TryCreate(url, UriKind.Absolute, out var uri))
            {
                throw new ArgumentException("Must be a valid url.", nameof(url));
            }
            int idx = _stackRepos.IndexOf(r => r.OriginUrl.ToString().Equals(url, StringComparison.OrdinalIgnoreCase));

            if (idx < 0)
            {
                var r = new StackRepo(this, uri, isPublic);
                _stackRepos.Add(r);
                if (r.Refresh(m))
                {
                    WriteStacksToLocalStacksFilePath(m);
                }
            }
            else
            {
                var r = _stackRepos[idx];
                if (r.IsPublic != isPublic)
                {
                    r.IsPublic = isPublic;
                    m.Info($"Changing configuration for '{r.OriginUrl}' from {(isPublic ? "Private to Public" : "Public to Private")}.");
                    WriteStacksToLocalStacksFilePath(m);
                }
            }
        }
Exemplo n.º 2
0
            internal static StackRepo Parse(GitWorldStore store, XElement e)
            {
                var uri = new Uri((string)e.AttributeRequired(nameof(OriginUrl)));
                var pub = (bool?)e.Attribute(nameof(IsPublic)) ?? false;
                var r   = new StackRepo(store, uri, pub, null);

                r._worlds.AddRange(e.Elements("Worlds").Elements(nameof(WorldInfo)).Select(eW => new WorldInfo(r, eW)));
                return(r);
            }
Exemplo n.º 3
0
            internal WorldInfo(StackRepo r, XElement e)
            {
                Repo = r;
                var n = (string)e.AttributeRequired(nameof(WorldName.FullName));

                _name = LocalWorldName.TryParse(r.Root.AppendPart(n + ".World.xml"), r.Store.WorldLocalMapping);
                _name.HasDefinitionFile = (bool?)e.Attribute(nameof(WorldName.HasDefinitionFile)) ?? false;
                _name.IsHidden          = (bool?)e.Attribute(nameof(WorldName.IsHidden)) ?? false;
            }
Exemplo n.º 4
0
        public void IsBalancedBrackets()
        {
            var _repo = new StackRepo();

            var data         = "([])[]({})";
            var actualResult = true;

            var result = _repo.IsBalancedBracket(data);


            Assert.IsTrue(actualResult == result, "Result Validated");
        }
Exemplo n.º 5
0
        void UpdateReposFromDefinitions(IActivityMonitor m, StackInitializeOption option)
        {
            var newWorlds = new List <LocalWorldName>();

            ++_syncCount;
            foreach (var gD in _stacks.GroupBy(d => d.OriginUrl))
            {
                if (gD.Any(d => d.IsPublic) && gD.Any(d => !d.IsPublic))     //Filter out repos with mixed public/private
                {
                    m.Error($"Repository {gD.Key} contains a mix of public and private Stacks. All stacks in this repository are ignored.");
                }
                else if (gD.Select(d => d.BranchName).Distinct().Count() > 1)   //Filter
                {
                    m.Error($"Repository {gD.Key} contains Stacks bound to different branches: it must be the same branch for all stacks. All stacks in this repository are ignored.");
                }
                else
                {
                    EnsureRepo(gD.Key).Synchronize(m, gD, option, newWorlds.Add);
                }
            }
            for (int i = 0; i < _repos.Count; ++i)
            {
                if (!_repos[i].PostSynchronize(m))
                {
                    _repos[i].Dispose();
                    _repos.RemoveAt(i--);
                }
            }
            SetWorlds(m, newWorlds);

            StackRepo EnsureRepo(Uri u)
            {
                int idx = _repos.IndexOf(r => r.OriginUrl == u);

                if (idx >= 0)
                {
                    return(_repos[idx]);
                }
                var newOne = new StackRepo(this, u);

                _repos.Add(newOne);
                return(newOne);
            }
        }
Exemplo n.º 6
0
        public T Push(T Data)
        {
            T result = default(T);

            if (StackRepo.ContainsKey(Top))
            {
                if (StackRepo[Top].Size == Thresold)
                {
                    Top++;
                    AddNewStack(Top);
                }
                result = StackRepo[Top].Push(Data);
            }
            else
            {
                AddNewStack(Top);
                result = StackRepo[Top].Push(Data);
            }
            return(result);
        }
Exemplo n.º 7
0
        protected override LocalWorldName DoCreateNewParallel(IActivityMonitor m, IRootedWorldName source, string parallelName, XDocument content)
        {
            Debug.Assert(source != null);
            Debug.Assert(content != null);
            Debug.Assert(!String.IsNullOrWhiteSpace(parallelName));

            StackRepo repo = null;

            if (source is LocalWorldName src &&
                (repo = _stackRepos.FirstOrDefault(r => src.XmlDescriptionFilePath.StartsWith(r.Root))) == null)
            {
                m.Error($"Unable to find source World.");
                return(null);
            }
            string wName = source.Name + (parallelName != null ? '[' + parallelName + ']' : String.Empty);
            var    world = _stackRepos.SelectMany(r => r.Worlds).FirstOrDefault(w => w.WorldName.FullName == wName);

            if (world != null)
            {
                m.Error($"World '{wName}' already exists.");
                return(null);
            }

            var path = repo.Root.AppendPart(wName + ".World.xml");

            if (!File.Exists(path))
            {
                var w = new LocalWorldName(path, source.Name, parallelName, WorldLocalMapping);
                if (!WriteWorldDescription(m, w, content))
                {
                    m.Error($"Unable to create {wName} world.");
                    return(null);
                }
                return(w);
            }
            m.Error($"World file '{path}' already exists.");
            return(null);
        }
Exemplo n.º 8
0
 internal WorldInfo(StackRepo repo, LocalWorldName name)
 {
     Debug.Assert(repo != null && name != null);
     Repo  = repo;
     _name = name;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Reads the Stacks.xml file and instanciates the <see cref="StackRepo"/> objects and
 /// their <see cref="WorldInfo"/>: creating the StackRepo registers the required secrets
 /// in the key store.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 internal void ReadStacksFromLocalStacksFilePath(IActivityMonitor m)
 {
     if (!File.Exists(StacksFilePath))
     {
         m.Warn($"File '{StacksFilePath}' not found.");
     }
     else
     {
         using (m.OpenInfo($"Reading '{StacksFilePath}'."))
         {
             try
             {
                 _stackRepos.Clear();
                 _stackRepos.AddRange(XDocument.Load(StacksFilePath).Root.Elements().Select(e => StackRepo.Parse(this, e)));
             }
             catch (Exception ex)
             {
                 m.Error($"Unable to read '{StacksFilePath}' file.", ex);
             }
         }
     }
     if (_stackRepos.Count == 0)
     {
         using (m.OpenInfo("Since there is no Stack defined, we initialize CK and CK-Build mapped to '/Dev/CK' by default."))
         {
             m.Info($"Use 'run World/{nameof( SetWorldMapping )}' command to update the mapping.");
             _stackRepos.Add(new StackRepo(this, new Uri("https://github.com/signature-opensource/CK-Stack.git"), true));
             _stackRepos.Add(new StackRepo(this, new Uri("https://github.com/CK-Build/CK-Build-Stack.git"), true));
             WorldLocalMapping.SetMap(m, "CK-Build", "/Dev/CK");
             WorldLocalMapping.SetMap(m, "CK", "/Dev/CK");
             WriteStacksToLocalStacksFilePath(m);
         }
     }
 }