コード例 #1
0
ファイル: NotificationService.cs プロジェクト: q4a/Wolven-kit
        private static void ShowNotificationInApp(string message, ENotificationType type)
        {
            Action action = type switch
            {
                ENotificationType.Success => () => Growl.Success(message),
                ENotificationType.Info => () => Growl.Info(message),
                ENotificationType.Warning => () => Growl.Warning(message),
                ENotificationType.Error => () => Growl.Error(message),
                ENotificationType.Fatal => () => Growl.Fatal(message),
                _ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
            };

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, action);
        }

        #endregion
    }
コード例 #2
0
        public async void Login()
        {
            BtnLoginEnable = false;

            if (Settings.Username.IsBlank() || Settings.Password.IsBlank())
            {
                Growl.Error("Username or password is err!", Global.TOKEN_LOGIN);
                goto RETURN_POINT;
            }

            //Proxy
            HttpHelper.ProxyInfo PROXY = Settings.ProxyEnable ? new HttpHelper.ProxyInfo(Settings.ProxyHost, Settings.ProxyPort, Settings.ProxyUser, Settings.ProxyPwd) : null;

            //Login
            (string msg, LoginKey key) = await Client.Login(Settings.Username, Settings.Password, null, PROXY);

            (string msg2, LoginKey key2) = await Client.Login(Settings.Accesstoken, PROXY);

            (string msg3, LoginKey key3) = await Client.Login(Settings.Username, Settings.Password, "_DSTon1kC8pABnTw", PROXY);

            if (msg.IsNotBlank() || key == null)
            {
                Growl.Error("Login Err! " + msg, Global.TOKEN_LOGIN);
                goto RETURN_POINT;
            }

            if (!Settings.Remember)
            {
                Settings.Password = null;
            }
            Settings.Userid      = key.UserID;
            Settings.Sessionid1  = key.SessionID;
            Settings.Accesstoken = Settings.Accesstoken;
            Settings.Save();
            Global.CommonKey = key;
            Global.VideoKey  = key3;
            Global.AccessKey = key2;

            Manager.ShowWindow(VMMain);
            RequestClose();

RETURN_POINT:
            BtnLoginEnable = true;
            return;
        }
コード例 #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var displayName = DisplayName.Text;

            _sr.InteractiveTask(() =>
            {
                int ret;

                _sr.Procedure = null;
                var local     = new ProfileProcedure();

                try
                {
                    ret = local.Step1(displayName, Helper.GetTrace(), null);

                    AccountStatus status = null;

                    ret = CheckVendor.NotValidResponseCode(ret) ? ret : local.Step2(out status);

                    if (!CheckVendor.NotValidResponseCode(ret) && status != null)
                    {
                        displayName = status.DisplayName;
                    }
                }
                catch (HttpRequestException ex)
                {
                    ret = 02_0000 + (int)(ex.Data["StatusCode"]);
                }
                catch (Exception)
                {
                    ret = 02_0000;
                }

                if (CheckVendor.NotValidResponseCode(ret))
                {
                    Growl.Error(MessageVendor.FormatError(ret));
                }
                else
                {
                    Growl.Success("成功修改显示名称");
                    _sr.Dispname = displayName;
                    SubwindowNavigator.Navigate(SubwindowPage.LoggedIn);
                }
            });
        }
コード例 #4
0
        private void HandleFuncCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            System.Drawing.Image img = Common.ocr.GetOCRAreaCap();

            SrcImg.Source = ImageProcFunc.ImageToBitmapImage(img);
            try
            {
                DstImg.Source = ImageProcFunc.ImageToBitmapImage(ImageProcFunc.Auto_Thresholding(new System.Drawing.Bitmap(img),
                                                                                                 ImageProcFunc.lstHandleFun[ImageProcFunclist[HandleFuncCombox.SelectedIndex]]));
            }
            catch (NullReferenceException ex)
            {
                Growl.Error(Application.Current.Resources["ChooseOCRAreaPage_RenewErrorHint"].ToString());
                return;
            }

            GC.Collect();
        }
コード例 #5
0
 public void Download()
 {
     if (Detail == null)
     {
         Growl.Error("Nothing to downlond!", "SearchMsg");
         return;
     }
     //remove uncheck item
     if (RemoveItems() != true)
     {
         Growl.Error("Nothing to downlond!", "SearchMsg");
         return;
     }
     //add task
     MainView.VMDownload.AddTask(Detail.Data);
     //go to download page
     MainView.ShowDownload();
 }
コード例 #6
0
        private void Red(string name)
        {
            var list = biqudu.GetSearchList(name, ProcedurePath);

            Dispatcher.Invoke(() =>
            {
                d.Close();
                if (list.Count == 0)
                {
                    Growl.Error(new GrowlInfo
                    {
                        Message  = "骚年,没有搜索到你想要的结果!",
                        WaitTime = 3,
                        Token    = "SuccessMsg"
                    });
                }
                NovelListData.ItemsSource = list;
            });
        }
コード例 #7
0
 private void ChooseWinBtn_Click(object sender, RoutedEventArgs e)
 {
     if (IsChoosingWin == false)
     {
         bool r = hook.Start(Process.GetCurrentProcess().MainModule.ModuleName);
         if (r)
         {
             IsChoosingWin = true;
         }
         else
         {
             Growl.Error(Application.Current.Resources["Hook_Error_Hint"].ToString());
         }
     }
     else if (IsChoosingWin == true)
     {
         hook.Stop();
         IsChoosingWin = false;
     }
 }
