Пример #1
0
    // Use this for initialization


    public static void SaveData(List <CardData> cardDataList)
    {
        BinaryFormatter bf     = new BinaryFormatter();
        FileStream      stream = new FileStream(Application.persistentDataPath + "/player.sav", FileMode.Create);
        //saves all the card data to the UserSaveData class
        UserSaveData data = new UserSaveData(cardDataList);

        bf.Serialize(stream, data);
        stream.Close();
        print("Game saved");
    }
Пример #2
0
    //Get the card data list from the saved data, return null for an error
    public static List <CardData> GetSavedCardList()
    {
        UserSaveData data = GetUserSaveData();

        if (GetUserSaveData() != null)
        {
            return(data.savedCardsList);
        }
        else
        {
            Debug.LogError("Cannot get card list."); return(null);
        }
    }
Пример #3
0
    private static UserSaveData GetUserSaveData()
    {
        if (File.Exists(Application.persistentDataPath + "/player.sav"))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(Application.persistentDataPath + "/player.sav", FileMode.Open);

            //doesn't actually know what game object it is so you need to cast it as the object
            UserSaveData data = bf.Deserialize(stream) as UserSaveData;
            stream.Close();
            print("Loading game finished");
            return(data);
        }
        else
        {
            Debug.LogError("File does not exist");
            return(null);
        }
    }
Пример #4
0
        public async Task <int> CreateIfNotExistsAsync(UserSaveData saveData)
        {
            var user = await _userContext.DataSet.FirstOrDefaultAsync(u => u.GoogleIdentifier == saveData.ProviderKey);

            if (user != null)
            {
                return(user.Id);
            }

            user = new User
            {
                GoogleIdentifier = saveData.ProviderKey,
                Firstname        = saveData.Firstname,
                Lastname         = saveData.Lastname,
                Email            = saveData.Email
            };
            _userContext.DataSet.Add(user);

            await _userContext.SaveChangesAsync();

            return(user.Id);
        }
