예제 #1
0
        public static void OnMetadataReceived(string key, string value)
        {
            switch (key)
            {
            case "JsonDowloadInfo":
                DowloadInfoUpdater.OnNewDowloadInfoInServer(value);
                break;

            case "ServerList":
                ServerInfoCollection.SetServerCollection(JsonConvert.DeserializeObject <ObservableCollection <ServerCollectionModel> >(value));

                UCLogsViewModel.TextLogs.Value += $"\nServerList - {value}";
                break;

            case "ServerOutputError":
                GameServerReceivedOutoutHandler.OnError(value);
                UCLogsViewModel.TextLogs.Value += $"\nServerOutputError - {value}";
                break;

            case "ServerOutputOutput":
                GameServerReceivedOutoutHandler.OnNewOutput(value);
                UCLogsViewModel.TextLogs.Value += $"\nServerOutputOutput - {value}";
                break;

            case "ServerOutputException":
                GameServerReceivedOutoutHandler.OnException(value);
                UCLogsViewModel.TextLogs.Value += $"\nServerOutputException - {value}";
                break;

            default:
                UCLogsViewModel.TextLogs.Value += $"\nMetadate is not registred";
                break;
            }
        }
예제 #2
0
        public static async void DowloadServer(string url, string fileName)
        {
            var downloadOpt = new DownloadConfiguration()
            {
                BufferBlockSize       = 10240,        // usually, hosts support max to 8000 bytes, default values is 8000
                ChunkCount            = 8,            // file parts to download, default value is 1
                MaximumBytesPerSecond = int.MaxValue, // download speed limited to 1MB/s, default values is zero or unlimited
                MaxTryAgainOnFailover = int.MaxValue, // the maximum number of times to fail
                OnTheFlyDownload      = false,        // caching in-memory or not? default values is true
                ParallelDownload      = true,         // download parts of file as parallel or not. Default value is false
                TempDirectory         = "C:\\temp",   // Set the temp path for buffering chunk files, the default path is Path.GetTempPath()
                Timeout = 1000,                       // timeout (millisecond) per stream block reader, default values is 1000
                RequestConfiguration =                // config and customize request headers
                {
                    Accept                 = "*/*",
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
                    CookieContainer        = new CookieContainer(),    // Add your cookies
                    Headers               = new WebHeaderCollection(), // Add your custom headers
                    KeepAlive             = false,
                    ProtocolVersion       = HttpVersion.Version11,     // Default value is HTTP 1.1
                    UseDefaultCredentials = false,
                    UserAgent             = $"DownloaderSample/{Assembly.GetExecutingAssembly().GetName().Version.ToString(3)}"
                }
            };

            DownloadService downloader = new DownloadService(downloadOpt);

            downloader.DownloadStarted         += OnDowloadStarted;
            downloader.DownloadFileCompleted   += OnDownloadFileCompleted;
            downloader.DownloadProgressChanged += OnDowloadProgresChanged;

            await downloader.DownloadFileTaskAsync(url, fileName);


            void OnDowloadStarted(object sender, DownloadStartedEventArgs e)
            {
                UCLogsViewModel.TextLogs.Value += "\nDowload started";
            }

            void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
            {
                DowloadInfoUpdater.OnStopUpdateInfo();
            }

            void OnDowloadProgresChanged(object sender, DownloadProgressChangedEventArgs e)
            {
                DowloadInfoUpdater.OnNewUpdateInfo(e);
            }
        }
예제 #3
0
        private static void MessageReceived(object sender, MessageReceivedEventArgs args)
        {
            if (args.Metadata != null)
            {
                foreach (KeyValuePair <object, object> keyValue in args.Metadata)
                {
                    ServerMetadataHandler.OnMetadataReceived(keyValue.Key.ToString(), keyValue.Value.ToString());
                }
                args.Metadata.Clear();
            }

            if (Encoding.UTF8.GetString(args.Data) != "" & Encoding.UTF8.GetString(args.Data) != string.Empty)
            {
                if (Encoding.UTF8.GetString(args.Data).Contains("Загрузка на сервере завершена"))
                {
                    DowloadInfoUpdater.OnDowloadComplitedOnServer();
                    UCServerCreateViewModel.TextLogs.Value += $"\n{Encoding.UTF8.GetString(args.Data)}";
                }
                else
                {
                    UCServerCreateViewModel.TextLogs.Value += $"\n{Encoding.UTF8.GetString(args.Data)}";
                }
            }
        }