/// <summary>
        /// Asynchronously downloads a <see cref="CustomPlatform"/> from modelsaber if the selected level requires it
        /// </summary>
        private async Task DownloadPlatform(string url, CancellationToken cancellationToken)
        {
            try
            {
                WebResponse downloadDataWebResponse = await _webClient.GetAsync(url, cancellationToken);

                if (!downloadDataWebResponse.IsSuccessStatusCode)
                {
                    return;
                }
                PlatformDownloadData platformDownloadData    = downloadDataWebResponse.ContentToJson <Dictionary <string, PlatformDownloadData> >().First().Value;
                WebResponse          platDownloadWebResponse = await _webClient.GetAsync(platformDownloadData.download, cancellationToken);

                if (!platDownloadWebResponse.IsSuccessStatusCode)
                {
                    return;
                }
                byte[] platData = platDownloadWebResponse.ContentToBytes();
                string path     = Path.Combine(_platformManager.DirectoryPath, $"{platformDownloadData.name}.plat");
                _fileSystemWatcher.EnableRaisingEvents = false;
                File.WriteAllBytes(path, platData);
                _fileSystemWatcher.EnableRaisingEvents = true;
                CustomPlatform?requestedPlatform = await _platformManager.CreatePlatformAsync(path);

                cancellationToken.ThrowIfCancellationRequested();
                if (requestedPlatform is null)
                {
                    return;
                }
                _platformManager.AllPlatforms.AddSorted(1, _platformManager.AllPlatforms.Count - 1, requestedPlatform);
                _platformManager.APIRequestedPlatform = requestedPlatform;
            }
            catch (TaskCanceledException) { }
            catch (OperationCanceledException) { }
        }
Пример #2
0
        /// <summary>
        /// Downloads the .plat file from modelsaber, then saves it in the CustomPlatforms directory and loads it
        /// </summary>
        /// <param name="data">The API deserialized API response containing the download link to the .plat file</param>
        /// <returns></returns>
        private IEnumerator <UnityWebRequestAsyncOperation> DownloadSavePlatform(PlatformDownloadData data)
        {
            using UnityWebRequest www = UnityWebRequest.Get(data.download);
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                _siraLog.Info("Error downloading a platform: \n" + www.error);
            }
            else
            {
                string destination = Path.Combine(_platformManager.customPlatformsFolderPath, data.name + ".plat");
                File.WriteAllBytes(destination, www.downloadHandler.data);
                apiRequest = true;
            }
        }
Пример #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SystemDefaultConfig.IsCS           = true;
            SystemDefaultConfig.DataUpdateFlag = 3;
            //显示托盘。
            SetNotifyIcon();
            JudgeProcessExist();

            var _startTime = DateTime.Now;
            //状态定时器
            DispatcherTimer dt = new DispatcherTimer();

            dt.Interval = TimeSpan.FromSeconds(1);
            dt.Tick    += (obj, args) =>
            {
                tbRunTime.Text = GetTimeString((int)(DateTime.Now - _startTime).TotalSeconds);
            };
            dt.Start();

            _basicHttpPort     = OptionHelper.ReadInt("CenterServer", "BasicHttpPort", 80);
            _netTcpPort        = OptionHelper.ReadInt("CenterServer", "NetTcpPort", 4508);
            _isBasicHttpOnly   = OptionHelper.ReadBool("CenterServer", "IsBasicHttpOnly", false);
            this.Title         = OptionHelper.ReadString("CenterServer", "Title", "智慧云平台服务");
            _ServerIP          = OptionHelper.ReadString("CenterServer", "ServerIP", "");
            SystemInfo.ImgPath = OptionHelper.ReadString("CenterServer", "ImgPath", "");

            SystemDefaultConfig.ReadConnectionString  = new ConnectionStringSettings("ReadConnectionString", "data source=" + OptionHelper.DataSource + ";database=" + OptionHelper.Database + ";user id=" + OptionHelper.LoginName + ";password="******"", "System.Data.SqlClient").ToString();
            SystemDefaultConfig.WriteConnectionString = new ConnectionStringSettings("ConnectionString", "data source=" + OptionHelper.DataSource + ";database=" + OptionHelper.Database + ";user id=" + OptionHelper.LoginName + ";password="******"", "System.Data.SqlClient").ToString();

            ThreadPool.QueueUserWorkItem(_ => TestDBConnectionState());

            LoadExtendConfig();

            foreach (var assembly in ExtendAssemblys.Where(a => a.IsEnabled))
            {
                StartAssembly(assembly);
            }

            lvservers.ItemsSource = ExtendAssemblys[0].ServiceHosts;
            PlatformWcfServers.WXServiceCallback.HeartChanged      += WXServiceCallback_HeartChanged;
            PlatformWcfServers.WXServiceCallback.HeartdelteChanged += WXServiceCallback_HeartdelteChanged;
            lvconnection.ItemsSource = PlatformClientes;

            PlatformDownloadData.StartDownload();
        }
Пример #4
0
        /// <summary>
        /// Handles when a song is selected, downloading a <see cref="CustomPlatform"/> from modelsaber if needed
        /// </summary>
        /// <param name="usePlatform">Wether the selected song requests a platform or not</param>
        /// <param name="name">The name of the requested platform</param>
        /// <param name="hash">The hash of the requested platform</param>
        /// <param name="level">The song the platform was requested for</param>
        /// <returns></returns>
        private IEnumerator <UnityWebRequestAsyncOperation> HandleSongSelected(bool usePlatform, string name, string hash, IPreviewBeatmapLevel level)
        {
            // No platform is requested, abort
            if (!usePlatform)
            {
                _platformManager.apiRequestIndex     = -1;
                _platformManager.apiRequestedLevelId = null;
                yield break;
            }

            _platformManager.apiRequestedLevelId = level.levelID;

            // Test if the requested platform is already downloaded
            for (int i = 0; i < _platformManager.allPlatforms.Count; i++)
            {
                if (_platformManager.allPlatforms[i].platHash == hash || _platformManager.allPlatforms[i].platName.StartsWith(name))
                {
                    _platformManager.apiRequestIndex = i;
                    yield break;
                }
            }

            if (hash != null)
            {
                using UnityWebRequest www = UnityWebRequest.Get("https://modelsaber.com/api/v2/get.php?type=platform&filter=hash:" + hash);
                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    _siraLog.Error("Error downloading a platform: \n" + www.error);
                }
                else
                {
                    Dictionary <string, PlatformDownloadData> downloadData = JsonConvert.DeserializeObject <Dictionary <string, PlatformDownloadData> >(www.downloadHandler.text);
                    PlatformDownloadData data = downloadData.FirstOrDefault().Value;
                    if (data != null)
                    {
                        SharedCoroutineStarter.instance.StartCoroutine(DownloadSavePlatform(data));
                    }
                }
            }

            else if (name != null)
            {
                using UnityWebRequest www = UnityWebRequest.Get("https://modelsaber.com/api/v2/get.php?type=platform&filter=name:" + name);
                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    _siraLog.Info("Error downloading a platform: \n" + www.error);
                }
                else
                {
                    Dictionary <string, PlatformDownloadData> downloadData = JsonConvert.DeserializeObject <Dictionary <string, PlatformDownloadData> >(www.downloadHandler.text);
                    PlatformDownloadData data = downloadData.FirstOrDefault().Value;
                    if (data != null)
                    {
                        SharedCoroutineStarter.instance.StartCoroutine(DownloadSavePlatform(data));
                    }
                }
            }
        }