Пример #1
0
        /// <summary>
        /// Load the project file for usage
        /// </summary>
        /// <param name="fileName">File to open</param>
        public void LoadMPP()
        {
            Debug.Assert(System.IO.Path.IsPathRooted(LoadProjectFilePath));
            Debug.Assert(System.IO.File.Exists(LoadProjectFilePath));

            if (false == System.IO.File.Exists(LoadProjectFilePath))
            {
                //System.Windows.Forms.MessageBox.Show("Unable to find project file \"" + LoadProjectFilePath + "\".", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                throw new ProjzillaException("Unable to write to existing project file \"" + LoadProjectFilePath + "\" because it does not exist.", new FileNotFoundException("Unable to write to existing project file \"" + LoadProjectFilePath + "\" because it does not exist.", LoadProjectFilePath));
            }

            #region Do the Temp File Thing
            // Ensure that temp directory exists
            if (!Directory.Exists(Path.GetTempPath() + "\\Projzilla"))
            {
                Directory.CreateDirectory(Path.GetTempPath() + "Projzilla");
            }

            // Delete the old temp file if there is one.
            string loadProjectFileName = Path.GetFileName(LoadProjectFilePath);
            TempProjectFilePath = Path.GetTempPath() + "Projzilla\\" + loadProjectFileName;
            if (File.Exists(TempProjectFilePath))
            {
                try
                {
                    File.Delete(TempProjectFilePath);
                }
                catch (IOException ioe)
                {
                    throw new ProjzillaException("Unable to create temporary project file.  This typically occurs when project already has the file open.  Please close project and run the program again.", ioe, ProjzillaExceptionSeverity.Warn);
                }
            }

            // Copy the Load File to the temp location.
            File.Copy(LoadProjectFilePath, TempProjectFilePath);

            #endregion

            _projectApp = new ApplicationClass();

            // When doing a save, this prevents the do you want to overwrite dialog coming up.
            _projectApp.DisplayAlerts = false;
            _projectApp.AppMinimize();
            _projectApp.FileOpen(TempProjectFilePath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, PjPoolOpen.pjPoolReadWrite, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            _projectApp.WindowState = PjWindowState.pjMinimized;
            _projectApp.Visible     = false;
        }