Ejemplo n.º 1
0
        public MainFormData(IList <Project> projects, int projectId, bool onlyMe, Filter filter)
        {
            Projects = new List <ClientProject>();
            Projects.Add(new ClientProject(new Project {
                Id = -1, Name = Languages.Lang.ShowAllIssues
            }));
            foreach (Project p in projects)
            {
                Projects.Add(new ClientProject(p));
            }
            NameValueCollection parameters = new NameValueCollection();

            if (projectId != -1)
            {
                parameters.Add("project_id", projectId.ToString());
            }

            if (RedmineClientForm.RedmineVersion >= ApiVersion.V13x)
            {
                if (projectId < 0)
                {
                    try
                    {
                        List <Tracker> allTrackers = (List <Tracker>)RedmineClientForm.redmine.GetTotalObjectList <Tracker>(null);
                        Trackers = allTrackers.ConvertAll(new Converter <Tracker, ProjectTracker>(TrackerToProjectTracker));
                    }
                    catch (Exception e)
                    {
                        throw new LoadException(Languages.Lang.BgWork_LoadTrackers, e);
                    }
                    Categories = null;
                    Versions   = null;
                }
                else
                {
                    try
                    {
                        NameValueCollection projectParameters = new NameValueCollection {
                            { "include", "trackers" }
                        };
                        Project project = RedmineClientForm.redmine.GetObject <Project>(projectId.ToString(), projectParameters);
                        Trackers = new List <ProjectTracker>(project.Trackers);
                    }
                    catch (Exception e)
                    {
                        throw new LoadException(Languages.Lang.BgWork_LoadProjectTrackers, e);
                    }

                    try
                    {
                        Categories = new List <IssueCategory>(RedmineClientForm.redmine.GetTotalObjectList <IssueCategory>(parameters));
                        Categories.Insert(0, new IssueCategory {
                            Id = 0, Name = ""
                        });
                    }
                    catch (Exception e)
                    {
                        throw new LoadException(Languages.Lang.BgWork_LoadCategories, e);
                    }

                    try
                    {
                        Versions = (List <Redmine.Net.Api.Types.Version>)RedmineClientForm.redmine.GetTotalObjectList <Redmine.Net.Api.Types.Version>(parameters);
                        Versions.Insert(0, new Redmine.Net.Api.Types.Version {
                            Id = 0, Name = ""
                        });
                    }
                    catch (Exception e)
                    {
                        throw new LoadException(Languages.Lang.BgWork_LoadVersions, e);
                    }
                }
                Trackers.Insert(0, new ProjectTracker {
                    Id = 0, Name = ""
                });

                try
                {
                    Statuses = new List <IssueStatus>(RedmineClientForm.redmine.GetTotalObjectList <IssueStatus>(parameters));
                    Statuses.Insert(0, new IssueStatus {
                        Id = 0, Name = Languages.Lang.AllOpenIssues
                    });
                    Statuses.Add(new IssueStatus {
                        Id = -1, Name = Languages.Lang.AllClosedIssues
                    });
                    Statuses.Add(new IssueStatus {
                        Id = -2, Name = Languages.Lang.AllOpenAndClosedIssues
                    });
                }
                catch (Exception e)
                {
                    throw new LoadException(Languages.Lang.BgWork_LoadStatuses, e);
                }

                try
                {
                    if (RedmineClientForm.RedmineVersion >= ApiVersion.V14x &&
                        projectId > 0)
                    {
                        List <ProjectMembership> projectMembers = (List <ProjectMembership>)RedmineClientForm.redmine.GetTotalObjectList <ProjectMembership>(parameters);
                        ProjectMembers = projectMembers.ConvertAll(new Converter <ProjectMembership, ProjectMember>(ProjectMember.MembershipToMember));
                    }
                    else
                    {
                        List <User> allUsers = (List <User>)RedmineClientForm.redmine.GetTotalObjectList <User>(null);
                        ProjectMembers = allUsers.ConvertAll(new Converter <User, ProjectMember>(UserToProjectMember));
                    }
                    ProjectMembers.Insert(0, new ProjectMember());
                }
                catch (Exception)
                {
                    ProjectMembers = null;
                    //throw new LoadException(Languages.Lang.BgWork_LoadProjectMembers, e);
                }

                try
                {
                    if (RedmineClientForm.RedmineVersion >= ApiVersion.V22x)
                    {
                        Enumerations.UpdateIssuePriorities(RedmineClientForm.redmine.GetTotalObjectList <IssuePriority>(null));
                        Enumerations.SaveIssuePriorities();

                        Enumerations.UpdateActivities(RedmineClientForm.redmine.GetTotalObjectList <TimeEntryActivity>(null));
                        Enumerations.SaveActivities();
                    }
                    IssuePriorities = new List <Enumerations.EnumerationItem>(Enumerations.IssuePriorities);
                    IssuePriorities.Insert(0, new Enumerations.EnumerationItem {
                        Id = 0, Name = "", IsDefault = false
                    });

                    Activities = new List <Enumerations.EnumerationItem>(Enumerations.Activities);
                    Activities.Insert(0, new Enumerations.EnumerationItem {
                        Id = 0, Name = "", IsDefault = false
                    });
                }
                catch (Exception e)
                {
                    throw new LoadException(Languages.Lang.BgWork_LoadPriorities, e);
                }

                try
                {
                    if (RedmineClientForm.RedmineVersion >= ApiVersion.V24x)
                    {
                        CustomFields = RedmineClientForm.redmine.GetTotalObjectList <CustomField>(null);
                    }
                }
                catch (Exception e)
                {
                    throw new LoadException(Languages.Lang.BgWork_LoadCustomFields, e);
                }
            }

            try
            {
                if (onlyMe)
                {
                    parameters.Add("assigned_to_id", "me");
                }
                else if (filter.AssignedToId > 0)
                {
                    parameters.Add("assigned_to_id", filter.AssignedToId.ToString());
                }

                if (filter.TrackerId > 0)
                {
                    parameters.Add("tracker_id", filter.TrackerId.ToString());
                }

                if (filter.StatusId > 0)
                {
                    parameters.Add("status_id", filter.StatusId.ToString());
                }
                else if (filter.StatusId < 0)
                {
                    switch (filter.StatusId)
                    {
                    case -1:     // all closed issues
                        parameters.Add("status_id", "closed");
                        break;

                    case -2:     // all open and closed issues
                        parameters.Add("status_id", "*");
                        break;
                    }
                }

                if (filter.PriorityId > 0)
                {
                    parameters.Add("priority_id", filter.PriorityId.ToString());
                }

                if (filter.VersionId > 0)
                {
                    parameters.Add("fixed_version_id", filter.VersionId.ToString());
                }

                if (filter.CategoryId > 0)
                {
                    parameters.Add("category_id", filter.CategoryId.ToString());
                }

                if (!String.IsNullOrEmpty(filter.Subject))
                {
                    parameters.Add("subject", "~" + filter.Subject);
                }

                Issues = RedmineClientForm.redmine.GetTotalObjectList <Issue>(parameters);
            }
            catch (Exception e)
            {
                throw new LoadException(Languages.Lang.BgWork_LoadIssues, e);
            }
        }
