Exemple #1
0
        private void SaveProjects(IBaseCamp basecampManager)
        {
            var projects          = basecampManager.Projects;
            var step              = 50.0 / projects.Count();
            var projectEngine     = _engineFactory.ProjectEngine;
            var participantEngine = _engineFactory.ParticipantEngine;

            if (_projects.Any())
            {
                projects = projects.Where(r => _projects.Any(pr => pr == r.ID)).ToArray();
            }

            foreach (var project in projects)
            {
                try
                {
                    StatusState.StatusLogInfo(string.Format(ImportResource.ImportProjectStarted, project.Name));
                    StatusState.StatusProjectProgress(step);
                    var newProject = new Project
                    {
                        Status      = !project.IsClosed ? ProjectStatus.Open : ProjectStatus.Closed,
                        Title       = ReplaceLineSeparator(project.Name),
                        Description = project.Description,
                        Responsible = _initiatorId,
                        Private     = true
                    };

                    projectEngine.SaveOrUpdate(newProject, true);
                    var prt = participantEngine.GetByID(newProject.Responsible);
                    projectEngine.AddToTeam(newProject, prt, true);

                    foreach (var wrapper in
                             project.People.SelectMany(user => _newUsersID.Where(wrapper => user.ID == wrapper.InBasecamp)))
                    {
                        prt = participantEngine.GetByID(wrapper.InProjects);
                        projectEngine.AddToTeam(newProject, prt, true);

                        //check permission
                        var user = project.People.ToList().Find(p => p.ID == wrapper.InBasecamp);
                        if (user != null)
                        {
                        }
                    }
                    _newProjectsID.Add(new ProjectIDWrapper {
                        InBasecamp = project.ID, InProjects = newProject.ID
                    });
                }
                catch (Exception e)
                {
                    StatusState.StatusLogError(string.Format(ImportResource.FailedToSaveProject, project.Name), e);
                    LogError(string.Format("project '{0}' failed", project.Name), e);
                    _newProjectsID.RemoveAll(x => x.InBasecamp == project.ID);
                }
            }

            //Select only suceeded projects
            var projectsToProcess = projects.Where(x => _newProjectsID.Count(y => y.InBasecamp == x.ID) > 0).ToList();

            step = 50.0 / projectsToProcess.Count;
            foreach (var project in projectsToProcess)
            {
                StatusState.StatusLogInfo(string.Format(ImportResource.ImportProjectDataStarted, project.Name));

                StatusState.StatusProjectProgress(step);

                var messages = project.RecentMessages;
                foreach (var message in messages)
                {
                    SaveMessages(message, project.ID);
                }

                var todoLists = project.ToDoLists;
                foreach (var todoList in todoLists)
                {
                    SaveTasks(todoList, project.ID);
                }
                LogStatus("import files");
                SaveFiles(basecampManager, project.Attachments, project.ID);
            }
        }
        private void SaveProjects(IBaseCamp basecampManager)
        {
            var projects = basecampManager.Projects;
            var step = 50.0 / projects.Count();
            var projectEngine = _engineFactory.GetProjectEngine();
            var participantEngine = _engineFactory.GetParticipantEngine();

            if (_projects.Any())
            {
                projects = projects.Where(r => _projects.Any(pr => pr == r.ID)).ToArray();
            }

            foreach (var project in projects)
            {
                try
                {
                    Status.LogInfo(string.Format(ImportResource.ImportProjectStarted, project.Name));
                    Status.ProjectProgress += step;
                    var newProject = new Project
                        {
                            Status = !project.IsClosed ? ProjectStatus.Open : ProjectStatus.Closed,
                            Title = ReplaceLineSeparator(project.Name),
                            Description = project.Description,
                            Responsible = _initiatorId,
                            Private = true
                        };

                    projectEngine.SaveOrUpdate(newProject, true);
                    Participant prt = participantEngine.GetByID(newProject.Responsible);
                    projectEngine.AddToTeam(newProject, prt, true);

                    foreach (var wrapper in
                        project.People.SelectMany(user => _newUsersID.Where(wrapper => user.ID == wrapper.InBasecamp)))
                    {
                        prt = participantEngine.GetByID(wrapper.InProjects);
                        projectEngine.AddToTeam(newProject, prt, true);

                        //check permission
                        var user = project.People.ToList().Find(p => p.ID == wrapper.InBasecamp);
                        if (user != null)
                        {
                        }
                    }
                    _newProjectsID.Add(new ProjectIDWrapper {InBasecamp = project.ID, InProjects = newProject.ID});
                }
                catch(Exception e)
                {
                    Status.LogError(string.Format(ImportResource.FailedToSaveProject, project.Name), e);
                    LogError(string.Format("project '{0}' failed", project.Name), e);
                    _newProjectsID.RemoveAll(x => x.InBasecamp == project.ID);
                }
            }

            //Select only suceeded projects
            var projectsToProcess = projects.Where(x => _newProjectsID.Count(y => y.InBasecamp == x.ID) > 0).ToList();
            step = 50.0 / projectsToProcess.Count;
            foreach (var project in projectsToProcess)
            {
                Status.LogInfo(string.Format(ImportResource.ImportProjectDataStarted, project.Name));

                Status.ProjectProgress += step;

                var messages = project.RecentMessages;
                foreach (var message in messages)
                {
                    SaveMessages(message, project.ID);
                }

                var todoLists = project.ToDoLists;
                foreach (var todoList in todoLists)
                {
                    SaveTasks(todoList, project.ID);
                }
                LogStatus("import files");
                SaveFiles(basecampManager, project.Attachments, project.ID);
            }
        }
        private void SaveProjects(BaseCamp basecampManager)
        {
            var projects = basecampManager.Projects;
            var step = 50.0 / projects.Count();
            var projectEngine = _engineFactory.GetProjectEngine();
            var participantEngine = _engineFactory.GetParticipantEngine();
            foreach (var project in projects.Where(x => _withClosed ? true : x.Status == "active"))
            {
                try
                {
                    Status.LogInfo(string.Format(SettingsResource.ImportProjectStarted, project.Name));
                    Status.ProjectProgress += step;
                    var newProject = new Project()
                                             {
                                                 Status = project.Status == "active" ? ProjectStatus.Open : ProjectStatus.Closed,
                                                 Title = ReplaceLineSeparator(project.Name),
                                                 Description = project.Description,
                                                 Responsible = _initiatorId,
                                                 Private = true
                                             };

                    projectEngine.SaveOrUpdate(newProject, true);
                    Participant prt = participantEngine.GetByID(newProject.Responsible);
                    projectEngine.AddToTeam(newProject, prt, true);

                    foreach (var wrapper in
                        project.People.SelectMany(user => NewUsersID.Where(wrapper => user.ID == wrapper.inBasecamp)))
                    {
                        prt = participantEngine.GetByID(wrapper.inProjects);
                        projectEngine.AddToTeam(newProject, prt, true);
                        
                        //check permission
                        var user = project.People.ToList().Find(p => p.ID == wrapper.inBasecamp);
                        if (user!=null)
                        {
                            if (!user.HasAccessToNewProjects)
                            {
                                switch (user.CanPost)
                                {
                                    case 1:
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Messages, true);
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Files, true);
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Tasks, false);
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Milestone, false);
                                        break;
                                    case 2:
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Messages, true);
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Files, true);
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Tasks, true);
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Milestone, false);
                                        break;
                                    case 3:
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Messages, true);
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Files, true);
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Tasks, true);
                                        projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Milestone, true);
                                        break;
                                }
                            }
                        }
                    }
                    NewProjectsID.Add(new ProjectIDWrapper() { inBasecamp = project.ID, inProjects = newProject.ID });
                }
                catch (Exception e)
                {
                    Status.LogError(string.Format(SettingsResource.FailedToSaveProject, project.Name), e);
                    LogError(string.Format("project '{0}' failed", project.Name), e);
                    NewProjectsID.RemoveAll(x => x.inBasecamp == project.ID);
                }

            }

            //Select only suceeded projects
            var projectsToProcess = projects.Where(x => NewProjectsID.Count(y => y.inBasecamp == x.ID) > 0).ToList();
            step = 50.0 / projectsToProcess.Count;
            foreach (var project in projectsToProcess)
            {
                Status.LogInfo(string.Format(SettingsResource.ImportProjectDataStarted, project.Name));

                Status.ProjectProgress += step;
                SaveMilestones(project.Milestones);

                var messages = project.RecentMessages;
                foreach (var message in messages)
                {
                    SaveMessages(message);
                }

                var todoLists = project.ToDoLists;
                foreach (var todoList in todoLists)
                {
                    SaveTasks(todoList);
                }
                SaveFileCategories(project.Categories);
                SaveTimeSpends(project.TimeEntries);
                Attachments.AddRange(project.Attachments);

            }
        }
        private void SaveProjects(BaseCamp basecampManager)
        {
            var projects          = basecampManager.Projects;
            var step              = 50.0 / projects.Count();
            var projectEngine     = _engineFactory.GetProjectEngine();
            var participantEngine = _engineFactory.GetParticipantEngine();

            foreach (var project in projects.Where(x => _withClosed ? true : x.Status == "active"))
            {
                try
                {
                    Status.LogInfo(string.Format(SettingsResource.ImportProjectStarted, project.Name));
                    Status.ProjectProgress += step;
                    var newProject = new Project()
                    {
                        Status      = project.Status == "active" ? ProjectStatus.Open : ProjectStatus.Closed,
                        Title       = ReplaceLineSeparator(project.Name),
                        Description = project.Description,
                        Responsible = _initiatorId,
                        Private     = true
                    };

                    projectEngine.SaveOrUpdate(newProject, true);
                    Participant prt = participantEngine.GetByID(newProject.Responsible);
                    projectEngine.AddToTeam(newProject, prt, true);

                    foreach (var wrapper in
                             project.People.SelectMany(user => NewUsersID.Where(wrapper => user.ID == wrapper.inBasecamp)))
                    {
                        prt = participantEngine.GetByID(wrapper.inProjects);
                        projectEngine.AddToTeam(newProject, prt, true);

                        //check permission
                        var user = project.People.ToList().Find(p => p.ID == wrapper.inBasecamp);
                        if (user != null)
                        {
                            if (!user.HasAccessToNewProjects)
                            {
                                switch (user.CanPost)
                                {
                                case 1:
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Messages, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Files, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Tasks, false);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Milestone, false);
                                    break;

                                case 2:
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Messages, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Files, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Tasks, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Milestone, false);
                                    break;

                                case 3:
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Messages, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Files, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Tasks, true);
                                    projectEngine.SetTeamSecurity(newProject, prt, ProjectTeamSecurity.Milestone, true);
                                    break;
                                }
                            }
                        }
                    }
                    NewProjectsID.Add(new ProjectIDWrapper()
                    {
                        inBasecamp = project.ID, inProjects = newProject.ID
                    });
                }
                catch (Exception e)
                {
                    Status.LogError(string.Format(SettingsResource.FailedToSaveProject, project.Name), e);
                    LogError(string.Format("project '{0}' failed", project.Name), e);
                    NewProjectsID.RemoveAll(x => x.inBasecamp == project.ID);
                }
            }

            //Select only suceeded projects
            var projectsToProcess = projects.Where(x => NewProjectsID.Count(y => y.inBasecamp == x.ID) > 0).ToList();

            step = 50.0 / projectsToProcess.Count;
            foreach (var project in projectsToProcess)
            {
                Status.LogInfo(string.Format(SettingsResource.ImportProjectDataStarted, project.Name));

                Status.ProjectProgress += step;
                SaveMilestones(project.Milestones);

                var messages = project.RecentMessages;
                foreach (var message in messages)
                {
                    SaveMessages(message);
                }

                var todoLists = project.ToDoLists;
                foreach (var todoList in todoLists)
                {
                    SaveTasks(todoList);
                }
                SaveFileCategories(project.Categories);
                SaveTimeSpends(project.TimeEntries);
                Attachments.AddRange(project.Attachments);
            }
        }