public string CreateSession(Entities.Session session)
        {
            var id = UniqueID();

            store.Add(id, session);
            return(id);
        }
Esempio n. 2
0
        public static FileRecord RetrieveFile(Entities.Session session, string fileId)
        {
            var        storageFile = DataAccess.StorageFiles.LoadByUUID(fileId);
            FileRecord fileRecord  = null;

            if (storageFile != null)
            {
                //Does file belongs to the same application:
                if (storageFile.Session?.Account?.Application_Id == session.Account?.Application_Id)
                {
                    fileRecord = new FileRecord()
                    {
                        FileName    = System.IO.Path.GetFileName(storageFile.FileName),
                        FileContent = storageFile.LoadFileContentAsBASE64(),
                        MimeType    = storageFile.GetMimeType(),
                        Extension   = storageFile.Extension
                    };
                }
                else
                {
                    throw new Exception("File access restricted.");
                }
            }
            else
            {
                throw new Exception("File not found.");
            }

            return(fileRecord);
        }
Esempio n. 3
0
 public void Remove(uint sessionId)
 {
     Entities.Session session = null;
     if (Sessions.ContainsKey(sessionId))
     {
         Sessions.TryRemove(sessionId, out session);
     }
 }
Esempio n. 4
0
 public Entities.Session Get(uint sessionId)
 {
     Entities.Session session = null;
     if (Sessions.ContainsKey(sessionId))
     {
         Sessions.TryGetValue(sessionId, out session);
     }
     return(session);
 }
Esempio n. 5
0
 public PlayerAuthorization(Entities.Session session)
     : base((ushort)Core.Enums.InternalPackets.PlayerAuthorization)
 {
     Append((ushort)PlayerAuthorizationErrorCodes.Login);
     Append(session.SessionID);
     Append(session.ID);
     Append(session.Name);
     Append(session.Displayname);
 }
 public PlayerAuthorization(Entities.Session session)
     : base((ushort)Core.Enums.InternalPackets.PlayerAuthorization, Core.Constants.xOrKeyServerSend)
 {
     Append((ushort)Core.Enums.Internal.PlayerAuthorizationErrorCodes.Login);
     Append(session.SessionID);
     Append(session.ID);
     Append(session.Name);
     Append(session.Displayname);
     Append(session.AccessLevel);
 }
Esempio n. 7
0
 public PlayerAuthentication(Entities.Session session)
     : base((ushort)Core.Networking.PacketList.PlayerAuthentication, Core.Networking.Constants.xOrKeyInternalSend)
 {
     Append((ushort)Core.Networking.ErrorCodes.Success);
     Append(session.SessionID);
     Append(session.ID);
     Append(session.Name);
     Append(session.UserDisplayName);
     Append((byte)session.AccessLevel);
 }
        public void UpdateSession(Entities.Session session)
        {
            var key = session.Id;

            if (store.ContainsKey(key) == false)
            {
                throw new Exception("Session with key " + session.Id + " does not exist!");
            }

            store[key] = session;
        }
Esempio n. 9
0
        /// <summary>
        /// Starts and logs an account session
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="deviceDescription"></param>
        /// <returns></returns>
        public static string StartSession(int accountId, string deviceDescription)
        {
            var session = new Entities.Session()
            {
                Account_Id  = accountId,
                SessionUUID = Guid.NewGuid().ToString().ToUpper(),
                StartedOn   = DateTime.UtcNow,
                Enabled     = true,
                Device      = deviceDescription
            };

            DataAccess.Sessions.Create(session);
            return(session.SessionUUID);
        }