Ejemplo n.º 2
0
        public static async Task <MainFormData> Init(IList <Project> projects, int projectId, bool onlyMe, Filter filter)
        {
            Func <NameValueCollection> InitParameters = () =>
            {
                NameValueCollection parameters = new NameValueCollection();
                if (projectId != -1)
                {
                    parameters.Add(RedmineKeys.PROJECT_ID, projectId.ToString());
                }
                return(parameters);
            };

            List <Tracker>                      allTrackers     = null;
            List <IssueCategory>                categories      = null;
            List <Net.Api.Types.Version>        versions        = null;
            List <ProjectTracker>               trackers        = null;
            List <IssueStatus>                  statuses        = null;
            List <ProjectMember>                projectMembers  = null;
            List <Enumerations.EnumerationItem> issuePriorities = null;
            List <Enumerations.EnumerationItem> activities      = null;
            List <CustomField>                  customFields    = null;

            if (RedmineClientForm.RedmineVersion >= ApiVersion.V13x)
            {
                try
                {
                    allTrackers = await RedmineClientForm.redmine.GetObjectsAsync <Tracker>(InitParameters());
                }
                catch (Exception e)
                {
                    throw new LoadException(Languages.Lang.BgWork_LoadTrackers, e);
                }
                if (projectId >= 0)
                {
                    try
                    {
                        NameValueCollection projectParameters = new NameValueCollection {
                            { "include", "trackers" }
                        };
                        Project project = await RedmineClientForm.redmine.GetObjectAsync <Project>(projectId.ToString(), projectParameters);

                        trackers = new List <ProjectTracker>(project.Trackers);
                    }
                    catch (Exception e)
                    {
                        throw new LoadException(Languages.Lang.BgWork_LoadProjectTrackers, e);
                    }

                    try
                    {
                        categories = new List <IssueCategory>(await RedmineClientForm.redmine.GetObjectsAsync <IssueCategory>(InitParameters()));
                        categories.Insert(0, new IssueCategory {
                            Id = 0, Name = ""
                        });
                    }
                    catch (Exception e)
                    {
                        throw new LoadException(Languages.Lang.BgWork_LoadCategories, e);
                    }

                    try
                    {
                        versions = await RedmineClientForm.redmine.GetObjectsAsync <Redmine.Net.Api.Types.Version>(InitParameters());

                        versions.Insert(0, new Redmine.Net.Api.Types.Version {
                            Id = 0, Name = ""
                        });
                    }
                    catch (Exception e)
                    {
                        throw new LoadException(Languages.Lang.BgWork_LoadVersions, e);
                    }
                }
                trackers.Insert(0, new ProjectTracker {
                    Id = 0, Name = ""
                });

                try
                {
                    statuses = await RedmineClientForm.redmine.GetObjectsAsync <IssueStatus>(InitParameters());

                    statuses.Insert(0, new IssueStatus {
                        Id = 0, Name = Languages.Lang.AllOpenIssues
                    });
                    statuses.Add(new IssueStatus {
                        Id = -1, Name = Languages.Lang.AllClosedIssues
                    });
                    statuses.Add(new IssueStatus {
                        Id = -2, Name = Languages.Lang.AllOpenAndClosedIssues
                    });
                }
                catch (Exception e)
                {
                    throw new LoadException(Languages.Lang.BgWork_LoadStatuses, e);
                }

                try
                {
                    if (RedmineClientForm.RedmineVersion >= ApiVersion.V14x &&
                        projectId > 0)
                    {
                        List <ProjectMembership> projectMembership = await RedmineClientForm.redmine.GetObjectsAsync <ProjectMembership>(InitParameters());

                        projectMembers = projectMembership.ConvertAll(new Converter <ProjectMembership, ProjectMember>(ProjectMember.MembershipToMember));
                    }
                    else
                    {
                        List <User> allUsers = await RedmineClientForm.redmine.GetObjectsAsync <User>(InitParameters());

                        projectMembers = allUsers.ConvertAll(new Converter <User, ProjectMember>(UserToProjectMember));
                    }
                    projectMembers.Insert(0, new ProjectMember());
                }
                catch (Exception)
                {
                    projectMembers = null;
                    //throw new LoadException(Languages.Lang.BgWork_LoadProjectMembers, e);
                }

                try
                {
                    if (RedmineClientForm.RedmineVersion >= ApiVersion.V22x)
                    {
                        Enumerations.UpdateIssuePriorities(await RedmineClientForm.redmine.GetObjectsAsync <IssuePriority>(InitParameters()));
                        Enumerations.SaveIssuePriorities();

                        Enumerations.UpdateActivities(await RedmineClientForm.redmine.GetObjectsAsync <TimeEntryActivity>(InitParameters()));
                        Enumerations.SaveActivities();
                    }
                    issuePriorities = new List <Enumerations.EnumerationItem>(Enumerations.IssuePriorities);
                    issuePriorities.Insert(0, new Enumerations.EnumerationItem {
                        Id = 0, Name = "", IsDefault = false
                    });

                    activities = new List <Enumerations.EnumerationItem>(Enumerations.Activities);
                    activities.Insert(0, new Enumerations.EnumerationItem {
                        Id = 0, Name = "", IsDefault = false
                    });
                }
                catch (Exception e)
                {
                    throw new LoadException(Languages.Lang.BgWork_LoadPriorities, e);
                }

                try
                {
                    if (RedmineClientForm.RedmineVersion >= ApiVersion.V24x)
                    {
                        customFields = await RedmineClientForm.redmine.GetObjectsAsync <CustomField>(InitParameters());
                    }
                }
                catch (Exception e)
                {
                    throw new LoadException(Languages.Lang.BgWork_LoadCustomFields, e);
                }
            }

            try
            {
                NameValueCollection parameters = InitParameters();
                if (onlyMe)
                {
                    parameters.Add(RedmineKeys.ASSIGNED_TO_ID, "me");
                }
                else if (filter.AssignedToId > 0)
                {
                    parameters.Add(RedmineKeys.ASSIGNED_TO_ID, filter.AssignedToId.ToString());
                }

                if (filter.TrackerId > 0)
                {
                    parameters.Add(RedmineKeys.TRACKER_ID, filter.TrackerId.ToString());
                }

                if (filter.StatusId > 0)
                {
                    parameters.Add(RedmineKeys.STATUS_ID, filter.StatusId.ToString());
                }
                else if (filter.StatusId < 0)
                {
                    switch (filter.StatusId)
                    {
                    case -1:     // all closed issues
                        parameters.Add(RedmineKeys.STATUS_ID, "closed");
                        break;

                    case -2:     // all open and closed issues
                        parameters.Add(RedmineKeys.STATUS_ID, " *");
                        break;
                    }
                }

                if (filter.PriorityId > 0)
                {
                    parameters.Add(RedmineKeys.PRIORITY_ID, filter.PriorityId.ToString());
                }

                if (filter.VersionId > 0)
                {
                    parameters.Add(RedmineKeys.FIXED_VERSION_ID, filter.VersionId.ToString());
                }

                if (filter.CategoryId > 0)
                {
                    parameters.Add(RedmineKeys.CATEGORY_ID, filter.CategoryId.ToString());
                }

                if (!String.IsNullOrEmpty(filter.Subject))
                {
                    parameters.Add(RedmineKeys.SUBJECT, "~" + filter.Subject);
                }

                var issues = await RedmineClientForm.redmine.GetObjectsAsync <Issue>(parameters);

                return(new MainFormData(projects, projectId, issues, allTrackers, categories,
                                        versions, trackers, statuses, projectMembers, issuePriorities,
                                        activities, customFields));
            }
            catch (Exception e)
            {
                throw new LoadException(Languages.Lang.BgWork_LoadIssues, e);
            }
        }