Пример #1
0
        private async void Button_ImportExcel_Click(object sender, RoutedEventArgs e)
        {
            var result = await Dialog.Show(new ExcelImportDialog()).GetResultAsync <(bool, UserData, List <WishData>)>();

            if (result.Item1)
            {
                try
                {
                    var str = JsonSerializer.Serialize(result.Item3, Const.JsonOptions);
                    File.WriteAllText(result.Item2.WishLogFile, str);
                    result.Item2.LastUpdateTime = DateTime.Now;
                    Growl.Success("导入数据成功");
                }
                catch (Exception ex)
                {
                    Growl.Error(ex.Message);
                }
            }
            else
            {
                if (result.Item2 != null)
                {
                    Growl.Error("导入数据失败");
                }
            }
        }
        public async void Confim()
        {
            if (AccessToken.IsNotBlank())
            {
                (string msg, LoginKey key) = await Client.Login(AccessToken);

                if (msg.IsNotBlank() || key == null)
                {
                    Growl.Warning("Accesstoken is not valid! " + msg, Global.TOKEN_MAIN);
                }
                else if (key.UserID != Global.CommonKey.UserID)
                {
                    Growl.Warning("User mismatch! Please use your own accesstoken.", Global.TOKEN_MAIN);
                }
                else
                {
                    UserSettings user = UserSettings.Read();
                    user.Accesstoken = AccessToken;
                    user.Save();
                    Global.AccessKey = key;
                }
            }

            Settings.Change(Settings, Global.Settings);

            Global.Settings = Settings;
            Global.Settings.Save();

            Load();
            Growl.Success("Refresh settings success!", Global.TOKEN_MAIN);
        }
Пример #3
0
 private void Button_Logout_Click(object sender, RoutedEventArgs e)
 {
     if (File.Exists("UserData\\Account"))
     {
         File.Delete("UserData\\Account");
     }
     ViewModel.CloudClient = null;
     Popup_Cloud.IsOpen    = false;
     Growl.Success("已删除保存的账号和密码");
 }
Пример #4
0
        public async void Success(string msg)
        {
            await WaitForTokenLoaded();

            if (Thread.CurrentThread != App.Current.Dispatcher.Thread)
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    Growl.Success(ParseMsg(msg), Token);
                });
            }
        }
Пример #5
0
        public void GetAccessToken()
        {
            (string msg, LoginKey key) = TidalLib.Client.GetAccessTokenFromTidalDesktop(UserID);
            if (msg.IsNotBlank())
            {
                Growl.Warning(msg, Global.TOKEN_MAIN);
                return;
            }

            Growl.Success(Language.Get("strmsgGetAccessTokenSuccess"), Global.TOKEN_MAIN);
            AccessToken = key.AccessToken;
        }
Пример #6
0
        private void SaveAll_OnClick(object sender, RoutedEventArgs e)
        {
            var result = ImageViewer.SaveFile(true);

            Growl.Clear();
            if (result)
            {
                Growl.Success($"图片已导出至{ImageViewer.FileDirectory}\\{ImageViewer.FileName}文件夹!");
            }
            else
            {
                Growl.Warning("未选中需要导出的图片!");
            }
        }
Пример #7
0
        private void Save_OnClick(object sender, RoutedEventArgs e)
        {
            var result = ImageViewer.SaveFile(false);

            Growl.Clear();
            if (result)
            {
                Growl.Success("图片已导出!");
            }
            else
            {
                Growl.Warning("取消导出!");
            }
        }
Пример #8
0
        private void ChooseFileLocation(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog m_Dialog = new System.Windows.Forms.FolderBrowserDialog();
            System.Windows.Forms.DialogResult        result   = m_Dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }
            string m_Dir = m_Dialog.SelectedPath.Trim();

            Setting.FileLocation = m_Dir;
            Growl.Success($"成功选择汉化包位置为 {m_Dir}");
        }
Пример #9
0
        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
    }
Пример #10
0
        public async void Success(string msg)
        {
            await WaitForTokenLoaded();

            App.Current.Dispatcher.Invoke(() =>
            {
                if (Program.CliOptions.GlobalNotification)
                {
                    Growl.SuccessGlobal(ParseMsg(msg));
                }
                else
                {
                    Growl.Success(ParseMsg(msg), Token);
                }
            });
        }
Пример #11
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);
                }
            });
        }
