示例#1
0
        public TestResult DoTest()
        {
            NetOffice.Settings.MessageFilter.Enabled = true;
            MSProject.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new MSProject.Application();

                application.ProjectTaskNewEvent += new MSProject.Application_ProjectTaskNewEventHandler(ApplicationProjectTaskNewEvent);
                application.ProjectBeforeCloseEvent += new MSProject.Application_ProjectBeforeCloseEventHandler(ApplicationProjectBeforeCloseEvent);
                application.ProjectBeforeTaskChangeEvent += new MSProject.Application_ProjectBeforeTaskChangeEventHandler(ApplicationProjectBeforeTaskChangeEvent);
                application.ProjectBeforeTaskDeleteEvent += new MSProject.Application_ProjectBeforeTaskDeleteEventHandler(ApplicationProjectBeforeTaskDeleteEvent);
               
                MSProject.Project newProject = application.Projects.Add();
                MSProject.Task task1 = newProject.Tasks.Add("Task 1");
                MSProject.Task task2 =  newProject.Tasks.Add("Task 2");
                
                task2.Delete();

                application.FileCloseAll(false);

                if (TaskDeleteEventCalled && TaskChangeEventCalled && BeforeCloseEventCalled && TaskChangeEventCalled)
                    return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
                else 
                {
                    string errorMessage = "";
                    if (!TaskDeleteEventCalled)
                        errorMessage += "ProjectBeforeTaskDeleteEvent failed ";
                    if (!TaskChangeEventCalled)
                        errorMessage += "ProjectBeforeTaskChangeEvent failed ";
                    if (!BeforeCloseEventCalled)
                        errorMessage += "ProjectBeforeCloseEvent failed ";
                    if (!TaskNewEventCalled)
                        errorMessage += "ProjectTaskNewEvent failed ";

                    return new TestResult(false, DateTime.Now.Subtract(startTime), errorMessage, null, "");
                }
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                NetOffice.Settings.MessageFilter.Enabled = false;

                if (null != application)
                {
                    application.Quit(false);
                    application.Dispose();
                }
            }
        }
示例#2
0
        public TestResult DoTest()
        {
            MSProject.Application application = null;
            DateTime startTime = DateTime.Now;

            try
            {
                application = COMObject.Create <MSProject.Application>(COMObjectCreateOptions.CreateNewCore);

                MSProject.Project newProject = application.Projects.Add();

                newProject.Tasks.Add("Task 0");
                newProject.Tasks.Add("Task 1");
                newProject.Tasks.Add("Task 2");
                newProject.Tasks.Add("Task 3");
                newProject.Tasks.Add("Task 4");
                newProject.Tasks.Add("Task 5");
                newProject.Tasks.Add("Task 6");
                newProject.Tasks.Add("Task 7");
                newProject.Tasks.Add("Task 8");
                newProject.Tasks.Add("Task 9");

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    application.Quit(PjSaveType.pjDoNotSave);
                    application.Dispose();
                }
            }
        }
示例#3
0
        public TestResult DoTest()
        {
            MSProject.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new MSProject.Application();

                MSProject.Project newProject = application.Projects.Add();

                newProject.Tasks.Add("Task 0");
                newProject.Tasks.Add("Task 1");
                newProject.Tasks.Add("Task 2");
                newProject.Tasks.Add("Task 3");
                newProject.Tasks.Add("Task 4");
                newProject.Tasks.Add("Task 5");
                newProject.Tasks.Add("Task 6");
                newProject.Tasks.Add("Task 7");
                newProject.Tasks.Add("Task 8");
                newProject.Tasks.Add("Task 9");

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit(PjSaveType.pjDoNotSave);
                    application.Dispose();
                }
            }
        }
