コード例 #1
0
        private void RemoveHSI(HubScriptItem HSI)
        {
            TokenManager TokMgr = new TokenManager();
            AESManager   AESMgr = new AESManager();

            RCache.POST(
                Shared.ShRequest.Server
                , Shared.ShRequest.ScriptRemove(AccessToken, HSI.Id)
                , (e2, QId) =>
            {
                try
                {
                    JsonStatus.Parse(e2.ResponseString);
                    TokMgr.UnassignId(HSI.Id);
                    AESMgr.UnassignId(HSI.Id);

                    MessageBus.SendUI(GetType(), AppKeys.SH_SCRIPT_REMOVE, HSI);
                    Exit();
                }
                catch (Exception ex)
                {
                    HSI.ErrorMessage = ex.Message;
                }
            }
                , (a, b, ex) =>
            {
                HSI.ErrorMessage = ex.Message;
            }
                , false
                );
        }
コード例 #2
0
ファイル: ScriptUpload.xaml.cs プロジェクト: MewX/wenku10
        public async Task <string> ReserveId(string AccessToken)
        {
            TaskCompletionSource <string> TCS = new TaskCompletionSource <string>();

            RuntimeCache RCache = new RuntimeCache();

            RCache.POST(
                Shared.ShRequest.Server
                , Shared.ShRequest.ReserveId(AccessToken)
                , (e, QueryId) =>
            {
                try
                {
                    JsonObject JDef = JsonStatus.Parse(e.ResponseString);
                    string Id       = JDef.GetNamedString("data");
                    TCS.SetResult(Id);
                }
                catch (Exception ex)
                {
                    Logger.Log(ID, ex.Message, LogType.WARNING);
                    TCS.TrySetResult(null);
                }
            }
                , (cache, Id, ex) =>
            {
                Logger.Log(ID, ex.Message, LogType.WARNING);
                TCS.TrySetResult(null);
            }
                , false
                );

            return(await TCS.Task);
        }
コード例 #3
0
        private void SetTemplate()
        {
            InitAppBar();

            RCache = new RuntimeCache();

            RCache.POST(
                Shared.ShRequest.Server
                , Shared.ShRequest.MyProfile()
                , (e, id) =>
            {
                try
                {
                    JsonObject JDef  = JsonStatus.Parse(e.ResponseString);
                    JsonObject JData = JDef.GetNamedObject("data");
                    var j            = Dispatcher.RunIdleAsync((x) => SetProfileData(JData));
                }
                catch (Exception ex)
                {
                    ShowErrorMessage(ex.Message);
                }
                MarkIdle();
            }
                , (a, b, ex) =>
            {
                ShowErrorMessage(ex.Message);
                MarkIdle();
            }
                , false
                );
        }
コード例 #4
0
ファイル: PlaceRequest.xaml.cs プロジェクト: MewX/wenku10
        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            args.Cancel = true;

            if (Keys.SelectedItem == null)
            {
                StringResources stx = StringResources.Load();
                ServerMessage.Text = "Please Select a key";
                return;
            }

            string PubKey  = RSA.SelectedItem.GenPublicKey();
            string Remarks = RemarksInput.Text.Trim();

            if (string.IsNullOrEmpty(Remarks))
            {
                Remarks = RemarksPlaceholder;
            }

            RCache.POST(
                Shared.ShRequest.Server
                , Shared.ShRequest.PlaceRequest(Target, PubKey, BindItem.Id, Remarks)
                , PlaceSuccess
                , (c, Id, ex) => { Error(ex.Message); }
                , false
                );
        }
コード例 #5
0
        private void SubmitDispName()
        {
            string NewDispName = DisplayName.Text.Trim();

            if (NewDispName == CurrentDispName)
            {
                return;
            }

            RCache.POST(
                Shared.ShRequest.Server
                , Shared.ShRequest.EditProfile(NewDispName)
                , (e, id) =>
            {
                try
                {
                    JsonObject JDef = JsonStatus.Parse(e.ResponseString);
                }
                catch (Exception ex)
                {
                    ShowErrorMessage(ex.Message);
                }
                MarkIdle();
            }
                , (a, b, ex) =>
            {
                ShowErrorMessage(ex.Message);
                MarkIdle();
            }
                , false
                );

            MarkBusy();
        }
