Ejemplo n.º 1
0
        private void SaveProject()
        {
            // commit data to CurrentProject
            SaveToCurrentProject();

            bool success;

            string data = XmlHelper.Serialize(CurrentProject, out success);

            if (success)
            {
                // actual save
                File.WriteAllText(CurrentProject.DataFile, data);

                MessageBox.Show(
                    "Project saved.", "Save",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);

                StamperLiveData.SendProjectChanged();
            }
            else
            {
                MessageBox.Show(
                    "A problem occured serializing the project data.",
                    "Save error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        private void DrivesForm_Load(object sender, EventArgs e)
        {
            LoadModeFromLiveData();
            LoadSessionLogFromLiveData();

            DriveStamperUI.Instance.OnActivityChanged += ActivityChanged;

            StamperLiveData.OnProjectChanged    += ProjectChanged;
            StamperLiveData.OnSessionLogChanged += SessionLogChanged;
            StamperLiveData.SendProjectChanged();

            StamperLiveData.OnDrivesUpdated += DrivesUpdated;
            DriveStamperUI.Instance.UpdateDrives();
        }
Ejemplo n.º 3
0
        protected override void OnLoad(EventArgs e)
        {
            Visible       = false; // Hide form window.
            ShowInTaskbar = false; // Remove from taskbar.

            base.OnLoad(e);

            StamperLiveData.Log("Application Started.");

            // load previous project or start new project
            InitialiseData();

            // show the drives form
            OnDrives(null, null);
        }
Ejemplo n.º 4
0
 public static void LoadProject(string file)
 {
     if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
     {
         StamperLiveData.Project = new Project();
         StamperLiveData.Project.SetDefaults();
         StamperLiveData.SendProjectChanged();
         StamperLiveData.SetLastProjectName(string.Empty);
     }
     else
     {
         StamperLiveData.Project = XmlHelper.Deserialize <Project>(File.ReadAllText(file));
         StamperLiveData.SendProjectChanged();
         StamperLiveData.SetLastProjectName(file);
     }
 }
Ejemplo n.º 5
0
        public void StampDrive(DriveInfo drive)
        {
            try
            {
                if (OnActivityChanged != null)
                {
                    OnActivityChanged(eActivity.Stamping);
                }

                IEnumerable <string> failiures = null;
                bool success = false;

                string msg = "Stamping drive: " + drive.Name;
                StamperLiveData.Log(msg);
                DriveStamperUI.ShowMessage(msg, ToolTipIcon.Info);

                success = Stamper.Stamp(drive, StamperLiveData.Project, out failiures);

                if (success)
                {
                    string msgOk = "Drive stamped: " + drive.Name;
                    StamperLiveData.Log(msgOk);
                    DriveStamperUI.ShowMessage(msgOk, ToolTipIcon.Info);
                }
                else
                {
                    string msgFail = "Drive not succesfully stamped:\n" + string.Join("\n", (failiures ?? new List <string>()).ToArray());
                    StamperLiveData.Log(msgFail);
                    DriveStamperUI.ShowMessage(msgFail, ToolTipIcon.Warning);
                }
            }
            catch (Exception e)
            {
                string msgFail = "Unexpected exception:\n" + e.Message;
                StamperLiveData.Log(msgFail);
                DriveStamperUI.ShowMessage(msgFail, ToolTipIcon.Warning);
            }
            finally
            {
                UpdateDrives();
                if (OnActivityChanged != null)
                {
                    OnActivityChanged(eActivity.None);
                }
            }
        }
Ejemplo n.º 6
0
        public void UpdateDrives()
        {
            StamperLiveData.ObservedDriveState.Clear();

            var drives = DriveHelper.FindDrives(StamperLiveData.Project);

            foreach (var drive in drives)
            {
                bool done  = Stamper.CheckDrive(drive, StamperLiveData.Project);
                bool space = Stamper.DriveHasSpace(drive, StamperLiveData.Project);

                eDriveState state = done ? eDriveState.Stamped : (space ? eDriveState.Ready : eDriveState.NoSpace);

                StamperLiveData.ObservedDriveState.Add(drive, state);
            }

            StamperLiveData.SendDrivesUpdate();
        }
Ejemplo n.º 7
0
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            e.HookQueryRemove = false;
            UpdateDrives();

            // match the drive to a key already in the observed state
            var drive = StamperLiveData.ObservedDriveState.Keys.Where(k => k.Name == new DriveInfo(e.Drive).Name).FirstOrDefault();

            if (drive != null)
            {
                StamperLiveData.Log("Drive detected: " + e.Drive + " - in state: " + StamperLiveData.ObservedDriveState[drive].ToString());
            }
            else
            {
                StamperLiveData.Log("Drive detected: " + e.Drive + " - state not detected.");
            }

            if (drive != null && StamperLiveData.ObservedDriveState[drive] == eDriveState.Ready)
            {
                if (StamperLiveData.Mode == eStampMode.Automatic)
                {
                    StampDrive(drive);
                }
                if (StamperLiveData.Mode == eStampMode.SemiAutomatic)
                {
                    var answer = MessageBox.Show("Stamp drive: " + drive.Name + "?", "Drive detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (answer == System.Windows.Forms.DialogResult.Yes)
                    {
                        StampDrive(drive);
                    }
                }

                UpdateDrives();
            }
        }
Ejemplo n.º 8
0
        private static void InitialiseData()
        {
            string file = StamperLiveData.GetLastProjectFilename();

            LoadProject(file);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Called by DriveDetector after removable device has been unplugged
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
 {
     StamperLiveData.Log("Drive removed: " + e.Drive);
     UpdateDrives();
 }