예제 #1
0
        protected override Resource ConvertToIssueTracker(IssueQueryResource resource)
        {
            Resource result = new Resource();

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                result.Meta.Title       = "Query result";
                result.Meta.Description = "This is the result of a query for issues. Follow issues 'self' link to get more information about individual issues.";
            }

            result.AddControl(MasonBuilderContext.BuildIssueQueryTemplate(CommunicationContext));

            ((dynamic)result).Issues = new List <SubResource>();

            foreach (Issue i in resource.Issues)
            {
                dynamic item = new SubResource();
                item.ID    = i.Id.ToString();
                item.Title = i.Title;

                Uri     itemSelfUri  = typeof(IssueResource).CreateUri(new { id = i.Id });
                Control itemSelfLink = MasonBuilderContext.NewLink("self", itemSelfUri);
                item.AddControl(itemSelfLink);

                ((dynamic)result).Issues.Add(item);
            }

            Control selfLink = MasonBuilderContext.NewLink("self", resource.SelfUri);

            result.AddControl(selfLink);

            return(result);
        }
예제 #2
0
        protected override Resource ConvertToIssueTracker(IssueAttachmentsResource issue)
        {
            Resource i = new Resource();

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                i.Meta.Title       = "Issue attachments";
                i.Meta.Description = "This is the list of attachments for a single issue.";
            }

            Uri     selfUrl  = typeof(IssueAttachmentsResource).CreateUri(new { id = issue.Issue.Id });
            Control selfLink = MasonBuilderContext.NewLink("self", selfUrl);

            i.AddControl(selfLink);

            Uri     issueUrl  = typeof(IssueResource).CreateUri(new { id = issue.Issue.Id });
            Control issueLink = MasonBuilderContext.NewLink("up", issueUrl);

            i.AddControl(issueLink);

            ((dynamic)i).Id    = issue.Issue.Id;
            ((dynamic)i).Title = issue.Issue.Title;

            ((dynamic)i).Attachments = new List <SubResource>();

            foreach (Attachment a in issue.Attachments)
            {
                SubResource item = new SubResource();
                ((dynamic)item).ID    = a.Id.ToString();
                ((dynamic)item).Title = a.Title;

                Uri     itemSelfUri  = typeof(AttachmentResource).CreateUri(new { id = a.Id });
                Control itemSelfLink = MasonBuilderContext.NewLink("self", itemSelfUri);
                item.AddControl(itemSelfLink);

                Uri     contentUrl  = typeof(AttachmentContentResource).CreateUri(new { id = a.Id });
                Control contentLink = MasonBuilderContext.NewLink(RelTypes.AttachmentContent, contentUrl, "Download content", a.ContentType);
                item.AddControl(contentLink);

                ((dynamic)i).Attachments.Add(item);
            }

            return(i);
        }
예제 #3
0
        private SubResource BuildProjectSubResource(Project p)
        {
            SubResource sp = new SubResource();

            Uri     selfUri  = typeof(ProjectResource).CreateUri(new { id = p.Id });
            Control selfLink = MasonBuilderContext.NewLink("self", selfUri, "Project details");

            sp.AddControl(selfLink);

            dynamic dp = sp;

            dp.Id    = p.Id;
            dp.Code  = p.Code;
            dp.Title = p.Title;

            return(sp);
        }
예제 #4
0
        protected override Resource ConvertToIssueTracker(ProjectIssuesResource project)
        {
            Resource p = new Resource();

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                p.Meta.Title       = "Project issues";
                p.Meta.Description = "This is the list of issues for a single project.";
            }

            Uri     selfUrl  = typeof(ProjectIssuesResource).CreateUri(new { id = project.Project.Id });
            Control selfLink = MasonBuilderContext.NewLink("self", selfUrl);

            p.AddControl(selfLink);

            Uri     projectUrl  = typeof(ProjectResource).CreateUri(new { id = project.Project.Id });
            Control projectLink = MasonBuilderContext.NewLink("up", projectUrl);

            p.AddControl(projectLink);

            ((dynamic)p).Id    = project.Project.Id;
            ((dynamic)p).Title = project.Project.Title;

            ((dynamic)p).Issues = new List <SubResource>();

            foreach (Issue i in project.Issues)
            {
                dynamic item = new SubResource();
                item.ID    = i.Id.ToString();
                item.Title = i.Title;

                Uri     itemSelfUri  = typeof(IssueResource).CreateUri(new { id = i.Id });
                Control itemSelfLink = MasonBuilderContext.NewLink("self", itemSelfUri);
                item.AddControl(itemSelfLink);

                ((dynamic)p).Issues.Add(item);
            }

            return(p);
        }
