diff --git a/.gitignore b/.gitignore index 363c7b2ec0283c1fb1b2d1d239fe573caffc5663..875f551323e15092ecf59ce40d12e3e1206d8f3b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# Database connection for t4 class generation from database +**/*.generated.cs + # Build results [Dd]ebug/ [Dd]ebugPublic/ @@ -265,3 +268,9 @@ __pycache__/ tools/* !tools/packages.config dist/ + +#linq2db +src/.tools/ + +# Dotnet Tool Manifest +.config/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b339a45c43a1dcb4b80ab99e6224bc7232abd723..555722dfd87d8e199bea6bda9b054ad45e674748 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,55 +1,24 @@ +include: + - project: coscine/tools/gitlab-ci-templates + file: + - /dotnet.yml + stages: + - build - test - - release - - releasetrigger + - publish -cake:Test: - stage: test - script: - - PowerShell .\build.ps1 -Target Test -Configuration Debug - variables: - GIT_STRATEGY: clone - artifacts: - reports: - junit: "./Artifacts/TestResults.xml" - paths: - - "./Artifacts/*" - except: - - master - - tags +variables: + DOTNET_MAIN_PROJECT_FOLDER: PIDMigrator -cake:Release: - stage: release - script: - - PowerShell .\build.ps1 -Target Release -Configuration Release --nugetApiKey="${NUGET_API_KEY}" - variables: - GIT_STRATEGY: clone - dependencies: - - cake:Test - artifacts: - paths: - - "./Artifacts/*" - only: - - tags +build-branch: + extends: .build-branch -cake:Prerelease: - stage: release - script: - - PowerShell .\build.ps1 -Target Prerelease -Configuration Release - variables: - GIT_STRATEGY: clone - dependencies: - - cake:Test - artifacts: - paths: - - "./Artifacts/*" - except: - - tags - - master +test: + extends: .test -cake:GitlabRelease: - stage: releasetrigger - script: - - PowerShell .\build.ps1 -Target GitlabRelease --GitlabProjectPath="${CI_PROJECT_PATH}" --gitlabProjectId="${CI_PROJECT_ID}" --gitlabToken="${GITLAB_TOKEN}" - only: - - master \ No newline at end of file +publish-gitlab-release: + extends: .publish-gitlab-release + +publish: + extends: .publish-artifact-release diff --git a/.releaserc b/.releaserc deleted file mode 100644 index 72ff2701baf27f6738b07f990506607bcc8dd562..0000000000000000000000000000000000000000 --- a/.releaserc +++ /dev/null @@ -1,23 +0,0 @@ -{ - "plugins": [ - ["@semantic-release/commit-analyzer", { - "preset": "eslint" - }], - ["@semantic-release/release-notes-generator", { - "preset": "eslint", - }], - ["@semantic-release/gitlab", { - "preset": "eslint", - "gitlabUrl": "https://git.rwth-aachen.de" - }], - ["@semantic-release/exec", { - "prepareCmd" : "echo ${nextRelease.version}", - "publishCmd" : "echo test" - }], - ["@semantic-release/git", { - "preset": "eslint", - "assets": "src/**/Properties/AssemblyInfo.cs", - "message": "Chore: ${nextRelease.version}\n\n${nextRelease.notes}" - }] - ] -} diff --git a/LICENSE b/LICENSE index 028e1445d83a05b6d68027507edb53033ca40ac3..1cacbda86167c5f5629e9d3f8605295ad009460f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 RWTH Aachen University +Copyright (c) 2019 RWTH Aachen University Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 478acaf2fc5cb286bd407331c57b3596943cb920..c89b932a93013a83da5a016b190871e95cb2feb2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,137 @@ -# PID Migrator +## Integrator -This repository migrates all existing PIDs to the current URL, METAURL and DATAURL definition for them. \ No newline at end of file +The integrator can deploy projects specified in a json file by downloading the artifacts of the specified job (default is `release`). + +### Config +The config (json) file can look like the following: +```json +{ + "apis":[ + { + "name":"Coscine.Api.Project", + "version":"v1.3.0", + "url":"coscine/api/project" + }, + { + "name":"Coscine.Api.User", + "version":"v1.1.0", + "url":"coscine/api/user" + }, + { + "name":"Coscine.STS", + "version":"v1.2.1", + "url":"coscine/api/sts" + } + ], + "apps":[ + { + "name":"usersview", + "version":"v1.0.2", + "url":"coscine/app/usersview" + }, + { + "name":"resourceview", + "version":"v1.0.1", + "url":"coscine/app/resourceview" + }, + { + "name":"projectview", + "version":"v1.2.1", + "url":"coscine/app/projectview" + }, + { + "name":"project2", + "version":"v1.3.1", + "url":"coscine/app/project" + }, + { + "name":"login", + "version":"v1.1.0", + "url":"coscine/app/login" + } + ] +} +``` + +Make sure to have the names prefix free (hence project2 and projectview). +The name must be the executable name for apis. + +The above example would deploy all specified versions and remove any integrations wich is currently deployed, but not specified. + +The version describes the tag or branch for the job artifacts. +When using a branch, also specifiy the job name. + +Example for prerelease: +```json +{ + "name":"login", + "version":"Topic-123/BranchNameTest", + "url":"coscine/app/login", + "job":"pre_release" +} +``` +``` + +The artifacts of the job `pre_release` will be downloaded and used instead of the default job `release`. The job needs to be added to the pipeline definition of each project and run manually(see this [.gitlab-ci.yml](.gitlab-ci.yml) under `pre_release`). + +Example for migrator: +```json +{ + "scripts":[ + { + "name":"Migrations", + "version":"v1.3.0", + "url":"coscine/cs/migrations", + "job":"cake:Release", + "scriptType":"Powershell.exe", + "command":"DEST_PATH\\Migrator.exe --migrate_up" + } + ] +} + +"DEST_PATH" will be replaced by the path of the downloaded and extracted folder. +scriptType defines the core command. Here we will use powershell to run the following command. +command takes in the arguments for script type. Here starting an executable with powershell. + +Example for cron: +{ + "cron":[ + { + "name":"CronTest", + "version":"v1.17.1", + "url":"coscine/api/project", + "job":"cake:Release", + "cron":"*/5 * * * * *" + } + ] +} + +Runs a nomad job as a cron job. +The cron parameter defines the repetition cycle. +[Cron definitions](https://github.com/gorhill/cronexpr#implementation) + +### Running +Start the integrator by running integrator.exe and specify the json file with `--s` or `--source` and the destination of the integrations with `--d`" or `--destination`. +Use `-h` or `--help` for help. +Use `--purge` to force a redeploy of all integrations. + +The parameter `--source` and `--destination` are mandatory, `--purge` is optional. + +To start a integration run: +```powershell +.\integrator.exe --source "integrator.json" --destination "C:\Integrations" +``` + +For a redeploy run: +```powershell +.\integrator.exe --source "integrator.json" --destination "C:\Integrations" --purge +``` + +## Building + +Build this project by running either the build.ps1 or the build<span></span>.sh script. +The project will be build and tested. + +## Necessary Keys + +The key "coscine/local/app/additional/url" is necessary for specifying the host url of the apps. \ No newline at end of file diff --git a/build.cake b/build.cake deleted file mode 100644 index 81648ff61bbee492e1bc7b4390eb8e0cc33d3056..0000000000000000000000000000000000000000 --- a/build.cake +++ /dev/null @@ -1,351 +0,0 @@ -#tool nuget:?package=NUnit.ConsoleRunner&version=3.10.0 -#tool nuget:?package=vswhere&version=2.8.4 -#tool nuget:?package=GitVersion.CommandLine&version=5.1.3 - -#addin nuget:https://api.nuget.org/v3/index.json?package=Cake.Json&version=4.0.0 -#addin nuget:https://api.nuget.org/v3/index.json?package=Newtonsoft.Json&version=11.0.2 -#addin nuget:https://api.nuget.org/v3/index.json?package=Cake.FileHelpers&version=3.2.1 - -using System.Net; -using System.Net.Http; - -// Commandline arguments -var target = Argument("target", "Default"); -var configuration = Argument("configuration", "Release"); -var nugetApiKey = Argument<string>("nugetApiKey", null); -var version = Argument("nugetVersion", ""); -var gitlabProjectPath = Argument("gitlabProjectPath", ""); -var gitlabProjectId = Argument("gitlabProjectId", ""); -var gitlabToken = Argument("gitlabToken", ""); - -// Define directories -var projects = GetFiles("./**/*.csproj"); -var artifactsDir = Directory("./Artifacts"); -string nupkgDir; -var solutionFile = GetFiles("./**/*.sln").First(); -var projectName = solutionFile.GetFilenameWithoutExtension().ToString(); -var nugetSource = "https://api.nuget.org/v3/index.json"; -var assemblyInfoSubPath = "Properties/AssemblyInfo.cs"; -var semanticVersion = ""; -string localNugetFeed; - -// get latest MSBuild version -var vsLatest = VSWhereLatest(); -var msBuildPathX64 = (vsLatest == null) ? null : vsLatest.CombineWithFilePath("./MSBuild/Current/Bin/MSBuild.exe"); - -Setup(context =>{ - nupkgDir = $"{artifactsDir.ToString()}/nupkg"; - var branch = GitVersion(new GitVersionSettings { - UpdateAssemblyInfo = false - }).BranchName.Replace("/", "-"); - - localNugetFeed = $"C:\\coscine\\LocalNugetFeeds\\{branch}"; - Information("{0}", branch); - Information("Started at {0}", DateTime.Now); -}); - -Teardown(context =>{ - Information("Finished at {0}", DateTime.Now); -}); - -Task("Clean") -.Description("Cleans all build and artifacts directories") -.Does(() =>{ - var settings = new DeleteDirectorySettings { - Recursive = true, - Force = true - }; - - var directoriesToClean = new List<DirectoryPath>(); - - foreach(var project in projects) { - directoriesToClean.Add(Directory($"{project.GetDirectory()}/obj")); - directoriesToClean.Add(Directory($"{project.GetDirectory()}/bin")); - } - - directoriesToClean.Add(artifactsDir); - - foreach(var dir in directoriesToClean) { - Information("Cleaning {0}", dir.ToString()); - if (DirectoryExists(dir)) { - DeleteDirectory(dir, settings); - CreateDirectory(dir); - } else { - CreateDirectory(dir); - } - } -}); - -Task("Restore") -.Does(() =>{ - NuGetRestore(solutionFile, new NuGetRestoreSettings { - NoCache = true, - FallbackSource = new List<string>{ localNugetFeed }, - }); -}); - -Task("Test") -.IsDependentOn("Build") -.Does(() =>{ - NUnit3($"./src/**/bin/{configuration}/*.Tests.dll", new NUnit3Settings { - // generate the xml file - NoResults = false, - Results = new NUnit3Result[] { - new NUnit3Result() { - FileName = $"{artifactsDir}/TestResults.xml", - Transform = $"{Context.Environment.WorkingDirectory}/nunit3-junit.xslt" - } - } - }); -}); - -Task("GitVersion") -.Does(() => { - if(string.IsNullOrWhiteSpace(version)) { - version = GitVersion(new GitVersionSettings { - UpdateAssemblyInfo = false - }).NuGetVersionV2; - } - var index = version.IndexOf("-"); - semanticVersion = index > 0 ? version.Substring(0, index) : version; - Information("Version: {0}, SemanticVersion: {1}", version, semanticVersion); -}); - -Task("UpdateAssemblyInfo") -.Does(() =>{ - var index = version.IndexOf("-"); - var semanticVersion = index > 0 ? version.Substring(0, index) : version; - - foreach(var project in projects) { - CreateAssemblyInfo($"{project.GetDirectory()}/{assemblyInfoSubPath}", new AssemblyInfoSettings { - Product = project.GetFilenameWithoutExtension().ToString(), - Title = project.GetFilenameWithoutExtension().ToString(), - Company = "IT Center, RWTH Aachen University", - Version = semanticVersion, - FileVersion = semanticVersion, - InformationalVersion = version, - Copyright = $"{DateTime.Now.Year} IT Center, RWTH Aachen University", - Description = $"{project.GetFilenameWithoutExtension().ToString()} is a part of the CoScInE group." - }); - } -}); - -Task("GitlabRelease") -.IsDependentOn("GitVersion") -.Does(() => { - var client = new HttpClient(); - client.DefaultRequestHeaders.Add("PRIVATE-TOKEN", gitlabToken); - - // get the latest tag - var result = client.GetAsync($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/repository/tags").Result; - if(!result.IsSuccessStatusCode) { - throw new Exception("Tag query failed."); - } - - var tagList = result.Content.ReadAsStringAsync().Result; - var jArray = JArray.Parse(tagList); - // null if not tags exists yet - var lastTag = jArray.Select(x => x["name"]).FirstOrDefault(); - - var url = $"https://git.rwth-aachen.de/{gitlabProjectPath}"; - - if(url.EndsWith(".git")) { - url = url.Substring(0, url.Length - ".git".Length); - } - - if(url.EndsWith("/")) { - url = url.Substring(0, url.Length - 1); - } - - var description = ""; - // First line of description - // Gitlab compare url, if something can be compared - if(lastTag == null) { - description = $"# {semanticVersion} ({DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day})\n\n\n"; - } else { - description = $"# [{semanticVersion}]({url}/compare/{lastTag}...v{semanticVersion}) ({DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day})\n\n\n"; - } - - // From when will messages be parsed, null results in all messages - var logParam = ""; - if(lastTag != null) { - logParam = $"{lastTag}..Head"; - } - - Information(lastTag); - - IEnumerable<string> redirectedStandardOutput; - var exitCodeWithArgument = - StartProcess( - "git", - new ProcessSettings { - Arguments = $"log {logParam} --pretty=format:HASH%h:%B", - RedirectStandardOutput = true - }, - out redirectedStandardOutput - ); - - var prefixList = new Dictionary<string, List<string>>{ - {"Fix", new List<string>()}, - {"Update", new List<string>()}, - {"New", new List<string>()}, - {"Breaking", new List<string>()}, - {"Docs", new List<string>()}, - {"Build", new List<string>()}, - {"Upgrade", new List<string>()}, - {"Chore", new List<string>()}, - }; - - var currentHash = ""; - // Output last line of process output. - foreach(var line in redirectedStandardOutput) { - var commitMessage = ""; - if(line.StartsWith("HASH")) { - currentHash = line.Substring("HASH".Length); - currentHash = currentHash.Substring(0, currentHash.IndexOf(":")); - commitMessage = line.Substring(currentHash.Length + line.IndexOf(currentHash) + 1); - } else { - commitMessage = line; - } - - foreach(var kv in prefixList) { - if(commitMessage.StartsWith($"{kv.Key}:")) { - kv.Value.Add($"* {commitMessage.Substring(kv.Key.Length + 1).Trim()} {currentHash}"); - break; - } - }; - } - - foreach(var kv in prefixList) { - if(kv.Value.Any()) { - description += $" ### {kv.Key}\n\n"; - foreach(var line in kv.Value) { - description += $"{line}\n"; - } - description += "\n"; - } - } - // correctly escape the json newlines - description = description.Replace("\n", "\\n"); - Information("Description: {0}", description); - - // create tag - result = client.PostAsync($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/repository/tags?tag_name=v{semanticVersion}&ref=master", null).Result; - Information("Create tag: {0}", result.Content.ReadAsStringAsync().Result); - if(!result.IsSuccessStatusCode) { - throw new Exception("Tag creation failed."); - } - - // create release - var json = $"{{\"name\": \"v{semanticVersion}\", \"tag_name\": \"v{semanticVersion}\", \"description\": \"{description}\"}}"; - var content = new StringContent(json, Encoding.UTF8, "application/json"); - result = client.PostAsync($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/releases", content).Result; - Information("Create release: {0}", result.Content.ReadAsStringAsync().Result); - if(!result.IsSuccessStatusCode) { - throw new Exception("Release creation failed."); - } -}); - -Task("Build") -.IsDependentOn("Clean") -.IsDependentOn("GitVersion") -.IsDependentOn("UpdateAssemblyInfo") -.IsDependentOn("Restore") -.Does(() =>{ - var frameworkSettingsWindows = new MSBuildSettings { - Configuration = configuration - }; - - frameworkSettingsWindows.ToolPath = msBuildPathX64; - frameworkSettingsWindows.WorkingDirectory = Context.Environment.WorkingDirectory; - - if (configuration.Equals("Release")) { - frameworkSettingsWindows.WithProperty("DebugSymbols", "false"); - frameworkSettingsWindows.WithProperty("DebugType", "None"); - } - - // Use MSBuild - Information("Building {0}", solutionFile); - MSBuild(solutionFile, frameworkSettingsWindows); -}); - -Task("NugetPack") -.IsDependentOn("Build") -.Does(() =>{ - foreach(var project in projects) { - var nuspec = $"{project.GetDirectory()}/{project.GetFilenameWithoutExtension()}.nuspec"; - if(!project.ToString().EndsWith(".Tests") && FileExists(nuspec)) - { - var settings = new NuGetPackSettings - { - OutputDirectory = nupkgDir, - Version = version, - Properties = new Dictionary<string, string> - { - { "Configuration", configuration} - } - }; - NuGetPack(project.ToString(), settings); - } - } -}); - -Task("NugetPush") -.IsDependentOn("NugetPack") -.Does(() =>{ - var nupkgs = GetFiles($"{nupkgDir}/*.nupkg"); - Information("Need to push {0} packages", nupkgs.Count); - if(!String.IsNullOrWhiteSpace(nugetApiKey)) { - foreach(var nupkg in nupkgs) { - Information("Pushing {0}", nupkg); - NuGetPush(nupkg, new NuGetPushSettings { - Source = nugetSource, - ApiKey = nugetApiKey - }); - } - } else { - Information("NugetApiKey is not set. Can't push."); - throw new Exception("NugetApiKey is not set. Can't push."); - } -}); - -Task("CopyToArtifacts") -.Does(() =>{ - foreach(var project in projects) { - if(!project.GetDirectory().ToString().EndsWith(".Tests") - && !FileExists($"{project.GetDirectory()}/{project.GetFilenameWithoutExtension()}.nuspec") - && DirectoryExists(project.GetDirectory())) - { - Information("Copying {0}/* to {1}", $"{project.GetDirectory()}/bin/{configuration}", artifactsDir); - CopyDirectory($"{project.GetDirectory()}/bin/{configuration}/", artifactsDir); - } - } -}); - -Task("NugetPushLocal") -.IsDependentOn("NugetPack") -.Does(() =>{ - var nupkgs = GetFiles($"{nupkgDir}/*.nupkg"); - foreach(var nupkg in nupkgs) { - if(!DirectoryExists(localNugetFeed)) { - CreateDirectory(localNugetFeed); - } - CopyFile(nupkg.ToString(), $"{localNugetFeed}\\{nupkg.GetFilename()}"); - } -}); - -Task("Prerelease") -.IsDependentOn("Build") -.IsDependentOn("CopyToArtifacts") -.IsDependentOn("NugetPushLocal"); - -Task("Release") -.IsDependentOn("NugetPack") -.IsDependentOn("CopyToArtifacts") -.IsDependentOn("NugetPushLocal") -.IsDependentOn("NugetPush"); - -Task("Default") -.IsDependentOn("Test"); - -RunTarget(target); diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index 7f1f813d74cf6c0826517482757c38b86e0467b3..0000000000000000000000000000000000000000 --- a/build.ps1 +++ /dev/null @@ -1,256 +0,0 @@ -########################################################################## -# This is the Cake bootstrapper script for PowerShell. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## - -<# - -.SYNOPSIS -This is a Powershell script to bootstrap a Cake build. - -.DESCRIPTION -This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) -and execute your Cake build script with the parameters you provide. - -.PARAMETER Script -The build script to execute. -.PARAMETER Target -The build script target to run. -.PARAMETER Configuration -The build configuration to use. -.PARAMETER Verbosity -Specifies the amount of information to be displayed. -.PARAMETER ShowDescription -Shows description about tasks. -.PARAMETER DryRun -Performs a dry run. -.PARAMETER SkipToolPackageRestore -Skips restoring of packages. -.PARAMETER ScriptArgs -Remaining arguments are added here. - -.LINK -https://cakebuild.net - -#> - -[CmdletBinding()] -Param( - [string]$Script = "build.cake", - [string]$Target, - [string]$Configuration, - [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity, - [switch]$ShowDescription, - [Alias("WhatIf", "Noop")] - [switch]$DryRun, - [switch]$SkipToolPackageRestore, - [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] - [string[]]$ScriptArgs -) - -# Attempt to set highest encryption available for SecurityProtocol. -# PowerShell will not set this by default (until maybe .NET 4.6.x). This -# will typically produce a message for PowerShell v2 (just an info -# message though) -try { - # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48) - # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't - # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is - # installed (.NET 4.5 is an in-place upgrade). - # PowerShell Core already has support for TLS 1.2 so we can skip this if running in that. - if (-not $IsCoreCLR) { - [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48 - } - } catch { - Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3' - } - -[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null -function MD5HashFile([string] $filePath) -{ - if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) - { - return $null - } - - [System.IO.Stream] $file = $null; - [System.Security.Cryptography.MD5] $md5 = $null; - try - { - $md5 = [System.Security.Cryptography.MD5]::Create() - $file = [System.IO.File]::OpenRead($filePath) - return [System.BitConverter]::ToString($md5.ComputeHash($file)) - } - finally - { - if ($file -ne $null) - { - $file.Dispose() - } - } -} - -function GetProxyEnabledWebClient -{ - $wc = New-Object System.Net.WebClient - $proxy = [System.Net.WebRequest]::GetSystemWebProxy() - $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials - $wc.Proxy = $proxy - return $wc -} - -Write-Host "Preparing to run build script..." - -if(!$PSScriptRoot){ - $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent -} - -$TOOLS_DIR = Join-Path $PSScriptRoot "tools" -$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" -$MODULES_DIR = Join-Path $TOOLS_DIR "Modules" -$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" -$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" -$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" -$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" -$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" -$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" - -# Make sure tools folder exists -if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { - Write-Verbose -Message "Creating tools directory..." - New-Item -Path $TOOLS_DIR -Type Directory | Out-Null -} - -# Make sure that packages.config exist. -if (!(Test-Path $PACKAGES_CONFIG)) { - Write-Verbose -Message "Downloading packages.config..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) - } catch { - Throw "Could not download packages.config." - } -} - -# Try find NuGet.exe in path if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Trying to find nuget.exe in PATH..." - $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } - $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 - if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { - Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." - $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName - } -} - -# Try download NuGet.exe if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Downloading NuGet.exe..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile($NUGET_URL, $NUGET_EXE) - } catch { - Throw "Could not download NuGet.exe." - } -} - -# Save nuget.exe path to environment to be available to child processed -$env:NUGET_EXE = $NUGET_EXE -$env:NUGET_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) { - "mono `"$NUGET_EXE`"" -} else { - "`"$NUGET_EXE`"" -} - -# Restore tools from NuGet? -if(-Not $SkipToolPackageRestore.IsPresent) { - Push-Location - Set-Location $TOOLS_DIR - - # Check for changes in packages.config and remove installed tools if true. - [string] $md5Hash = MD5HashFile $PACKAGES_CONFIG - if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or - ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { - Write-Verbose -Message "Missing or changed package.config hash..." - Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery | - Remove-Item -Recurse - } - - Write-Verbose -Message "Restoring tools from NuGet..." - - $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet tools." - } - else - { - $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" - } - Write-Verbose -Message ($NuGetOutput | Out-String) - - Pop-Location -} - -# Restore addins from NuGet -if (Test-Path $ADDINS_PACKAGES_CONFIG) { - Push-Location - Set-Location $ADDINS_DIR - - Write-Verbose -Message "Restoring addins from NuGet..." - $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet addins." - } - - Write-Verbose -Message ($NuGetOutput | Out-String) - - Pop-Location -} - -# Restore modules from NuGet -if (Test-Path $MODULES_PACKAGES_CONFIG) { - Push-Location - Set-Location $MODULES_DIR - - Write-Verbose -Message "Restoring modules from NuGet..." - $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet modules." - } - - Write-Verbose -Message ($NuGetOutput | Out-String) - - Pop-Location -} - -# Make sure that Cake has been installed. -if (!(Test-Path $CAKE_EXE)) { - Throw "Could not find Cake.exe at $CAKE_EXE" -} - -$CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) { - "mono `"$CAKE_EXE`"" -} else { - "`"$CAKE_EXE`"" -} - - -# Build Cake arguments -$cakeArguments = @("$Script"); -if ($Target) { $cakeArguments += "-target=$Target" } -if ($Configuration) { $cakeArguments += "-configuration=$Configuration" } -if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } -if ($ShowDescription) { $cakeArguments += "-showdescription" } -if ($DryRun) { $cakeArguments += "-dryrun" } -$cakeArguments += $ScriptArgs - -# Start Cake -Write-Host "Running build script..." -Invoke-Expression "& $CAKE_EXE_INVOCATION $($cakeArguments -join " ")" -exit $LASTEXITCODE diff --git a/build.sh b/build.sh deleted file mode 100644 index d088917ed78538ff57cf654cf71aad6bf045d655..0000000000000000000000000000000000000000 --- a/build.sh +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env bash - -#The MIT License (MIT) -# -#Copyright (c) 2014 - 2016 Patrik Svensson, Mattias Karlsson, Gary Ewan Park and contributors -# -#Permission is hereby granted, free of charge, to any person obtaining a copy of -#this software and associated documentation files (the "Software"), to deal in -#the Software without restriction, including without limitation the rights to -#use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -#the Software, and to permit persons to whom the Software is furnished to do so, -#subject to the following conditions: -# -#The above copyright notice and this permission notice shall be included in all -#copies or substantial portions of the Software. -# -#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -#FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -#COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -#IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -#CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -########################################################################## -# This is the Cake bootstrapper script for Linux and OS X. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## - -# Define directories. -SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -TOOLS_DIR=$SCRIPT_DIR/tools -NUGET_EXE=$TOOLS_DIR/nuget.exe -CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe -PACKAGES_CONFIG=$TOOLS_DIR/packages.config -PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum - -# Define md5sum or md5 depending on Linux/OSX -MD5_EXE= -if [[ "$(uname -s)" == "Darwin" ]]; then - MD5_EXE="md5 -r" -else - MD5_EXE="md5sum" -fi - -# Define default arguments. -SCRIPT="build.cake" -TARGET="Default" -CONFIGURATION="Release" -VERBOSITY="verbose" -DRYRUN= -SHOW_VERSION=false -SCRIPT_ARGUMENTS=() - -# Parse arguments. -for i in "$@"; do - case $1 in - -s|--script) SCRIPT="$2"; shift ;; - -t|--target) TARGET="$2"; shift ;; - -c|--configuration) CONFIGURATION="$2"; shift ;; - -v|--verbosity) VERBOSITY="$2"; shift ;; - -d|--dryrun) DRYRUN="-dryrun" ;; - --version) SHOW_VERSION=true ;; - --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; - *) SCRIPT_ARGUMENTS+=("$1") ;; - esac - shift -done - -# Make sure the tools folder exist. -if [ ! -d "$TOOLS_DIR" ]; then - mkdir "$TOOLS_DIR" -fi - -# Make sure that packages.config exist. -if [ ! -f "$TOOLS_DIR/packages.config" ]; then - echo "Downloading packages.config..." - curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages - if [ $? -ne 0 ]; then - echo "An error occurred while downloading packages.config." - exit 1 - fi -fi - -# Download NuGet if it does not exist. -if [ ! -f "$NUGET_EXE" ]; then - echo "Downloading NuGet..." - curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - if [ $? -ne 0 ]; then - echo "An error occurred while downloading nuget.exe." - exit 1 - fi -fi - -# Restore tools from NuGet. -pushd "$TOOLS_DIR" >/dev/null -if [ ! -f $PACKAGES_CONFIG_MD5 ] || [ "$( cat $PACKAGES_CONFIG_MD5 | sed 's/\r$//' )" != "$( $MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' )" ]; then - find . -type d ! -name . | xargs rm -rf -fi - -mono "$NUGET_EXE" install -ExcludeVersion -if [ $? -ne 0 ]; then - echo "Could not restore NuGet packages." - exit 1 -fi - -$MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' >| $PACKAGES_CONFIG_MD5 - -popd >/dev/null - -# Make sure that Cake has been installed. -if [ ! -f "$CAKE_EXE" ]; then - echo "Could not find Cake.exe at '$CAKE_EXE'." - exit 1 -fi - -# Start Cake -if $SHOW_VERSION; then - exec mono "$CAKE_EXE" -version -else - exec mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" -fi \ No newline at end of file diff --git a/src/PIDMigrator.sln b/src/PIDMigrator.sln index f26f2aeb42bc7ffe120a0d0661f8bab5ffb3f7a9..24925bc0b2cb5833137c162a49146f5277aafff6 100644 --- a/src/PIDMigrator.sln +++ b/src/PIDMigrator.sln @@ -1,9 +1,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30011.22 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PIDMigrator", "PIDMigrator\PIDMigrator.csproj", "{3BC5BCCA-28A9-4108-A791-BF6A2FB7935F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PIDMigrator", "PIDMigrator\PIDMigrator.csproj", "{A37696F4-54C3-48F1-861C-C8C6F4FC3BFC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,15 +11,15 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3BC5BCCA-28A9-4108-A791-BF6A2FB7935F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3BC5BCCA-28A9-4108-A791-BF6A2FB7935F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3BC5BCCA-28A9-4108-A791-BF6A2FB7935F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3BC5BCCA-28A9-4108-A791-BF6A2FB7935F}.Release|Any CPU.Build.0 = Release|Any CPU + {A37696F4-54C3-48F1-861C-C8C6F4FC3BFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A37696F4-54C3-48F1-861C-C8C6F4FC3BFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A37696F4-54C3-48F1-861C-C8C6F4FC3BFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A37696F4-54C3-48F1-861C-C8C6F4FC3BFC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {D77DD753-87A3-4B0F-9014-5954B5A68BA8} + SolutionGuid = {2EBFD6EC-82FB-45C3-B7A3-183B46EFCE1E} EndGlobalSection EndGlobal diff --git a/src/PIDMigrator/App.config b/src/PIDMigrator/App.config deleted file mode 100644 index 1fa932bbec5740e2a42d3fbce76b48028d532a97..0000000000000000000000000000000000000000 --- a/src/PIDMigrator/App.config +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<configuration> - <configSections> - <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> - </configSections> - <startup> - <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> - </startup> - <entityFramework> - <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> - <parameters> - <parameter value="mssqllocaldb" /> - </parameters> - </defaultConnectionFactory> - <providers> - <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> - </providers> - </entityFramework> - <runtime> - <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> - <dependentAssembly> - <assemblyIdentity name="Coscine.Configuration" publicKeyToken="ce3d7a32d7dc1e5a" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-1.5.0.0" newVersion="1.5.0.0" /> - </dependentAssembly> - <dependentAssembly> - <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> - </dependentAssembly> - <dependentAssembly> - <assemblyIdentity name="Coscine.Database" publicKeyToken="767d77427707b70a" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-1.25.0.0" newVersion="1.25.0.0" /> - </dependentAssembly> - <dependentAssembly> - <assemblyIdentity name="linq2db" publicKeyToken="e41013125f9e410a" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-3.1.1.0" newVersion="3.1.1.0" /> - </dependentAssembly> - <dependentAssembly> - <assemblyIdentity name="Coscine.Database.T4" publicKeyToken="84b4c404a0696261" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-1.25.0.0" newVersion="1.25.0.0" /> - </dependentAssembly> - </assemblyBinding> - </runtime> -</configuration> \ No newline at end of file diff --git a/src/PIDMigrator/PIDMigrator.csproj b/src/PIDMigrator/PIDMigrator.csproj index cdbec3b395e5ae5cf6522d88fb1ba787a031221a..e9b05f07f2389a8f82a1e1fbc0deafce64541875 100644 --- a/src/PIDMigrator/PIDMigrator.csproj +++ b/src/PIDMigrator/PIDMigrator.csproj @@ -1,128 +1,14 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" /> - <Import Project="..\packages\linq2db.t4models.2.6.4\build\linq2db.t4models.props" Condition="Exists('..\packages\linq2db.t4models.2.6.4\build\linq2db.t4models.props')" /> - <Import Project="..\packages\linq2db.SqlServer.2.6.4\build\linq2db.SqlServer.props" Condition="Exists('..\packages\linq2db.SqlServer.2.6.4\build\linq2db.SqlServer.props')" /> - <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{3BC5BCCA-28A9-4108-A791-BF6A2FB7935F}</ProjectGuid> <OutputType>Exe</OutputType> - <RootNamespace>Coscine.PIDMigrator</RootNamespace> - <AssemblyName>Coscine.PIDMigrator</AssemblyName> - <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> - <Deterministic>true</Deterministic> - <NuGetPackageImportStamp> - </NuGetPackageImportStamp> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <PlatformTarget>x64</PlatformTarget> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <PlatformTarget>x64</PlatformTarget> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <Reference Include="Consul, Version=0.7.2.6, Culture=neutral, PublicKeyToken=20a6ad9a81df1d95, processorArchitecture=MSIL"> - <HintPath>..\packages\Consul.0.7.2.6\lib\net45\Consul.dll</HintPath> - </Reference> - <Reference Include="Coscine.Action, Version=1.16.0.0, Culture=neutral, processorArchitecture=AMD64"> - <HintPath>..\packages\Coscine.Action.1.16.0\lib\net461\Coscine.Action.dll</HintPath> - </Reference> - <Reference Include="Coscine.Configuration, Version=1.5.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL"> - <HintPath>..\packages\Coscine.Configuration.1.5.0\lib\net461\Coscine.Configuration.dll</HintPath> - </Reference> - <Reference Include="Coscine.Database, Version=1.25.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL"> - <HintPath>..\packages\Coscine.Database.1.25.0\lib\net461\Coscine.Database.dll</HintPath> - </Reference> - <Reference Include="Coscine.Database.T4, Version=1.25.0.0, Culture=neutral, PublicKeyToken=84b4c404a0696261, processorArchitecture=MSIL"> - <HintPath>..\packages\Coscine.Database.1.25.0\lib\net461\Coscine.Database.T4.dll</HintPath> - </Reference> - <Reference Include="Coscine.ProxyApi, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Coscine.ProxyApi.1.3.0\lib\net461\Coscine.ProxyApi.dll</HintPath> - </Reference> - <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> - <HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath> - </Reference> - <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> - <HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath> - </Reference> - <Reference Include="linq2db, Version=3.1.1.0, Culture=neutral, PublicKeyToken=e41013125f9e410a, processorArchitecture=MSIL"> - <HintPath>..\packages\linq2db.3.1.1\lib\net46\linq2db.dll</HintPath> - </Reference> - <Reference Include="LinqKit, Version=1.1.17.0, Culture=neutral, PublicKeyToken=bc217f8844052a91, processorArchitecture=MSIL"> - <HintPath>..\packages\LinqKit.1.1.17\lib\net45\LinqKit.dll</HintPath> - </Reference> - <Reference Include="Microsoft.Data.Edm, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll</HintPath> - </Reference> - <Reference Include="Microsoft.Data.OData, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll</HintPath> - </Reference> - <Reference Include="microsoft.identitymodel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.IdentityModel.7.0.0\lib\net35\microsoft.identitymodel.dll</HintPath> - </Reference> - <Reference Include="Microsoft.IdentityModel.JsonWebTokens, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.IdentityModel.JsonWebTokens.5.6.0\lib\net461\Microsoft.IdentityModel.JsonWebTokens.dll</HintPath> - </Reference> - <Reference Include="Microsoft.IdentityModel.Logging, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.IdentityModel.Logging.5.6.0\lib\net461\Microsoft.IdentityModel.Logging.dll</HintPath> - </Reference> - <Reference Include="Microsoft.IdentityModel.Tokens, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.IdentityModel.Tokens.5.6.0\lib\net461\Microsoft.IdentityModel.Tokens.dll</HintPath> - </Reference> - <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> - <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> - </Reference> - <Reference Include="System" /> - <Reference Include="System.ComponentModel.DataAnnotations" /> - <Reference Include="System.Core" /> - <Reference Include="System.IdentityModel.Tokens.Jwt, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\System.IdentityModel.Tokens.Jwt.5.6.0\lib\net461\System.IdentityModel.Tokens.Jwt.dll</HintPath> - </Reference> - <Reference Include="System.Net.Http.WebRequest" /> - <Reference Include="System.Spatial, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll</HintPath> - </Reference> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Data.DataSetExtensions" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Data" /> - <Reference Include="System.Net.Http" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="Program.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - </ItemGroup> + <ItemGroup> - <None Include="App.config" /> - <None Include="packages.config" /> + <PackageReference Include="Coscine.Action" Version="3.*-*" /> </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> - <PropertyGroup> - <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> - </PropertyGroup> - <Error Condition="!Exists('..\packages\linq2db.SqlServer.2.6.4\build\linq2db.SqlServer.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\linq2db.SqlServer.2.6.4\build\linq2db.SqlServer.props'))" /> - <Error Condition="!Exists('..\packages\linq2db.t4models.2.6.4\build\linq2db.t4models.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\linq2db.t4models.2.6.4\build\linq2db.t4models.props'))" /> - <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" /> - <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" /> - </Target> - <Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" /> -</Project> \ No newline at end of file + +</Project> diff --git a/src/PIDMigrator/Program.cs b/src/PIDMigrator/Program.cs index 8f8b2a119dfbbc03f01f28535df61b4f58ba9796..43cc77ff3149a6db8b31e84c4ec3b4b82291e4ca 100644 --- a/src/PIDMigrator/Program.cs +++ b/src/PIDMigrator/Program.cs @@ -1,28 +1,180 @@ using Coscine.Action.Utils; using Coscine.Configuration; using Coscine.Database.Models; -using Coscine.Database.Settings; -using LinqToDB.Data; -using System; +using Coscine.ProxyApi.Utils; -namespace Coscine.PIDMigrator +namespace PIDMigrator; + +public static class Program { - public class Program + public static List<Guid> ProjectPIDs { get; set; } = new(); + public static List<Guid> ResourcePIDs { get; set; } = new(); + public static List<Guid> UnclassifiedPIDs { get; set; } = new(); + public static List<string> SkippedPIDs { get; set; } = new(); + + private static readonly ConsulConfiguration _configuration = new(); + private static bool _dummyMode = true; + + static void Main(string[] args) { - public static void Main(string[] args) + _dummyMode = !(args.Length > 0 && args[0] == "--noDryRun"); + + // Console text output + Console.Write($"{new string('=', 80)}\n PID Migrator"); + if (_dummyMode) { - var configuration = new ConsulConfiguration(); - DataConnection.DefaultSettings = new CoscineSettings(configuration); - var projectModel = new ProjectModel(); - var resourceModel = new ResourceModel(); - foreach (var project in projectModel.GetAll()) + Console.Write(" : DUMMY MODE"); + } + Console.WriteLine($"\n{new string('-', 80)}"); + + var epicClient = CreateEpicClient(_configuration); + + /*==============================================*/ + var hostUrl = "coscine.rwth-aachen.de"; + /*==============================================*/ + + Console.WriteLine($"- Searching for PIDs containing \"{hostUrl}\" ..."); + var pidMatches = epicClient.Search($"*{hostUrl}*"); // Define as wildcard with *<text>* + Console.WriteLine($"- Search yelded {pidMatches.Count()} results"); + + var projectModel = new ProjectModel(); + var resourceModel = new ResourceModel(); + + Console.WriteLine($"- Collecting Coscine data ..."); + var projects = projectModel.GetAll(); + var resources = resourceModel.GetAll(); + Console.WriteLine($"- Search yelded {projects.Count()} projects and {resources.Count()} resources."); + + Console.WriteLine(); + + // Sanity check the data + if (projects.Count() + resources.Count() > pidMatches.Count()) + { + Console.WriteLine("!! Failed sanity check... Since we're not deleting PIDs, it is not realistic, that we have more non-deleted projects and resources than PID matches."); + Console.WriteLine("Aborting..."); + return; + } + else + { + Console.WriteLine($"Iterating through {pidMatches.Count()} PIDs\n"); + foreach (var pidMatch in pidMatches) { - EpicUtil.UpdatePID(project.Id.ToString(), configuration); + if (Guid.TryParse(pidMatch.EpicPid, out var pid)) + { + Console.WriteLine($"┌ PID \"{pid}\""); + // Get it from the EpicClient + var epicClientPid = epicClient.Get(pid.ToString()); + if (!epicClientPid.Any(e => + { + var parsedData = e.ParsedData.ToString(); + if (parsedData is not null) + { + return parsedData.ToString().Contains("rwth-aachen.de/coscine/apps/pidresolve/?pid="); + } + return false; + })) + { + Console.WriteLine($"└ PID already up to date, or NOT a Coscine PID. Skipping.\n"); + continue; + } + + // Check if it's a project + var project = projectModel.GetByIdIncludingDeleted(pid); + if (project is not null) + { + MigratePid(pid, project.DisplayName, project.Deleted, "project"); + } + else + { + var resource = resourceModel.GetByIdIncludingDeleted(pid); + if (resource is not null) + { + MigratePid(pid, resource.DisplayName, resource.Deleted, "resource"); + } + else + { + Console.WriteLine($"├ Not a project nor a resource. Could be a deleted legacy resource."); + MigratePid(pid, "<UNKNOWN>", true, "unclassified"); + continue; + } + } + } + else + { + Console.WriteLine($"─ PID \"{pidMatch.EpicPid}\" is not a GUID, therefore is not relevant for Coscine. Continuing..."); + SkippedPIDs.Add(pidMatch.EpicPid); + continue; + } } - foreach (var resource in resourceModel.GetAll()) + + var activeProjectsNotMigrated = projects.ExceptBy(ProjectPIDs, p => p.Id); + var activeResourcesNotMigrated = resources.ExceptBy(ResourcePIDs, r => r.Id); + + Console.WriteLine($"\n{new string('-', 80)}"); + Console.WriteLine($" - Active Project that were NOT migrated: {activeProjectsNotMigrated.Count()}"); + activeProjectsNotMigrated.ToList().ForEach(p => Console.WriteLine($" - {p.Id}")); + Console.WriteLine($" - Active Resoures that were NOT migrated: {activeResourcesNotMigrated.Count()}"); + activeResourcesNotMigrated.ToList().ForEach(r => Console.WriteLine($" - {r.Id}")); + + Console.WriteLine(); + Console.WriteLine($" - Project PIDs migrated: {ProjectPIDs.Count()}"); + Console.WriteLine($" - Resource PIDs migrated: {ResourcePIDs.Count()}"); + Console.WriteLine($" - Unclassified PIDs migrated: {UnclassifiedPIDs.Count()}"); + Console.WriteLine($" - TOTAL PIDs MIGRATED: {ProjectPIDs.Count() + ResourcePIDs.Count() + UnclassifiedPIDs.Count()}/{pidMatches.Count()}"); + + Console.WriteLine("\nFinished."); + } + } + + public static EpicClient CreateEpicClient(ConsulConfiguration _configuration) + { + // default localhost + var _prefix = _configuration.GetString("coscine/global/epic/prefix"); + + var _epicClient = new EpicClient( + _configuration.GetString("coscine/global/epic/url"), + _prefix, + _configuration.GetString("coscine/global/epic/user"), + _configuration.GetString("coscine/global/epic/password") + ); + return _epicClient; + } + + public static void MigratePid(Guid pid, string displayName, bool isDeleted, string type) + { + Console.Write($"├ Is a "); + if (isDeleted) + { + Console.Write($"DELETED "); + } + Console.WriteLine($"{type} with display name \"{displayName}\""); + + if (!_dummyMode) + { + try + { + EpicUtil.UpdatePID(pid.ToString(), _configuration); + } + catch (Exception e) { - EpicUtil.UpdatePID(resource.Id.ToString(), configuration); + Console.WriteLine($"└ Migration FAILED. {e.Message}"); + return; } } + + if (type.ToLower().Equals("project")) + { + ProjectPIDs.Add(pid); + } + else if (type.ToLower().Equals("resource")) + { + ResourcePIDs.Add(pid); + } + else + { + UnclassifiedPIDs.Add(pid); + } + Console.WriteLine($"└ Successfully migrated and added to statistics."); + Console.WriteLine(); } -} +} \ No newline at end of file diff --git a/src/PIDMigrator/Properties/AssemblyInfo.cs b/src/PIDMigrator/Properties/AssemblyInfo.cs deleted file mode 100644 index 38bc2792d1a1960e1d16c48b38b2733ba0c876a1..0000000000000000000000000000000000000000 --- a/src/PIDMigrator/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Coscine.PIDMigrator")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Coscine.PIDMigrator")] -[assembly: AssemblyCopyright("Copyright © 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("3bc5bcca-28a9-4108-a791-bf6a2fb7935f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/PIDMigrator/packages.config b/src/PIDMigrator/packages.config deleted file mode 100644 index 35e40042d3d69e079d4146ee11420deebd20858d..0000000000000000000000000000000000000000 --- a/src/PIDMigrator/packages.config +++ /dev/null @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="Consul" version="0.7.2.6" targetFramework="net461" /> - <package id="Coscine.Action" version="1.16.0" targetFramework="net461" /> - <package id="Coscine.Configuration" version="1.5.0" targetFramework="net461" /> - <package id="Coscine.Database" version="1.25.0" targetFramework="net461" /> - <package id="Coscine.ProxyApi" version="1.3.0" targetFramework="net461" /> - <package id="EntityFramework" version="6.4.4" targetFramework="net461" /> - <package id="linq2db" version="3.1.1" targetFramework="net461" /> - <package id="linq2db.SqlServer" version="2.6.4" targetFramework="net461" /> - <package id="linq2db.t4models" version="2.6.4" targetFramework="net461" /> - <package id="LinqKit" version="1.1.17" targetFramework="net461" /> - <package id="Microsoft.Data.Edm" version="5.6.4" targetFramework="net461" /> - <package id="Microsoft.Data.OData" version="5.6.4" targetFramework="net461" /> - <package id="Microsoft.IdentityModel" version="7.0.0" targetFramework="net461" /> - <package id="Microsoft.IdentityModel.JsonWebTokens" version="5.6.0" targetFramework="net461" /> - <package id="Microsoft.IdentityModel.Logging" version="5.6.0" targetFramework="net461" /> - <package id="Microsoft.IdentityModel.Tokens" version="5.6.0" targetFramework="net461" /> - <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net461" /> - <package id="System.IdentityModel.Tokens.Jwt" version="5.6.0" targetFramework="net461" /> - <package id="System.Spatial" version="5.6.4" targetFramework="net461" /> -</packages> \ No newline at end of file diff --git a/tools/packages.config b/tools/packages.config deleted file mode 100644 index 14aef3bf00189e621993b61ccea2e4a203e73b9b..0000000000000000000000000000000000000000 --- a/tools/packages.config +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="Cake" version="0.36.0" /> -</packages>