Esempio n. 10
0
        public async Task <Response> Handle(AddSessionRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                AddNotification("Request", Resource.RequestNotbeNull);
                return(new Response(this));
            }

            if (string.IsNullOrEmpty(request.SessionEnd))
            {
                AddNotification("Request", Resource.SessionEndIsInvalid);
                return(new Response(this));
            }


            var time       = TimeSpan.Parse(request.SessionEnd);
            var sessionEnd = request.SessionStart;

            sessionEnd = sessionEnd.AddHours(time.Hours);
            sessionEnd = sessionEnd.AddMinutes(time.Minutes);

            Entities.Session session = new Entities.Session(request.SessionStart, sessionEnd, request.TicketValue, request.Animation, request.Audio, request.MovieId, request.RoomId);
            AddNotifications(session);

            if (IsInvalid())
            {
                return(new Response(this));
            }

            if (_repositorySession.Exists(x => x.RoomId == session.RoomId &&
                                          (
                                              (session.SessionStart >= x.SessionStart && session.SessionStart <= x.SessionEnd) ||
                                              (session.SessionEnd >= x.SessionStart && session.SessionEnd <= x.SessionEnd)
                                          )
                                          )
                )
            {
                AddNotification("Request", Resource.ExisteRoominAnotherSession);
                return(new Response(this));
            }

            session = _repositorySession.Add(session);
            AddSessionNotification addSessionNotification = new AddSessionNotification(session);
            var response = new Response(this, session);

            await _mediator.Publish(addSessionNotification);

            return(await Task.FromResult(response));
        }
Esempio n. 11
0
        public void Setup()
        {
            sut            = MakeSut();
            SessionGateway = new SessionGatewaySpy();

            // Insert fake session
            var session = new Entities.Session()
            {
                GameId   = 1,
                Id       = "", // Assigned by gateway
                PlayerId = 1
            };

            SessionGateway.CreateSession(session);
            storedSession = session;
        }
        public string PersistFile(Entities.Session session, string fileName, string fileContent)
        {
            var fileId      = Guid.NewGuid().ToString().ToUpper();
            var account     = session.Account;
            var application = account.Application;

            var finalDestination = GetDestinationDirectory(application.ApplicationKey);
            var outputDir        = System.IO.Path.Combine(
                Properties.Settings.Default.StorageLocation, finalDestination);

            if (!System.IO.Directory.Exists(outputDir))
            {
                System.IO.Directory.CreateDirectory(outputDir);
            }

            var extension      = System.IO.Path.GetExtension(fileName);
            var localFile      = string.Format("{0}{1}", fileId, extension);
            var outputFileName = System.IO.Path.Combine(outputDir, localFile);

            var bytes = System.Convert.FromBase64String(fileContent);

            System.IO.File.WriteAllBytes(outputFileName, bytes);

            var storageFile = new Entities.StorageFile()
            {
                FileUUID    = fileId,
                FileName    = fileName,
                UploadedOn  = DateTime.UtcNow,
                Extension   = extension,
                StoragePath = finalDestination,
                FileSize    = bytes.Length,
                Session_Id  = session.Id
            };

            DataAccess.StorageFiles.Create(storageFile);

            return(fileId);
        }
Esempio n. 13
0
        public async Task <Response> Handle(DeleteSessionRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                AddNotification("Request", Resource.RequestNotbeNull);
                return(new Response(this));
            }

            Entities.Session session = _repositorySession.GetById(request.Id);

            if (session == null)
            {
                AddNotification("Request", Resource.SessionNotFound);
                return(new Response(this));
            }

            var dateNow = DateTime.Now;

            dateNow.AddDays(10);

            if (_repositorySession.Exists(x => x.Id == request.Id && x.SessionStart <= dateNow))
            {
                AddNotification("Request", Resource.SessionCanNotBeDeleteUnder10Days);
                return(new Response(this));
            }

            _repositorySession.Delete(session);

            var result = new { Id = session.Id };

            var response = new Response(this, result);

            DeleteSessionNotification removeSessionNotification = new DeleteSessionNotification(session);
            await _mediator.Publish(removeSessionNotification);

            return(await Task.FromResult(response));
        }
Esempio n. 14
0
 public DeleteSessionNotification(Entities.Session session)
 {
     Session = session;
 }
Esempio n. 15
0
        public static string PersistFile(Entities.Session session, string originalFileName, string fileContent)
        {
            var persister = new FilePersister(Properties.Settings.Default.StorageLocation);

            return(persister.PersistFile(session, originalFileName, fileContent));
        }
 public AddSessionNotification(Entities.Session session)
 {
     Session = session;
 }
Esempio n. 17
0
 public void Add(Entities.Session item)
 {
     _sessionRepository.Insert(item);
 }
Esempio n. 18
0
 public void Update(Entities.Session item)
 {
     _sessionRepository.Update(item);
 }
Esempio n. 19
0
 public void Delete(Entities.Session item)
 {
     _sessionRepository.Delete(item);
 }