Пример #5
0
 public async Task LogUsers(List <LocationData> locations, int countUp = 1)
 {
     if (savedUsers == null)
     {
         Debug.Log("Create Log ...");
         savedUsers = new UsersSaveData();
     }
     Debug.Log("Write Log ...");
     for (int i = 0; i < locations.Count; i++)
     {
         for (int j = 0; j < locations[i].Users.Count; j++)
         {
             UserSaveData u = null;
             for (int k = 0; k < savedUsers.users.Count; k++)
             {
                 if (savedUsers.users[k].id == locations[i].Users[j].Id)
                 {
                     u = savedUsers.users[k];
                     break;
                 }
             }
             if (u == null)
             {
                 u            = new UserSaveData();
                 u.id         = locations[i].Users[j].Id;
                 u.name       = locations[i].Users[j].Name;
                 u.lastUpdate = Functions.DateString;
                 u.friends    = new List <FriendUserSaveData>();
                 u.footprint  = new WeeksFootprint();
                 savedUsers.users.Add(u);
             }
             // 時間ごとのログイン履歴を記録
             u.footprint.CountupFootorint(
                 Functions.WeekInt(), Functions.HourInt(),
                 locations[i].Status, countUp);
         }
         if (locations[i].Id == "offline")
         {
             // continue;
         }
         else
         if (locations[i].Id == "private")
         {
             // プラべの場合自分だけ加算
             for (int j = 0; j < locations[i].Users.Count; j++)
             {
                 UserSaveData u = null;
                 for (int k = 0; k < savedUsers.users.Count; k++)
                 {
                     if (savedUsers.users[k].id == locations[i].Users[j].Id)
                     {
                         u = savedUsers.users[k];
                         break;
                     }
                 }
                 if (u == null)
                 {
                     u            = new UserSaveData();
                     u.id         = locations[i].Users[j].Id;
                     u.name       = locations[i].Users[j].Name;
                     u.lastUpdate = Functions.DateString;
                     u.friends    = new List <FriendUserSaveData>();
                     savedUsers.users.Add(u);
                 }
                 {
                     var friend           = locations[i].Users[j];
                     FriendUserSaveData f = null;
                     for (int m = 0; m < u.friends.Count; m++)
                     {
                         if (u.friends[m]?.id == friend.Id)
                         {
                             f = u.friends[m];
                             break;
                         }
                     }
                     if (f == null)
                     {
                         f            = new FriendUserSaveData();
                         f.id         = friend.Id;
                         f.name       = friend.Name;
                         f.lastUpdate = Functions.DateString;
                         f.count      = 0;
                         u.friends.Add(f);
                     }
                     f.count += countUp;
                 }
             }
         }
         else
         {
             // インスタンスないの全員を加算
             for (int j = 0; j < locations[i].Users.Count; j++)
             {
                 UserSaveData u = null;
                 for (int k = 0; k < savedUsers.users.Count; k++)
                 {
                     if (savedUsers.users[k].id == locations[i].Users[j].Id)
                     {
                         u = savedUsers.users[k];
                         break;
                     }
                 }
                 if (u == null)
                 {
                     u            = new UserSaveData();
                     u.id         = locations[i].Users[j].Id;
                     u.name       = locations[i].Users[j].Name;
                     u.lastUpdate = Functions.DateString;
                     u.friends    = new List <FriendUserSaveData>();
                     savedUsers.users.Add(u);
                 }
                 for (int k = 0; k < locations[i].Users.Count; k++)
                 {
                     FriendUserSaveData f = null;
                     for (int m = 0; m < u.friends.Count; m++)
                     {
                         if (u.friends[m]?.id == locations[i].Users[k].Id)
                         {
                             f = u.friends[m];
                             break;
                         }
                     }
                     if (f == null)
                     {
                         f            = new FriendUserSaveData();
                         f.id         = locations[i].Users[k].Id;
                         f.name       = locations[i].Users[k].Name;
                         f.lastUpdate = Functions.DateString;
                         f.count      = 0;
                         u.friends.Add(f);
                     }
                     f.count += countUp;
                 }
                 // ロケーションデータ側にも記録
                 if (!locations[i].UserHistry.ContainsKey(locations[i].Users[j].Id))
                 {
                     locations[i].UserHistry.Add(locations[i].Users[j].Id, new UserFootprints(locations[i].Users[j].Name, locations[i].Users[j].Id));
                 }
                 locations[i].UserHistry[locations[i].Users[j].Id].Count += countUp;
             }
         }
     }
     SaveLog();
 }
Пример #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var builder = services.AddControllersWithViews();

            builder.AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ContractResolver = new DefaultContractResolver();
            });

            if (_webEnvironment.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }

            // Database configuration
            services.Configure <Neo4jOptions>(_configuration.GetSection("neo4j"));
            services.AddDbContext <EasyCiteDbContext>();
            services.AddTransient(typeof(IGenericDataContextAsync <>), typeof(GenericDataContextAsync <>));

            services.AddHttpContextAccessor();
            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();
            services.AddScoped <IUrlHelper>(x =>
            {
                var actionContext = x.GetRequiredService <IActionContextAccessor>().ActionContext;
                var factory       = x.GetRequiredService <IUrlHelperFactory>();
                return(factory.GetUrlHelper(actionContext));
            });
            services.AddHttpClient();
            services.AddMemoryCache();

            // Google login configuration
            services
            .AddAuthentication(options =>
            {
                options.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddGoogle(options =>
            {
                var googleAuthNSection = _configuration.GetSection("Authentication:Google");

                options.ClientId                = googleAuthNSection["ClientId"];
                options.ClientSecret            = googleAuthNSection["ClientSecret"];
                options.Events.OnCreatingTicket = async ctx =>
                {
                    var userData = new UserSaveData
                    {
                        ProviderKey = ctx.Identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value,
                        Email       = ctx.Identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value,
                        Firstname   = ctx.Identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.GivenName)?.Value,
                        Lastname    = ctx.Identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Surname)?.Value
                    };

                    var createUserProcessor = ctx.HttpContext.RequestServices.GetRequiredService <ICreateUserProcessor>();

                    var userId = await createUserProcessor.CreateIfNotExistsAsync(userData);

                    ctx.Identity.AddClaim(new Claim(ClaimTypes.Sid, userId.ToString()));
                };
            });
        }