示例#1
0
        public SharedWorldState(WorldStore store, IWorldName w, XDocument d = null)
            : base(store, w, false, d)
        {
            var r = XDocument.Root;

            _cidKeyVault = r.EnsureElement(XmlNames.xCICDKeyVault);
        }
示例#2
0
        public XWorld(
            FileSystem fileSystem,
            IWorldName worldName,
            WorldStore worldStore,
            IEnvLocalFeedProvider localFeeds,
            SecretKeyStore keyStore,
            ArtifactCenter artifacts,
            CommandRegister commandRegister,
            IBasicApplicationLifetime appLife,
            Initializer initializer)
            : base(initializer)
        {
            _localFeeds = localFeeds;
            _fileSystem = fileSystem;

            _userMonitorFilter = initializer.Monitor.Output.Clients.OfType <IActivityMonitorFilteredClient>().FirstOrDefault();
            if (_userMonitorFilter == null)
            {
                throw new InvalidOperationException();
            }

            bool isPublic = initializer.Reader.HandleRequiredAttribute <bool>("IsPublic");

            _world = new World(commandRegister, artifacts, worldStore, worldName, isPublic, _localFeeds, keyStore, _userMonitorFilter, appLife)
            {
                VersionSelector = new ReleaseVersionSelector()
            };
            _world.DumpWorldStatus += (o, e) => OnDumpWorldStatus(e.Monitor);
            initializer.Services.Add(_world);
            fileSystem.ServiceContainer.Add <ISolutionDriverWorld>(_world);
        }
示例#3
0
        internal BaseWorldState(WorldStore store, IWorldName w, bool isLocal, XDocument d = null)
        {
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }
            if (w == null)
            {
                throw new ArgumentNullException(nameof(w));
            }

            _store = store;
            World  = w;

            string safeName = SafeElementName(w, isLocal);

            if (d == null)
            {
                d = new XDocument(new XElement(safeName, new XAttribute(XmlNames.xWorkStatus, GlobalWorkStatus.Idle.ToString())));
            }
            else if (d.Root.Name != safeName)
            {
                throw new ArgumentException($"Invalid state document root. Must be {safeName}, found {d.Root.Name}.", nameof(d));
            }
            d.Changed += (o, e) => IsStateDirty = true;

            XDocument = d;
        }
示例#4
0
 LocalWorldName ToLocal(IWorldName w)
 {
     if (w is LocalWorldName loc)
     {
         return(loc);
     }
     throw new ArgumentException("Must be a valid LocalWorldName.", nameof(w));
 }
示例#5
0
        protected override bool SaveSharedState(IActivityMonitor m, IWorldName w, XDocument d)
        {
            var p = ToSharedStateFilePath(w);

            d.Save(p.Item2);
            OnWorkingFolderChanged(m, p.Item1);
            return(true);
        }
示例#6
0
        /// <summary>
        /// Finds or creates a <see cref="ProtoGitFolder"/>.
        /// </summary>
        /// <param name="folderPath">The folder relative to the <see cref="Root"/> and contains the .git sub folder.</param>
        /// <param name="urlRepository">The url repository.</param>
        /// <param name="isPublic">Whether the repository is public.</param>
        /// <returns>The <see cref="ProtoGitFolder"/>.</returns>
        public ProtoGitFolder FindOrCreateProtoGitFolder(IActivityMonitor m, IWorldName world, NormalizedPath folderPath, string urlRepository, bool isPublic = false)
        {
            ProtoGitFolder g = _protoGits.FirstOrDefault(f => f.FolderPath == folderPath);

            if (g == null)
            {
                g = new ProtoGitFolder(new Uri(urlRepository), isPublic, folderPath, world, _secretKeyStore, this, _commandRegister);
                _protoGits.Add(g);
            }
            return(g);
        }
示例#7
0
        public override SharedWorldState GetOrCreateSharedState(IActivityMonitor m, IWorldName w)
        {
            var p = ToSharedStateFilePath(w).Item2;

            if (File.Exists(p))
            {
                return(new SharedWorldState(this, w, XDocument.Load(p, LoadOptions.SetLineInfo)));
            }
            m.Info($"Creating new shared state for {w.FullName}.");
            return(new SharedWorldState(this, w));
        }
示例#8
0
        public override bool WriteWorldDescription(IActivityMonitor m, IWorldName w, XDocument content)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            var local = ToLocal(w);

            content.Save(local.XmlDescriptionFilePath);
            OnWorkingFolderChanged(m, local);
            return(true);
        }
示例#9
0
        /// <summary>
        /// Gets or creates the <see cref="LocalWorldState"/> for a world.
        /// Default implemenation implements xml state file in the root world directory.
        /// </summary>
        /// <param name="m">The monitor to use.</param>
        /// <param name="w">The world name. It must exist in this store.</param>
        /// <returns>The existing or new world local state.</returns>
        public LocalWorldState GetOrCreateLocalState(IActivityMonitor m, IWorldName w)
        {
            if (w == null)
            {
                throw new ArgumentNullException(nameof(w));
            }
            var d = GetLocalState(m, w);

            if (d == null)
            {
                m.Info($"Creating new local state for {w.FullName}.");
            }
            return(new LocalWorldState(this, w, d));
        }
示例#10
0
        public LocalWorldState(WorldStore store, IWorldName w, XDocument d = null)
            : base(store, w, true, d)
        {
            var r = XDocument.Root;

            _generalState          = r.EnsureElement(XmlNames.xGeneralState);
            _lastBuild             = r.EnsureElement(XmlNames.xLastBuild);
            _builds                = r.EnsureElement(XmlNames.xBuilds);
            _releaseBuildResult    = _builds.EnsureElement(XmlNames.xRelease);
            _ciBuildResult         = _builds.EnsureElement(XmlNames.xCI);
            _localBuildResult      = _builds.EnsureElement(XmlNames.xLocal);
            _publishedBuildHistory = r.EnsureElement(XmlNames.xPublishedBuildHistory);
            LastBuildType          = _lastBuild.AttributeEnum(XmlNames.xType, BuildResultType.None);
            _buildResults          = new BuildResult[3];
        }
示例#11
0
 /// <summary>
 /// Gets or creates the <see cref="SharedWorldState"/> for a world.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 /// <param name="w">The world name. It must exist in this store.</param>
 /// <returns>The existing or new world shared state.</returns>
 public abstract SharedWorldState GetOrCreateSharedState(IActivityMonitor m, IWorldName w);
示例#12
0
 /// <summary>
 /// Updates the world description in this store.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 /// <param name="w">The world name that must exist in this store.</param>
 /// <param name="content">The updated content. Must not be null or empty.</param>
 /// <returns>True on success, false on error.</returns>
 public abstract bool WriteWorldDescription(IActivityMonitor m, IWorldName w, XDocument content);
示例#13
0
 /// <summary>
 /// Gets the world description of one world.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 /// <param name="w">The world that must exist in the <see cref="ReadWorlds"/> result.</param>
 /// <returns>The Xml document.</returns>
 public abstract XDocument ReadWorldDescription(IActivityMonitor m, IWorldName w);
示例#14
0
        /// <summary>
        /// Computes the path of the local state file: it is stored at the root of the world
        /// path (see <see cref="IWorldLocalMapping.GetRootPath(IWorldName)"/>).
        /// </summary>
        /// <param name="w">The world name.</param>
        /// <returns>The path to use to read/write the local state.</returns>
        protected virtual NormalizedPath ToLocalStateFilePath(IWorldName w)
        {
            var p = w is IRootedWorldName r ? r.Root : WorldLocalMapping.GetRootPath(w);

            return(p.AppendPart(w.FullName + ".World.State.xml"));
        }
示例#15
0
 /// <summary>
 /// Must saves the shared state xml document.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 /// <param name="w">The world name.</param>
 /// <param name="d">The document state.</param>
 /// <returns>True on success, false on error.</returns>
 protected abstract bool SaveSharedState(IActivityMonitor m, IWorldName w, XDocument d);
示例#16
0
 /// <summary>
 /// Saves the local state xml document in <see cref="ToLocalStateFilePath(IWorldName)"/> file.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 /// <param name="w">The world name.</param>
 /// <param name="d">The document state.</param>
 /// <returns>True on success, false on error.</returns>
 protected virtual bool SaveLocalState(IActivityMonitor m, IWorldName w, XDocument d)
 {
     d.Save(ToLocalStateFilePath(w));
     return(true);
 }
示例#17
0
        /// <summary>
        /// Gets the local state by reading the file <see cref="ToLocalStateFilePath(IWorldName)"/> if it exists.
        /// Returns null otherwise.
        /// </summary>
        /// <param name="m">The monitor to use.</param>
        /// <param name="w">The world name.</param>
        /// <returns>The Xml document or null.</returns>
        protected virtual XDocument GetLocalState(IActivityMonitor m, IWorldName w)
        {
            var path = ToLocalStateFilePath(w);

            return(File.Exists(path) ? XDocument.Load(path) : null);
        }
示例#18
0
 static string SafeElementName(IWorldName w, bool isLocal) => w.FullName.Replace('[', '-').Replace("]", "") + ".World." + (isLocal ? "" : "Shared") + "State";
示例#19
0
 public override XDocument ReadWorldDescription(IActivityMonitor m, IWorldName w)
 {
     return(XDocument.Load(ToLocal(w).XmlDescriptionFilePath, LoadOptions.SetLineInfo));
 }