Exemplo n.º 1
0
        //private DispatcherTimer _dispatcherTimer;
        private void OnUploadCfgFile_Button_Click(object sender, RoutedEventArgs e)
        {
            // Configure open file dialog box
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName   = "origin";                     // Default file name
            dlg.DefaultExt = ".csv";                       // Default file extension
            dlg.Filter     = "CSV documents (.csv)|*.csv"; // Filter files by extension

            // Show open file dialog box
            bool?result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                try
                {
                    // Open document
                    var filePath = dlg.FileName;
                    HttpHandlers.SendFileContent(filePath, this);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 2
0
 private void OnClearExceptionCount_Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         HttpHandlers.SendGetMethod("/support/clearRoomException", null);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 3
0
        private async Task LoadAndSaveTableConfig(string recorderTableConfigId, string jsonFileName)
        {
            var result = await HttpHandlers.ExportTableCfg(recorderTableConfigId, this);

            if (result == null)
            {
                return;
            }

            using (var textWriter =
                       new StreamWriter(new FileStream(jsonFileName, FileMode.Create, FileAccess.ReadWrite), Encoding.Default))
            {
                textWriter.Write(Encoding.UTF8.GetString(result));
            }
        }
Exemplo n.º 4
0
        private async Task ExportAllTableOps(string text)
        {
            string xid    = "recordSID=" + text;
            var    result = await HttpHandlers.ExportTableShareIDs(xid, this);

            if (result == null)
            {
                return;
            }

            var strArray = ParseTableShareIDs(result);

            for (var i = 0; i < strArray.Length; i++)
            {
                string recordID = strArray[i];
                var    filename = $"table-{i}-{recordID}";
                await ExportOps(recordID, filename);
            }
        }
Exemplo n.º 5
0
        public static void LoadConfigFromFile()
        {
            var dir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (string.IsNullOrWhiteSpace(dir))
            {
                return;
            }

            var filePath = Path.Combine(dir, ConfigFileName);

            if (!File.Exists(filePath))
            {
                return;
            }

            var str = HttpHandlers.WriteSafeReadAllLines(filePath);

            if (!string.IsNullOrWhiteSpace(str))
            {
                //var a = JObject.Parse(str);
                //var url = (string) a["serverUrl"];
                //if (!string.IsNullOrWhiteSpace(url))
                //{
                //    ServerUrl = url;
                //}

                var des = (ProgramConfigJSON)JsonConvert.DeserializeObject(str, typeof(ProgramConfigJSON));
                configJSON = des;

                ServerUrl = configJSON.serverURL;

                if (!string.IsNullOrWhiteSpace(configJSON.account))
                {
                    Account = configJSON.account;
                }

                if (!string.IsNullOrWhiteSpace(configJSON.password))
                {
                    Password = configJSON.password;
                }
            }
        }
Exemplo n.º 6
0
        private void OnKickAllInRoom_Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var inputWnd = new InputWnd {
                    Owner = this, IsNeedUserId = false
                };
                var result = inputWnd.ShowDialog();
                if (result == false)
                {
                    return;
                }

                var roomNumber = inputWnd.TextBoxRoomId.Text;

                HttpHandlers.SendPostMethod("/support/kickAll", roomNumber, "&roomNumber=" + roomNumber);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 7
0
        private void OnExportTableCfg_Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var inputWnd = new InputWnd {
                    Owner = this, IsNeedUserId = false
                };
                var result = inputWnd.ShowDialog();
                if (result == false)
                {
                    return;
                }

                var tableNumber = inputWnd.TextBoxTableId.Text;

                HttpHandlers.SendPostMethod("/resetTable", tableNumber, "&tableNumber=" + tableNumber);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 8
0
        private void OnAttachDealCfg_Button_Click(object sender, RoutedEventArgs e)
        {
            //TestManualProto();
            // Configure open file dialog box
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName   = "origin";                     // Default file name
            dlg.DefaultExt = ".csv";                       // Default file extension
            dlg.Filter     = "CSV documents (.csv)|*.csv"; // Filter files by extension

            // Show open file dialog box
            bool?result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                try
                {
                    var inputWnd = new InputWnd {
                        Owner = this, IsNeedUserId = false
                    };
                    result = inputWnd.ShowDialog();
                    if (result == false)
                    {
                        return;
                    }

                    var roomNumber = inputWnd.TextBoxRoomId.Text;
                    // Open document
                    var filePath = dlg.FileName;
                    HttpHandlers.SendFileContent2(filePath, roomNumber, HttpHandlers.PathAttachDealCfgFile, this);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 9
0
        private void OnLoad_Button_Clicked(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName   = "origin";                     // Default file name
            dlg.DefaultExt = ".csv";                       // Default file extension
            dlg.Filter     = "CSV documents (.csv)|*.csv"; // Filter files by extension

            // Show open file dialog box
            bool?result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                try
                {
                    var x = HttpHandlers.WriteSafeReadAllLines(dlg.FileName);
                    if (!string.IsNullOrWhiteSpace(x))
                    {
                        using (var stringReader = new StringReader(x))
                        {
                            // csv reader
                            var csvReader = new CsvReader(stringReader);

                            // 读取头部
                            if (!csvReader.ReadHeader())
                            {
                                MessageBox.Show("Invalid input csv file, no record found");
                                return;
                            }


                            if (Headers.Length != csvReader.FieldHeaders.Length)
                            {
                                MessageBox.Show("Invalid input csv file, header count not match");
                                return;
                            }

                            for (var i = 0; i < Headers.Length; i++)
                            {
                                if (string.Compare(Headers[i], csvReader.FieldHeaders[i], StringComparison.Ordinal) != 0)
                                {
                                    MessageBox.Show("Invalid input csv file, header not match");
                                    return;
                                }
                            }

                            while (csvReader.Read())
                            {
                                for (var i = 0; i < 4; i++)
                                {
                                    var dealCfg = _dealCfgs[i];

                                    dealCfg.ReadCsv(csvReader);

                                    dealCfg.Tiles2Ui();
                                }

                                _drawCfg.ReadCsv(csvReader);
                                _drawCfg.Tiles2Ui();

                                //_endXTile.ReadCsv(csvReader);
                                //_endXTile.Tiles2Ui();

                                WallTiles2Ui();

                                // 仅读取第一个记录
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 10
0
        private async Task ExportOps(string text, string fileName)
        {
            string xid;

            if (RbUserId.IsChecked == true)
            {
                xid = "userID=" + text;
            }
            else
            {
                xid = "recordSID=" + text;
            }

            var result = await HttpHandlers.ExportTableOps(xid, this);

            if (result == null)
            {
                return;
            }

            //var recorder = result.ToProto<SRMsgHandRecorder>();

            //List<PlayerData> players = FromRecorder(recorder);
            ////string drawSequence = ExtractDrawSequence(recorder);
            ////string kongSequence = ExtractKongSequence(recorder);

            //var windId = recorder.windFlowerID;
            //var bankerPlayer = players.Find((p) => p.ChairId == recorder.bankerChairID);
            //var bankderUserId = bankerPlayer.UserId;
            //players = sortPlayers(players, bankderUserId);
            //var extra = recorder.extra;
            //var markup = extra.markup;

            ////名称	userID1	手牌	花牌	动作提示	userID2	手牌	花牌	动作提示	userID3	手牌	花牌	动作提示	userID4	手牌	花牌	动作提示	抽牌序列	庄家	风牌
            //Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            //dlg.FileName = fileName; // Default file name

            //dlg.DefaultExt = ".csv"; // Default file extension
            //dlg.Filter = "CSV documents (.csv)|*.csv"; // Filter files by extension

            //// Show save file dialog box
            //bool? dlgResult = dlg.ShowDialog();
            //// Process save file dialog box results
            //if (dlgResult == true)
            //{
            //    // Save document
            //    string filename = dlg.FileName;
            //    using (var textWriter =
            //        new StreamWriter(new FileStream(filename, FileMode.Create, FileAccess.ReadWrite), Encoding.Default))
            //    {
            //        var headers = DealCfgWnd.Headers;

            //        // 第一行
            //        var csv = new CsvWriter(textWriter);
            //        foreach (var header in headers)
            //        {
            //            csv.WriteField(header);
            //        }
            //        csv.NextRecord();

            //        // 第二行
            //        csv.WriteField("bug"); // 名字
            //        csv.WriteField("大丰关张"); // 名字

            //        foreach (var playerData in players)
            //        {
            //            playerData.WriteCsv(csv);
            //        }

            //        int pad = 4 - players.Count();
            //        for (int i = 0; i < pad; ++i)
            //        {
            //            for (int j = 0; j < 3; ++j)
            //                csv.WriteField("");
            //        }

            //        //csv.WriteField(drawSequence);
            //        //csv.WriteField(kongSequence);//杠后牌
            //        //csv.WriteField(markup); // 上楼计数
            //        csv.WriteField(1); // 强制一致
            //        csv.WriteField(recorder.tableConfigID);
            //        csv.WriteField(recorder.isContinuousBanker ? "1" : "0");
            //        csv.NextRecord();
            //    }

            //    if (!string.IsNullOrWhiteSpace(recorder.tableConfigID))
            //    {
            //        var dir = Path.GetDirectoryName(filename);
            //        if (dir == null)
            //        {
            //            return;
            //        }

            //        var jsonFileName = Path.Combine(dir, Path.GetFileNameWithoutExtension(filename) + ".json");
            //        await LoadAndSaveTableConfig(recorder.tableConfigID, jsonFileName);
            //    }
            //}
        }
Exemplo n.º 11
0
 private void OnDestroyRoom_Button_Click(object sender, RoutedEventArgs e)
 {
     HttpHandlers.SendPostMethod(@"/support/destroyMonkeyRoom", "", null);
     IsPlaying = false;
 }
Exemplo n.º 12
0
 private void OnCreateRoom_Button_Click(object sender, RoutedEventArgs e)
 {
     HttpHandlers.SendPostMethod(@"/support/createMonkeyRoom", "monkey", null);
 }
Exemplo n.º 13
0
 private void OnDestroyTable_Button_Click(object sender, RoutedEventArgs e)
 {
     HttpHandlers.SendPostMethod(@"/monkey/destroy-monkey-table", "", "&tableID=monkey-table");
     IsPlaying = false;
 }
Exemplo n.º 14
0
 private void OnCreateTable_Button_Click(object sender, RoutedEventArgs e)
 {
     HttpHandlers.SendPostMethod(@"/monkey/create-monkey-table", "", "&tableID=monkey-table");
 }