コード例 #6
0
ファイル: UserInfo.xaml.cs プロジェクト: tgckpg/wenku10
        private void SetTemplate()
        {
            RCache = new RuntimeCache();

            RCache.POST(
                Shared.ShRequest.Server
                , Shared.ShRequest.MyProfile()
                , ( e, id ) =>
                {
                    try
                    {
                        JsonObject JDef = JsonStatus.Parse( e.ResponseString );
                        JsonObject JData = JDef.GetNamedObject( "data" );
                        var j = Dispatcher.RunIdleAsync( ( x ) => SetProfileData( JData ) );
                    }
                    catch ( Exception ex )
                    {
                        ShowErrorMessage( ex.Message );
                    }
                    MarkIdle();
                }
                , ( a, b, ex ) =>
                {
                    ShowErrorMessage( ex.Message );
                    MarkIdle();
                }
                , false
            );
        }
コード例 #7
0
ファイル: Register.xaml.cs プロジェクト: MewX/wenku10
        private void DetectInputLogin()
        {
            string Name    = Account.Text.Trim();
            string Passwd  = Password.Password;
            string PasswdV = PasswordV.Password;
            string Email   = EmailInput.Text.Trim();

            if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Passwd) || string.IsNullOrEmpty(PasswdV) || string.IsNullOrEmpty(Email))
            {
                if (string.IsNullOrEmpty(Name))
                {
                    Account.Focus(FocusState.Keyboard);
                }
                else if (string.IsNullOrEmpty(Passwd))
                {
                    Password.Focus(FocusState.Keyboard);
                }
                else if (string.IsNullOrEmpty(PasswdV))
                {
                    PasswordV.Focus(FocusState.Keyboard);
                }
                else if (string.IsNullOrEmpty(Email))
                {
                    EmailInput.Focus(FocusState.Keyboard);
                }
            }
            else if (Passwd != PasswdV)
            {
                StringResources stx = StringResources.Load("Error");
                ServerMessage.Text = stx.Str("PasswordMismatch");
                Password.Focus(FocusState.Keyboard);
            }
            else
            {
                ServerMessage.Text = "";

                IsPrimaryButtonEnabled
                              = IsSecondaryButtonEnabled
                              = Account.IsEnabled
                              = Password.IsEnabled
                              = PasswordV.IsEnabled
                              = EmailInput.IsEnabled
                              = false
                    ;

                this.Focus(FocusState.Pointer);

                IndicateLoad();

                RuntimeCache RCache = new RuntimeCache()
                {
                    EN_UI_Thead = true
                };
                RCache.POST(
                    Shared.ShRequest.Server
                    , Shared.ShRequest.Register(Name, Passwd, Email)
                    , RequestComplete, RequestFailed, false);
            }
        }
コード例 #8
0
ファイル: ChangePassword.xaml.cs プロジェクト: MewX/wenku10
        private void DetectInputLogin()
        {
            string CurrPasswd = CurrentPassword.Password;
            string NewPasswd  = Password.Password;
            string PasswdV    = PasswordV.Password;

            if (string.IsNullOrEmpty(CurrPasswd) || string.IsNullOrEmpty(NewPasswd) || string.IsNullOrEmpty(PasswdV))
            {
                if (string.IsNullOrEmpty(CurrPasswd))
                {
                    CurrentPassword.Focus(FocusState.Keyboard);
                }
                else if (string.IsNullOrEmpty(NewPasswd))
                {
                    Password.Focus(FocusState.Keyboard);
                }
                else if (string.IsNullOrEmpty(PasswdV))
                {
                    PasswordV.Focus(FocusState.Keyboard);
                }
            }
            else if (NewPasswd != PasswdV)
            {
                StringResources stx = StringResources.Load("Error");
                ServerMessage.Text = stx.Str("PasswordMismatch");
                Password.Focus(FocusState.Keyboard);
            }
            else
            {
                ServerMessage.Text = "";

                IsPrimaryButtonEnabled
                            = IsSecondaryButtonEnabled
                            = CurrentPassword.IsEnabled
                            = Password.IsEnabled
                            = PasswordV.IsEnabled
                            = false
                    ;

                this.Focus(FocusState.Pointer);

                IndicateLoad();

                RuntimeCache RCache = new RuntimeCache()
                {
                    EN_UI_Thead = true
                };
                RCache.POST(
                    Shared.ShRequest.Server
                    , Shared.ShRequest.ChangePassword(CurrPasswd, NewPasswd)
                    , RequestComplete, RequestFailed, false);
            }
        }
