Beispiel #1
0
        private dynamic getJsonFromApi(string request)
        {
            var req = new JsonWebRequest <dynamic>($"{base_url}/api/{request}");

            req.Perform();
            return(req.ResponseObject);
        }
Beispiel #2
0
        private static void AnnounceToDiscord(string version)
        {
            if (!AnnounceDiscord)
            {
                return;
            }

            var req = new JsonWebRequest <DiscordWebhook>(DiscordWebhookURL)
            {
                Method      = HttpMethod.Post,
                ContentType = "application/json"
            };

            // Get all of the previous PR's name
            var body = $"Version {version} for {GitHubRepoName} has been released! this now fixes and adds:\r\n";

            // Adds every pull requests after the last release
            pullRequests.ForEach(pr => { body += $"- {pr.Title} | {pr.User.Name}\r\n"; });

            body += $"\r\nDownload:\r\n<https://github.com/{GitHubUsername}/{GitHubRepoName}/releases>\r\n<https://www.nuget.org/packages/{GitHubRepoName}/{version}>";

            req.AddRaw(JsonConvert.SerializeObject(new DiscordWebhook
            {
                Content = body
            }));

            req.Perform();
        }
Beispiel #3
0
        protected dynamic GetJsonFromApi(string request)
        {
            using var req = new JsonWebRequest <dynamic>($"{Program.ENDPOINT_CONFIGURATION.APIEndpointUrl}/api/v2/{request}");

            req.AddHeader(System.Net.HttpRequestHeader.Authorization.ToString(), $"Bearer {apiAccessToken}");
            req.Perform();

            return(req.ResponseObject);
        }
 public static T FromUrl <T>(string url)
 {
     using var jsonReq = new JsonWebRequest <T>(url)
           {
               AllowRetryOnTimeout = true
           };
     jsonReq.AddHeader("user-agent", "osu!ude");
     jsonReq.AddHeader("referer", "https://zhzi233.cn");
     jsonReq.Perform();
     return(jsonReq.ResponseObject);
 }
Beispiel #5
0
        private void getAccessToken()
        {
            using var req = new JsonWebRequest <dynamic>($"{Program.ENDPOINT_CONFIGURATION.APIEndpointUrl}/oauth/token")
                  {
                      Method = HttpMethod.Post
                  };

            req.AddParameter("client_id", ClientId);
            req.AddParameter("client_secret", ClientSecret);
            req.AddParameter("grant_type", "client_credentials");
            req.AddParameter("scope", "public");
            req.Perform();

            apiAccessToken = req.ResponseObject.access_token.ToString();
        }
Beispiel #6
0
        public bool Crawl(int id, PisstaubeDbContext _context)
        {
            try
            {
                var setRequest = new JsonWebRequest <BeatmapSet>($"https://{Environment.GetEnvironmentVariable("CHEESEGULL_API")}/api/s/{id}");

                try
                {
                    setRequest.Perform();
                }
                catch
                {
                    if (!setRequest.ResponseString.StartsWith("null"))
                    {
                        throw;
                    }
                }

                var apiSet = setRequest.ResponseObject;
                if (apiSet == null)
                {
                    return(false);
                }

                _searchEngine.IndexBeatmap(apiSet);
                _context.BeatmapSet.Add(apiSet);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, $"Unknown Error occured while crawling Id {id}!");

                // lock (_lock)
                // Thread.Sleep(TimeSpan.FromMinutes(1));
                return(false);
            }

            return(true);
        }
Beispiel #7
0
        private static void Main()
        {
            var currentDirectory  = new NativeStorage(".");
            var solutionDirectory = new NativeStorage("..");

            currentDirectory.DeleteDirectory("./staging");

            if (!Directory.Exists("releases"))
            {
                Directory.CreateDirectory("releases");
            }

            var stagingDirectory = currentDirectory.GetStorageForDirectory("staging");
            var currentDate      = DateTime.Now.ToString("yyyy.Mdd.");

            currentDate += currentDirectory.GetDirectories("releases").Count(s => s.Contains(currentDate));

            var releaseDirectory = currentDirectory.GetStorageForDirectory($"./releases/App-{currentDate}");

            Console.WriteLine($"Package: Qsor");
            Console.WriteLine($"Release Version: {currentDate}");
            Console.WriteLine($"Release Directory: {releaseDirectory.GetFullPath(".")}");
            Console.WriteLine($"Changelog: \n{ChangelogGenerator.GenerateChangelog()}");

            var logo = solutionDirectory.GetFullPath("Qsor.Game/Resources/Textures/Logo-256x256.png");
            var icon = solutionDirectory.GetFullPath("Qsor.Desktop/icon.ico");

            RunCommand("dotnet", $"publish -f netcoreapp3.1 Qsor.Desktop --configuration Release --runtime win-x64 -p:Version={currentDate} -o {stagingDirectory.GetFullPath(".")}",
                       solutionDirectory.GetFullPath("."));

            RunCommand("./tools/rcedit-x64.exe", $"\"{stagingDirectory.GetFullPath(".")}\\Qsor.exe\" --set-icon \"{icon}\"");

            RunCommand(NugetPath, $"pack Qsor.Desktop/qsor.nuspec -Version {currentDate} -Properties Configuration=Release -OutputDirectory {stagingDirectory.GetFullPath(".")} -BasePath {stagingDirectory.GetFullPath(".")}",
                       solutionDirectory.GetFullPath("."));

            RunCommand(SquirrelPath, $"--releasify {stagingDirectory.GetFullPath($"./Qsor.{currentDate}.nupkg")} --releaseDir {releaseDirectory.GetFullPath(".")} --no-msi --icon {icon} --setupIcon {icon} --loadingGif {logo}",
                       stagingDirectory.GetFullPath("."));

            RunCommand("git", $"tag {currentDate}");
            RunCommand("git", $"push origin {currentDate}");

            File.Move(releaseDirectory.GetFullPath("Setup.exe"), releaseDirectory.GetFullPath("install.exe"));

            stagingDirectory.DeleteDirectory(".");

            var req = new JsonWebRequest <GitHubRelease>($"https://api.github.com/repos/Mempler/Qsor/releases")
            {
                Method = HttpMethod.Post,
            };

            Console.WriteLine($"Creating release {currentDate}...");

            req.AddRaw(JsonConvert.SerializeObject(new GitHubRelease
            {
                Name  = currentDate,
                Draft = true,
                Body  = ChangelogGenerator.GenerateChangelog()
            }));

            req.AddHeader("Authorization", $"token {GithubAccessToken}");
            req.Perform();

            var targetRelease = req.ResponseObject;

            var assetUploadUrl = targetRelease.UploadUrl.Replace("{?name,label}", "?name={0}");

            foreach (var a in Directory.GetFiles(releaseDirectory.GetFullPath(".")).Reverse())
            {
                if (Path.GetFileName(a).StartsWith('.'))
                {
                    continue;
                }

                Console.WriteLine($"- Pushing asset {a}...");
                var upload = new WebRequest(assetUploadUrl, Path.GetFileName(a))
                {
                    Method      = HttpMethod.Post,
                    Timeout     = 240000,
                    ContentType = "application/octet-stream",
                };

                upload.AddRaw(File.ReadAllBytes(a));
                upload.AddHeader("Authorization", $"token {GithubAccessToken}");
                upload.Perform();
            }
        }