コード例 #1
0
        private void Button_History(object sender, RoutedEventArgs e)
        {
            CalcHistory history = new CalcHistory();
            String      message = "";

            try
            {
                using (Stream streamLoad = File.Open("MyFile.bin", FileMode.Open))
                {
                    var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    history = (CalcHistory)binaryFormatter.Deserialize(streamLoad);
                }
            }
            catch (FileNotFoundException errorMessage)
            {
                Console.WriteLine(@"file not there", errorMessage);
            }
            catch (SerializationException errorMesage)
            {
                Console.WriteLine(@"File empty", errorMesage);
            }
            List <String> historyList;

            historyList = history.GetList();
            for (int i = 0; i < historyList.Count; i++)
            {
                message += historyList.ElementAt(i) + "\n";
            }
            MessageBox.Show(message);
        }
コード例 #2
0
        // exceptions used down here
        // async used down here
        //
        //Button_Calculate eq. Enter
        //Calulates and saves entert calc. + result
        //
        private void Button_Calculate(object sender, RoutedEventArgs e)
        {
            CalcHistory save = new CalcHistory();

            try
            {
                using (Stream streamLoad = File.Open("MyFile.bin", FileMode.Open))
                {
                    var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    save = (CalcHistory)binaryFormatter.Deserialize(streamLoad);
                }
            }
            catch (FileNotFoundException errorMessage)
            {
                Console.WriteLine(@"file not there");
            }
            catch (SerializationException errorMesage)
            {
                Console.WriteLine(@"File empty", errorMesage);
            }

            save.AddResultToList(Anzeige.GetLineText(0));
            String anzeigeString = Anzeige.GetLineText(0);

            string[] stringValues;
            for (int i = 0; i < 20; ++i)
            {
                stringValues = anzeigeString.Split(null);
                math_operator(stringValues[0], stringValues);
                Console.WriteLine(@"ausgabe" + i);
            }
            save.AddResultToList(Anzeige.GetLineText(0));
            IFormatter    formatter = new BinaryFormatter();
            Stream        stream    = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);
            List <String> test;

            test = save.GetList();
            formatter.Serialize(stream, save);
            stream.Close();
        }