Esempio n. 1
0
        private void btn_inject_rollResults_Click(object sender, EventArgs e)
        {
            DB db = new DB();

            if (db.Dices.Count() == 0)
            {
                MessageBox.Show("Please create dices first");
                return;
            }

            openFileDialog1.Filter = "JSON files (*.json)|*.json|XML files (*.xml)|*.xml";
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName == string.Empty)
            {
                return;
            }
            if (openFileDialog1.FileName.ToLower().EndsWith("json"))
            {
                //Deserialize JSON file to RollResult
                FileStore         fileStore      = Factory.CreateFileStore("JSON");
                List <RollResult> rollResultList = fileStore.DeserializedRollResults(openFileDialog1.FileName);

                db.RollResults.AddRange(rollResultList);
                db.SaveChanges();

                //update labels
                UpdateLabelsAndCounters();
            }
            else if (openFileDialog1.FileName.ToLower().EndsWith("xml"))
            {
                //Deserialize XML file to RollResults
                FileStore         fileStore      = Factory.CreateFileStore("XML");
                List <RollResult> rollResultList = fileStore.DeserializedRollResults(openFileDialog1.FileName);

                db.RollResults.AddRange(rollResultList);
                db.SaveChanges();

                //update labels
                UpdateLabelsAndCounters();
            }
        }