Пример #1
0
        public string LoginAuthorized(string email)
        {
            using (var _db = new DatabaseContext())
            {
                IUserService _userService = new UserService(_db);
                user = _userService.GetUser(email);
                string  generateToken = _tokenService.GenerateToken();
                Session session       = new Session
                {
                    Token  = generateToken,
                    UserId = user.Id
                };

                ISessionService _sessionService = new SessionService(_db);
                var             response        = _sessionService.CreateSession(session);
                try
                {
                    _db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    _db.Entry(session).State = System.Data.Entity.EntityState.Detached;
                }
                return(session.Token);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            bool isSandbox = false;

            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

            try
            {
                AccountCredentials credentials = PagSeguroConfiguration.GetAccountCredentials(isSandbox);

                Session result = SessionService.CreateSession(credentials);

                Console.WriteLine(result.ToString());
                Console.ReadKey();
            }
            catch (PagSeguroServiceException exception)
            {
                Console.WriteLine(exception.Message + "\n");

                foreach (ServiceError element in exception.Errors)
                {
                    Console.WriteLine(element + "\n");
                }
                Console.ReadKey();
            }
        }
Пример #3
0
        public IEnumerable <Session> CreateSession(Session session)
        {
            var tmpId = _sessionService.GetAll().Last().Id;

            session.Id = tmpId + 1;
            return(_sessionService.CreateSession(session));
        }
Пример #4
0
        public void Delete_Session_Success()
        {
            // Arrange
            newUser    = tu.CreateUserObject();
            newSession = tu.CreateSessionObject(newUser);

            using (var _db = tu.CreateDataBaseContext())
            {
                // Act
                SessionService ss = new SessionService(_db);
                newSession = ss.CreateSession(newSession);
                var expectedResponse = newSession;

                _db.SaveChanges();

                var response = ss.DeleteSession(newSession.Token);
                _db.SaveChanges();
                var result = _db.Sessions.Find(expectedResponse.Id);

                // Assert
                Assert.IsNotNull(response);
                Assert.IsNull(result);
                Assert.AreEqual(response.Id, expectedResponse.Id);
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            // Use session authentication
            try
            {
                SessionService sessionService = new SessionService(Credentials);

                Credentials.SessionId = sessionService.CreateSession();
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
            }

            // TODO: Remove these comments to expose the example functionality.

            // SendMessageExample();

            // GetSentMessagesExample();

            // GetInboxMessagesExample();

            // GetContactsExample();

            Console.ReadLine();
        }
Пример #6
0
        public void Update_Session_Success()
        {
            // Arrange
            newUser    = tu.CreateUserObject();
            newSession = tu.CreateSessionObject(newUser);
            var expectedResult = newSession;

            // ACT
            using (var _db = tu.CreateDataBaseContext())
            {
                SessionService ss = new SessionService(_db);
                newSession = ss.CreateSession(newSession);
                _db.SaveChanges();
                newSession.CreatedAt = newSession.CreatedAt.AddYears(60);
                var response = ss.UpdateSession(newSession);
                _db.SaveChanges();
                var result = _db.Sessions.Find(expectedResult.Id);

                // Assert
                Assert.IsNotNull(response);
                Assert.IsNotNull(result);
                Assert.AreEqual(result.Id, expectedResult.Id);
                Assert.AreEqual(result.UpdatedAt, expectedResult.UpdatedAt);
                Assert.AreEqual(result.ExpiresAt, expectedResult.ExpiresAt);
            }
        }
Пример #7
0
        private string CreateSession()
        {
            try
            {
                if (!string.IsNullOrEmpty(this.configuration))
                {
                    PagSeguroConfiguration.UrlXmlConfiguration = this.configuration;

                    //bool isSandbox = true;
                    EnvironmentConfiguration.ChangeEnvironment(this.isSandbox);

                    AccountCredentials credentials = PagSeguroConfiguration.Credentials(this.isSandbox);

                    Uol.PagSeguro.Domain.Direct.Session result = SessionService.CreateSession(credentials);

                    return(result.id);
                }

                return(string.Empty);
            }
            catch (PagSeguroServiceException exception)
            {
                //Gravar Log do erro
                return(string.Empty);
            }
        }
        public void CreateSession_ReturnsSessionId()
        {
            // Arrange
            RestResource resource = new SessionResource();

            var response = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = "serialisedResponse"
            };

            var expectedResult = new EsendexSession
            {
                Id = Guid.NewGuid()
            };

            mockRestClient
            .Setup(rc => rc.Post(resource))
            .Returns(response);

            mockSerialiser
            .Setup(s => s.Deserialise <EsendexSession>(response.Content))
            .Returns(expectedResult);

            // Act
            var actualSessionId = service.CreateSession();

            // Assert
            Assert.AreEqual(expectedResult.Id, actualSessionId);
        }
Пример #9
0
        protected void CreateBtn_Click(object sender, EventArgs e)
        {
            try
            {
                logger.Info(SessionDate.Text + " --- " + EnrollDate.Text);
                var sessionStart = SessionDate.Text.Split(new char[] { '-' })[0].Trim();
                var sessionEnd   = SessionDate.Text.Split(new char[] { '-' })[1].Trim();

                var enrollStart = EnrollDate.Text.Split(new char[] { '-' })[0].Trim();
                var enrollEnd   = EnrollDate.Text.Split(new char[] { '-' })[1].Trim();

                SessionService.CreateSession(SessionVariable.Current.Company.Id, courseId, SessionName.Text, Description.Text, Cost.Text,
                                             sessionStart, sessionEnd, enrollStart, enrollEnd);
            }
            catch (CourseException cex)
            {
                logger.Info(cex.ToString());
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
            }

            Response.Redirect("CS0201?csid=" + courseId);
        }
Пример #10
0
        public void ProcessStsConnection(Connection connection, string header, string body)
        {
            switch (header)
            {
            case "/Sts/Ping":
            case "/Sts/Connect":
                break;

            case "/Auth/GetHostname":
                AuthService.HostNameRequest(connection, body);
                break;

            case "/Auth/StartTls":
                AuthService.StartTls(connection, body);
                break;

            case "/Auth/LoginFinish":
                AuthService.LoginFinish(connection, body);
                break;

            case "/Auth/ListMyGameAccounts":
                AuthService.ListMyGameAccounts(connection, body);
                break;

            case "/Auth/RequestGameToken":
                AuthService.RequestGameToken(connection, body);
                break;

            case "/Auth/GetUserInfo":
                AuthService.RequestUserInfo(connection, body);
                break;

            case "/Presence/GetUserInfo":
                PresenceService.GetUserInfo(connection, body);
                break;

            case "/Presence/SetWatch":
                PresenceService.SetWatch(connection, body);
                break;

            case "/Session/CreateSession":
                SessionService.CreateSession(connection, body);
                break;

            default:
                Log.ErrorFormat("Unknown request: {0}", header);
                Log.ErrorFormat("Data: {0}", body.Replace('\n', ' '));
                return;
            }

            Log.InfoFormat("Received {0}", header);
        }
Пример #11
0
        public void ProcessStsConnection(Connection connection, string header, string body)
        {
            switch (header)
            {
            case "/Sts/Ping":
            case "/Sts/Connect":
                break;

            case "/Auth/GetHostname":
                AuthService.HostNameRequest(connection, body);
                break;

            case "/Auth/StartTls":
                AuthService.StartTls(connection, body);
                break;

            case "/Auth/LoginFinish":
                AuthService.LoginFinish(connection, body);
                break;

            case "/Auth/ListMyGameAccounts":
                AuthService.ListMyGameAccounts(connection, body);
                break;

            case "/Auth/RequestGameToken":
                AuthService.RequestGameToken(connection, body);
                break;

            case "/Auth/GetUserInfo":
                AuthService.RequestUserInfo(connection, body);
                break;

            case "/Presence/GetUserInfo":
                PresenceService.GetUserInfo(connection, body);
                break;

            case "/Presence/SetWatch":
                PresenceService.SetWatch(connection, body);
                break;

            case "/Session/CreateSession":
                SessionService.CreateSession(connection, body);
                break;

            default:
                Log.Error("ProccessStsConnection", "Invalid header: " + header);
                return;
            }
        }
Пример #12
0
        public ActionResult <ScriptSession> Get()
        {
            return(Execute(() =>
            {
                ScriptSession pythonSession = SessionService.CreateSession();

                ExpireSessionTimer sessionTimer = new ExpireSessionTimer(pythonSession, SettingsProvider.SessionLifetime);
                Sessions.Add(pythonSession.Id, sessionTimer);
                sessionTimer.Start();

                Log.Information($"Request new session DONE. Created session with ID '{pythonSession.Id}' and expire date '{pythonSession.ExpireDate.ToLongTimeString()}'");

                return Ok(pythonSession);
            }));
        }
Пример #13
0
        public async void CreateSession()
        {
            var session = new SessionDto
            {
                SessionType = "1",
                Scheduled   = DateTime.Now,
                Location    = new LocationDto()
                {
                    Id = 1
                }
            };

            var result = await _service.CreateSession(session);

            Assert.NotEqual(0, result);
        }
Пример #14
0
        public void Create_Session_Success()
        {
            // Arrange
            newUser    = tu.CreateUserObject();
            newSession = tu.CreateSessionObject(newUser);
            var expected = newSession;

            using (_db = tu.CreateDataBaseContext())
            {
                // Act
                var response = ss.CreateSession(newSession);
                _db.SaveChanges();

                //Assert
                Assert.IsNotNull(response);
                Assert.AreEqual(response.Id, expected.Id);
            }
        }
Пример #15
0
        public void NewMessageIdIsZero()
        {
            // Arrange
            string alicePassword = "******";
            IUser  alice         = new User(0, "Alice", new SHA256PasswordHandler(alicePassword));

            IIdentityProvider idProvider     = new SequentialIdentityProvider();
            IRepo <ISession>  sessionRepo    = new InMemoryRepo <ISession>();
            SessionService    sessionService = new SessionService(idProvider, sessionRepo);

            int expectedSessionId = 0;

            // Act
            sessionService.CreateSession(alice, alicePassword);

            // Assert
            Assert.AreEqual(expectedSessionId, sessionRepo.Items.First().Id);
        }
Пример #16
0
        public async Task <IActionResult> CreateSession([FromBody, Required] SessionDto sessionDto)
        {
            try
            {
                if (sessionDto == null)
                {
                    return(BadRequest());
                }

                var result = await _service.CreateSession(sessionDto);

                return(CreatedAtRoute("default", result));
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
                return(BadRequest(ex.Message));
            }
        }
Пример #17
0
        static void Main(string[] args)
        {
            bool isSandbox = false;

            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

            try
            {
                AccountCredentials credentials = PagSeguroConfiguration.GetAccountCredentials(isSandbox);

                Session result = SessionService.CreateSession(credentials);
            }
            catch (PagSeguroServiceException exception)
            {
                foreach (ServiceError element in exception.Errors)
                {
                }
            }
        }
Пример #18
0
        public void Get_Session_Success()
        {
            // Arrange
            newUser    = tu.CreateUserObject();
            newSession = tu.CreateSessionObject(newUser);
            var expectedResult = newSession;

            // ACT
            using (var _db = tu.CreateDataBaseContext())
            {
                SessionService ss = new SessionService(_db);
                newSession = ss.CreateSession(newSession);
                _db.SaveChanges();
                var result = ss.GetSession(newSession.Token);

                // Assert
                Assert.IsNotNull(result);
                Assert.AreEqual(expectedResult.Id, result.Id);
            }
        }
Пример #19
0
        public void Create_Session_RetrieveNew_Success()
        {
            // Arrange
            newUser    = tu.CreateUserObject();
            newSession = tu.CreateSessionObject(newUser);
            var expected = newSession;

            using (var _db = tu.CreateDataBaseContext())
            {
                // Act
                SessionService ss       = new SessionService(_db);
                var            response = ss.CreateSession(newSession);
                _db.SaveChanges();

                //Assert
                var result = _db.Sessions.Find(newSession.Id);
                Assert.IsNotNull(response);
                Assert.IsNotNull(result);
                Assert.AreSame(result, expected);
            }
        }
Пример #20
0
        public void Create_Session_Fail_ExceptionThrown()
        {
            newUser = tu.CreateUserObject();

            // Arrange
            newSession = new Session
            {
                ExpiresAt = DateTime.UtcNow.AddMinutes(Session.MINUTES_UNTIL_EXPIRATION),
                CreatedAt = DateTime.UtcNow,
                User      = newUser,
                UserId    = newUser.Id

                            //missing required fields
            };
            var expected = newSession;

            using (var _db = tu.CreateDataBaseContext())
            {
                // ACT
                SessionService ss       = new SessionService(_db);
                var            response = ss.CreateSession(newSession);
                try
                {
                    _db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //catch error
                    // detach Session attempted to be created from the db context - rollback
                    _db.Entry(response).State = System.Data.Entity.EntityState.Detached;
                }
                var result = _db.Sessions.Find(newSession.Id);

                // Assert
                Assert.IsNull(result);
                Assert.IsNotNull(response);
                Assert.AreEqual(expected, response);
                Assert.AreNotEqual(expected, result);
            }
        }
        static void Main(string[] args)
        {
            var helpRequested = false;
            var sendMessage   = false;
            var optionSet     = new OptionSet
            {
                { "u|user="******"Username to use", user => _username = user },
                { "p|pass="******"Password for Username", pass => _password = pass },
                { "a|account=", "Account Reference to use", reference => _accountReference = reference },
                {
                    "s|send=", "Send a message to the provided number", sendTo =>
                    {
                        sendMessage = true;
                        _sendTo     = sendTo;
                    }
                },
                { "b|bodies+", "Retrieve message bodies", v => _getBodies = true },
                {
                    "h|help", "Help about the command line interface", key => { helpRequested = key != null; }
                }
            };

            try
            {
                optionSet.Parse(args);
                if (!helpRequested && (string.IsNullOrEmpty(_username) ||
                                       string.IsNullOrEmpty(_password) ||
                                       string.IsNullOrEmpty(_accountReference)))
                {
                    throw new ApplicationException("Samples require username, password and account reference be given");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                helpRequested = true;
            }

            if (helpRequested)
            {
                ShowUsage(optionSet);
                return;
            }

            EsendexCredentials credentials;

            try
            {
                credentials = new EsendexCredentials(_username, _password);
                var sessionService = new SessionService(credentials);

                credentials.SessionId = sessionService.CreateSession();
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
                return;
            }

            if (sendMessage)
            {
                Console.WriteLine("Send Message Example\r\n");
                SendMessageExample(credentials);
            }

            MessageBodyService messageBodyService = null;

            if (_getBodies)
            {
                messageBodyService = new MessageBodyService(credentials);
            }

            Console.WriteLine();
            Console.WriteLine("Sent Messages Example\r\n");
            GetSentMessagesExample(credentials, messageBodyService);

            Console.WriteLine();
            Console.WriteLine("Inbox Messages Example\r\n");
            GetInboxMessagesExample(credentials, messageBodyService);

            Console.WriteLine();
            Console.WriteLine("Contacts Example\r\n");
            GetContactsExample(credentials);

            Console.WriteLine();
            Console.WriteLine("Groups Example\r\n");
            GetGroupsExample(credentials);

            Console.WriteLine();
            Console.WriteLine("Contacts in Group Example\r\n");
            GetContactsByGroupExample(credentials);

            AddContactToGroup(credentials);

            Console.WriteLine();
            Console.WriteLine("Press enter to continue ... ");
            Console.ReadLine();
        }