Example #1
0
        private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (pendingHandler != null)
            {
                pendingHandler.Close();
            }
            string log = e.Result as string;

            if (!string.IsNullOrEmpty(log))
            {
                this.Result = log;
            }
            else
            {
                this.Result = "无搜索结果";
            }
        }
        public async void EnableLoaclApi()
        {
            if (ApiUpdateInfo == "ApiUpdate" || !Directory.Exists(Api.ApiFilePath1) || !Directory.Exists(Api.ApiFilePath2))
            {
                IPendingHandler pb = PendingBox.Show("初始化信息接口中...", null, false, Application.Current.MainWindow, new PendingBoxConfigurations()
                {
                    MinHeight = 110,
                    MaxHeight = 110,
                    MinWidth  = 280,
                    MaxWidth  = 280
                });

                await Task.Run(() =>
                {
                    Api.ApiStart(music.apiver, music.zipurl);
                    while (!Api.ok)
                    {
                    }
                });

                if (!Api.SetCookie(music.qqcookie))
                {
                    AduMessageBox.Show("初始化错误", "提示");
                    Api.StopApi();
                    Environment.Exit(0);
                }
                pb.Close();
            }
            else
            {
                IPendingHandler pb = PendingBox.Show("启动服务中...", null, false, Application.Current.MainWindow, new PendingBoxConfigurations()
                {
                    MinHeight = 110,
                    MaxHeight = 110,
                    MinWidth  = 280,
                    MaxWidth  = 280
                });
                await Task.Run(() =>
                {
                    Api.ApiStart(music.apiver, music.zipurl);
                    while (!Api.ok)
                    {
                    }
                });

                if (!Api.SetCookie(music.qqcookie))
                {
                    AduMessageBox.Show("服务启动错误", "提示");
                    Api.StopApi();
                    Environment.Exit(0);
                }
                pb.Close();
            }
            music.NeteaseApiUrl = "http://127.0.0.1:" + Api.port1 + "/";
            music.QQApiUrl      = "http://127.0.0.1:" + Api.port2 + "/";
        }
        private async void DownloadNodejsButton_Click(object sender, RoutedEventArgs e)
        {
            IPendingHandler pb = PendingBox.Show("下载中......", null, false, Application.Current.MainWindow, new PendingBoxConfigurations()
            {
                MinHeight = 110,
                MaxHeight = 110,
                MinWidth  = 280,
                MaxWidth  = 280
            });
            await Task.Run(new Action(() =>
            {
                Api.DownloadNodejs();
                while (!Api.NodejsDownloadSuc)
                {
                }
            }));

            pb.Close();
        }
        public async void PendingBox(string cap)
        {
            IPendingHandler handler = null;

            switch (cap)
            {
            case "normal":
                handler = PendingBoxX.Show("Processing .....", "Normal", true, Application.Current.MainWindow);
                break;
            }
            if (handler != null)
            {
                handler.Cancelling += Handler_Cancelling;
                await Task.Delay(2000);

                handler.UpdateMessage("Almost complete ...");
                await Task.Delay(4000);

                handler.Close();
            }
        }
        public async void EnableLoaclApi()
        {
            if (ApiUpdateInfo == "ApiUpdate" /*|| !Directory.Exists(Api.ApiFilePath1)*/ || !Directory.Exists(Api.ApiFilePath2))
            {
                IPendingHandler pb = PendingBox.Show("初始化信息接口中...", null, false, Application.Current.MainWindow, new PendingBoxConfigurations()
                {
                    MinHeight = 110,
                    MaxHeight = 110,
                    MinWidth  = 280,
                    MaxWidth  = 280
                });

                await Task.Run(() =>
                {
                    bool r = Api.ApiStart(music.apiver, music.zipurl);
                    if (!r)
                    {
                        Dispatcher.Invoke(new Action(() => { setting.EnableLoacApi = false; pb.Close(); AduMessageBox.Show("服务启动错误", "提示"); }));
                    }
                    while (!Api.ok)
                    {
                    }
                });

                if (!Api.SetCookie(music.qqcookie))
                {
                    AduMessageBox.Show("初始化错误", "提示");
                    Api.StopApi();
                    Environment.Exit(0);
                }
                pb.Close();
            }
            else
            {
                IPendingHandler pb = PendingBox.Show("启动服务中...", null, false, Application.Current.MainWindow, new PendingBoxConfigurations()
                {
                    MinHeight = 110,
                    MaxHeight = 110,
                    MinWidth  = 280,
                    MaxWidth  = 280
                });
                await Task.Run(() =>
                {
                    bool r = Api.ApiStart(music.apiver, music.zipurl);
                    Dispatcher.Invoke(new Action(() =>
                    {
                        if (!r)
                        {
                            AduMessageBox.Show("服务启动错误(调用错误)", "提示");
                        }
                    }));

                    while (!Api.ok)
                    {
                    }
                });

                System.Threading.Thread.Sleep(1000);
                if (!Api.SetCookie(music.qqcookie))
                {
                    AduMessageBox.Show("服务启动错误(Cookie设置错误)", "提示");
                    Api.StopApi();
                    Environment.Exit(0);
                }
                pb.Close();
            }
            //music.NeteaseApiUrl = "http://127.0.0.1:" + Api.port1 + "/";
            music.QQApiUrl = "http://127.0.0.1:" + Api.port2 + "/";
        }
 private void Handler_Cancelling(IPendingHandler sender, Panuon.UI.Silver.Core.PendingBoxCancellingEventArgs e)
 {
     sender.Close();
 }