コード例 #8
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var code = VerifyCode.Text;

            _sr.InteractiveTask(() =>
            {
                int ret;

                try
                {
                    if (!(_sr.Procedure is RecoveryProcedure local))
                    {
                        ret = 02_0009;
                        goto FAIL;
                    }

                    ret = local.Step2(code);
                }
                catch (HttpRequestException ex)
                {
                    ret = 02_0000 + (int)(ex.Data["StatusCode"]);
                }
                catch (Exception)
                {
                    ret = 02_0000;
                }

                FAIL:
                if (CheckVendor.NotValidResponseCode(ret))
                {
                    Growl.Error(MessageVendor.FormatError(ret));
                }
                else
                {
                    SubwindowNavigator.Navigate(SubwindowPage.Recovery2);
                }
            });
        }
コード例 #9
0
        public string BitlyShorten(string longUrl)
        {
            string url = string.Format(
                "http://api.bit.ly/shorten?format=json&version=2.0.1&longUrl={0}&login={1}&apiKey={2}",
                HttpUtility.UrlEncode(longUrl), BitlyLoginKey, BitlyApiKey);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            try
            {
                WebResponse response = request.GetResponse();
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader         reader = new StreamReader(responseStream, Encoding.UTF8);
                    JavaScriptSerializer js     = new JavaScriptSerializer();
                    dynamic jsonResponse        = js.Deserialize <dynamic>(reader.ReadToEnd());
                    string  s = jsonResponse["results"][longUrl]["shortUrl"];
                    return(s);
                }
            }
            catch (WebException ex)
            {
                WebResponse errorResponse = ex.Response;
                using (Stream responseStream = errorResponse.GetResponseStream())
                {
                    StreamReader reader    = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
                    string       errorText = reader.ReadToEnd();
                    Growl.Error(errorText);
                }

                throw;
            }
            catch (RuntimeBinderException ex)
            {
                Growl.Error(ex.Message);
                return("");
            }
        }
コード例 #10
0
        public PageRegister1(SubwindowRouter sr)
        {
            _sr = sr;
            InitializeComponent();

            _sr.InteractiveTask(() =>
            {
                _sr.Service   = null;
                _sr.Character = null;

                if (!SubwindowDataCollector.Collect(5 * 60 * 1000, out _sr.Service, out _sr.Character))
                {
                    Growl.Error("等待超时,请返回上一页重试");

                    return;
                }

                if (_sr.Service != null && _sr.Character != null)
                {
                    SubwindowNavigator.Navigate(SubwindowPage.Register2);
                }
            });
        }
コード例 #11
0
 private void EffectPicture(object source, ElapsedEventArgs e)
 {
     try
     {
         ImgInfo info = imgHelper.GetNextImage();
         if (UserDataManage.IsDislike(info.Id))
         {
             info = imgHelper.GetNextImage();
         }
         picBox.Dispatcher.BeginInvoke(new Action <Image, ImgInfo>((image, imgInfo) =>
         {
             timerP.Stop();
             imageQueue.Queue(picBox, info);
         }), new Object[] { picBox, info });
     }
     catch (Exception ex)
     {
         Common.LogHelper.WriteLog(ex.Message, Common.EnumLogLevel.Error);
         picBox.Dispatcher.BeginInvoke(new Action <Exception>((exc) =>
         {
             Growl.Error("壁纸切换异常:\n\t" + exc.Message);
         }), new Object[] { ex });
     }
 }
コード例 #12
0
        public string PlinkShorten(string longUrl, string customURL = "")
        {
            string link = string.Empty;

            using (WebClient wb = new WebClient())
            {
                UTF8Encoding utf8        = new UTF8Encoding();
                string       utf8Encoded = HttpUtility.UrlEncode(longUrl, utf8);

                string response = wb.DownloadString("https://plink.ir/api?api=" + PlinkApiKey + "& url=" + utf8Encoded +
                                                    "&custom=" + customURL);
                PlinkData root = JsonConvert.DeserializeObject <PlinkData>(response);
                if (root.error.Contains("0"))
                {
                    link = root.@short;
                }
                else
                {
                    Growl.Error(root.msg);
                }
            }

            return(link);
        }
コード例 #13
0
 private void ImageQueue_OnError(Exception e)
 {
     Growl.Error(e.Message);
 }
