Esempio n. 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public frmMain()
        {
            InitializeComponent();

            Process currentProc = Process.GetCurrentProcess();

            bool continueProcessing = true;

            Process[] existingProcesses = Process.GetProcessesByName(currentProc.ProcessName, currentProc.MachineName);
            if (existingProcesses.Count() > 0)
            {
                Process sameProc  = null;
                int     currIndex = 0;
                while (sameProc == null && currIndex < existingProcesses.Count())
                {
                    if (existingProcesses[currIndex].Id != currentProc.Id && string.Equals(existingProcesses[currIndex].StartInfo.FileName, currentProc.StartInfo.FileName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        sameProc = existingProcesses[currIndex];
                    }
                    currIndex++;
                }

                if (sameProc != null)
                {
                    MessageBox.Show(string.Format("Error: The file {0} is already running, you cannot run it more than once.  If you cannot see it, kill the process in task manager (ctrl+alt+del).  Process Id = {1} Process Name = {2}", sameProc.StartInfo.FileName, sameProc.Id.ToString(), sameProc.ProcessName), "Error - Program already running", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continueProcessing = false;
                    Application.Exit();
                    this.Close();
                    this.Dispose();
                }
            }

            if (continueProcessing)
            {
                //todo: popup a window and ask for either windows identity or login with username and password
                m_currUser = OperationsReadOnly.CreateOrGetUser(System.Security.Principal.WindowsIdentity.GetCurrent());

                //Turn this on for initialising one project and task on entry
                //OperationsReadWrite.TempInit();

                this.ShowInTaskbar = false;
                this.WindowState   = FormWindowState.Minimized;

                //set the last reminder so that it will show straight away the first time
                m_dtLastReminder = DateTime.Now.AddMilliseconds(-m_reminderMilliseconds);

                //set the last entry initially - taken out as it can be annoying when days apart, need to think about this
                //m_lastEntry = OperationsReadOnly.GetLatestTimeEntry( m_currUser );


                //instead, get from settings
                LocalSettings settings = OperationsReadOnly.GetLocalSettings();
                if (settings != null)
                {
                    if (settings.LastTimeEntryId != Guid.Empty)
                    {
                        m_lastEntry = OperationsReadOnly.GetTimeEntryById(settings.LastTimeEntryId, m_currUser);
                    }

                    if (settings.LastReminderPeriodInMilliseconds > 0)
                    {
                        m_reminderMilliseconds = settings.LastReminderPeriodInMilliseconds;
                    }
                }
            }
        }