コード例 #9
0
        private void GrantRequest(object sender, RoutedEventArgs e)
        {
            SHRequest Req = (( Button )sender).DataContext as SHRequest;

            if (Req == null)
            {
                return;
            }

            try
            {
                CryptRSA RSA       = new CryptRSA(Req.Pubkey);
                string   GrantData = null;

                switch (ReqTarget)
                {
                case SHTarget.TOKEN:
                    if (!string.IsNullOrEmpty(AccessToken))
                    {
                        GrantData = RSA.Encrypt(AccessToken);
                    }
                    break;

                case SHTarget.KEY:
                    if (Crypt != null)
                    {
                        GrantData = RSA.Encrypt(Crypt.KeyBuffer);
                    }
                    break;
                }

                if (!string.IsNullOrEmpty(GrantData))
                {
                    RCache.POST(
                        Shared.ShRequest.Server
                        , Shared.ShRequest.GrantRequest(Req.Id, GrantData)
                        , GrantComplete
                        , GrantFailed
                        , false
                        );
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ID, ex.Message);
            }
        }
コード例 #10
0
ファイル: HSLoader.cs プロジェクト: MewX/wenku10
        public async Task <IList <T> > NextPage(uint ExpectedCount = 30)
        {
            TaskCompletionSource <T[]> Ts = new TaskCompletionSource <T[]>();

            RCache.POST(
                Shared.ShRequest.Server
                , PostArgs(Target, CurrentPage, ExpectedCount, new string[] { Id })
                , (e, Id) =>
            {
                try
                {
                    JsonObject JObj = JsonStatus.Parse(e.ResponseString);
                    JsonArray JData = JObj.GetNamedArray("data");

                    int LoadedCount = JData.Count();

                    List <T> HSI = new List <T>(LoadedCount);
                    foreach (JsonValue ItemDef in JData)
                    {
                        HSI.Add(( T )Activator.CreateInstance(TType, ItemDef.GetObject()));
                    }

                    PageEnded    = LoadedCount < ExpectedCount;
                    CurrentPage += LoadedCount;

                    Ts.SetResult(ConvertResult(HSI));
                }
                catch (Exception ex)
                {
                    Logger.Log(ID, ex.Message, LogType.WARNING);
                    PageEnded = true;
                    Ts.TrySetResult(new T[0]);
                }
            }
                , (cacheName, Id, ex) =>
            {
                Logger.Log(ID, ex.Message, LogType.WARNING);
                PageEnded = true;
                Ts.TrySetResult(new T[0]);
            }
                , false
                );

            T[] Cs = await Ts.Task;
            return(Cs);
        }
コード例 #11
0
ファイル: MyInbox.cs プロジェクト: MewX/wenku10
        public Task <bool> Get()
        {
            TaskCompletionSource <bool> TCS = new TaskCompletionSource <bool>();

            RCache.POST(
                Shared.ShRequest.Server
                , Shared.ShRequest.MyInbox()
                , (a, b) =>
            {
                ProcessInbox(a, b);
                TCS.TrySetResult(true);
            }
                , (a, b, c) => TCS.TrySetResult(false)
                , false
                );

            return(TCS.Task);
        }
コード例 #12
0
        public async Task <IList <HubScriptItem> > NextPage(uint ExpectedCount = 0)
        {
            TaskCompletionSource <HubScriptItem[]> HSItems = new TaskCompletionSource <HubScriptItem[]>();

            RCache.POST(
                Shared.ShRequest.Server
                , Shared.ShRequest.Search(Query, CurrentPage, ExpectedCount, AccessTokens)
                , (e, Id) =>
            {
                try
                {
                    JsonObject JResponse = JsonStatus.Parse(e.ResponseString);
                    JsonArray JHS        = JResponse.GetNamedArray("data");

                    int LoadedCount = JHS.Count();

                    PageEnded    = LoadedCount < ExpectedCount;
                    CurrentPage += LoadedCount;

                    HSItems.SetResult(JHS.Remap(x => HubScriptItem.Create(x.GetObject())).ToArray());
                }
                catch (Exception ex)
                {
                    Logger.Log(ID, ex.Message, LogType.WARNING);
                    PageEnded = true;
                    HSItems.TrySetResult(new HubScriptItem[0]);
                }
            }
                , (cacheName, Id, ex) =>
            {
                Logger.Log(ID, ex.Message, LogType.WARNING);
                PageEnded = true;
                HSItems.TrySetResult(new HubScriptItem[0]);
            }
                , false
                );

            return(await HSItems.Task);
        }
