Ejemplo n.º 1
0
        public void ProjectServerCredentials()
        {
            // ExStart:CreateProjectOnline
            // ExFor: ProjectServerCredentials
            // ExFor: ProjectServerCredentials.#ctor(String,String,String)
            // ExSummary: Shows how to use project server credentials to retrieve list of project from Microsoft Project Online.
            try
            {
                const string SharepointDomainAddress = "https://contoso.sharepoint.com/sites/pwa";
                const string UserName = "******";
                const string Password = "******";

                var credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);

                var newProject = new Project(DataDir + @"Project1.mpp");

                var manager = new ProjectServerManager(credentials);
                manager.CreateNewProject(newProject);

                IEnumerable <ProjectInfo> list = manager.GetProjectList();

                foreach (var info in list)
                {
                    var project = manager.GetProject(info.Id);
                    Console.WriteLine("{0} - {1} - {2}", info.Name, info.CreatedDate, info.LastSavedDate);
                    Console.WriteLine("Resources count: {0}", project.Resources.Count);
                }
            }
            catch (ProjectOnlineException ex)
            {
                Console.WriteLine(ex.Message);
            }

            // ExEnd:CreateProjectOnline
        }
Ejemplo n.º 2
0
        public void UpdateProjectInProjectOnlineWithOptions()
        {
            // ExStart:UpdateProjectOnlineWithOptions
            // ExFor: ProjectServerSaveOptions.Timeout
            // ExSummary: Shows how to update project on Microsoft Project Online and control save timeout value.
            const string SharepointDomainAddress = "https://contoso.sharepoint.com/sites/pwa";
            const string UserName = "******";
            const string Password = "******";

            var credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);

            try
            {
                var manager = new ProjectServerManager(credentials);

                ProjectInfo projectInfo = null;
                foreach (var info in manager.GetProjectList())
                {
                    if (info.Name == "My project")
                    {
                        projectInfo = info;
                    }
                }

                if (projectInfo == null)
                {
                    Console.WriteLine("Project 'My project' not found in working store of Project Online account.");
                    return;
                }

                var project = manager.GetProject(projectInfo.Id);
                project.Set(Prj.FinishDate, new DateTime(2020, 03, 01));

                var task = project.RootTask.Children.Add("New task");
                task.Set(Tsk.Start, new DateTime(2020, 02, 26));
                task.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));

                var options = new ProjectServerSaveOptions {
                    Timeout = TimeSpan.FromMinutes(5)
                };

                manager.UpdateProject(project, options);
            }
            catch (ProjectOnlineException ex)
            {
                Console.WriteLine("Failed to update the project. Error: " + ex);
            }

            // ExEnd:UpdateProjectOnlineWithOptions
            catch (NotSupportedException ex)
            {
                Console.WriteLine(
                    ex.Message
                    + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
        public void UpdateProjectServer()
        {
            // ExStart:UpdateProjectServer
            // ExFor: ProjectServerManager.UpdateProject(Project)
            // ExSummary: Shows how to update project on Microsoft Project Online.
            const string URL      = "https://contoso.sharepoint.com/sites/pwa";
            const string Domain   = "CONTOSO.COM";
            const string UserName = "******";
            const string Password = "******";

            var windowsCredentials       = new NetworkCredential(UserName, Password, Domain);
            var projectServerCredentials = new ProjectServerCredentials(URL, windowsCredentials);

            try
            {
                var manager = new ProjectServerManager(projectServerCredentials);

                ProjectInfo projectInfo = null;
                foreach (var info in manager.GetProjectList())
                {
                    if (info.Name == "My project")
                    {
                        projectInfo = info;
                    }
                }

                if (projectInfo == null)
                {
                    Console.WriteLine("Project 'My project' not found in working store of Project Online account.");
                    return;
                }

                var project = manager.GetProject(projectInfo.Id);
                project.Set(Prj.FinishDate, new DateTime(2020, 03, 01));

                var task = project.RootTask.Children.Add("New task");
                task.Set(Tsk.Start, new DateTime(2020, 02, 26));
                task.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));

                manager.UpdateProject(project);
            }
            catch (ProjectOnlineException ex)
            {
                Console.WriteLine("Failed to update the project. Error: " + ex);
            }

            // ExEnd:UpdateProjectServer
            catch (NotSupportedException ex)
            {
                Console.WriteLine(
                    ex.Message
                    + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            //ExStart:ReadingProjectOnline
            string sharepointDomainAddress = "https://contoso.sharepoint.com";
            string userName = "******";
            string password = "******";

            var credentials = new ProjectServerCredentials(sharepointDomainAddress, userName, password);
            var reader      = new ProjectServerManager(credentials);
            var list        = reader.GetProjectList();

            foreach (var p in list)
            {
                var project = reader.GetProject(p.Id);
                Console.WriteLine("{0} - {1} - {2}", p.Name, p.CreatedDate, p.LastSavedDate);
                Console.WriteLine("Resources count: {0}", project.Resources.Count);
            }
            //ExEnd:ReadingProjectOnline
        }
Ejemplo n.º 5
0
        public static void ReadProjectFromProjectServer()
        {
            // ExStart:ReadProjectFromProjectServer
            string url      = "https://contoso.sharepoint.com";
            string domain   = "CONTOSO.COM";
            string userName = "******";
            string password = "******";

            var windowsCredentials       = new NetworkCredential(userName, password, domain);
            var projectServerCredentials = new ProjectServerCredentials(url, windowsCredentials);
            ProjectServerManager manager = new ProjectServerManager(projectServerCredentials);

            var list = manager.GetProjectList();

            foreach (var projectInfo in list)
            {
                Console.WriteLine("{0} - {1} - {2}", projectInfo.Id, projectInfo.CreatedDate, projectInfo.Name);
            }
            // ExEnd:ReadProjectFromProjectServer
        }
Ejemplo n.º 6
0
        public void WorkWithProjectInfo()
        {
            // ExStart
            // ExFor: ProjectInfo
            // ExFor: ProjectInfo.#ctor
            // ExFor: ProjectInfo.Id
            // ExFor: ProjectInfo.Name
            // ExFor: ProjectInfo.CreatedDate
            // ExFor: ProjectInfo.Description
            // ExFor: ProjectInfo.IsCheckedOut
            // ExFor: ProjectInfo.LastPublishedDate
            // ExFor: ProjectInfo.LastSavedDate
            // ExSummary: Shows how to read information about projects from Project Online.
            const string SharepointDomainAddress = "https://contoso.sharepoint.com/sites/pwa";
            const string UserName = "******";
            const string Password = "******";

            var credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);

            var reader = new ProjectServerManager(credentials);
            IEnumerable <ProjectInfo> list = reader.GetProjectList();

            // read project's information
            Console.WriteLine("Print information about projects:");
            foreach (var info in list)
            {
                Console.WriteLine("Id: " + info.Id);
                Console.WriteLine("Name: " + info.Name);
                Console.WriteLine("Description: " + info.Description);
                Console.WriteLine("Created Date: " + info.CreatedDate);
                Console.WriteLine("Last Saved Date: " + info.LastSavedDate);
                Console.WriteLine("Last Published Date: " + info.LastPublishedDate);
                Console.WriteLine("Is Checked Out: " + info.IsCheckedOut);
            }

            // ExEnd
        }
        public void ReadingProjectOnline()
        {
            try
            {
                // ExStart:ReadingProjectOnline
                // ExFor: ProjectServerManager.#ctor(ProjectServerCredentials)
                // ExFor: ProjectServerManager.GetProjectList
                // ExFor: ProjectServerManager.GetProject(Guid)
                // ExFor: ProjectServerManager.GetProjectRawData(Guid)
                // ExSummary: Shows how to read a project from Microsoft Project Online.
                const string SharepointDomainAddress = "https://contoso.sharepoint.com/sites/pwa";
                const string UserName = "******";
                const string Password = "******";

                var credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);
                var manager     = new ProjectServerManager(credentials);
                IEnumerable <ProjectInfo> list = manager.GetProjectList();

                foreach (var info in list)
                {
                    var project = manager.GetProject(info.Id);
                    Console.WriteLine("{0} - {1} - {2}", info.Name, info.CreatedDate, info.LastSavedDate);
                    Console.WriteLine("Resources count: {0}", project.Resources.Count);

                    // an user can read the project as raw data stream
                    var stream = manager.GetProjectRawData(info.Id);

                    // work with raw project data
                }

                // ExEnd:ReadingProjectOnline
            }
            catch (ProjectOnlineException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }