public SharedWorldState(WorldStore store, IWorldName w, XDocument d = null) : base(store, w, false, d) { var r = XDocument.Root; _cidKeyVault = r.EnsureElement(XmlNames.xCICDKeyVault); }
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); }
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; }
LocalWorldName ToLocal(IWorldName w) { if (w is LocalWorldName loc) { return(loc); } throw new ArgumentException("Must be a valid LocalWorldName.", nameof(w)); }
protected override bool SaveSharedState(IActivityMonitor m, IWorldName w, XDocument d) { var p = ToSharedStateFilePath(w); d.Save(p.Item2); OnWorkingFolderChanged(m, p.Item1); return(true); }
/// <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); }
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)); }
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); }
/// <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)); }
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]; }
/// <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);
/// <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);
/// <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);
/// <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")); }
/// <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);
/// <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); }
/// <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); }
static string SafeElementName(IWorldName w, bool isLocal) => w.FullName.Replace('[', '-').Replace("]", "") + ".World." + (isLocal ? "" : "Shared") + "State";
public override XDocument ReadWorldDescription(IActivityMonitor m, IWorldName w) { return(XDocument.Load(ToLocal(w).XmlDescriptionFilePath, LoadOptions.SetLineInfo)); }