Beispiel #1
0
        public async Task <MaybeResult <PlayerProfile, GenericErrorResult> > GetProfile(Guid id)
        {
            var profilePath = Directory.EnumerateFiles(_appDataDir, "*.json", SearchOption.TopDirectoryOnly)
                              .Select(Path.GetFileName)
                              .FirstOrDefault(x =>
            {
                var idAndName = x.Split('_');
                return(id == Guid.Parse(idAndName[0]));
            });

            if (profilePath == null)
            {
                return(MaybeResult <PlayerProfile, GenericErrorResult> .CreateError(GenericErrorResult.NotFound));
            }

            var profile = File.OpenRead(Path.Combine(_appDataDir, profilePath))
                          .DeserializeJsonFromStream <PlayerProfile>();

            if (profile?.PlayerInfo == null)
            {
                return(MaybeResult <PlayerProfile, GenericErrorResult> .CreateError(GenericErrorResult.NotFound));
            }

            return(MaybeResult <PlayerProfile, GenericErrorResult> .CreateOk(profile));
        }
 public static MaybeResult <T, GenericErrorResult> Success <T>(T success)
 {
     return(MaybeResult <T, GenericErrorResult> .CreateOk(success));
 }