コード例 #13
0
ファイル: Register.xaml.cs プロジェクト: tgckpg/wenku10
        private void DetectInputLogin()
        {
            string Name = Account.Text.Trim();
            string Passwd = Password.Password;
            string PasswdV = PasswordV.Password;
            string Email = EmailInput.Text.Trim();

            if ( string.IsNullOrEmpty( Name ) || string.IsNullOrEmpty( Passwd ) || string.IsNullOrEmpty( PasswdV ) || string.IsNullOrEmpty( Email ) )
            {
                if ( string.IsNullOrEmpty( Name ) )
                {
                    Account.Focus( FocusState.Keyboard );
                }
                else if ( string.IsNullOrEmpty( Passwd ) )
                {
                    Password.Focus( FocusState.Keyboard );
                }
                else if( string.IsNullOrEmpty( PasswdV ) )
                {
                    PasswordV.Focus( FocusState.Keyboard );
                }
                else if( string.IsNullOrEmpty( Email ) )
                {
                    EmailInput.Focus( FocusState.Keyboard );
                }
            }
            else if( Passwd != PasswdV )
            {
                StringResources stx = new StringResources( "Error" );
                ServerMessage.Text = stx.Str( "PasswordMismatch" );
                Password.Focus( FocusState.Keyboard );
            }
            else
            {
                ServerMessage.Text = "";

                IsPrimaryButtonEnabled
                    = IsSecondaryButtonEnabled
                    = Account.IsEnabled
                    = Password.IsEnabled
                    = PasswordV.IsEnabled
                    = EmailInput.IsEnabled
                    = false
                    ;

                this.Focus( FocusState.Pointer );

                IndicateLoad();

                RuntimeCache RCache = new RuntimeCache() { EN_UI_Thead = true };
                RCache.POST(
                    Shared.ShRequest.Server
                    , Shared.ShRequest.Register( Name, Passwd, Email )
                    , RequestComplete, RequestFailed, false );
            }
        }
コード例 #14
0
ファイル: ScriptUpload.xaml.cs プロジェクト: tgckpg/wenku10
        public async Task<string> ReserveId( string AccessToken )
        {
            TaskCompletionSource<string> TCS = new TaskCompletionSource<string>();

            RuntimeCache RCache = new RuntimeCache();
            RCache.POST(
                Shared.ShRequest.Server
                , Shared.ShRequest.ReserveId( AccessToken )
                , ( e, QueryId ) =>
                {
                    try
                    {
                        JsonObject JDef = JsonStatus.Parse( e.ResponseString );
                        string Id = JDef.GetNamedString( "data" );
                        TCS.SetResult( Id );
                    }
                    catch( Exception ex )
                    {
                        Logger.Log( ID, ex.Message, LogType.WARNING );
                        TCS.TrySetResult( null );
                    }
                }
                , ( cache, Id, ex ) =>
                {
                    Logger.Log( ID, ex.Message, LogType.WARNING );
                    TCS.TrySetResult( null );
                }
                , false
            );

            return await TCS.Task;
        }
コード例 #15
0
ファイル: ChangePassword.xaml.cs プロジェクト: tgckpg/wenku10
        private void DetectInputLogin()
        {
            string CurrPasswd = CurrentPassword.Password;
            string NewPasswd = Password.Password;
            string PasswdV = PasswordV.Password;

            if ( string.IsNullOrEmpty( CurrPasswd ) || string.IsNullOrEmpty( NewPasswd ) || string.IsNullOrEmpty( PasswdV ) )
            {
                if ( string.IsNullOrEmpty( CurrPasswd ) )
                {
                    CurrentPassword.Focus( FocusState.Keyboard );
                }
                else if ( string.IsNullOrEmpty( NewPasswd ) )
                {
                    Password.Focus( FocusState.Keyboard );
                }
                else if( string.IsNullOrEmpty( PasswdV ) )
                {
                    PasswordV.Focus( FocusState.Keyboard );
                }
            }
            else if( NewPasswd != PasswdV )
            {
                StringResources stx = new StringResources( "Error" );
                ServerMessage.Text = stx.Str( "PasswordMismatch" );
                Password.Focus( FocusState.Keyboard );
            }
            else
            {
                ServerMessage.Text = "";

                IsPrimaryButtonEnabled
                    = IsSecondaryButtonEnabled
                    = CurrentPassword.IsEnabled
                    = Password.IsEnabled
                    = PasswordV.IsEnabled
                    = false
                    ;

                this.Focus( FocusState.Pointer );

                IndicateLoad();

                RuntimeCache RCache = new RuntimeCache() { EN_UI_Thead = true };
                RCache.POST(
                    Shared.ShRequest.Server
                    , Shared.ShRequest.ChangePassword( CurrPasswd, NewPasswd )
                    , RequestComplete, RequestFailed, false );
            }
        }