コード例 #1
0
        private async void submitButton(object sender, EventArgs e)
        {
            try
            {
                Shared.Application app         = new Shared.Application();
                String             plainTextPw = pwTextBox.Text;
                var               encryptedPw  = Shared.CryptManager.encrypt(plainTextPw, secretKey);
                Shared.Username   username     = new Shared.Username(usernameTextBox.Text, encryptedPw);
                Shared.Username[] userName     = new Shared.Username[] { username };
                app.Usernames = userName;
                app.Type      = appTypeComboBox.Text;
                app.Name      = appNameTextBox.Text;
                NewAppRequest request  = new NewAppRequest(app);
                var           response = await SocketManager.Instance.SendRequest <NewAppResponse>(request);

                this.managerForm.addAppToTree(response.application);
                this.Close();
            }
            catch (ResponseException ex)
            {
                using (var details = new TaskDialog()
                {
                    Caption = "Cannot Add User",
                    InstructionText = "Unable to add this application and user",
                    Text = ex.Message,
                    Icon = TaskDialogStandardIcon.Error,
                    StandardButtons = TaskDialogStandardButtons.Close
                })
                {
                    details.Show();
                }
            }
        }
コード例 #2
0
        private static bool handleNewApp(ClientSession session)
        {
            NewAppRequest request = (NewAppRequest)session.Reader.GetMessage();

            if (db.addUsername(request.application, session.loginUsername.name))
            {
                NewAppResponse resp    = new NewAppResponse(request.application);
                byte[]         payLoad = MessageUtils.SerializeMessage(resp).GetAwaiter().GetResult();
                session.Client.Client.Send(payLoad);
                return(true);
            }
            else
            {
                ErrorResponse resp = new ErrorResponse(NewAppResponse.MessageID,
                                                       "A username for this application already exists");
                byte[] payload = MessageUtils.SerializeMessage(resp).GetAwaiter().GetResult();
                session.Client.Client.Send(payload);
                return(false);
            }
        }