示例#4
0
        private void CreateOfficeApplication()
        {
            switch (_officeApp)
            {
            case "Excel":
                _excelApplication = new Excel.Application("Excel.Application");
                break;

            case "Word":
                _wordApplication = new Word.Application("Word.Application");
                break;

            case "Outlook":
                _outlookApplication = new Outlook.Application("Outlook.Application");
                break;

            case "Power Point":
                _powerpointApplication = new PowerPoint.Application("PowerPoint.Application");
                break;

            case "Access":
                _accessApplication = new Access.Application("Access.Application");
                break;

            case "Project":
                _projectApplication = new Project.Application("MSProject.Application");
                break;

            case "Visio":
                _visioApplication = new Visio.Application("Visio.Application");
                break;

            default:
                throw new ArgumentOutOfRangeException("officeApp");
            }
        }
 public NetOfficeSupportTable()
 {
     Project.Application app1 = null;
     Visio.Application   app2 = null;
     Console.WriteLine(app1);
     Console.WriteLine(app2);
     AssemblyName[] referencedAssemblies = _thisAssembly.GetReferencedAssemblies();
     foreach (AssemblyName item in referencedAssemblies)
     {
         {
             if (item.Name.StartsWith("OfficeApi"))
             {
                 string assemblyPath = GetPhysicalPath(item);
                 Stream stream       = System.IO.File.OpenRead(assemblyPath);
                 _assOffice = AssemblyDefinition.ReadAssembly(stream);
             }
             else if (item.Name.StartsWith("ExcelApi"))
             {
                 string assemblyPath = GetPhysicalPath(item);
                 Stream stream       = System.IO.File.OpenRead(assemblyPath);
                 _assExcel = AssemblyDefinition.ReadAssembly(stream);
             }
             else if (item.Name.StartsWith("WordApi"))
             {
                 string assemblyPath = GetPhysicalPath(item);
                 Stream stream       = System.IO.File.OpenRead(assemblyPath);
                 _assWord = AssemblyDefinition.ReadAssembly(stream);
             }
             else if (item.Name.StartsWith("OutlookApi"))
             {
                 string assemblyPath = GetPhysicalPath(item);
                 Stream stream       = System.IO.File.OpenRead(assemblyPath);
                 _assOutlook = AssemblyDefinition.ReadAssembly(stream);
             }
             else if (item.Name.StartsWith("OutlookApi"))
             {
                 string assemblyPath = GetPhysicalPath(item);
                 Stream stream       = System.IO.File.OpenRead(assemblyPath);
                 _assOutlook = AssemblyDefinition.ReadAssembly(stream);
             }
             else if (item.Name.StartsWith("PowerPointApi"))
             {
                 string assemblyPath = GetPhysicalPath(item);
                 Stream stream       = System.IO.File.OpenRead(assemblyPath);
                 _assPowerPoint = AssemblyDefinition.ReadAssembly(stream);
             }
             else if (item.Name.StartsWith("AccessApi"))
             {
                 string assemblyPath = GetPhysicalPath(item);
                 Stream stream       = System.IO.File.OpenRead(assemblyPath);
                 _assAccess = AssemblyDefinition.ReadAssembly(stream);
             }
             else if (item.Name.StartsWith("MSProjectApi"))
             {
                 string assemblyPath = GetPhysicalPath(item);
                 Stream stream       = System.IO.File.OpenRead(assemblyPath);
                 _assMSProject = AssemblyDefinition.ReadAssembly(stream);
             }
             else if (item.Name.StartsWith("VisioApi"))
             {
                 string assemblyPath = GetPhysicalPath(item);
                 Stream stream       = System.IO.File.OpenRead(assemblyPath);
                 _assVisio = AssemblyDefinition.ReadAssembly(stream);
             }
         }
     }
 }
示例#6
0
        public TestResult DoTest()
        {
            NetOffice.Settings.Default.MessageFilter.Enabled = true;
            MSProject.Application application = null;
            DateTime startTime = DateTime.Now;

            try
            {
                application = new MSProject.Application();

                application.ProjectTaskNewEvent          += new MSProject.Application_ProjectTaskNewEventHandler(ApplicationProjectTaskNewEvent);
                application.ProjectBeforeCloseEvent      += new MSProject.Application_ProjectBeforeCloseEventHandler(ApplicationProjectBeforeCloseEvent);
                application.ProjectBeforeTaskChangeEvent += new MSProject.Application_ProjectBeforeTaskChangeEventHandler(ApplicationProjectBeforeTaskChangeEvent);
                application.ProjectBeforeTaskDeleteEvent += new MSProject.Application_ProjectBeforeTaskDeleteEventHandler(ApplicationProjectBeforeTaskDeleteEvent);

                MSProject.Project newProject = application.Projects.Add();
                MSProject.Task    task1      = newProject.Tasks.Add("Task 1");
                MSProject.Task    task2      = newProject.Tasks.Add("Task 2");

                task2.Delete();

                application.FileCloseAll(PjSaveType.pjDoNotSave);

                if (TaskDeleteEventCalled && TaskChangeEventCalled && BeforeCloseEventCalled && TaskChangeEventCalled)
                {
                    return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
                }
                else
                {
                    string errorMessage = "";
                    if (!TaskDeleteEventCalled)
                    {
                        errorMessage += "ProjectBeforeTaskDeleteEvent failed ";
                    }
                    if (!TaskChangeEventCalled)
                    {
                        errorMessage += "ProjectBeforeTaskChangeEvent failed ";
                    }
                    if (!BeforeCloseEventCalled)
                    {
                        errorMessage += "ProjectBeforeCloseEvent failed ";
                    }
                    if (!TaskNewEventCalled)
                    {
                        errorMessage += "ProjectTaskNewEvent failed ";
                    }

                    return(new TestResult(false, DateTime.Now.Subtract(startTime), errorMessage, null, ""));
                }
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                NetOffice.Settings.Default.MessageFilter.Enabled = false;

                if (null != application)
                {
                    application.Quit(PjSaveType.pjDoNotSave);
                    application.Dispose();
                }
            }
        }
示例#7
0
 private void CreateOfficeApplication()
 {
     switch (_officeApp)
     {
         case "Excel":
             _excelApplication = new Excel.Application("Excel.Application");
             break;
         case "Word":
             _wordApplication = new Word.Application("Word.Application");
             break;
         case "Outlook":
             _outlookApplication = new Outlook.Application("Outlook.Application");
             break;
         case "Power Point":
             _powerpointApplication = new PowerPoint.Application("PowerPoint.Application");
             break;
         case "Access":
             _accessApplication = new Access.Application("Access.Application");
             break;
         case "Project":
             _projectApplication = new Project.Application("MSProject.Application");
             break;
         case "Visio":
             _visioApplication = new Visio.Application("Visio.Application");
             break;
         default:
             throw new ArgumentOutOfRangeException("officeApp");
     }
 }