Пример #12
0
        private async void Button_Cloud_Click(object sender, RoutedEventArgs e)
        {
            if (ViewModel.CloudClient == null)
            {
                var client = await Dialog.Show(new CloudLoginDialog()).Initialize <CloudLoginDialog>(x => { }).GetResultAsync <CloudBackup.CloudClient>();

                if (client != null)
                {
                    ViewModel.CloudClient = client;
                    Popup_Cloud.IsOpen    = true;
                    Growl.Success("登录成功");
                }
            }
            else
            {
                Popup_Cloud.IsOpen = true;
            }
        }
Пример #13
0
        public async void Confim()
        {
            if (AccessToken.IsNotBlank())
            {
                (string msg, LoginKey key) = await Client.Login(AccessToken);

                if (msg.IsNotBlank() || key == null)
                {
                    Growl.Warning(Language.Get("strmsgAccessTokenIsNotValid") + msg, Global.TOKEN_MAIN);
                }
                else if (key.UserID != Global.CommonKey.UserID)
                {
                    Growl.Warning(Language.Get("strmsgUserMismatch"), Global.TOKEN_MAIN);
                }
                else
                {
                    UserSettings user = UserSettings.Read();
                    user.Accesstoken = AccessToken;
                    user.Save();
                    Global.AccessKey = key;
                }
            }
            else
            {
                UserSettings user = UserSettings.Read();
                user.Accesstoken = null;
                user.Save();
                Global.AccessKey = null;
            }

            Settings.Change(Settings, Global.Settings);

            Global.Settings = Settings;
            Global.Settings.Save();

            Load();
            Growl.Success(Language.Get("strmsgRefreshSettingsSuccess"), Global.TOKEN_MAIN);
        }
Пример #14
0
        public void Confim()
        {
            Config.ThreadNum(ThreadNum.ToString());
            Config.SearchNum(SearchNum.ToString());
            Config.OnlyM4a(OnlyM4a.ToString());
            Config.AddExplicitTag(AddExplicitTag.ToString());
            Config.SaveCovers(SaveCovers.ToString());
            Config.IncludeEP(IncludeEPSingle.ToString());
            Config.CheckExist(CheckExist.ToString());
            Config.ArtistBeforeTitle(ArtistBeforeTitle.ToString());
            Config.AddHyphen(AddHyphen.ToString());
            Config.AddYear(AddYearIndex);
            Config.OutputDir(OutputDir);
            Config.UseTrackNumber(UseTrackNumber.ToString());
            Config.MaxFileName(MaxFileName.ToString());
            Config.MaxDirName(MaxDirName.ToString());
            Config.AddAlbumIDBeforeFolder(AddAlbumIDBeforeFolder.ToString());
            Config.ThemeIndex(ThemeIndex.ToString());

            TidalTool.SetSearchMaxNum(int.Parse(Config.SearchNum()));
            ThreadTool.SetThreadNum(ThreadNum);
            ChangeTheme(ThemeIndex);

            if (AccessToken.IsNotBlank())
            {
                if (TidalTool.loginByAccesstoken(AccessToken))
                {
                    Config.Accesstoken(AccessToken);
                }
                else
                {
                    Growl.Warning("Accesstoken is not valid!", "SettingsMsg");
                    return;
                }
            }
            Growl.Success("Refresh settings success!", "SettingsMsg");
        }
Пример #15
0
 public static void Success(string message)
 {
     Growl.Success(App.Current.Resources[message]?.ToString() ?? message, TOKEN_PANEL_MAIN);
 }
Пример #16
0
        /// <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;
            }
        }
Пример #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
        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;
                        }
                    });
                });
            });
        }
Пример #19
0
 private void Select(string header) => Growl.Success(header);
Пример #20
0
 private void Select(string header) => Growl.Success(header, "InfoMessage");
Пример #21
0
 internal static void FinishedConversion() => Growl.Success(GetGrowlInfo("Finished with the conversion!"));
Пример #22
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);
                }
            });
        }
Пример #23
0
        private void Btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (btn == null)
            {
                return;
            }
            ImgInfo imgInfo = (btn.Parent as StackPanel).Tag as ImgInfo;

            switch (btn.Name)
            {
            case "btn_down":
            {
                if (btn.Foreground == Brushes.White)
                {
                    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;
                    UserDataManage.SetDown(imgFullName, imgInfo);
                    Growl.Success("下载成功。");

                    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)
                {
                    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();
                    }
                    WinApi.SetWallpaper(imgFullName);
                    btn.Foreground = Brushes.Red;
                    Growl.Success("壁纸设置成功。");
                    UserDataManage.AddRecord(RecordType.ManualWallpaper, imgInfo);
                }
            }
            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;
                    this.EffectPicture(null, null);
                }
            }
            break;
            }
        }
        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;
        }
Пример #25
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
                    });
                }
            }
        }