コード例 #14
0
        public async void Login2()
        {
            BtnLoginEnable = false;

            if (Settings.Username.IsBlank() || Settings.Password.IsBlank())
            {
                Growl.Error("Username or password is err!", Global.TOKEN_LOGIN);
                goto RETURN_POINT;
            }

            //Proxy
            HttpHelper.ProxyInfo PROXY = Settings.ProxyEnable ? new HttpHelper.ProxyInfo(Settings.ProxyHost, Settings.ProxyPort, Settings.ProxyUser, Settings.ProxyPwd) : null;

            //token
            (string token1, string token2) = await GetToken();

            //Login (lossless key \ video key)
            (string msg, LoginKey key) = await Client.Login(Settings.Username, Settings.Password, token1, PROXY);

            (string msg3, LoginKey key3) = await Client.Login(Settings.Username, Settings.Password, token2, PROXY);

            if (msg.IsNotBlank() || key == null)
            {
                Growl.Error("Login Err! " + msg, Global.TOKEN_LOGIN);
                goto RETURN_POINT;
            }

            //Auto get accesstoken(master key)
            string printSuccess = null;
            string printWarning = null;

            (string msg2, LoginKey key2) = Client.GetAccessTokenFromTidalDesktop(key.UserID);
            if (key2 != null && msg2.IsBlank() && key2.AccessToken != Settings.Accesstoken)
            {
                (msg2, key2) = await Client.Login(key2.AccessToken, PROXY);

                if (msg2.IsBlank() && key2 != null)
                {
                    printSuccess         = "Auto get accesstoken success!";
                    Settings.Accesstoken = key2.AccessToken;
                }
            }
            else
            {
                key2 = null;
            }

            if (key2 == null && Settings.Accesstoken.IsNotBlank())
            {
                (msg2, key2) = await Client.Login(Settings.Accesstoken, PROXY);

                if (msg2.IsNotBlank() || key2 == null)
                {
                    printWarning = "Accesstoken is not valid! " + msg;
                }
            }

            if (!Settings.Remember)
            {
                Settings.Password = null;
            }
            Settings.Userid      = key.UserID;
            Settings.Sessionid1  = key.SessionID;
            Settings.Accesstoken = Settings.Accesstoken;
            Settings.Save();
            Global.CommonKey = key;
            Global.VideoKey  = key3;
            Global.AccessKey = key2;

            Manager.ShowWindow(VMMain);
            if (printSuccess.IsNotBlank())
            {
                Growl.Success(printSuccess, Global.TOKEN_MAIN);
            }
            else if (printWarning.IsNotBlank())
            {
                Growl.Warning(printWarning, Global.TOKEN_MAIN);
            }

            RequestClose();

RETURN_POINT:
            BtnLoginEnable = true;
            return;
        }
