Example #1
0
        protected FuncResult <Session> GetSessionInternal(string sessionId)
        {
            if (!sessions.ContainsKey(sessionId))
            {
                return(FuncResult.Failed <Session>());
            }

            return(sessions[sessionId].AsFuncResult());
        }
Example #2
0
        protected FuncResult <string> ReadFromFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(FuncResult.Failed <string>());
            }

            var content = File.ReadAllText(filePath);

            return(content.AsFuncResult());
        }
Example #3
0
        public FuncResult <Snapshot> GetSnapshotSave(string sessionId, string snapshotId)
        {
            var sessionResult = GetSessionSave(sessionId);

            if (sessionResult.IsSuccessful)
            {
                var snapshotResult = sessionResult.Value.GetSnapshotSave(snapshotId);
                return(snapshotResult);
            }

            return(FuncResult.Failed <Snapshot>());
        }
Example #4
0
        public FuncResult <Snapshot> GetSnapshotSave(string sessionId, string snapshotId)
        {
            Contract.NotNull <ArgumentNullException>(sessionId);
            Contract.NotNull <ArgumentNullException>(snapshotId);

            var filePath       = GetPathForSnapshot(sessionId, snapshotId);
            var resultFromFile = ReadFromFile(filePath);

            if (resultFromFile.IsSuccessful)
            {
                var snapshot = Deserialize <Snapshot>(resultFromFile.Value);
                return(snapshot.AsFuncResult());
            }

            return(FuncResult <Snapshot> .Failed());
        }
Example #5
0
        public FuncResult <Session> GetSessionSave(string sessionId)
        {
            Contract.NotNull <ArgumentNullException>(sessionId);

            var filePath       = GetPathForSession(sessionId);
            var resultFromFile = ReadFromFile(filePath);

            if (resultFromFile.IsSuccessful)
            {
                var session = Deserialize <Session>(resultFromFile.Value);
                session = FillSnapshotsFromSnapshotFiles(session);
                return(session.AsFuncResult());
            }

            return(FuncResult <Session> .Failed());
        }
Example #6
0
        public FuncResult <Session> GetSessionSave(string sessionId)
        {
            var result = GetSessionInternal(sessionId);

            if (result.IsSuccessful)
            {
                return(result);
            }

            if (settings.IsSessionAutoCreate)
            {
                var session = CreateSession(sessionId);
                return(session.AsFuncResult());
            }

            return(FuncResult.Failed <Session>());
        }
Example #7
0
        public FuncResult <Session> GetSessionSave(string sessionId)
        {
            if (settings.IsEnabledFileCache && inMemoryStorage.DoesSessionExist(sessionId))
            {
                return(inMemoryStorage.GetSessionSave(sessionId));
            }

            var resultFromFile = dataProvider.GetSessionSave(sessionId);

            if (resultFromFile.IsSuccessful)
            {
                inMemoryStorage.Add(resultFromFile.Value);
                return(resultFromFile);
            }

            if (settings.IsSessionAutoCreate)
            {
                var session = inMemoryStorage.CreateSession(sessionId);
                return(session.AsFuncResult());
            }

            return(FuncResult.Failed <Session>());
        }
Example #8
0
 public static FuncResult <TValue> Failed <TValue>()
 {
     return(FuncResult <TValue> .Failed());
 }