/// <summary> /// BrainNet network object to zip stream /// </summary> /// <param name="network">The network.</param> /// <param name="zip">The zip.</param> /// <param name="fileName">Name of the file.</param> public static void NetworkToZip(INeuralNetwork network, ZipOutputStream zip, string fileName) { // in this case we have to use a temp file string tempFileName = System.IO.Path.GetTempFileName(); NetworkSerializer serializer = new NetworkSerializer(); serializer.SaveNetwork(tempFileName, network); FileStream fileStream = File.OpenRead(tempFileName); byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); PutZipEntry(zip, buffer, fileName); fileStream.Close(); // cleans up File.Delete(tempFileName); }
/// <summary> /// Save the network data to a file /// </summary> public void SaveToFile(string fileFilter, string fileExt, string fileName) { NetworkSerializer serializer = new NetworkSerializer(); SaveFileDialog dialog = new SaveFileDialog(); dialog.SupportMultiDottedExtensions = true; dialog.Filter = fileFilter; dialog.DefaultExt = fileExt; dialog.FileName = fileName; if (dialog.ShowDialog() == DialogResult.OK) { try { serializer.SaveNetwork(dialog.FileName, _network); MessageBox.Show("Saved to file " + dialog.FileName, "File Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { StaticClasses.ShowError("Error: Invalid File? " + ex.Message); } } }