Ejemplo n.º 1
0
 public PartWriter(PartCollection parts)
 {
     List<Rotor> cloneRots = new List<Rotor>();
     parts.Rotors.ForEach(rot => cloneRots.Add(new Rotor(rot)));
     cloneRots.ForEach(rot => rot.Name += "(" + DateTime.Now.ToString("ddMMyy") + "Exported)");
     Reflector cloneRef = new Reflector(parts.Reflector);
     cloneRef.Name += "(" + DateTime.Now.ToString("ddMMyy") + "Exported)";
     this.parts = new PartCollection
     {
         PlugBoard = parts.PlugBoard,
         Rotors = cloneRots,
         Reflector = cloneRef
     };
 }
Ejemplo n.º 2
0
        public PartCollection ReadFromFile(string fileName)
        {
            Stream streamRead = null;
            try
            {
                streamRead = File.OpenRead(fileName);
                BinaryFormatter formatter = new BinaryFormatter();
                this.parts = (PartCollection)formatter.Deserialize(streamRead);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (streamRead != null)
                {
                    streamRead.Close();
                }
            }

            return this.parts;
        }
Ejemplo n.º 3
0
 private void WriteRotors(object saveDialog, CancelEventArgs e)
 {
     SaveFileDialog saveDlg = (SaveFileDialog)saveDialog;
     if (saveDlg.FileName != "")
     {
         PartCollection parts = new PartCollection
         {
             PlugBoard = this.enigmaOp.PlugBoard,
             Rotors = this.enigmaOp.WorkingRotors,
             Reflector = this.enigmaOp.WorkingReflector
         };
         PartWriter writer = new PartWriter(parts);
         try
         {
             writer.WriteTo(saveDlg.FileName);
         }
         catch (Exception error)
         {
             MessageBox.Show(error.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
Ejemplo n.º 4
0
 public void ImportParts(PartCollection parts)
 {
     this.machine.PlugBoard = parts.PlugBoard;
     this.machine.Reflector = parts.Reflector;
     this.machine.Rotors = new RotorSet(parts.Rotors);
     this.AllReflectors.Add(parts.Reflector);
     this.AllRotors.AddRange(parts.Rotors);
     this.PartInfo.UpdatePartInfo();
     this.PartInfo.UpdateRotorWindows();
 }