// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Text.Json.Serialization;
using EpicGames.Core;
using Horde.Server.Acls;
using Horde.Server.Agents.Pools;
using Horde.Server.Configuration;
using Horde.Server.Server;
using Horde.Server.Streams;
using HordeCommon.Rpc.Tasks;
using EpicGames.Horde.Api;
namespace Horde.Server.Projects
{
///
/// Stores configuration for a project
///
[JsonSchema("https://unrealengine.com/horde/project")]
[JsonSchemaCatalog("Horde Project", "Horde project configuration file", new[] { "*.project.json", "Projects/*.json" })]
[ConfigIncludeRoot]
[DebuggerDisplay("{Id}")]
public class ProjectConfig : IAclScope
{
///
/// Accessor for the global config owning this project
///
[JsonIgnore]
public GlobalConfig GlobalConfig { get; private set; } = null!;
///
[JsonIgnore]
public IAclScope? ParentScope => GlobalConfig;
///
[JsonIgnore]
public AclScopeName ScopeName { get; private set; }
///
/// The project id
///
public ProjectId Id { get; set; }
///
/// Name for the new project
///
public string Name { get; set; } = null!;
///
/// Direct include path for the project config. For backwards compatibility with old config files when including from a GlobalConfig object.
///
[ConfigInclude, ConfigRelativePath]
public string? Path { get; set; }
///
/// Includes for other configuration files
///
public List Include { get; set; } = new List();
///
/// Order of this project on the dashboard
///
public int Order { get; set; } = 128;
///
/// Path to the project logo
///
public ConfigResource? Logo { get; set; }
///
/// List of pools for this project
///
public List Pools { get; set; } = new List();
///
/// Categories to include in this project
///
public List Categories { get; set; } = new List();
///
/// Default settings for executing jobs
///
public JobOptions JobOptions { get; set; } = new JobOptions();
///
/// List of streams
///
public List Streams { get; set; } = new List();
///
/// Acl entries
///
public AclConfig? Acl { get; set; }
///
/// Callback after this configuration has been read
///
/// Id of this project
/// The owning global config object
public void PostLoad(ProjectId id, GlobalConfig globalConfig)
{
Id = id;
GlobalConfig = globalConfig;
ScopeName = globalConfig.ScopeName.Append("p", Id.ToString());
foreach (StreamConfig stream in Streams)
{
stream.PostLoad(stream.Id, this);
}
}
}
///
/// Information about a category to display for a stream
///
public class ProjectCategoryConfig
{
///
/// Name of this category
///
[Required]
public string Name { get; set; } = String.Empty;
///
/// Index of the row to display this category on
///
public int Row { get; set; }
///
/// Whether to show this category on the nav menu
///
public bool ShowOnNavMenu { get; set; }
///
/// Patterns for stream names to include
///
public List IncludePatterns { get; set; } = new List();
///
/// Patterns for stream names to exclude
///
public List ExcludePatterns { get; set; } = new List();
}
}