コード例 #15
0
        public async void GetDetail()
        {
            if (SearchResult == null)
            {
                Growl.Error("Please search first!", Global.TOKEN_MAIN);
                return;
            }

            ShowWait = true;

            string id           = null;
            eType  type         = eType.NONE;
            string selectHeader = ((System.Windows.Controls.TabItem)((SearchView)this.View).ctrSearchTab.SelectedItem).Header.ToString();

            if (selectHeader == "ALBUM")
            {
                if (((SearchView)this.View).ctrAlbumGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                id   = SearchResult.Albums[((SearchView)this.View).ctrAlbumGrid.SelectedIndex].ID.ToString();
                type = eType.ALBUM;
            }
            else if (selectHeader == "TRACK")
            {
                if (((SearchView)this.View).ctrTrackGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                id   = SearchResult.Tracks[((SearchView)this.View).ctrTrackGrid.SelectedIndex].ID.ToString();
                type = eType.TRACK;
            }
            else if (selectHeader == "VIDEO")
            {
                if (((SearchView)this.View).ctrVideoGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                id   = SearchResult.Videos[((SearchView)this.View).ctrVideoGrid.SelectedIndex].ID.ToString();
                type = eType.VIDEO;
            }
            else if (selectHeader == "ARTIST")
            {
                if (((SearchView)this.View).ctrArtistGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                id   = SearchResult.Artists[((SearchView)this.View).ctrArtistGrid.SelectedIndex].ID.ToString();
                type = eType.ARTIST;
            }
            else if (selectHeader == "PLAYLIST")
            {
                if (((SearchView)this.View).ctrPlaylistGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                id   = SearchResult.Playlists[((SearchView)this.View).ctrPlaylistGrid.SelectedIndex].UUID;
                type = eType.PLAYLIST;
            }

            (string msg, eType otype, object data) = await Client.Get(Global.CommonKey, id, type, Global.Settings.SearchNum, Global.Settings.IncludeEP, false);

            Detail     = Detail.Creat(data, type);
            ShowDetail = true;
            ShowList   = false;
            ShowWait   = false;
            return;

ERR_NO_SELECT:
            Growl.Error("Please select one item!", Global.TOKEN_MAIN);
            ShowWait = false;
            return;
        }
コード例 #16
0
ファイル: MainWindowBus.cs プロジェクト: duyi324/AutumnBox
 public static void Error(string message)
 {
     Growl.Error(App.Current.Resources[message]?.ToString() ?? message, TOKEN_PANEL_MAIN);
 }
コード例 #17
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var password    = NewPassword.Password.ToCharArray();
            var passconfirm = NewConfirm.Password.ToCharArray();
            var username    = Username.Text;
            var display     = DisplayName.Text;
            var email       = Email.Text;

            _sr.InteractiveTask(() =>
            {
                int ret;


                if (!password.SequenceEqual(passconfirm))
                {
                    Growl.Error("密码输入不一致");
                    return;
                }

                if (password.Length < 8)
                {
                    Growl.Error("请使用八位及以上长度的密码");
                    return;
                }

                if (!password.Intersect("0123456789".ToCharArray()).Any())
                {
                    Growl.Error("密码应包含数字");
                    return;
                }

                if (!password.Intersect("ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray()).Any())
                {
                    Growl.Error("密码应包含大写字母");
                    return;
                }

                if (!password.Intersect("abcdefghijklmnopqrstuvwxyz".ToCharArray()).Any())
                {
                    Growl.Error("密码应包含小写字母");
                    return;
                }

                _sr.Procedure = null;
                var local     = new RegisterProcedure();

                try
                {
                    ret = local.Step1(_sr.Service, _sr.Character, username, display, email,
                                      Encoding.UTF8.GetBytes(password), Helper.GetTrace());

                    ret = CheckVendor.NotValidResponseCode(ret) ? ret : local.Step2();

                    byte[] token = null;

                    ret = CheckVendor.NotValidResponseCode(ret) ? ret : local.Step3(out token);

                    _sr.RenewToken = token;

                    if (!CheckVendor.NotValidResponseCode(ret))
                    {
                        var prof     = new ProfileProcedure();
                        ret          = prof.Step2(out var status);
                        _sr.Username = status.Username;
                        _sr.Dispname = status.DisplayName;
                    }
                }
                catch (HttpRequestException ex)
                {
                    ret = 02_0000 + (int)(ex.Data["StatusCode"]);
                }
                catch (Exception)
                {
                    ret = 02_0000;
                }

                if (CheckVendor.NotValidResponseCode(ret))
                {
                    Growl.Error(MessageVendor.FormatError(ret));
                }
                else
                {
                    Growl.Success("欢迎," + (!string.IsNullOrWhiteSpace(_sr.Dispname) ? _sr.Dispname : _sr.Username));
                    SubwindowNavigator.Navigate(SubwindowPage.LoggedIn);
                }
            });
        }
コード例 #18
0
ファイル: ImageList.xaml.cs プロジェクト: HaiqTop/HWallpaper
        /// <summary>
        /// 壁纸上动态显示的按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (btn == null)
            {
                return;
            }
            ImgInfo imgInfo;

            if ((btn.Parent as StackPanel).Tag is ImgInfo info)
            {
                imgInfo = info;
            }
            else
            {
                imgInfo = this.GetimgInfo((btn.Parent as StackPanel).Tag);
            }
            switch (btn.Name)
            {
            case "btn_down":
            {
                if (btn.Foreground == Brushes.White)
                {
                    btn.IsEnabled = false;
                    string imgFullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName());
                    if (!System.IO.File.Exists(imgFullName))
                    {
                        System.Drawing.Image img = WebHelper.GetImage(imgInfo.url);
                        img.Save(imgFullName);
                        img.Dispose();
                    }
                    btn.Foreground = Brushes.Red;
                    btn.IsEnabled  = true;
                    Growl.Success("下载成功。");
                    UserDataManage.SetDown(imgFullName, imgInfo);
                    if (btn_love.Foreground == Brushes.White)
                    {
                        UserDataManage.SetLove(LoveType.Love, imgInfo);
                        btn_love.Foreground    = Brushes.Red;
                        btn_dislike.Foreground = Brushes.White;
                    }
                }
            }
            break;

            case "btn_wallpaper":
            {
                if (btn.Foreground == Brushes.White)
                {
                    btn.IsEnabled = false;
                    string imgFullName = System.IO.Path.Combine(this.CachePath, imgInfo.GetFileName());
                    if (!System.IO.File.Exists(imgFullName))
                    {
                        System.Drawing.Image img = WebHelper.GetImage(imgInfo.url);
                        img.Save(imgFullName);
                        img.Dispose();
                    }
                    if (System.IO.File.Exists(imgFullName))
                    {
                        WinApi.SetWallpaper(imgFullName);
                        btn.Foreground = Brushes.Red;
                        Growl.Success("壁纸设置成功。");
                        btn.IsEnabled = true;
                        UserDataManage.AddRecord(RecordType.ManualWallpaper, imgInfo);
                    }
                    else
                    {
                        Growl.Error("未找到壁纸文件,壁纸设置失败。");
                    }
                }
            }
            break;

            case "btn_love":
            {
                if (btn.Foreground == Brushes.White)
                {
                    UserDataManage.SetLove(LoveType.Love, imgInfo);
                    btn.Foreground         = Brushes.Red;
                    btn_dislike.Foreground = Brushes.White;
                }
            }
            break;

            case "btn_dislike":
            {
                if (btn.Foreground == Brushes.White)
                {
                    UserDataManage.SetLove(LoveType.Dislike, imgInfo);
                    btn.Foreground      = Brushes.Red;
                    btn_love.Foreground = Brushes.White;
                }
            }
            break;
            }
        }
コード例 #19
0
        public MainWindow(MainWindowViewModel viewModel)
        {
            InitializeComponent();
            ViewModel  = viewModel;
            growlToken = GrowlStackPanel.Name;
            Growl.Register(growlToken, GrowlStackPanel);
            this.WhenActivated(disposableRegistration =>
            {
                this.OneWayBind(ViewModel,
                                vm => vm.AccountAuthorityLevel,
                                v => v.LoginSideMenu.Visibility,
                                value => value == AuthorityLevel.Visitor ? Visibility.Visible : Visibility.Collapsed)
                .DisposeWith(disposableRegistration);
                this.OneWayBind(ViewModel,
                                vm => vm.AccountAuthorityLevel,
                                v => v.RegisterSideMenu.Visibility,
                                value => value == AuthorityLevel.Visitor ? Visibility.Visible : Visibility.Collapsed)
                .DisposeWith(disposableRegistration);
                this.OneWayBind(ViewModel,
                                vm => vm.AccountAuthorityLevel,
                                v => v.BorrowLogSideMenu.Visibility,
                                value => value >= AuthorityLevel.Member ? Visibility.Visible : Visibility.Collapsed)
                .DisposeWith(disposableRegistration);
                this.OneWayBind(ViewModel,
                                vm => vm.AccountAuthorityLevel,
                                v => v.AccountInfoSideMenu.Visibility,
                                value => value >= AuthorityLevel.Member ? Visibility.Visible : Visibility.Collapsed)
                .DisposeWith(disposableRegistration);
                this.OneWayBind(ViewModel,
                                vm => vm.AccountAuthorityLevel,
                                v => v.BooksSideMenu.Visibility,
                                value => value >= AuthorityLevel.Member ? Visibility.Visible : Visibility.Collapsed)
                .DisposeWith(disposableRegistration);

                Observable.FromEventPattern(MainSideMenu, nameof(MainSideMenu.SelectionChanged))
                .Select(ep => (ep.EventArgs as FunctionEventArgs <object>)?.Info as SideMenuItem)
                .Where(smi => smi != null)
                .Subscribe(smi => Navigate(smi.Name))
                .DisposeWith(disposableRegistration);

                Observable.FromEventPattern(AboutMenuItem, nameof(AboutMenuItem.Click))
                .Subscribe(ep => aboutWindow.Show())
                .DisposeWith(disposableRegistration);

                foreach (SideMenuItem smi in MainSideMenu.Items.OfType <SideMenuItem>().SelectMany(smi => smi.Items).OfType <SideMenuItem>())
                {
                    sideMenuItems.Add(smi.Name, smi);
                }

                // 注册右上角漂浮通知
                ViewModel.GUINotify.RegisterHandler(async interactioni =>
                {
                    await Task.Run(() =>
                    {
                        GUINotifyingDataPackage info = interactioni.Input;
                        interactioni.SetOutput(Unit.Default);
                        GrowlInfo growlInfo = new GrowlInfo
                        {
                            Message   = info.Message,
                            WaitTime  = (int)info.Duration.TotalSeconds,
                            Token     = growlToken,
                            StaysOpen = false,
                            IsCustom  = true
                        };
                        switch (info.Type)
                        {
                        case NotifyingType.Success:
                            growlInfo.WaitTime = growlInfo.WaitTime == 0 ? 4 : growlInfo.WaitTime;
                            Growl.Success(growlInfo);
                            break;

                        default:
                        case NotifyingType.Info:
                            growlInfo.WaitTime = growlInfo.WaitTime == 0 ? 4 : growlInfo.WaitTime;
                            Growl.Info(growlInfo);
                            break;

                        case NotifyingType.Warning:
                            growlInfo.WaitTime = growlInfo.WaitTime == 0 ? 6 : growlInfo.WaitTime;
                            Growl.Warning(growlInfo);
                            break;

                        case NotifyingType.Error:
                            growlInfo.WaitTime = growlInfo.WaitTime == 0 ? 8 : growlInfo.WaitTime;
                            Growl.Error(growlInfo);
                            break;

                        case NotifyingType.Fatal:
                            growlInfo.WaitTime = growlInfo.WaitTime == 0 ? 10 : growlInfo.WaitTime;
                            Growl.Fatal(growlInfo);
                            break;
                        }
                    });
                });
            });
        }
コード例 #20
0
        public static List <LocpackData> ReadAllLocpack()
        {
            /*return await Task.Run(() => {
             *
             * });*/
            List <LocpackData> list = new List <LocpackData>();
            string             path = Properties.Settings.Default.FileLocation;

            if (path == null || path == string.Empty)
            {
                Growl.Warning("未指定Localizer汉化包存放位置.");
                return(list);
            }
            var files = Directory.GetFiles(path, "*.locpack");

            if (files.Any())
            {
                foreach (var filename in files)
                {
                    try  //开始读取单个文件
                    {
                        var jsons = new Dictionary <string, JObject>();
                        var zip   = ZipFile.Read(filename);
                        if (!zip.ContainsEntry("Package.json"))
                        {
                            Growl.Info($"未在文件 {filename} 中找到 Package.json, 文件可能损坏或非Localizer汉化包.");
                            continue;
                        }
                        var json = JObject.Parse(new StreamReader(zip["Package.json"].OpenReader()).ReadToEnd());
                        jsons.Add("Package", json);
                        var  locpackdata = new LocpackData(json);
                        long count       = 0;
                        foreach (string zipfile in json["FileList"].ToArray())
                        {
                            try
                            {
                                if (zip.ContainsEntry(zipfile + ".json"))
                                {
                                    var tempjson = JObject.Parse(new StreamReader(zip[zipfile + ".json"].OpenReader()).ReadToEnd());
                                    jsons.Add(zipfile, tempjson);
                                    switch (zipfile)
                                    {
                                    case "Package":
                                        break;

                                    case "LdstrFile":
                                        foreach (var ldstrentries in tempjson["LdstrEntries"].Children())
                                        {
                                            count += ldstrentries.Children().Count();
                                        }
                                        break;

                                    default:
                                        count += tempjson.Count;
                                        break;
                                    }
                                }
                            }
                            catch (Exception zipex) { Growl.Error(zipex.Message); }
                        }
                        locpackdata.EntriesCount = count;
                        locpackdata.Data         = jsons;
                        list.Add(locpackdata);
                    }
                    catch (Exception ex) { Growl.Error(ex.Message); }
                }
            }
            return(list);
        }
コード例 #21
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var email = _sr.Email;

            Task.Run(() =>
            {
                if (this.Dispatcher != null && !this.Dispatcher.CheckAccess())
                {
                    this.Dispatcher.Invoke(() => SendCaptcha.IsEnabled = false);
                    for (var i = 60; i > 0; i--)
                    {
                        this.Dispatcher.Invoke(() => SendCaptcha.Content = $"请稍候({i}s)");
                        Thread.Sleep(1000);
                    }
                    this.Dispatcher.Invoke(() => SendCaptcha.IsEnabled = true);
                }
                else
                {
                    SendCaptcha.IsEnabled = false;
                    for (var i = 60; i > 0; i--)
                    {
                        SendCaptcha.Content = $"请稍候({i}s)";
                        Thread.Sleep(1000);
                    }
                    SendCaptcha.IsEnabled = true;
                }
            });

            _sr.InteractiveTask(() =>
            {
                int ret;

                if (CheckVendor.NotValidEmail(email))
                {
                    Growl.Error("无效邮件地址");
                }

                _sr.Procedure = null;
                var local     = new RecoveryProcedure();

                try
                {
                    if (string.IsNullOrEmpty(_sr.Username))
                    {
                        ret = 02_0009;
                        goto FAIL;
                    }

                    ret = local.Step1(_sr.Username, email, Helper.GetTrace());
                }
                catch (HttpRequestException ex)
                {
                    ret = 02_0000 + (int)(ex.Data["StatusCode"]);
                }
                catch (Exception)
                {
                    ret = 02_0000;
                }

                FAIL:
                if (CheckVendor.NotValidResponseCode(ret))
                {
                    Growl.Error(MessageVendor.FormatError(ret));
                }
                else
                {
                    _sr.Procedure = local;
                }
            });
        }
コード例 #22
0
        protected override async void OnViewLoaded()
        {
            if (HaveInit)
            {
                return;
            }
            HaveInit = true;

            BtnLoginEnable = false;

            //Proxy
            HttpHelper.ProxyInfo PROXY = Settings.ProxyEnable ? new HttpHelper.ProxyInfo(Settings.ProxyHost, Settings.ProxyPort, Settings.ProxyUser, Settings.ProxyPwd) : null;

            //Auto login by accessToken
            string   msg;
            LoginKey key;

            if (Settings.Accesstoken.IsNotBlank())
            {
                (msg, key) = await Client.Login(Settings.Accesstoken, PROXY);

                if (msg.IsBlank())
                {
                    goto LOGIN_SUCCESS;
                }
                if (Settings.Refreshtoken.IsNotBlank())
                {
                    (msg, key) = await Client.RefreshAccessToken(Settings.Refreshtoken, PROXY);

                    if (msg.IsBlank())
                    {
                        Settings.Userid      = key.UserID;
                        Settings.Accesstoken = key.AccessToken;
                        Settings.Save();
                        Global.AccessKey = key;
                        goto LOGIN_SUCCESS;
                    }
                }
            }

            //get device code
            (string msg1, TidalDeviceCode code) = await Client.GetDeviceCode(PROXY);

            if (msg1.IsNotBlank())
            {
                Growl.Error("Get device code failed!", Global.TOKEN_LOGIN);
            }
            else
            {
                DeviceCode = code;
            }
            goto RETURN_POINT;

LOGIN_SUCCESS:
            Global.AccessKey = key;
            Global.CommonKey = key;
            Global.VideoKey  = key;
            Manager.ShowWindow(VMMain);
            RequestClose();

RETURN_POINT:
            BtnLoginEnable = true;
            return;
        }
コード例 #23
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var password    = NewPassword.Password.ToCharArray();
            var passconfirm = NewConfirm.Password.ToCharArray();

            _sr.InteractiveTask(() =>
            {
                int ret = 00_0000;

                if (!password.SequenceEqual(passconfirm))
                {
                    Growl.Error("密码输入不一致");
                    return;
                }

                if (password.Length < 8)
                {
                    Growl.Error("请使用八位及以上长度的密码");
                    return;
                }

                if (!password.Intersect("0123456789".ToCharArray()).Any())
                {
                    Growl.Error("密码应包含数字");
                    return;
                }

                if (!password.Intersect("ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray()).Any())
                {
                    Growl.Error("密码应包含大写字母");
                    return;
                }

                if (!password.Intersect("abcdefghijklmnopqrstuvwxyz".ToCharArray()).Any())
                {
                    Growl.Error("密码应包含小写字母");
                    return;
                }

                try
                {
                    if (!(_sr.Procedure is ChangeProcedure local))
                    {
                        ret = 02_0009;
                        goto FAIL;
                    }

                    ret = CheckVendor.NotValidResponseCode(ret) ? ret : local.Step4(Encoding.UTF8.GetBytes(password));

                    ret = CheckVendor.NotValidResponseCode(ret) ? ret : local.Step5();

                    ret = CheckVendor.NotValidResponseCode(ret) ? ret : local.Step6();

                    byte[] token = null;

                    ret = CheckVendor.NotValidResponseCode(ret) ? ret : local.Step7(out token);

                    _sr.RenewToken = token;
                }
                catch (HttpRequestException ex)
                {
                    ret = 02_0000 + (int)(ex.Data["StatusCode"]);
                }
                catch (Exception)
                {
                    ret = 02_0000;
                }

                FAIL:
                if (CheckVendor.NotValidResponseCode(ret))
                {
                    Growl.Error(MessageVendor.FormatError(ret));
                }
                else
                {
                    _sr.Procedure = null;
                    Growl.Success("成功修改密码");
                    SubwindowNavigator.Navigate(SubwindowPage.LoggedIn);
                }
            });
        }
コード例 #24
0
        public void showGrowlNotification(string NotificationKEY, bool isAvailableOrSuccess = false, params string[] param)
        {
            //Delete Confirm
            if (NotificationKEY.Equals(AppVariable.Delete_Confirm_KEY))
            {
                Growl.Warning(new GrowlInfo
                {
                    Message           = $"آیا برای حذف {param[1]} {param[0]} اطمینان دارید؟",
                    CancelStr         = "انصراف",
                    ConfirmStr        = "بله",
                    ShowDateTime      = false,
                    ActionBeforeClose = isConfirm =>
                    {
                        if (isConfirm)
                        {
                            switch (param[1])
                            {
                            case "مدرسه":
                                AddSchoolView.main.deleteSchool();
                                break;

                            case "دانش آموز":
                                AddStudentView.main.deleteStudent();
                                break;

                            case "کاربر":
                                AddUserView.main.deleteUser();
                                break;

                            case "حضورغیاب":
                                AttendancelistView.main.deleteAttendance();
                                break;

                            case "نمره":
                                QuestionsListView.main.deleteScore();
                                break;

                            case "گروه":
                                AddAzmonGroupView.main.deleteGroup();
                                break;

                            case "سوال":
                                AddQuestionsView.main.deleteGroup();
                                break;
                            }
                        }
                        return(true);
                    }
                });
            }
            //Reset Data Confirm
            else if (NotificationKEY.Equals(AppVariable.Reset_Data_Confirm_KEY))
            {
                Growl.Warning(new GrowlInfo
                {
                    Message      = $"آیا برای بازیابی {param[0]} اطمینان دارید؟",
                    CancelStr    = "انصراف",
                    ConfirmStr   = "بله",
                    ShowDateTime = false,

                    ActionBeforeClose = isConfirm =>
                    {
                        if (isConfirm)
                        {
                            if (param[0] == "تنظیمات برنامه")
                            {
                                SettingsView.main.resetConfig();
                            }
                            else
                            {
                                SettingsView.main.resetDatabase();
                            }
                        }
                        return(true);
                    }
                });
            }

            //Reset Data Deleted
            else if (NotificationKEY.Equals(AppVariable.Data_Reset_Deleted_KEY))
            {
                Growl.Ask(new GrowlInfo
                {
                    Message           = $"{param[0]} به حالت پیشفرض تغییر یافت، برنامه را دوباره راه اندازی کنید",
                    CancelStr         = "انصراف",
                    ConfirmStr        = "راه اندازی",
                    ShowDateTime      = false,
                    ActionBeforeClose = isConfirm =>
                    {
                        if (isConfirm)
                        {
                            Application.Current.Shutdown();
                            System.Windows.Forms.Application.Restart();
                        }
                        return(true);
                    }
                });
            }

            //Password Same
            else if (NotificationKEY.Equals(AppVariable.Same_Password_KEY))
            {
                Growl.Warning(new GrowlInfo {
                    Message = "رمز های عبور باید یکسان باشند", ShowDateTime = false
                });
            }

            //Delete Exist
            else if (NotificationKEY.Equals(AppVariable.Delete_Exist_KEY))
            {
                Growl.Warning(new GrowlInfo {
                    Message = $"نمی توان این {param[0]} را حذف کرد، ابتدا {param[1]} این {param[0]} را حذف کنید", ShowDateTime = false
                });
            }

            //Azmon
            else if (NotificationKEY.Equals(AppVariable.Azmon_KEY))
            {
                Growl.Warning(new GrowlInfo {
                    Message = "تعداد سوالات وارد شده بیشتر از سوالات موجود است", ShowDateTime = false
                });
            }

            //Fill All Data
            else if (NotificationKEY.Equals(AppVariable.Fill_All_Data_KEY))
            {
                Growl.Warning(new GrowlInfo {
                    Message = "لطفا تمام فیلدها را پر کنید", ShowDateTime = false
                });
            }

            //No Data
            else if (NotificationKEY.Equals(AppVariable.No_Data_KEY))
            {
                var navigationService = NavigationServiceProvider.GetNavigationServiceInstance();

                Growl.Error(new GrowlInfo
                {
                    Message           = "اطلاعاتی در پایگاه داده یافت نشد",
                    CancelStr         = "انصراف",
                    ConfirmStr        = "ثبت اطلاعات جدید",
                    ShowDateTime      = false,
                    ActionBeforeClose = isConfirm =>
                    {
                        if (isConfirm)
                        {
                            switch (param[0])
                            {
                            case "School":
                                AddSchoolView.main.tabc.SelectedIndex = 0;
                                break;

                            case "User":
                                AddUserView.main.tabc.SelectedIndex = 0;
                                break;

                            case "Student":
                                AddStudentView.main.tabc.SelectedIndex = 0;
                                break;

                            case "Attendance":
                                AttendancelistView.main.tabc.SelectedIndex = 0;
                                break;

                            case "Question":
                                navigationService.GetController <UserControls.UserControlsController>().AddStudent();
                                break;

                            case "Score":
                                QuestionsListView.main.tabc.SelectedIndex = 0;
                                break;

                            case "TopStudent":
                                navigationService.GetController <UserControls.UserControlsController>().Questionslist();
                                break;

                            case "Group":
                                AddAzmonGroupView.main.tabc.SelectedIndex = 0;
                                break;

                            case "AQuestions":
                                AddQuestionsView.main.tabc.SelectedIndex = 0;
                                break;
                            }
                        }
                        return(true);
                    }
                });
            }

            //Backup
            else if (NotificationKEY.Equals(AppVariable.Backup_KEY))
            {
                if (isAvailableOrSuccess)
                {
                    Growl.Success(new GrowlInfo {
                        Message = $"{param[0]} با موفقیت انجام شد", ShowDateTime = false
                    });
                }
                else
                {
                    Growl.Error(new GrowlInfo {
                        Message = $"{param[0]} با مشکل مواجه شد", ShowDateTime = false
                    });
                }
            }

            //Circular
            else if (NotificationKEY.Equals(AppVariable.Recived_Circular_KEY))
            {
                if (isAvailableOrSuccess)
                {
                    Growl.Success(new GrowlInfo {
                        Message = "تمامی بخشنامه ها با موفقیت دریافت شد", ShowDateTime = false
                    });
                }
                else
                {
                    Growl.Error(new GrowlInfo {
                        Message = "درحال حاظر سرور در دسترس نیست! لطفا در صورت فعال بودن، VPN خود را غیرفعال کنید", ShowDateTime = false
                    });
                }
            }

            //Update Data
            else if (NotificationKEY.Equals(AppVariable.Update_Data_KEY))
            {
                if (isAvailableOrSuccess)
                {
                    Growl.Success(new GrowlInfo {
                        Message = $"{param[1]} {param[0]} با موفقیت ویرایش شد", ShowDateTime = false
                    });
                }
                else
                {
                    Growl.Error(new GrowlInfo {
                        Message = $"ویرایش {param[1]} {param[0]} با خطا مواجه شد", ShowDateTime = false
                    });
                }
            }

            //Deleted
            else if (NotificationKEY.Equals(AppVariable.Deleted_KEY))
            {
                if (isAvailableOrSuccess)
                {
                    Growl.Success(new GrowlInfo {
                        Message = $"{param[1]} {param[0]} با موفقیت حذف شد", ShowDateTime = false
                    });
                }
                else
                {
                    Growl.Error(new GrowlInfo {
                        Message = $"حذف {param[1]} {param[0]} با خطا مواجه شد", ShowDateTime = false
                    });
                }
            }

            //Add Data
            else if (NotificationKEY.Equals(AppVariable.Add_Data_KEY))
            {
                if (isAvailableOrSuccess)
                {
                    Growl.Success(new GrowlInfo {
                        Message = $"{param[1]} {param[0]} با موفقیت ثبت شد", ShowDateTime = false
                    });
                }
                else
                {
                    Growl.Error(new GrowlInfo {
                        Message = $"ثبت {param[1]} {param[0]} با خطا مواجه شد", ShowDateTime = false
                    });
                }
            }

            //Update
            else if (NotificationKEY.Equals(AppVariable.Update_KEY))
            {
                if (isAvailableOrSuccess)
                {
                    Growl.Info(new GrowlInfo
                    {
                        Message           = $"نسخه جدید {param[0]} پیدا شد،همین حالا به آخرین نسخه بروزرسانی کنید",
                        CancelStr         = "انصراف",
                        ConfirmStr        = "دانلود",
                        ShowDateTime      = false,
                        ActionBeforeClose = isConfirm =>
                        {
                            if (isConfirm)
                            {
                                System.Diagnostics.Process.Start(param[1]);
                            }

                            return(true);
                        }
                    });
                }
                else
                {
                    Growl.Error(new GrowlInfo {
                        Message = $"شما از آخرین نسخه {AppVariable.getAppVersion} استفاده می کنید", ShowDateTime = false
                    });
                }
            }
        }
コード例 #25
0
        public async void GetDetail()
        {
            if (SearchResult == null)
            {
                Growl.Error("Please search first!", "SearchMsg");
                return;
            }

            ShowWait();
            string      sID     = null;
            object      oObject = null;
            eObjectType oType   = eObjectType.None;
            eObjectType inType  = eObjectType.None;

            string selectHeader = ((System.Windows.Controls.TabItem)((SearchView)this.View).ctrSearchTab.SelectedItem).Header.ToString();

            if (selectHeader == "ALBUM")
            {
                if (((SearchView)this.View).ctrAlbumGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                sID    = SearchResult.Albums[((SearchView)this.View).ctrAlbumGrid.SelectedIndex].ID.ToString();
                inType = eObjectType.ALBUM;
            }
            else if (selectHeader == "TRACK")
            {
                if (((SearchView)this.View).ctrTrackGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                sID    = SearchResult.Tracks[((SearchView)this.View).ctrTrackGrid.SelectedIndex].ID.ToString();
                inType = eObjectType.TRACK;
            }
            else if (selectHeader == "VIDEO")
            {
                if (((SearchView)this.View).ctrVideoGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                sID    = SearchResult.Videos[((SearchView)this.View).ctrVideoGrid.SelectedIndex].ID.ToString();
                inType = eObjectType.VIDEO;
            }
            else if (selectHeader == "ARTIST")
            {
                if (((SearchView)this.View).ctrArtistGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                sID    = SearchResult.Artists[((SearchView)this.View).ctrArtistGrid.SelectedIndex].ID.ToString();
                inType = eObjectType.ARTIST;
            }
            else if (selectHeader == "PLAYLIST")
            {
                if (((SearchView)this.View).ctrPlaylistGrid.SelectedIndex < 0)
                {
                    goto ERR_NO_SELECT;
                }
                sID    = SearchResult.Playlists[((SearchView)this.View).ctrPlaylistGrid.SelectedIndex].UUID;
                inType = eObjectType.PLAYLIST;
            }

            oObject = await Task.Run(() => { return(TidalTool.tryGet(sID, out oType, inType)); });

            LoadDetail(oObject);
            ShowDetailView = Visibility.Visible;

            ShowWait(false);
            return;

ERR_NO_SELECT:
            Growl.Error("Please select one item!", "SearchMsg");
            ShowWait(false);
            return;
        }