Exemplo n.º 1
0
        public async Task <IActionResult> RedirectToRandomID()
        {
            string id = Generate.GenerateRandomID(5, new string[] { "A-Z", "a-z", "0-9" });

            while (Directory.Exists(Path.Join(UserDataConstant.UserDataDir, id)) == true)
            {
                //if there's already same id then re-roll
                id = Generate.GenerateRandomID(5, new string[] { "A-Z", "a-z", "0-9" });
            }


            PickAndBan pick_and_ban = new PickAndBan(id);

            string user_data_per_sess_dir = Path.Join(UserDataConstant.UserDataDir, id);

            string style_per_sess_path         = Path.Join(UserDataConstant.UserDataDir, id, UserDataConstant.StyleFileName);
            string pickban_style_per_sess_path = Path.Join(UserDataConstant.UserDataDir, id, UserDataConstant.PickAndBanFileName);



            if (Directory.Exists(user_data_per_sess_dir) == false)
            {
                Directory.CreateDirectory(user_data_per_sess_dir);;
                await Generate.GenerateChampionStyleFileAsync(id, UserDataConstant.GetChampionStylePerSessFilePath(id));

                await Generate.GeneratePickBanStyleFileAsync(id, UserDataConstant.GetPickBanStylePerSessFilePath(id));
            }
            return(RedirectToAction("", id));
        }
Exemplo n.º 2
0
        public static async Task GeneratePickBanStyleFileAsync(string sessID, string path)
        {
            PickAndBan pb      = new PickAndBan(sessID);
            string     json_in = JsonConvert.SerializeObject(pb, Formatting.Indented);

            byte[] tmp = Encoding.ASCII.GetBytes(json_in);
            while (IO_Related.IsFileLocked(new FileInfo(path), FileMode.Create, FileAccess.Write))
            {
            }
            using (var fs = File.Open(path, FileMode.Open, FileAccess.Write, FileShare.Write))
            {
                await fs.WriteAsync(tmp);
            }
        }
Exemplo n.º 3
0
        public void UpdatePickAndBanAsync(PickAndBan pb)
        {
            string json_out = JsonConvert.SerializeObject(pb, Formatting.Indented);

            //byte[] buffer = Encoding.UTF8.GetBytes(json_out);

            //var buffer = Encoding.UTF8.GetBytes(json_out);
            while (IO_Related.IsFileLocked(new FileInfo(UserDataConstant.GetPickBanStylePerSessFilePath(pb.sessID)), FileMode.Open, FileAccess.Read))
            {
            }
            System.IO.File.WriteAllText(UserDataConstant.GetPickBanStylePerSessFilePath(pb.sessID), json_out);
            //using (var fs = System.IO.File.Open(UserDataConstant.GetPickBanStylePerSessFilePath(pb.sessID), FileMode.Open, FileAccess.Write))
            //{
            //    fs.Write(buffer);
            //}
        }
Exemplo n.º 4
0
        public PickAndBan GetPickAndBanAsync(string id)
        {
            byte[] buffer = new byte[20000];

            while (IO_Related.IsFileLocked(new FileInfo(UserDataConstant.GetPickBanStylePerSessFilePath(id)), FileMode.Open, FileAccess.Read))
            {
            }
            //using (var fs = System.IO.File.Open(UserDataConstant.GetPickBanStylePerSessFilePath(id), FileMode.Open, FileAccess.Read/*, FileShare.Read*/))
            //{
            //    await fs.ReadAsync(buffer);
            //}
            //string json_out = Encoding.UTF8.GetString(buffer);
            string     json_out = System.IO.File.ReadAllText(UserDataConstant.GetPickBanStylePerSessFilePath(id));
            PickAndBan result   = JsonConvert.DeserializeObject <PickAndBan>(json_out);

            return(result);
        }