예제 #1
0
        private async Task BeginServerUpdate(PhotonServerDefinition server, HttpPackageIndex index)
        {
            ConsoleEx.Out.Write("Downloading Server update ", ConsoleColor.DarkCyan)
            .Write(index.Version, ConsoleColor.Cyan)
            .WriteLine("...", ConsoleColor.DarkCyan);

            var updateDirectory = Path.Combine(Configuration.Directory, "Updates");
            var updateFilename  = Path.Combine(updateDirectory, "Photon.Server.msi");

            PathEx.CreatePath(updateDirectory);

            using (var client = new WebClient()) {
                var url = NetPath.Combine(Configuration.DownloadUrl, "server", index.Version, index.MsiFilename);
                await client.DownloadFileTaskAsync(url, updateFilename);
            }

            ConsoleEx.Out
            .WriteLine("Download Complete.", ConsoleColor.DarkBlue)
            .WriteLine("Uploading update to Server...", ConsoleColor.DarkCyan);

            await WebClientEx(server, client => {
                client.Method      = "POST";
                client.Url         = NetPath.Combine(server.Url, "api/server/update");
                client.ContentType = "application/octet-stream";
                client.BodyFunc    = () => File.Open(updateFilename, FileMode.Open, FileAccess.Read);
            }, null);

            ConsoleEx.Out.WriteLine("Upload Complete.", ConsoleColor.DarkBlue);
        }
예제 #2
0
        private async Task DownloadUpdate(HttpPackageIndex index)
        {
            if (!Directory.Exists(updateDirectory))
            {
                Directory.CreateDirectory(updateDirectory);
            }

            try {
                var url = NetPath.Combine(Configuration.DownloadUrl, "CLI", index.Version, index.MsiFilename);

                using (var client = HttpClientEx.Get(url)) {
                    await client.Send();

                    using (var fileStream = File.Open(updateFilename, FileMode.Create, FileAccess.Write))
                        using (var responseStream = client.ResponseBase.GetResponseStream()) {
                            if (responseStream != null)
                            {
                                await responseStream.CopyToAsync(fileStream);
                            }
                        }
                }
            }
            catch (HttpStatusCodeException error) {
                throw new ApplicationException("Failed to download CLI update!", error);
            }
        }
예제 #3
0
        private async Task BeginServerUpdate(PhotonServerDefinition server, HttpPackageIndex index)
        {
            ConsoleEx.Out.Write("Downloading Server update ", ConsoleColor.DarkCyan)
            .Write(index.Version, ConsoleColor.Cyan)
            .WriteLine("...", ConsoleColor.DarkCyan);

            string updateFilename;

            try {
                var url = NetPath.Combine(Configuration.DownloadUrl, "server", index.Version, index.MsiFilename);

                var updateDirectory = Path.Combine(Configuration.Directory, "Updates");
                updateFilename = Path.Combine(updateDirectory, "Photon.Server.msi");

                PathEx.CreatePath(updateDirectory);

                using (var client = HttpClientEx.Get(url)) {
                    await client.Send();

                    using (var responseStream = client.ResponseBase.GetResponseStream()) {
                        using (var fileStream = File.Open(updateFilename, FileMode.Create, FileAccess.Write))
                            if (responseStream != null)
                            {
                                await responseStream.CopyToAsync(fileStream);
                            }
                    }
                }

                ConsoleEx.Out.WriteLine("Download Complete.", ConsoleColor.DarkBlue);
            }
            catch (HttpStatusCodeException error) {
                if (error.HttpCode == HttpStatusCode.NotFound)
                {
                    throw new ApplicationException($"Photon-Server instance '{server.Name}' not found!");
                }

                throw;
            }

            ConsoleEx.Out.WriteLine("Uploading update to Server...", ConsoleColor.DarkCyan);

            try {
                var url = NetPath.Combine(server.Url, "api/server/update");

                using (var client = HttpClientEx.Post(url)) {
                    client.ContentType = "application/octet-stream";
                    client.BodyFunc    = () => File.Open(updateFilename, FileMode.Open, FileAccess.Read);

                    await client.Send();

                    if (client.ResponseBase.StatusCode == HttpStatusCode.BadRequest)
                    {
                        var text = await client.GetResponseTextAsync();

                        throw new ApplicationException($"Bad Update Request! {text}");
                    }
                }

                ConsoleEx.Out.WriteLine("Upload Complete.", ConsoleColor.DarkBlue);
            }
            catch (HttpStatusCodeException error) {
                if (error.HttpCode == HttpStatusCode.NotFound)
                {
                    throw new ApplicationException($"Photon-Server instance '{server.Name}' not found!");
                }

                throw;
            }
        }