Пример #1
0
 public static void ProtoSaveToFile(object sender, DoWorkEventArgs e)
 {
     try
     {
         worker = sender as BackgroundWorker;
         string       filename = e.Argument as string;
         SaveLoadData data     = new SaveLoadData();
         data.railml = XML.ToXElement <railml>(Data.DataContainer.model).ToString();
         data.NN     = DataContainer.NeuralNetwork;
         if (DataContainer.NeuralNetwork.Network != null)
         {
             data.network = SerializeNetwork();
         }
         if (DataContainer.NeuralNetwork.Data != null)
         {
             data.trainingset = SerializeDataSet();
         }
         MyStream stream = new MyStream(filename, FileMode.Create, FileAccess.Write);
         stream.ProgressChanged += new ProgressChangedEventHandler(Save_ProgressChanged);
         Serializer.Serialize(stream, data);
         stream.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex + "      Inner Exception: " + ex.InnerException);
         worker.ReportProgress(1, ex + "      Inner Exception: " + ex.InnerException);
     }
 }
Пример #2
0
        private static void Load_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            MyStream stream     = sender as MyStream;
            long     percentage = ((long)e.UserState) * 100 / stream.Length;

            worker.ReportProgress(0, percentage);
        }
Пример #3
0
        public static void LoadFile(object sender, DoWorkEventArgs e)
        {
            worker = sender as BackgroundWorker;
            string   filename = e.Argument as string;
            MyStream stream   = new MyStream(filename, FileMode.Open, FileAccess.Read);

            stream.ProgressChanged += new ProgressChangedEventHandler(Load_ProgressChanged);
            IFormatter   formatter = new BinaryFormatter();
            SaveLoadData data      = (SaveLoadData)formatter.Deserialize(stream);
            XElement     elem      = XElement.Parse(data.railml);

            DataContainer.model         = XML.FromXElement <railml>(elem);
            DataContainer.NeuralNetwork = data.NN;
            stream.Close();
        }
Пример #4
0
        public static void SaveToFile(object sender, DoWorkEventArgs e)
        {
            worker = sender as BackgroundWorker;
            string       filename = e.Argument as string;
            SaveLoadData data     = new SaveLoadData();

            data.railml = XML.ToXElement <railml>(Data.DataContainer.model).ToString();
            data.NN     = DataContainer.NeuralNetwork;
            MyStream stream = new MyStream(filename, FileMode.Create, FileAccess.Write);

            stream.ProgressChanged += new ProgressChangedEventHandler(Save_ProgressChanged);
            IFormatter formatter = new BinaryFormatter();

            formatter.Serialize(stream, data);
            stream.Close();
        }
Пример #5
0
        public static void ProtoLoadFile(object sender, DoWorkEventArgs e)
        {
            worker = sender as BackgroundWorker;
            string   filename = e.Argument as string;
            MyStream stream   = new MyStream(filename, FileMode.Open, FileAccess.Read);

            stream.ProgressChanged += new ProgressChangedEventHandler(Load_ProgressChanged);
            SaveLoadData data = Serializer.Deserialize <SaveLoadData>(stream);
            XElement     elem = XElement.Parse(data.railml);

            DataContainer.model         = XML.FromXElement <railml>(elem);
            DataContainer.NeuralNetwork = data.NN;
            if (data.trainingset != null)
            {
                DataContainer.NeuralNetwork.Data = DeserializeDataSet(data.trainingset);
            }
            if (data.network != null)
            {
                DataContainer.NeuralNetwork.Network = DeserializeNetwork(data.network);
            }
            stream.Close();
        }
Пример #6
0
 public static void SaveToFile(object sender, DoWorkEventArgs e )
 {
     worker = sender as BackgroundWorker;
     string filename = e.Argument as string;
     SaveLoadData data = new SaveLoadData();
     data.railml = XML.ToXElement<railml>(Data.DataContainer.model).ToString();
     data.NN = DataContainer.NeuralNetwork;
     MyStream stream = new MyStream(filename, FileMode.Create, FileAccess.Write);
     stream.ProgressChanged += new ProgressChangedEventHandler(Save_ProgressChanged);
     IFormatter formatter = new BinaryFormatter();
     formatter.Serialize(stream, data);
     stream.Close();
 }
Пример #7
0
 public static void ProtoSaveToFile(object sender, DoWorkEventArgs e)
 {
     try
     {
         worker = sender as BackgroundWorker;
         string filename = e.Argument as string;
         SaveLoadData data = new SaveLoadData();
         data.railml = XML.ToXElement<railml>(Data.DataContainer.model).ToString();
         data.NN = DataContainer.NeuralNetwork;
         if (DataContainer.NeuralNetwork.Network != null) { data.network = SerializeNetwork(); }
         if (DataContainer.NeuralNetwork.Data != null) { data.trainingset = SerializeDataSet(); }
         MyStream stream = new MyStream(filename, FileMode.Create, FileAccess.Write);
         stream.ProgressChanged += new ProgressChangedEventHandler(Save_ProgressChanged);
         Serializer.Serialize(stream, data);
         stream.Close();
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex + "      Inner Exception: " + ex.InnerException);
         worker.ReportProgress(1, ex + "      Inner Exception: " + ex.InnerException);
     }
 }
Пример #8
0
 public static void ProtoLoadFile(object sender, DoWorkEventArgs e)
 {
     worker = sender as BackgroundWorker;
     string filename = e.Argument as string;
     MyStream stream = new MyStream(filename, FileMode.Open, FileAccess.Read);
     stream.ProgressChanged += new ProgressChangedEventHandler(Load_ProgressChanged);
     SaveLoadData data = Serializer.Deserialize<SaveLoadData>(stream);
     XElement elem = XElement.Parse(data.railml);
     DataContainer.model = XML.FromXElement<railml>(elem);
     DataContainer.NeuralNetwork = data.NN;
     if (data.trainingset != null) { DataContainer.NeuralNetwork.Data = DeserializeDataSet(data.trainingset); }
     if (data.network != null) { DataContainer.NeuralNetwork.Network = DeserializeNetwork(data.network); }
     stream.Close();
 }
Пример #9
0
 public static void LoadFile(object sender, DoWorkEventArgs e)
 {
     worker = sender as BackgroundWorker;
     string filename = e.Argument as string;
     MyStream stream = new MyStream(filename, FileMode.Open, FileAccess.Read);
     stream.ProgressChanged += new ProgressChangedEventHandler(Load_ProgressChanged);
     IFormatter formatter = new BinaryFormatter();
     SaveLoadData data = (SaveLoadData)formatter.Deserialize(stream);
     XElement elem = XElement.Parse(data.railml);
     DataContainer.model = XML.FromXElement<railml>(elem);
     DataContainer.NeuralNetwork = data.NN;
     stream.Close();
 }