예제 #5
0
        protected override Resource ConvertToIssueTracker(IssueResource issue)
        {
            Resource i = new Resource();

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                i.Meta.Title       = "Issue";
                i.Meta.Description = "This resource represents a single issue with its data and related actions.";
            }

            Uri     selfUrl  = typeof(IssueResource).CreateUri(new { id = issue.Issue.Id });
            Control selfLink = MasonBuilderContext.NewLink("self", selfUrl);

            i.AddControl(selfLink);

            Uri     projectUrl  = typeof(ProjectResource).CreateUri(new { id = issue.Issue.OwnerProject.Id });
            Control projectLink = MasonBuilderContext.NewLink("up", projectUrl, "Containing project");

            i.AddControl(projectLink);

            Uri     attachmentsUrl  = typeof(IssueAttachmentsResource).CreateUri(new { id = issue.Issue.Id });
            Control attachmentsLink = MasonBuilderContext.NewLink(RelTypes.Attachments, attachmentsUrl, "All attachments for this issue");

            i.AddControl(attachmentsLink);

            dynamic updateTemplate = new DynamicDictionary();

            updateTemplate.Title       = issue.Issue.Title;
            updateTemplate.Description = issue.Issue.Description;
            updateTemplate.Severity    = issue.Issue.Severity;

            Control updateAction = MasonBuilderContext.NewJsonAction(RelTypes.IssueUpdate, selfUrl, "Update issue details", template: (DynamicDictionary)updateTemplate);

            i.AddControl(updateAction);

            Control deleteAction = MasonBuilderContext.NewVoidAction(RelTypes.IssueDelete, selfUrl, "Delete issue", method: "DELETE");

            i.AddControl(deleteAction);

            Uri     addAttachmentSchemaUrl = typeof(SchemaTypeResource).CreateUri(new { name = "create-attachment" });
            Control addAttachmentAction    = MasonBuilderContext.NewJsonFilesAction(RelTypes.IssueAddAttachment, attachmentsUrl, "args", "Add new attachment to issue", schemaUrl: addAttachmentSchemaUrl);

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                addAttachmentAction.AddFile(new FileDefinition {
                    name = "attachment", title = "Attachment for issue"
                });
            }
            i.AddControl(addAttachmentAction);

            ((dynamic)i).ID          = issue.Issue.Id;
            ((dynamic)i).Title       = issue.Issue.Title;
            ((dynamic)i).Description = issue.Issue.Description;
            ((dynamic)i).Severity    = issue.Issue.Severity;

            List <SubResource> attachments = new List <SubResource>();

            foreach (Attachment att in issue.Attachments)
            {
                dynamic a = new SubResource();
                a.Id    = att.Id;
                a.Title = att.Title;

                Uri     attachmentUrl  = typeof(AttachmentResource).CreateUri(new { id = att.Id });
                Control attachmentLink = MasonBuilderContext.NewLink("self", attachmentUrl);
                a.AddControl(attachmentLink);

                Uri     contentUrl  = typeof(AttachmentContentResource).CreateUri(new { id = att.Id });
                Control contentLink = MasonBuilderContext.NewLink(RelTypes.AttachmentContent, contentUrl, "Download content", att.ContentType);
                a.AddControl(contentLink);

                attachments.Add(a);
            }

            ((dynamic)i).Attachments = attachments;

            return(i);
        }