├── LICENSE.md ├── MetadataServer ├── appsettings.Development.json ├── .config │ └── dotnet-tools.json ├── Connectors │ ├── ConnectionStrings.cs │ ├── IMySqlConnector.cs │ └── MySqlConnector.cs ├── Models │ ├── LatestData.cs │ ├── CommentData.cs │ ├── TelemetryTimingData.cs │ ├── TelemetryErrorData.cs │ ├── EventData.cs │ ├── EventSummary.cs │ ├── BuildData.cs │ └── IssueData.cs ├── appsettings.json ├── MetadataServer.csproj ├── Program.cs ├── ActionConstraints │ └── ExactQueryParam.cs ├── Controllers │ ├── LatestController.cs │ ├── TelemetryController.cs │ ├── BuildController.cs │ ├── EventController.cs │ ├── CommentController.cs │ ├── ErrorController.cs │ └── IssuesController.cs ├── Properties │ └── launchSettings.json ├── Startup.cs └── Setup.sql ├── README.md ├── UnrealGameSync.sln └── .gitignore /LICENSE.md: -------------------------------------------------------------------------------- 1 | Use of the Unreal Engine is governed by the terms of the Unreal® Engine End User License Agreement, which can be found at [https://www.unrealengine.com/eula](https://www.unrealengine.com/eula). 2 | -------------------------------------------------------------------------------- /MetadataServer/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MetadataServer/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "dotnet-ef": { 6 | "version": "5.0.6", 7 | "commands": [ 8 | "dotnet-ef" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /MetadataServer/Connectors/ConnectionStrings.cs: -------------------------------------------------------------------------------- 1 | // Copyright CodeWareGames. All Rights Reserved. 2 | 3 | namespace MetadataServer.Connectors 4 | { 5 | public class ConnectionStrings 6 | { 7 | public string MySqlConnection { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MetadataServer/Models/LatestData.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | namespace MetadataServer.Models 4 | { 5 | public class LatestData 6 | { 7 | public long LastEventId { get; set; } 8 | public long LastCommentId { get; set; } 9 | public long LastBuildId { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /MetadataServer/Models/CommentData.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | namespace MetadataServer.Models 4 | { 5 | public class CommentData 6 | { 7 | public long Id; 8 | public int ChangeNumber; 9 | public string UserName; 10 | public string Text; 11 | public string Project; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MetadataServer/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*", 10 | "ConnectionStrings": { 11 | "MySqlConnection": "server=localhost;UserId=service_account_username;password=service_account_password;" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MetadataServer/Models/TelemetryTimingData.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | using System; 4 | 5 | namespace MetadataServer.Models 6 | { 7 | public class TelemetryTimingData 8 | { 9 | public string Action; 10 | public string Result; 11 | public string UserName; 12 | public string Project; 13 | public DateTime Timestamp; 14 | public float Duration; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MetadataServer/Models/TelemetryErrorData.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | using System; 4 | 5 | namespace MetadataServer.Models 6 | { 7 | public class TelemetryErrorData 8 | { 9 | public enum TelemetryErrorType 10 | { 11 | Crash, 12 | } 13 | public int Id; 14 | public TelemetryErrorType Type; 15 | public string Text; 16 | public string UserName; 17 | public string Project; 18 | public DateTime Timestamp; 19 | public string Version; 20 | public string IpAddress; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /MetadataServer/Models/EventData.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | namespace MetadataServer.Models 4 | { 5 | public class EventData 6 | { 7 | public enum EventType 8 | { 9 | Syncing, 10 | 11 | // Reviews 12 | Compiles, 13 | DoesNotCompile, 14 | Good, 15 | Bad, 16 | Unknown, 17 | 18 | // Starred builds 19 | Starred, 20 | Unstarred, 21 | 22 | // Investigating events 23 | Investigating, 24 | Resolved, 25 | } 26 | 27 | public long Id; 28 | public int Change; 29 | public string UserName; 30 | public EventType Type; 31 | public string Project; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /MetadataServer/MetadataServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | Exe 6 | MetadataServer 7 | UnrealGameSync 8 | Copyright Epic Games, Inc. All Rights Reserved. 9 | Epic Games, Inc 10 | 11 | 9c556f1b-b661-441b-bbbd-c2ab4057dc4b 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /MetadataServer/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Extensions.Hosting; 6 | 7 | namespace MetadataServer 8 | { 9 | public class Program 10 | { 11 | public static void Main(string[] args) 12 | { 13 | CreateHostBuilder(args).Build().Run(); 14 | } 15 | 16 | public static IHostBuilder CreateHostBuilder(string[] args) => 17 | Host.CreateDefaultBuilder(args) 18 | .ConfigureWebHostDefaults(webBuilder => 19 | { 20 | webBuilder.UseStartup(); 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MetadataServer/Models/EventSummary.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace MetadataServer.Models 6 | { 7 | public class EventSummary 8 | { 9 | public enum ReviewVerdict 10 | { 11 | Unknown, 12 | Good, 13 | Bad, 14 | Mixed, 15 | } 16 | 17 | public int ChangeNumber; 18 | public ReviewVerdict Verdict; 19 | public List SyncEvents = new List(); 20 | public List Reviews = new List(); 21 | public List CurrentUsers = new List(); 22 | public EventData LastStarReview; 23 | public List Builds = new List(); 24 | public List Comments = new List(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MetadataServer/Models/BuildData.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | namespace MetadataServer.Models 4 | { 5 | public class BuildData 6 | { 7 | public enum BuildDataResult 8 | { 9 | Starting, 10 | Failure, 11 | Warning, 12 | Success, 13 | Skipped, 14 | } 15 | 16 | public long Id; 17 | public int ChangeNumber; 18 | public string BuildType; 19 | public BuildDataResult Result; 20 | public string Url; 21 | public string Project; 22 | public string ArchivePath; 23 | 24 | public bool IsSuccess 25 | { 26 | get { return Result == BuildDataResult.Success || Result == BuildDataResult.Warning; } 27 | } 28 | 29 | public bool IsFailure 30 | { 31 | get { return Result == BuildDataResult.Failure; } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /MetadataServer/ActionConstraints/ExactQueryParam.cs: -------------------------------------------------------------------------------- 1 | // Copyright CodeWareGames. All Rights Reserved. 2 | 3 | using System; 4 | using System.Linq; 5 | using Microsoft.AspNetCore.Mvc.ActionConstraints; 6 | 7 | namespace MetadataServer.ActionConstraints 8 | { 9 | public class ExactQueryParamAttribute : Attribute, IActionConstraint 10 | { 11 | private readonly string[] keys; 12 | 13 | public ExactQueryParamAttribute(params string[] keys) 14 | { 15 | this.keys = keys; 16 | } 17 | 18 | public int Order => 0; 19 | 20 | public bool Accept(ActionConstraintContext context) 21 | { 22 | var query = context.RouteContext.HttpContext.Request.Query; 23 | return query.Count == keys.Length && keys.All(key => query.ContainsKey(key)); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |
3 | UnrealGameSync 4 |
5 |

6 | 7 | ![screenshot](https://docs.unrealengine.com/4.26/Images/ProductionPipelines/DeployingTheEngine/UnrealGameSync/QuickStart/UGSQS_Step1_EndResult-2.webp) 8 | 9 | This is a custom version of the MetadataServer (Component of [UnrealGameSync](https://docs.unrealengine.com/en-US/ProductionPipelines/DeployingTheEngine/UnrealGameSync/index.html)) updated to ASP.Net 5 with async/await functionality 10 | 11 | Requirements 12 | --------------------------- 13 | ASP.NET Core Runtime 5 Hosting Bundle or Above. 14 | 15 | 16 | Licensing 17 | --------------------------- 18 | 19 | The source code is governed by the [Unreal Engine End User License Agreement](https://www.unrealengine.com/eula). If you don't agree to those terms, as amended from time to time, you are not permitted to access or use the source code. 20 | 21 | 22 | -------------------------------------------------------------------------------- /MetadataServer/Controllers/LatestController.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using Microsoft.AspNetCore.Mvc; 5 | using System.Threading.Tasks; 6 | using MetadataServer.Connectors; 7 | using MetadataServer.Models; 8 | 9 | namespace MetadataServer.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class LatestController : ControllerBase 14 | { 15 | private readonly IMySqlConnector _MySqlConnector; 16 | public LatestController(IMySqlConnector MySqlConnector) 17 | { 18 | _MySqlConnector = MySqlConnector; 19 | } 20 | 21 | [HttpGet] 22 | public async Task Get(string Project = null) 23 | { 24 | return await _MySqlConnector.GetLastIds(Project); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MetadataServer/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40838", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "api/latest", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "MetadataServer": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "api/latest", 25 | "applicationUrl": "http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MetadataServer/Controllers/TelemetryController.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using Microsoft.AspNetCore.Mvc; 5 | using System.Threading.Tasks; 6 | using MetadataServer.Connectors; 7 | using MetadataServer.Models; 8 | 9 | namespace MetadataServer.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class TelemetryController : ControllerBase 14 | { 15 | private readonly IMySqlConnector _MySqlConnector; 16 | public TelemetryController(IMySqlConnector MySqlConnector) 17 | { 18 | _MySqlConnector = MySqlConnector; 19 | } 20 | 21 | [HttpPost] 22 | public async Task Post([FromBody] TelemetryTimingData Data, string Version, string IpAddress) 23 | { 24 | return await _MySqlConnector.PostTelemetryData(Data, Version, IpAddress); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MetadataServer/Controllers/BuildController.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using Microsoft.AspNetCore.Mvc; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | using MetadataServer.Connectors; 8 | using MetadataServer.Models; 9 | 10 | namespace MetadataServer.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class BuildController : ControllerBase 15 | { 16 | private readonly IMySqlConnector _MySqlConnector; 17 | public BuildController(IMySqlConnector MySqlConnector) 18 | { 19 | _MySqlConnector = MySqlConnector; 20 | } 21 | 22 | [HttpGet] 23 | public async Task> Get(string Project, long LastBuildId) 24 | { 25 | return await _MySqlConnector.GetBuilds(Project, LastBuildId); 26 | } 27 | 28 | [HttpPost] 29 | public async Task Post([FromBody]BuildData Build) 30 | { 31 | return await _MySqlConnector.PostBuild(Build); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /MetadataServer/Controllers/EventController.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using Microsoft.AspNetCore.Mvc; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | using MetadataServer.Connectors; 8 | using MetadataServer.Models; 9 | 10 | namespace MetadataServer.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class EventController : ControllerBase 15 | { 16 | private readonly IMySqlConnector _MySqlConnector; 17 | public EventController(IMySqlConnector MySqlConnector) 18 | { 19 | _MySqlConnector = MySqlConnector; 20 | } 21 | 22 | [HttpGet] 23 | public async Task> Get(string Project, long LastEventId) 24 | { 25 | return await _MySqlConnector.GetUserVotes(Project, LastEventId); 26 | } 27 | 28 | [HttpPost] 29 | public async Task Post([FromBody] EventData Event) 30 | { 31 | return await _MySqlConnector.PostEvent(Event); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /MetadataServer/Controllers/CommentController.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using Microsoft.AspNetCore.Mvc; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | using MetadataServer.Connectors; 8 | using MetadataServer.Models; 9 | 10 | namespace MetadataServer.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CommentController : ControllerBase 15 | { 16 | private readonly IMySqlConnector _MySqlConnector; 17 | public CommentController(IMySqlConnector MySqlConnector) 18 | { 19 | _MySqlConnector = MySqlConnector; 20 | } 21 | 22 | [HttpGet] 23 | public async Task> Get(string Project, long LastCommentId) 24 | { 25 | return await _MySqlConnector.GetComments(Project, LastCommentId); 26 | } 27 | 28 | [HttpPost] 29 | public async Task Post([FromBody] CommentData Comment) 30 | { 31 | return await _MySqlConnector.PostComment(Comment); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /MetadataServer/Controllers/ErrorController.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using Microsoft.AspNetCore.Mvc; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | using MetadataServer.Connectors; 8 | using MetadataServer.Models; 9 | 10 | namespace MetadataServer.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class ErrorController : ControllerBase 15 | { 16 | private readonly IMySqlConnector _MySqlConnector; 17 | public ErrorController(IMySqlConnector MySqlConnector) 18 | { 19 | _MySqlConnector = MySqlConnector; 20 | } 21 | 22 | [HttpGet] 23 | public async Task> Get(int Records = 10) 24 | { 25 | return await _MySqlConnector.GetErrorData(Records); 26 | } 27 | 28 | [HttpPost] 29 | public async Task Post([FromBody] TelemetryErrorData Data, string Version, string IpAddress) 30 | { 31 | return await _MySqlConnector.PostErrorData(Data, Version, IpAddress); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /UnrealGameSync.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31205.134 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetadataServer", "MetadataServer\MetadataServer.csproj", "{C95B3BC3-7911-473B-8D1A-57DB4E142030}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C95B3BC3-7911-473B-8D1A-57DB4E142030}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C95B3BC3-7911-473B-8D1A-57DB4E142030}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C95B3BC3-7911-473B-8D1A-57DB4E142030}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C95B3BC3-7911-473B-8D1A-57DB4E142030}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {6E1ABADE-6FD3-4895-90AE-8469AAD8094E} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /MetadataServer/Models/IssueData.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | using System; 4 | 5 | namespace MetadataServer.Models 6 | { 7 | public class IssueWatcherData 8 | { 9 | public string UserName; 10 | } 11 | 12 | public class IssueBuildData 13 | { 14 | public long Id; 15 | public string Stream; 16 | public int Change; 17 | public string JobName; 18 | public string JobUrl; 19 | public string JobStepName; 20 | public string JobStepUrl; 21 | public string ErrorUrl; 22 | public int Outcome; 23 | } 24 | 25 | public class IssueBuildUpdateData 26 | { 27 | public int Outcome; 28 | } 29 | 30 | public class IssueDiagnosticData 31 | { 32 | public long? BuildId; 33 | public string Message; 34 | public string Url; 35 | } 36 | 37 | public class IssueData 38 | { 39 | public long Id; 40 | public DateTime CreatedAt; 41 | public DateTime RetrievedAt; 42 | public string Project; 43 | public string Summary; 44 | public string Owner; 45 | public string NominatedBy; 46 | public DateTime? AcknowledgedAt; 47 | public int FixChange; 48 | public DateTime? ResolvedAt; 49 | public bool bNotify; 50 | } 51 | 52 | public class IssueUpdateData 53 | { 54 | public string Summary; 55 | public string Owner; 56 | public string NominatedBy; 57 | public bool? Acknowledged; 58 | public int? FixChange; 59 | public bool? Resolved; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /MetadataServer/Startup.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using Microsoft.AspNetCore.Builder; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Microsoft.Extensions.Hosting; 9 | using MetadataServer.Connectors; 10 | 11 | namespace MetadataServer 12 | { 13 | public class Startup 14 | { 15 | public Startup(IConfiguration configuration) 16 | { 17 | Configuration = configuration; 18 | } 19 | 20 | public IConfiguration Configuration { get; } 21 | 22 | public void ConfigureServices(IServiceCollection services) 23 | { 24 | 25 | services.AddControllers().AddNewtonsoftJson(); 26 | services.Configure(Configuration.GetSection("ConnectionStrings")); 27 | services.AddSingleton(); 28 | } 29 | 30 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 31 | { 32 | if (env.IsDevelopment()) 33 | { 34 | app.UseDeveloperExceptionPage(); 35 | } 36 | 37 | app.UseRouting(); 38 | 39 | app.UseAuthorization(); 40 | 41 | app.UseEndpoints(endpoints => 42 | { 43 | endpoints.MapControllers(); 44 | }); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /MetadataServer/Connectors/IMySqlConnector.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using MetadataServer.Models; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | 8 | 9 | namespace MetadataServer.Connectors 10 | { 11 | public interface IMySqlConnector 12 | { 13 | Task GetLastIds(string Project); 14 | Task> GetUserVotes(string Project, long LastEventId); 15 | Task> GetComments(string Project, long LastCommentId); 16 | Task> GetBuilds(string Project, long LastBuildId); 17 | Task> GetErrorData(int Records); 18 | Task PostBuild(BuildData Build); 19 | Task PostEvent(EventData Event); 20 | Task PostComment(CommentData Comment); 21 | Task PostTelemetryData(TelemetryTimingData Data, string Version, string IpAddress); 22 | Task PostErrorData(TelemetryErrorData Data, string Version, string IpAddress); 23 | Task FindOrAddUserId(string Name); 24 | Task AddIssue(IssueData Issue); 25 | Task GetIssue(long IssueId); 26 | Task> GetIssues(bool IncludeResolved, int NumResults); 27 | Task> GetIssues(string UserName); 28 | Task UpdateIssue(long IssueId, IssueUpdateData Issue); 29 | string SanitizeText(string Text, int Length); 30 | Task DeleteIssue(long IssueId); 31 | Task AddDiagnostic(long IssueId, IssueDiagnosticData Diagnostic); 32 | Task> GetDiagnostics(long IssueId); 33 | Task AddWatcher(long IssueId, string UserName); 34 | Task> GetWatchers(long IssueId); 35 | Task RemoveWatcher(long IssueId, string UserName); 36 | Task AddBuild(long IssueId, IssueBuildData Build); 37 | Task> GetBuilds(long IssueId); 38 | Task GetBuild(long BuildId); 39 | Task UpdateBuild(long BuildId, int Outcome); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /MetadataServer/Setup.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS ugs_db; 2 | 3 | CREATE TABLE IF NOT EXISTS ugs_db.Projects ( 4 | Id INT NOT NULL AUTO_INCREMENT, 5 | `Name` NVARCHAR(128) NOT NULL UNIQUE, 6 | PRIMARY KEY ( Id ) 7 | ); 8 | 9 | CREATE TABLE IF NOT EXISTS ugs_db.CIS ( 10 | Id INT NOT NULL AUTO_INCREMENT, 11 | ChangeNumber INT NOT NULL, 12 | BuildType NCHAR(32) NOT NULL, 13 | Result NCHAR(10) NOT NULL, 14 | Url VARCHAR(512) NOT NULL, 15 | Project VARCHAR(512) NULL, 16 | ProjectId INTEGER NULL, 17 | ArchivePath VARCHAR(512) NULL, 18 | PRIMARY KEY ( Id ), 19 | FOREIGN KEY(ProjectId) REFERENCES Projects(Id) 20 | ); 21 | 22 | CREATE TABLE IF NOT EXISTS ugs_db.Comments ( 23 | Id INT NOT NULL AUTO_INCREMENT, 24 | ChangeNumber INT NOT NULL, 25 | UserName VARCHAR(128) NOT NULL, 26 | Text VARCHAR(1024) NOT NULL, 27 | Project VARCHAR(128) NOT NULL, 28 | ProjectId INTEGER NULL, 29 | PRIMARY KEY ( Id ), 30 | FOREIGN KEY(ProjectId) REFERENCES Projects(Id) 31 | ); 32 | 33 | CREATE TABLE IF NOT EXISTS ugs_db.Errors ( 34 | Id INT NOT NULL AUTO_INCREMENT, 35 | Type VARCHAR(50) NOT NULL, 36 | Text VARCHAR(1024) NOT NULL, 37 | UserName NVARCHAR(128) NOT NULL, 38 | Project VARCHAR(128) NOT NULL, 39 | ProjectId INTEGER NULL, 40 | Timestamp DATETIME NOT NULL, 41 | Version VARCHAR(64) NOT NULL, 42 | IpAddress VARCHAR(64) NOT NULL, 43 | PRIMARY KEY ( Id ), 44 | FOREIGN KEY(ProjectId) REFERENCES Projects(Id) 45 | ); 46 | 47 | CREATE TABLE IF NOT EXISTS ugs_db.Telemetry_v2 ( 48 | Id INT NOT NULL AUTO_INCREMENT, 49 | Action VARCHAR(128) NOT NULL, 50 | Result VARCHAR(128) NOT NULL, 51 | UserName VARCHAR(128) NOT NULL, 52 | Project VARCHAR(128) NOT NULL, 53 | ProjectId INTEGER NULL, 54 | Timestamp DATETIME NOT NULL, 55 | Duration REAL NOT NULL, 56 | Version VARCHAR(64) NOT NULL, 57 | IpAddress VARCHAR(64) NOT NULL, 58 | PRIMARY KEY ( Id ), 59 | FOREIGN KEY(ProjectId) REFERENCES Projects(Id) 60 | ); 61 | 62 | CREATE TABLE IF NOT EXISTS ugs_db.UserVotes ( 63 | Id INT NOT NULL AUTO_INCREMENT, 64 | Changelist INT NOT NULL, 65 | UserName NVARCHAR(128) NOT NULL, 66 | Verdict NCHAR(32) NOT NULL, 67 | Project NVARCHAR(256) NULL, 68 | ProjectId INTEGER NULL, 69 | PRIMARY KEY ( Id ), 70 | FOREIGN KEY(ProjectId) REFERENCES Projects(Id) 71 | ); 72 | 73 | CREATE TABLE IF NOT EXISTS ugs_db.Issues ( 74 | Id INT NOT NULL AUTO_INCREMENT, 75 | CreatedAt DATETIME NOT NULL, 76 | Project NVARCHAR(64) NOT NULL, 77 | Summary NVARCHAR(256) NOT NULL, 78 | OwnerId INT NULL, 79 | NominatedById INT NULL, 80 | AcknowledgedAt DATETIME NULL, 81 | FixChange INT NULL, 82 | ResolvedAt DATETIME NULL, 83 | PRIMARY KEY ( Id ) 84 | ); 85 | 86 | CREATE TABLE IF NOT EXISTS ugs_db.IssueBuilds ( 87 | Id INT NOT NULL AUTO_INCREMENT, 88 | IssueId INT NOT NULL, 89 | Stream NVARCHAR(128) NOT NULL, 90 | `Change` INT NOT NULL, 91 | JobName NVARCHAR(1024) NOT NULL, 92 | JobUrl NVARCHAR(1024) NOT NULL, 93 | JobStepName NVARCHAR(1024) NULL, 94 | JobStepUrl NVARCHAR(1024) NULL, 95 | ErrorUrl NVARCHAR(1024) NULL, 96 | Outcome INT NOT NULL, 97 | PRIMARY KEY ( Id ), 98 | FOREIGN KEY(IssueId) REFERENCES Issues(Id) 99 | ); 100 | 101 | CREATE TABLE IF NOT EXISTS ugs_db.IssueDiagnostics ( 102 | Id INT NOT NULL AUTO_INCREMENT, 103 | IssueId INT NOT NULL, 104 | BuildId INT NULL, 105 | Message NVARCHAR (1024) NOT NULL, 106 | Url NVARCHAR (1024) NULL, 107 | PRIMARY KEY ( Id ), 108 | FOREIGN KEY(IssueId) REFERENCES Issues(Id), 109 | FOREIGN KEY(BuildId) REFERENCES IssueBuilds(Id) 110 | ); 111 | 112 | CREATE TABLE IF NOT EXISTS ugs_db.Users ( 113 | Id INT NOT NULL AUTO_INCREMENT, 114 | `Name` NVARCHAR(128) NOT NULL UNIQUE, 115 | PRIMARY KEY ( Id ) 116 | ); 117 | 118 | CREATE TABLE IF NOT EXISTS ugs_db.IssueWatchers ( 119 | IssueId INT NOT NULL, 120 | UserId INT NOT NULL, 121 | PRIMARY KEY(IssueId, UserId), 122 | FOREIGN KEY(IssueId) REFERENCES Issues(Id), 123 | FOREIGN KEY(UserId) REFERENCES Users(Id) 124 | ); 125 | 126 | CREATE TABLE IF NOT EXISTS ugs_db.Badges ( 127 | Id INT NOT NULL AUTO_INCREMENT, 128 | ChangeNumber INT NOT NULL, 129 | BuildType NVARCHAR(32) NOT NULL, 130 | Result NVARCHAR(10) NOT NULL, 131 | Url NVARCHAR(512) NOT NULL, 132 | ProjectId INT NOT NULL, 133 | ArchivePath NVARCHAR(512) NULL, 134 | PRIMARY KEY ( Id ), 135 | FOREIGN KEY(ProjectId) REFERENCES Projects(Id) 136 | ); -------------------------------------------------------------------------------- /MetadataServer/Controllers/IssuesController.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using Microsoft.AspNetCore.Mvc; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | using MetadataServer.Connectors; 8 | using MetadataServer.Models; 9 | using MetadataServer.ActionConstraints; 10 | 11 | namespace MetadataServer.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class IssuesController : ControllerBase 16 | { 17 | private readonly IMySqlConnector _MySqlConnector; 18 | public IssuesController(IMySqlConnector MySqlConnector) 19 | { 20 | _MySqlConnector = MySqlConnector; 21 | } 22 | 23 | [HttpGet] 24 | public async Task> Get([FromQuery] bool IncludeResolved = false, [FromQuery] int MaxResults = -1) 25 | { 26 | return await _MySqlConnector.GetIssues(IncludeResolved, MaxResults); 27 | } 28 | 29 | [HttpGet] 30 | [ExactQueryParam("user")] 31 | public async Task> Get([FromQuery] string User) 32 | { 33 | return await _MySqlConnector.GetIssues(User); 34 | } 35 | 36 | [HttpGet] 37 | [Route("{id}")] 38 | public async Task Get(long id) 39 | { 40 | return await _MySqlConnector.GetIssue(id); 41 | } 42 | 43 | [HttpPut] 44 | public async Task Put(long id, IssueUpdateData Issue) 45 | { 46 | return await _MySqlConnector.UpdateIssue(id, Issue); 47 | } 48 | 49 | [HttpPost] 50 | public async Task Post(IssueData Issue) 51 | { 52 | long IssueId = await _MySqlConnector.AddIssue(Issue); 53 | return new { Id = IssueId }; 54 | } 55 | 56 | [HttpDelete] 57 | public async Task Delete(long id) 58 | { 59 | return await _MySqlConnector.DeleteIssue(id); 60 | } 61 | 62 | 63 | } 64 | 65 | [Route("api/issues/{IssueId}/builds")] 66 | [ApiController] 67 | public class IssueBuildsSubController : ControllerBase 68 | { 69 | private readonly IMySqlConnector _MySqlConnector; 70 | public IssueBuildsSubController(IMySqlConnector MySqlConnector) 71 | { 72 | _MySqlConnector = MySqlConnector; 73 | } 74 | 75 | [HttpGet] 76 | public async Task> Get(long IssueId) 77 | { 78 | return await _MySqlConnector.GetBuilds(IssueId); 79 | } 80 | 81 | [HttpPost] 82 | public async Task Post(long IssueId, [FromBody] IssueBuildData Data) 83 | { 84 | long BuildId = await _MySqlConnector.AddBuild(IssueId, Data); 85 | return new { Id = BuildId }; 86 | } 87 | } 88 | 89 | [Route("api/issues/{IssueId}/diagnostics")] 90 | [ApiController] 91 | public class IssueDiagnosticsSubController : ControllerBase 92 | { 93 | private readonly IMySqlConnector _MySqlConnector; 94 | public IssueDiagnosticsSubController(IMySqlConnector MySqlConnector) 95 | { 96 | _MySqlConnector = MySqlConnector; 97 | } 98 | 99 | [HttpGet] 100 | public async Task> Get(long IssueId) 101 | { 102 | return await _MySqlConnector.GetDiagnostics(IssueId); 103 | } 104 | 105 | [HttpPost] 106 | public async Task Post(long IssueId, [FromBody] IssueDiagnosticData Data) 107 | { 108 | return await _MySqlConnector.AddDiagnostic(IssueId, Data); 109 | } 110 | } 111 | 112 | [Route("api/issuebuilds/{BuildId}")] 113 | [ApiController] 114 | public class IssueBuildsController : ControllerBase 115 | { 116 | private readonly IMySqlConnector _MySqlConnector; 117 | public IssueBuildsController(IMySqlConnector MySqlConnector) 118 | { 119 | _MySqlConnector = MySqlConnector; 120 | } 121 | 122 | [HttpGet] 123 | public async Task Get(long BuildId) 124 | { 125 | return await _MySqlConnector.GetBuild(BuildId); 126 | } 127 | 128 | [HttpPut] 129 | public async Task Put(long BuildId, [FromBody] IssueBuildUpdateData Data) 130 | { 131 | return await _MySqlConnector.UpdateBuild(BuildId, Data.Outcome); 132 | } 133 | } 134 | 135 | [Route("api/issues/{IssueId}/watchers")] 136 | [ApiController] 137 | public class IssueWatchersController : ControllerBase 138 | { 139 | private readonly IMySqlConnector _MySqlConnector; 140 | public IssueWatchersController(IMySqlConnector MySqlConnector) 141 | { 142 | _MySqlConnector = MySqlConnector; 143 | } 144 | 145 | [HttpGet] 146 | public async Task> Get(long IssueId) 147 | { 148 | return await _MySqlConnector.GetWatchers(IssueId); 149 | } 150 | 151 | [HttpPost] 152 | public async Task Post(long IssueId, [FromBody] IssueWatcherData Data) 153 | { 154 | return await _MySqlConnector.AddWatcher(IssueId, Data.UserName); 155 | } 156 | 157 | [HttpDelete] 158 | public async Task Delete(long IssueId, [FromBody] IssueWatcherData Data) 159 | { 160 | return await _MySqlConnector.RemoveWatcher(IssueId, Data.UserName); 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Nuget personal access tokens and Credentials 210 | nuget.config 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | # Ionide (cross platform F# VS Code tools) working folder 363 | .ionide/ 364 | 365 | # Fody - auto-generated XML schema 366 | FodyWeavers.xsd 367 | 368 | # VS Code files for those working on multiple tools 369 | .vscode/* 370 | !.vscode/settings.json 371 | !.vscode/tasks.json 372 | !.vscode/launch.json 373 | !.vscode/extensions.json 374 | *.code-workspace 375 | 376 | # Local History for Visual Studio Code 377 | .history/ 378 | 379 | # Windows Installer files from build outputs 380 | *.cab 381 | *.msi 382 | *.msix 383 | *.msm 384 | *.msp 385 | 386 | # JetBrains Rider 387 | .idea/ 388 | *.sln.iml -------------------------------------------------------------------------------- /MetadataServer/Connectors/MySqlConnector.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | // Modifications Copyright CodeWareGames. All Rights Reserved. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using Microsoft.Extensions.Options; 10 | using MySql.Data.MySqlClient; 11 | using MetadataServer.Models; 12 | 13 | namespace MetadataServer.Connectors 14 | { 15 | public class MySqlConnector : IMySqlConnector 16 | { 17 | private readonly ConnectionStrings _connectionStrings; 18 | public MySqlConnector(IOptions connectionStrings) 19 | { 20 | _connectionStrings = connectionStrings.Value; 21 | } 22 | public async Task GetLastIds(string Project = null) 23 | { 24 | // Get ids going back 432 builds for the project being asked for 25 | // Do this by grouping by ChangeNumber to get unique entries, then take the 432nd id 26 | long LastEventId = 0; 27 | long LastCommentId = 0; 28 | long LastBuildId = 0; 29 | string ProjectLikeString = "%" + (Project == null ? String.Empty : GetProjectStream(Project)) + "%"; 30 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 31 | { 32 | await Connection.OpenAsync(); 33 | using (MySqlCommand Command = new MySqlCommand("WITH user_votes AS (SELECT UserVotes.Id, UserVotes.Changelist FROM ugs_db.UserVotes " + 34 | "INNER JOIN ugs_db.Projects ON Projects.Id = UserVotes.ProjectId " + 35 | "WHERE Projects.Name LIKE @param1 GROUP BY Changelist ORDER BY Changelist DESC LIMIT 100) " + 36 | "SELECT * FROM user_votes ORDER BY user_votes.Changelist ASC LIMIT 1", Connection)) 37 | { 38 | Command.Parameters.AddWithValue("@param1", ProjectLikeString); 39 | using (var Reader = await Command.ExecuteReaderAsync()) 40 | { 41 | while (await Reader.ReadAsync()) 42 | { 43 | LastEventId = Reader.GetInt64(0); 44 | break; 45 | } 46 | } 47 | } 48 | 49 | using (MySqlCommand Command = new MySqlCommand("WITH comments AS (SELECT Comments.Id, Comments.ChangeNumber FROM ugs_db.Comments " + 50 | "INNER JOIN ugs_db.Projects ON Projects.Id = Comments.ProjectId " + 51 | "WHERE Projects.Name LIKE @param1 GROUP BY ChangeNumber ORDER BY ChangeNumber DESC LIMIT 100) " + 52 | "SELECT * FROM comments ORDER BY comments.ChangeNumber ASC LIMIT 1", Connection)) 53 | { 54 | Command.Parameters.AddWithValue("@param1", ProjectLikeString); 55 | using (var Reader = await Command.ExecuteReaderAsync()) 56 | { 57 | while (await Reader.ReadAsync()) 58 | { 59 | LastCommentId = Reader.GetInt32(0); 60 | break; 61 | } 62 | } 63 | } 64 | 65 | using (MySqlCommand Command = new MySqlCommand("WITH badges AS (SELECT Badges.Id, Badges.ChangeNumber FROM ugs_db.Badges " + 66 | "INNER JOIN ugs_db.Projects ON Projects.Id = Badges.ProjectId " + 67 | "WHERE Projects.Name LIKE @param1 GROUP BY ChangeNumber ORDER BY ChangeNumber DESC LIMIT 100) " + 68 | "SELECT * FROM badges ORDER BY badges.ChangeNumber ASC LIMIT 1", Connection)) 69 | { 70 | //Command.Parameters.AddWithValue("@param1", ProjectId); 71 | Command.Parameters.AddWithValue("@param1", ProjectLikeString); 72 | using (var Reader = await Command.ExecuteReaderAsync()) 73 | { 74 | while (await Reader.ReadAsync()) 75 | { 76 | LastBuildId = Math.Max(LastBuildId, Reader.GetInt32(0)); 77 | break; 78 | } 79 | } 80 | } 81 | } 82 | return new LatestData { LastBuildId = LastBuildId, LastCommentId = LastCommentId, LastEventId = LastEventId }; 83 | } 84 | 85 | public async Task> GetUserVotes(string Project, long LastEventId) 86 | { 87 | List ReturnedEvents = new List(); 88 | string ProjectLikeString = "%" + (Project == null ? String.Empty : GetProjectStream(Project)) + "%"; 89 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 90 | { 91 | await Connection.OpenAsync(); 92 | using (MySqlCommand Command = new MySqlCommand("SELECT UserVotes.Id, UserVotes.Changelist, UserVotes.UserName, UserVotes.Verdict, UserVotes.Project FROM ugs_db.UserVotes " + 93 | "INNER JOIN ugs_db.Projects ON Projects.Id = UserVotes.ProjectId WHERE UserVotes.Id > @param1 AND Projects.Name LIKE @param2 ORDER BY UserVotes.Id", Connection)) 94 | { 95 | Command.Parameters.AddWithValue("@param1", LastEventId); 96 | Command.Parameters.AddWithValue("@param2", ProjectLikeString); 97 | using (var Reader = await Command.ExecuteReaderAsync()) 98 | { 99 | while (await Reader.ReadAsync()) 100 | { 101 | EventData Review = new EventData(); 102 | Review.Id = Reader.GetInt64(0); 103 | Review.Change = Reader.GetInt32(1); 104 | Review.UserName = Reader.GetString(2); 105 | Review.Project = Reader.IsDBNull(4) ? null : Reader.GetString(4); 106 | if (Enum.TryParse(Reader.GetString(3), out Review.Type)) 107 | { 108 | if (Review.Project == null || String.Compare(Review.Project, Project, true) == 0) 109 | { 110 | ReturnedEvents.Add(Review); 111 | } 112 | } 113 | } 114 | } 115 | } 116 | } 117 | return ReturnedEvents; 118 | } 119 | 120 | public async Task> GetComments(string Project, long LastCommentId) 121 | { 122 | List ReturnedComments = new List(); 123 | string ProjectLikeString = "%" + (Project == null ? String.Empty : GetProjectStream(Project)) + "%"; 124 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 125 | { 126 | await Connection.OpenAsync(); 127 | using (MySqlCommand Command = new MySqlCommand("SELECT Comments.Id, Comments.ChangeNumber, Comments.UserName, Comments.Text, Comments.Project FROM ugs_db.Comments " + 128 | "INNER JOIN ugs_db.Projects ON Projects.Id = Comments.ProjectId WHERE Comments.Id > @param1 AND Projects.Name LIKE @param2 ORDER BY Comments.Id", Connection)) 129 | { 130 | Command.Parameters.AddWithValue("@param1", LastCommentId); 131 | Command.Parameters.AddWithValue("@param2", ProjectLikeString); 132 | using (var Reader = await Command.ExecuteReaderAsync()) 133 | { 134 | while (await Reader.ReadAsync()) 135 | { 136 | CommentData Comment = new CommentData(); 137 | Comment.Id = Reader.GetInt32(0); 138 | Comment.ChangeNumber = Reader.GetInt32(1); 139 | Comment.UserName = Reader.GetString(2); 140 | Comment.Text = Reader.GetString(3); 141 | Comment.Project = Reader.GetString(4); 142 | if (Comment.Project == null || String.Compare(Comment.Project, Project, true) == 0) 143 | { 144 | ReturnedComments.Add(Comment); 145 | } 146 | } 147 | } 148 | } 149 | } 150 | return ReturnedComments; 151 | } 152 | 153 | public async Task> GetBuilds(string Project, long LastBuildId) 154 | { 155 | List ReturnedBuilds = new List(); 156 | string ProjectLikeString = "%" + (Project == null ? String.Empty : GetProjectStream(Project)) + "%"; 157 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 158 | { 159 | await Connection.OpenAsync(); 160 | using (MySqlCommand Command = new MySqlCommand("SELECT Badges.Id, Badges.ChangeNumber, Badges.BuildType, Badges.Result, Badges.Url, Projects.Name, Badges.ArchivePath FROM ugs_db.Badges " + 161 | "INNER JOIN ugs_db.Projects ON Projects.Id = Badges.ProjectId WHERE Badges.Id > @param1 AND Projects.Name LIKE @param2 ORDER BY Badges.Id", Connection)) 162 | { 163 | Command.Parameters.AddWithValue("@param1", LastBuildId); 164 | Command.Parameters.AddWithValue("@param2", ProjectLikeString); 165 | using (var Reader = await Command.ExecuteReaderAsync()) 166 | { 167 | while (await Reader.ReadAsync()) 168 | { 169 | BuildData Build = new BuildData(); 170 | Build.Id = Reader.GetInt32(0); 171 | Build.ChangeNumber = Reader.GetInt32(1); 172 | Build.BuildType = Reader.GetString(2).TrimEnd(); 173 | if (Enum.TryParse(Reader.GetString(3).TrimEnd(), true, out Build.Result)) 174 | { 175 | Build.Url = Reader.GetString(4); 176 | Build.Project = Reader.IsDBNull(5) ? null : Reader.GetString(5); 177 | if (Build.Project == null || String.Compare(Build.Project, Project, true) == 0 || MatchesWildcard(Build.Project, Project)) 178 | { 179 | ReturnedBuilds.Add(Build); 180 | } 181 | } 182 | LastBuildId = Math.Max(LastBuildId, Build.Id); 183 | } 184 | } 185 | } 186 | } 187 | return ReturnedBuilds; 188 | } 189 | 190 | public async Task> GetErrorData(int Records) 191 | { 192 | List ReturnedErrors = new List(); 193 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 194 | { 195 | await Connection.OpenAsync(); 196 | using (MySqlCommand Command = new MySqlCommand("SELECT Id, Type, Text, UserName, Project, Timestamp, Version, IpAddress FROM ugs_db.Errors ORDER BY Id DESC LIMIT @param1", Connection)) 197 | { 198 | Command.Parameters.AddWithValue("@param1", Records); 199 | using (var Reader = await Command.ExecuteReaderAsync()) 200 | { 201 | while (await Reader.ReadAsync()) 202 | { 203 | TelemetryErrorData Error = new TelemetryErrorData(); 204 | Error.Id = Reader.GetInt32(0); 205 | Enum.TryParse(Reader.GetString(1), true, out Error.Type); 206 | Error.Text = Reader.GetString(2); 207 | Error.UserName = Reader.GetString(3); 208 | Error.Project = Reader.IsDBNull(4) ? null : Reader.GetString(4); 209 | Error.Timestamp = Reader.GetDateTime(5); 210 | Error.Version = Reader.GetString(6); 211 | Error.IpAddress = Reader.GetString(7); 212 | ReturnedErrors.Add(Error); 213 | } 214 | } 215 | } 216 | return ReturnedErrors; 217 | } 218 | } 219 | 220 | private async Task TryInsertAndGetProject(MySqlConnection Connection, string Project) 221 | { 222 | using (MySqlCommand Command = new MySqlCommand("INSERT IGNORE INTO ugs_db.Projects (Name) VALUES (@Project); SELECT Id FROM ugs_db.Projects WHERE Name = @Project", Connection)) 223 | { 224 | Command.Parameters.AddWithValue("@Project", Project); 225 | object ProjectId = await Command.ExecuteScalarAsync(); 226 | return Convert.ToInt64(ProjectId); 227 | } 228 | } 229 | 230 | public async Task PostBuild(BuildData Build) 231 | { 232 | long AffectedRows; 233 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 234 | { 235 | await Connection.OpenAsync(); 236 | long ProjectId = await TryInsertAndGetProject(Connection, Build.Project); 237 | using (MySqlCommand Command = new MySqlCommand("INSERT INTO ugs_db.Badges (ChangeNumber, BuildType, Result, URL, ArchivePath, ProjectId) VALUES (@ChangeNumber, @BuildType, @Result, @URL, @ArchivePath, @ProjectId)", Connection)) 238 | { 239 | Command.Parameters.AddWithValue("@ChangeNumber", Build.ChangeNumber); 240 | Command.Parameters.AddWithValue("@BuildType", Build.BuildType); 241 | Command.Parameters.AddWithValue("@Result", Build.Result); 242 | Command.Parameters.AddWithValue("@URL", Build.Url); 243 | Command.Parameters.AddWithValue("@ArchivePath", Build.ArchivePath); 244 | Command.Parameters.AddWithValue("@ProjectId", ProjectId); 245 | AffectedRows = await Command.ExecuteNonQueryAsync(); 246 | } 247 | } 248 | return AffectedRows; 249 | } 250 | 251 | public async Task PostEvent(EventData Event) 252 | { 253 | long AffectedRows; 254 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 255 | { 256 | await Connection.OpenAsync(); 257 | long ProjectId = await TryInsertAndGetProject(Connection, Event.Project); 258 | using (MySqlCommand Command = new MySqlCommand("INSERT INTO ugs_db.UserVotes (Changelist, UserName, Verdict, Project, ProjectId) VALUES (@Changelist, @UserName, @Verdict, @Project, @ProjectId)", Connection)) 259 | { 260 | Command.Parameters.AddWithValue("@Changelist", Event.Change); 261 | Command.Parameters.AddWithValue("@UserName", Event.UserName.ToString()); 262 | Command.Parameters.AddWithValue("@Verdict", Event.Type.ToString()); 263 | Command.Parameters.AddWithValue("@Project", Event.Project); 264 | Command.Parameters.AddWithValue("@ProjectId", ProjectId); 265 | AffectedRows = await Command.ExecuteNonQueryAsync(); 266 | } 267 | } 268 | return AffectedRows; 269 | } 270 | 271 | public async Task PostComment(CommentData Comment) 272 | { 273 | long AffectedRows; 274 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 275 | { 276 | await Connection.OpenAsync(); 277 | long ProjectId = await TryInsertAndGetProject(Connection, Comment.Project); 278 | using (MySqlCommand Command = new MySqlCommand("INSERT INTO ugs_db.Comments (ChangeNumber, UserName, Text, Project, ProjectId) VALUES (@ChangeNumber, @UserName, @Text, @Project, @ProjectId)", Connection)) 279 | { 280 | Command.Parameters.AddWithValue("@ChangeNumber", Comment.ChangeNumber); 281 | Command.Parameters.AddWithValue("@UserName", Comment.UserName); 282 | Command.Parameters.AddWithValue("@Text", Comment.Text); 283 | Command.Parameters.AddWithValue("@Project", Comment.Project); 284 | Command.Parameters.AddWithValue("@ProjectId", ProjectId); 285 | AffectedRows = await Command.ExecuteNonQueryAsync(); 286 | } 287 | } 288 | return AffectedRows; 289 | } 290 | 291 | public async Task PostTelemetryData(TelemetryTimingData Data, string Version, string IpAddress) 292 | { 293 | long AffectedRows; 294 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 295 | { 296 | await Connection.OpenAsync(); 297 | long ProjectId = await TryInsertAndGetProject(Connection, Data.Project); 298 | using (MySqlCommand Command = new MySqlCommand("INSERT INTO ugs_db.Telemetry_v2 (Action, Result, UserName, Project, Timestamp, Duration, Version, IpAddress, ProjectId) VALUES (@Action, @Result, @UserName, @Project, @Timestamp, @Duration, @Version, @IpAddress, @ProjectId)", Connection)) 299 | { 300 | Command.Parameters.AddWithValue("@Action", Data.Action); 301 | Command.Parameters.AddWithValue("@Result", Data.Result); 302 | Command.Parameters.AddWithValue("@UserName", Data.UserName); 303 | Command.Parameters.AddWithValue("@Project", Data.Project); 304 | Command.Parameters.AddWithValue("@Timestamp", Data.Timestamp); 305 | Command.Parameters.AddWithValue("@Duration", Data.Duration); 306 | Command.Parameters.AddWithValue("@Version", Version); 307 | Command.Parameters.AddWithValue("@IPAddress", IpAddress); 308 | Command.Parameters.AddWithValue("@ProjectId", ProjectId); 309 | AffectedRows = await Command.ExecuteNonQueryAsync(); 310 | } 311 | } 312 | return AffectedRows; 313 | } 314 | 315 | public async Task PostErrorData(TelemetryErrorData Data, string Version, string IpAddress) 316 | { 317 | long AffectedRows; 318 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 319 | { 320 | await Connection.OpenAsync(); 321 | long? ProjectId = null; 322 | if (Data.Project != null) 323 | { 324 | ProjectId = await TryInsertAndGetProject(Connection, Data.Project); 325 | } 326 | using (MySqlCommand Command = new MySqlCommand("INSERT INTO ugs_db.Errors (Type, Text, UserName, Project, Timestamp, Version, IpAddress, ProjectId) VALUES (@Type, @Text, @UserName, @Project, @Timestamp, @Version, @IpAddress, @ProjectId)", Connection)) 327 | { 328 | Command.Parameters.AddWithValue("@Type", Data.Type.ToString()); 329 | Command.Parameters.AddWithValue("@Text", Data.Text); 330 | Command.Parameters.AddWithValue("@UserName", Data.UserName); 331 | if (Data.Project == null) 332 | { 333 | Command.Parameters.AddWithValue("@Project", DBNull.Value); 334 | Command.Parameters.AddWithValue("@ProjectId", DBNull.Value); 335 | } 336 | else 337 | { 338 | Command.Parameters.AddWithValue("@Project", Data.Project); 339 | Command.Parameters.AddWithValue("@ProjectId", ProjectId.Value); 340 | } 341 | Command.Parameters.AddWithValue("@Timestamp", Data.Timestamp); 342 | Command.Parameters.AddWithValue("@Version", Version); 343 | Command.Parameters.AddWithValue("@IPAddress", IpAddress); 344 | AffectedRows = await Command.ExecuteNonQueryAsync(); 345 | } 346 | } 347 | return AffectedRows; 348 | } 349 | 350 | private string GetProjectStream(string Project) 351 | { 352 | // Get first two fragments of the p4 path. If it doesn't work, just return back the project. 353 | Regex StreamPattern = new Regex("(\\/\\/[a-zA-Z0-9\\.\\-_]{1,}\\/[a-zA-Z0-9\\.\\-_]{1,})"); 354 | Match StreamMatch = StreamPattern.Match(Project); 355 | if (StreamMatch.Success) 356 | { 357 | return StreamMatch.Groups[1].Value; 358 | } 359 | return Project; 360 | } 361 | 362 | private bool MatchesWildcard(string Wildcard, string Project) 363 | { 364 | return Wildcard.EndsWith("...") && Project.StartsWith(Wildcard.Substring(0, Wildcard.Length - 4), StringComparison.InvariantCultureIgnoreCase); 365 | } 366 | 367 | private string NormalizeUserName(string UserName) 368 | { 369 | return UserName.ToUpperInvariant(); 370 | } 371 | 372 | public async Task FindOrAddUserId(string Name) 373 | { 374 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 375 | { 376 | await Connection.OpenAsync(); 377 | return await FindOrAddUserId(Name, Connection); 378 | } 379 | } 380 | 381 | private async Task FindOrAddUserId(string Name, MySqlConnection Connection) 382 | { 383 | if (Name.Length == 0) 384 | { 385 | return -1; 386 | } 387 | 388 | string NormalizedName = NormalizeUserName(Name); 389 | 390 | using (MySqlCommand Command = new MySqlCommand("SELECT Id FROM ugs_db.Users WHERE Name = @Name", Connection)) 391 | { 392 | Command.Parameters.AddWithValue("@Name", NormalizedName); 393 | object UserId = await Command.ExecuteScalarAsync(); 394 | if (UserId != null) 395 | { 396 | return Convert.ToInt64(UserId); 397 | } 398 | } 399 | 400 | using (MySqlCommand Command = new MySqlCommand("INSERT IGNORE INTO ugs_db.Users (Name) VALUES (@Name); SELECT Id FROM ugs_db.Users WHERE Name = @Name", Connection)) 401 | { 402 | Command.Parameters.AddWithValue("@Name", NormalizedName); 403 | object UserId = await Command.ExecuteScalarAsync(); 404 | return Convert.ToInt64(UserId); 405 | } 406 | } 407 | 408 | const int IssueSummaryMaxLength = 200; 409 | 410 | public async Task AddIssue(IssueData Issue) 411 | { 412 | long IssueId; 413 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 414 | { 415 | await Connection.OpenAsync(); 416 | using (MySqlCommand Command = new MySqlCommand("INSERT INTO ugs_db.Issues (Project, Summary, OwnerId, CreatedAt, FixChange) VALUES (@Project, @Summary, @OwnerId, UTC_TIMESTAMP(), 0)", Connection)) 417 | { 418 | Command.Parameters.AddWithValue("@Project", Issue.Project); 419 | Command.Parameters.AddWithValue("@Summary", SanitizeText(Issue.Summary, IssueSummaryMaxLength)); 420 | if (Issue.Owner != null) 421 | { 422 | Command.Parameters.AddWithValue("OwnerId", await FindOrAddUserId(Issue.Owner, Connection)); 423 | } 424 | else 425 | { 426 | Command.Parameters.AddWithValue("OwnerId", null); 427 | } 428 | await Command.ExecuteNonQueryAsync(); 429 | 430 | IssueId = Command.LastInsertedId; 431 | } 432 | } 433 | return IssueId; 434 | } 435 | 436 | public async Task GetIssue(long IssueId) 437 | { 438 | List Issues = await GetIssuesInternal(IssueId, null, true, -1); 439 | if (Issues.Count == 0) 440 | { 441 | return null; 442 | } 443 | else 444 | { 445 | return Issues[0]; 446 | } 447 | } 448 | 449 | public async Task> GetIssues(bool IncludeResolved, int NumResults) 450 | { 451 | return await GetIssuesInternal(-1, null, IncludeResolved, NumResults); 452 | } 453 | 454 | public async Task> GetIssues(string UserName) 455 | { 456 | return await GetIssuesInternal(-1, UserName, false, -1); 457 | } 458 | 459 | private async Task> GetIssuesInternal(long IssueId, string UserName, bool IncludeResolved, int NumResults) 460 | { 461 | List Issues = new List(); 462 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 463 | { 464 | await Connection.OpenAsync(); 465 | 466 | long UserId = -1; 467 | if (UserName != null) 468 | { 469 | UserId = await FindOrAddUserId(UserName); 470 | } 471 | 472 | StringBuilder CommandBuilder = new StringBuilder(); 473 | CommandBuilder.Append("SELECT"); 474 | CommandBuilder.Append(" Issues.Id, Issues.CreatedAt, UTC_TIMESTAMP(), Issues.Project, Issues.Summary, OwnerUsers.Name, NominatedByUsers.Name, Issues.AcknowledgedAt, Issues.FixChange, Issues.ResolvedAt"); 475 | if (UserName != null) 476 | { 477 | CommandBuilder.Append(", IssueWatchers.UserId"); 478 | } 479 | CommandBuilder.Append(" FROM ugs_db.Issues"); 480 | CommandBuilder.Append(" LEFT JOIN ugs_db.Users AS OwnerUsers ON OwnerUsers.Id = Issues.OwnerId"); 481 | CommandBuilder.Append(" LEFT JOIN ugs_db.Users AS NominatedByUsers ON NominatedByUsers.Id = Issues.NominatedById"); 482 | if (UserName != null) 483 | { 484 | CommandBuilder.Append(" LEFT JOIN ugs_db.IssueWatchers ON IssueWatchers.IssueId = Issues.Id AND IssueWatchers.UserId = @UserId"); 485 | } 486 | if (IssueId != -1) 487 | { 488 | CommandBuilder.Append(" WHERE Issues.Id = @IssueId"); 489 | } 490 | else if (!IncludeResolved) 491 | { 492 | CommandBuilder.Append(" WHERE Issues.ResolvedAt IS NULL"); 493 | } 494 | if (NumResults > 0) 495 | { 496 | CommandBuilder.AppendFormat(" ORDER BY Issues.Id DESC LIMIT {0}", NumResults); 497 | } 498 | 499 | using (MySqlCommand Command = new MySqlCommand(CommandBuilder.ToString(), Connection)) 500 | { 501 | if (IssueId != -1) 502 | { 503 | Command.Parameters.AddWithValue("@IssueId", IssueId); 504 | } 505 | if (UserName != null) 506 | { 507 | Command.Parameters.AddWithValue("@UserId", UserId); 508 | } 509 | 510 | using (var Reader = await Command.ExecuteReaderAsync()) 511 | { 512 | while (await Reader.ReadAsync()) 513 | { 514 | IssueData Issue = new IssueData(); 515 | Issue.Id = Reader.GetInt64(0); 516 | Issue.CreatedAt = Reader.GetDateTime(1); 517 | Issue.RetrievedAt = Reader.GetDateTime(2); 518 | Issue.Project = Reader.GetString(3); 519 | Issue.Summary = Reader.GetString(4); 520 | Issue.Owner = Reader.IsDBNull(5) ? null : Reader.GetString(5); 521 | Issue.NominatedBy = Reader.IsDBNull(6) ? null : Reader.GetString(6); 522 | Issue.AcknowledgedAt = Reader.IsDBNull(7) ? (DateTime?)null : Reader.GetDateTime(7); 523 | Issue.FixChange = Reader.GetInt32(8); 524 | Issue.ResolvedAt = Reader.IsDBNull(9) ? (DateTime?)null : Reader.GetDateTime(9); 525 | if (UserName != null) 526 | { 527 | Issue.bNotify = !Reader.IsDBNull(10); 528 | } 529 | Issues.Add(Issue); 530 | } 531 | } 532 | } 533 | } 534 | return Issues; 535 | } 536 | 537 | public async Task UpdateIssue(long IssueId, IssueUpdateData Issue) 538 | { 539 | long AffectedRows; 540 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 541 | { 542 | await Connection.OpenAsync(); 543 | 544 | using (MySqlCommand Command = Connection.CreateCommand()) 545 | { 546 | List Columns = new List(); 547 | List Values = new List(); 548 | if (Issue.Summary != null) 549 | { 550 | Columns.Add("Summary"); 551 | Values.Add("@Summary"); 552 | Command.Parameters.AddWithValue("@Summary", SanitizeText(Issue.Summary, IssueSummaryMaxLength)); 553 | } 554 | if (Issue.Owner != null) 555 | { 556 | Columns.Add("OwnerId"); 557 | Values.Add("@OwnerId"); 558 | Command.Parameters.AddWithValue("OwnerId", FindOrAddUserId(Issue.Owner, Connection)); 559 | } 560 | if (Issue.NominatedBy != null) 561 | { 562 | Columns.Add("NominatedById"); 563 | Values.Add("@NominatedById"); 564 | Command.Parameters.AddWithValue("NominatedById", FindOrAddUserId(Issue.NominatedBy, Connection)); 565 | } 566 | if (Issue.Acknowledged.HasValue) 567 | { 568 | Columns.Add("AcknowledgedAt"); 569 | Values.Add(Issue.Acknowledged.Value ? "UTC_TIMESTAMP()" : "NULL"); 570 | } 571 | if (Issue.FixChange.HasValue) 572 | { 573 | Columns.Add("FixChange"); 574 | Values.Add("@FixChange"); 575 | Command.Parameters.AddWithValue("FixChange", Issue.FixChange.Value); 576 | } 577 | if (Issue.Resolved.HasValue) 578 | { 579 | Columns.Add("ResolvedAt"); 580 | Values.Add(Issue.Resolved.Value ? "UTC_TIMESTAMP()" : "NULL"); 581 | } 582 | 583 | StringBuilder CommandText = new StringBuilder("UPDATE ugs_db.Issues SET "); 584 | for (int idx = 0; idx < Columns.Count; idx++) 585 | { 586 | CommandText.Append(String.Format("{0}={1}", Columns[idx], Values[idx])); 587 | if (idx != Columns.Count - 1) 588 | { 589 | CommandText.Append(","); 590 | } 591 | } 592 | CommandText.Append(" WHERE Id = @IssueId"); 593 | Command.CommandText = CommandText.ToString(); 594 | Command.Parameters.AddWithValue("@IssueId", IssueId); 595 | AffectedRows = await Command.ExecuteNonQueryAsync(); 596 | } 597 | } 598 | return AffectedRows; 599 | } 600 | 601 | public string SanitizeText(string Text, int Length) 602 | { 603 | if (Text.Length > Length) 604 | { 605 | int NewlineIdx = Text.LastIndexOf('\n', Length); 606 | if (NewlineIdx == -1) 607 | { 608 | Text = Text.Substring(0, Length - 3).TrimEnd() + "..."; 609 | } 610 | else 611 | { 612 | Text = Text.Substring(0, NewlineIdx + 1) + "..."; 613 | } 614 | } 615 | return Text; 616 | } 617 | 618 | public async Task DeleteIssue(long IssueId) 619 | { 620 | long AffectedRows; 621 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 622 | { 623 | await Connection.OpenAsync(); 624 | using (MySqlTransaction Transaction = await Connection.BeginTransactionAsync()) 625 | { 626 | using (MySqlCommand Command = Connection.CreateCommand()) 627 | { 628 | Command.Transaction = Transaction; 629 | 630 | Command.CommandText = "DELETE FROM ugs_db.IssueWatchers WHERE IssueId = @IssueId"; 631 | Command.Parameters.AddWithValue("@IssueId", IssueId); 632 | AffectedRows = await Command.ExecuteNonQueryAsync(); 633 | 634 | Command.CommandText = "DELETE FROM ugs_db.IssueBuilds WHERE IssueId = @IssueId"; 635 | Command.Parameters.AddWithValue("@IssueId", IssueId); 636 | AffectedRows = AffectedRows + await Command.ExecuteNonQueryAsync(); 637 | 638 | Command.CommandText = "DELETE FROM ugs_db.Issues WHERE Id = @IssueId"; 639 | Command.Parameters.AddWithValue("@IssueId", IssueId); 640 | AffectedRows = AffectedRows + await Command.ExecuteNonQueryAsync(); 641 | 642 | Transaction.Commit(); 643 | } 644 | } 645 | } 646 | return AffectedRows; 647 | } 648 | 649 | public async Task AddDiagnostic(long IssueId, IssueDiagnosticData Diagnostic) 650 | { 651 | long AffectedRows; 652 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 653 | { 654 | await Connection.OpenAsync(); 655 | using (MySqlCommand Command = new MySqlCommand("INSERT INTO ugs_db.IssueDiagnostics (IssueId, BuildId, Message, Url) VALUES (@IssueId, @BuildId, @Message, @Url)", Connection)) 656 | { 657 | Command.Parameters.AddWithValue("@IssueId", IssueId); 658 | Command.Parameters.AddWithValue("@BuildId", Diagnostic.BuildId); 659 | Command.Parameters.AddWithValue("@Message", SanitizeText(Diagnostic.Message, 1000)); 660 | Command.Parameters.AddWithValue("@Url", Diagnostic.Url); 661 | AffectedRows = await Command.ExecuteNonQueryAsync(); 662 | } 663 | } 664 | return AffectedRows; 665 | } 666 | 667 | public async Task> GetDiagnostics(long IssueId) 668 | { 669 | List Diagnostics = new List(); 670 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 671 | { 672 | await Connection.OpenAsync(); 673 | 674 | StringBuilder CommandBuilder = new StringBuilder(); 675 | CommandBuilder.Append("SELECT BuildId, Message, Url FROM ugs_db.IssueDiagnostics"); 676 | CommandBuilder.Append(" WHERE IssueDiagnostics.IssueId = @IssueId"); 677 | 678 | using (MySqlCommand Command = new MySqlCommand(CommandBuilder.ToString(), Connection)) 679 | { 680 | Command.Parameters.AddWithValue("@IssueId", IssueId); 681 | using (var Reader = await Command.ExecuteReaderAsync()) 682 | { 683 | while (await Reader.ReadAsync()) 684 | { 685 | IssueDiagnosticData Diagnostic = new IssueDiagnosticData(); 686 | Diagnostic.BuildId = Reader.IsDBNull(0) ? (long?)null : (long?)Reader.GetInt64(0); 687 | Diagnostic.Message = Reader.GetString(1); 688 | Diagnostic.Url = Reader.GetString(2); 689 | Diagnostics.Add(Diagnostic); 690 | } 691 | } 692 | } 693 | } 694 | return Diagnostics; 695 | } 696 | 697 | public async Task AddWatcher(long IssueId, string UserName) 698 | { 699 | long AffectedRows; 700 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 701 | { 702 | await Connection.OpenAsync(); 703 | 704 | long UserId = await FindOrAddUserId(UserName, Connection); 705 | 706 | using (MySqlCommand Command = new MySqlCommand("INSERT IGNORE INTO ugs_db.IssueWatchers (IssueId, UserId) VALUES (@IssueId, @UserId)", Connection)) 707 | { 708 | Command.Parameters.AddWithValue("@IssueId", IssueId); 709 | Command.Parameters.AddWithValue("@UserId", UserId); 710 | AffectedRows = await Command.ExecuteNonQueryAsync(); 711 | } 712 | } 713 | return AffectedRows; 714 | } 715 | 716 | public async Task> GetWatchers(long IssueId) 717 | { 718 | List Watchers = new List(); 719 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 720 | { 721 | await Connection.OpenAsync(); 722 | 723 | StringBuilder CommandBuilder = new StringBuilder(); 724 | CommandBuilder.Append("SELECT Users.Name FROM ugs_db.IssueWatchers"); 725 | CommandBuilder.Append(" LEFT JOIN ugs_db.Users ON IssueWatchers.UserId = Users.Id"); 726 | CommandBuilder.Append(" WHERE IssueWatchers.IssueId = @IssueId"); 727 | 728 | using (MySqlCommand Command = new MySqlCommand(CommandBuilder.ToString(), Connection)) 729 | { 730 | Command.Parameters.AddWithValue("@IssueId", IssueId); 731 | using (var Reader = await Command.ExecuteReaderAsync()) 732 | { 733 | while (await Reader.ReadAsync()) 734 | { 735 | Watchers.Add(Reader.GetString(0)); 736 | } 737 | } 738 | } 739 | } 740 | return Watchers; 741 | } 742 | 743 | public async Task RemoveWatcher(long IssueId, string UserName) 744 | { 745 | long AffectedRows; 746 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 747 | { 748 | await Connection.OpenAsync(); 749 | 750 | long UserId = await FindOrAddUserId(UserName, Connection); 751 | 752 | using (MySqlCommand Command = new MySqlCommand("DELETE FROM ugs_db.IssueWatchers WHERE IssueId = @IssueId AND UserId = @UserId", Connection)) 753 | { 754 | Command.Parameters.AddWithValue("@IssueId", IssueId); 755 | Command.Parameters.AddWithValue("@UserId", UserId); 756 | AffectedRows = await Command.ExecuteNonQueryAsync(); 757 | } 758 | } 759 | return AffectedRows; 760 | } 761 | 762 | public async Task AddBuild(long IssueId, IssueBuildData Build) 763 | { 764 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 765 | { 766 | await Connection.OpenAsync(); 767 | 768 | using (MySqlCommand Command = new MySqlCommand("INSERT INTO ugs_db.IssueBuilds (IssueId, Stream, `Change`, JobName, JobUrl, JobStepName, JobStepUrl, ErrorUrl, Outcome) VALUES (@IssueId, @Stream, @Change, @JobName, @JobUrl, @JobStepName, @JobStepUrl, @ErrorUrl, @Outcome)", Connection)) 769 | { 770 | Command.Parameters.AddWithValue("@IssueId", IssueId); 771 | Command.Parameters.AddWithValue("@Stream", Build.Stream); 772 | Command.Parameters.AddWithValue("@Change", Build.Change); 773 | Command.Parameters.AddWithValue("@JobName", Build.JobName); 774 | Command.Parameters.AddWithValue("@JobUrl", Build.JobUrl); 775 | Command.Parameters.AddWithValue("@JobStepName", Build.JobStepName); 776 | Command.Parameters.AddWithValue("@JobStepUrl", Build.JobStepUrl); 777 | Command.Parameters.AddWithValue("@ErrorUrl", Build.ErrorUrl); 778 | Command.Parameters.AddWithValue("@Outcome", Build.Outcome); 779 | await Command.ExecuteNonQueryAsync(); 780 | 781 | return Command.LastInsertedId; 782 | } 783 | } 784 | } 785 | 786 | public async Task> GetBuilds(long IssueId) 787 | { 788 | List Builds = new List(); 789 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 790 | { 791 | await Connection.OpenAsync(); 792 | 793 | using (MySqlCommand Command = new MySqlCommand("SELECT IssueBuilds.Id, IssueBuilds.Stream, IssueBuilds.Change, IssueBuilds.JobName, IssueBuilds.JobUrl, IssueBuilds.JobStepName, IssueBuilds.JobStepUrl, IssueBuilds.ErrorUrl, IssueBuilds.Outcome FROM ugs_db.IssueBuilds WHERE IssueBuilds.IssueId = @IssueId", Connection)) 794 | { 795 | Command.Parameters.AddWithValue("@IssueId", IssueId); 796 | using (var Reader = await Command.ExecuteReaderAsync()) 797 | { 798 | while (await Reader.ReadAsync()) 799 | { 800 | long Id = Reader.GetInt64(0); 801 | string Stream = Reader.GetString(1); 802 | int Change = Reader.GetInt32(2); 803 | string JobName = Reader.GetString(3); 804 | string JobUrl = Reader.GetString(4); 805 | string JobStepName = Reader.GetString(5); 806 | string JobStepUrl = Reader.GetString(6); 807 | string ErrorUrl = Reader.IsDBNull(7) ? null : Reader.GetString(7); 808 | int Outcome = Reader.GetInt32(8); 809 | Builds.Add(new IssueBuildData { Id = Id, Stream = Stream, Change = Change, JobName = JobName, JobUrl = JobUrl, JobStepName = JobStepName, JobStepUrl = JobStepUrl, ErrorUrl = ErrorUrl, Outcome = Outcome }); 810 | } 811 | } 812 | } 813 | } 814 | return Builds; 815 | } 816 | 817 | public async Task GetBuild(long BuildId) 818 | { 819 | IssueBuildData Build = null; 820 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 821 | { 822 | await Connection.OpenAsync(); 823 | 824 | using (MySqlCommand Command = new MySqlCommand("SELECT IssueBuilds.Id, IssueBuilds.Stream, IssueBuilds.Change, IssueBuilds.JobName, IssueBuilds.JobUrl, IssueBuilds.JobStepName, IssueBuilds.JobStepUrl, IssueBuilds.ErrorUrl, IssueBuilds.Outcome FROM ugs_db.IssueBuilds WHERE IssueBuilds.Id = @BuildId", Connection)) 825 | { 826 | Command.Parameters.AddWithValue("@BuildId", BuildId); 827 | using (var Reader = await Command.ExecuteReaderAsync()) 828 | { 829 | while (await Reader.ReadAsync()) 830 | { 831 | long Id = Reader.GetInt64(0); 832 | string Stream = Reader.GetString(1); 833 | int Change = Reader.GetInt32(2); 834 | string JobName = Reader.GetString(3); 835 | string JobUrl = Reader.GetString(4); 836 | string JobStepName = Reader.GetString(5); 837 | string JobStepUrl = Reader.GetString(6); 838 | string ErrorUrl = Reader.GetString(7); 839 | int Outcome = Reader.GetInt32(8); 840 | 841 | Build = new IssueBuildData { Id = Id, Stream = Stream, Change = Change, JobName = JobName, JobUrl = JobUrl, JobStepName = JobStepName, JobStepUrl = JobStepUrl, ErrorUrl = ErrorUrl, Outcome = Outcome }; 842 | } 843 | } 844 | } 845 | } 846 | return Build; 847 | } 848 | 849 | public async Task UpdateBuild(long BuildId, int Outcome) 850 | { 851 | long AffectedRows; 852 | using (MySqlConnection Connection = new MySqlConnection(_connectionStrings.MySqlConnection)) 853 | { 854 | await Connection.OpenAsync(); 855 | using (MySqlCommand Command = new MySqlCommand("UPDATE ugs_db.IssueBuilds SET (Outcome) = (@Outcome) WHERE Id = @BuildId", Connection)) 856 | { 857 | Command.Parameters.AddWithValue("@BuildId", BuildId); 858 | Command.Parameters.AddWithValue("@Outcome", Outcome); 859 | AffectedRows = await Command.ExecuteNonQueryAsync(); 860 | } 861 | } 862 | return AffectedRows; 863 | } 864 | } 865 | } 866 | --------------------------------------------------------------------------------