Exemplo n.º 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);
        }
Exemplo n.º 2
0
        protected override Resource ConvertToIssueTracker(AttachmentResource attachment)
        {
            Resource a = new Resource();

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

            Uri     selfUrl  = typeof(AttachmentResource).CreateUri(new { id = attachment.Attachment.Id });
            Control selfLink = MasonBuilderContext.NewLink("self", selfUrl);

            a.AddControl(selfLink);

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

            a.AddControl(issueLink);

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

            dynamic updateTemplate = new DynamicDictionary();

            updateTemplate.Title       = attachment.Attachment.Title;
            updateTemplate.Description = attachment.Attachment.Description;

            Control updateAction = MasonBuilderContext.NewJsonFilesAction(RelTypes.AttachmentUpdate, selfUrl, "args", "Update attachment details", description: "Update title and description of attachment", template: (DynamicDictionary)updateTemplate);

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                updateAction.AddFile(new FileDefinition {
                    name = "attachment", title = "Attachment content"
                });
            }
            a.AddControl(updateAction);

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

            a.AddControl(deleteAction);

            dynamic da = a;

            da.ID            = attachment.Attachment.Id;
            da.Title         = attachment.Attachment.Title;
            da.Description   = attachment.Attachment.Description;
            da.ContentType   = attachment.Attachment.ContentType;
            da.ContentLength = attachment.Attachment.ContentLength;
            da.CreatedDate   = attachment.Attachment.CreatedDate;

            return(a);
        }
Exemplo n.º 3
0
        protected override Resource ConvertToIssueTracker(ProjectResource project)
        {
            Resource p = new Resource();

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

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

            p.AddControl(selfLink);

            Uri     issuesUrl  = typeof(ProjectIssuesResource).CreateUri(new { id = project.Project.Id });
            Control issuesLink = MasonBuilderContext.NewLink(RelTypes.Issues, issuesUrl, "All issues in project");

            p.AddControl(issuesLink);

            dynamic updateTemplate = new DynamicDictionary();

            updateTemplate.Code        = project.Project.Code;
            updateTemplate.Title       = project.Project.Title;
            updateTemplate.Description = project.Project.Description;

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

            p.AddControl(updateAction);

            Uri     addIssueSchemaUrl = typeof(SchemaTypeResource).CreateUri(new { name = "create-issue" });
            Control addIssueAction    = MasonBuilderContext.NewJsonFilesAction(RelTypes.ProjectAddIssue, issuesUrl, "args", "Add issue", "Add new issue to project", schemaUrl: addIssueSchemaUrl);

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                addIssueAction.AddFile(new FileDefinition {
                    name = "attachment", title = "Attachment", description = "Include attachment for new issue."
                });
            }
            p.AddControl(addIssueAction);

            Control deleteAction = MasonBuilderContext.NewVoidAction(RelTypes.ProjectDelete, selfUrl, "Delete project", "This will delete the whole project and all issues in it.", method: "DELETE");

            p.AddControl(deleteAction);

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

            return(p);
        }
Exemplo n.º 4
0
        protected override Resource ConvertToMason(T resource)
        {
            Resource r = ConvertToIssueTracker(resource);

            r.AddNamespace(new Namespace(RelTypes.NSPrefix, RelTypes.NSName));

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                string msg = string.Format("This application restarts in {0:m\\:ss} minutes", ApplicationLifeTimeManager.NextRestart - DateTime.Now);
                if (r.Meta.Description == null)
                {
                    r.Meta.Description = msg;
                }
                else
                {
                    r.Meta.Description += " [" + msg + "]";
                }
                r.Meta.AddControl(MasonBuilderContext.NewLink("documentation", "https://github.com/JornWildt/Mason", "Documentation of Mason media type (hosted on GitHub)."));
            }

            Uri     resourceCommonUri  = typeof(ResourceCommonResource).CreateUri();
            Control resourceCommonLink = MasonBuilderContext.NewLink(RelTypes.ResourceCommon, resourceCommonUri, "Common information shared by all resources");

            r.AddControl(resourceCommonLink);

            return(r);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        protected override Resource ConvertToIssueTracker(ContactResource resource)
        {
            Resource contact = new Resource();

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                contact.Meta.Title       = "Contact information for " + Settings.OriginName;
                contact.Meta.Description = "This resource contains the contact information for " + Settings.OriginName + ". Use either content negotiation or links for different formats.";
            }

            dynamic c = contact;

            c.Name       = resource.Contact.FullName;
            c.Address1   = resource.Contact.Address1;
            c.Address2   = resource.Contact.Address2;
            c.PostalCode = resource.Contact.PostalCode;
            c.City       = resource.Contact.City;
            c.EMail      = resource.Contact.EMail;
            c.Phone      = resource.Contact.Phone;
            c.Country    = resource.Contact.Country;

            string cardBaseUrl = typeof(ContactResource).CreateUri().AbsoluteUri;

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

            contact.AddControl(selfLink);

            Uri     vCardUri  = new Uri(cardBaseUrl + ".vcard");
            Control vCardLink = MasonBuilderContext.NewLink("alternate", vCardUri, "Contact information as vCard", "text/vcard");

            contact.AddControl(vCardLink);

            Uri     jCardUri  = new Uri(cardBaseUrl + ".jcard");
            Control jCardLink = MasonBuilderContext.NewLink("alternate", jCardUri, "Contact information as jCard", "application/json");

            vCardLink.AddAlternateControl(jCardLink);

            return(c);
        }
Exemplo n.º 8
0
        public object Get()
        {
            Resource common = new Resource();

            Uri     selfUri  = typeof(ResourceCommonResource).CreateUri();
            Control selfLink = MasonBuilderContext.NewLink("self", selfUri);

            common.AddControl(selfLink);

            Uri     contactUri  = typeof(ContactResource).CreateUri();
            Control contactLink = MasonBuilderContext.NewLink(RelTypes.Contact, contactUri, "Contact information");

            contactLink.description = "Complete contact information in standard formats such as vCard and jCard.";
            common.AddControl(contactLink);

            Uri     logoUri  = new Uri(CommunicationContext.ApplicationBaseUri.EnsureHasTrailingSlash(), "Origins/JoeHacker/logo.png");
            Control logoLink = MasonBuilderContext.NewLink(RelTypes.Logo, logoUri);

            common.AddControl(logoLink);

            if (!MasonBuilderContext.PreferMinimalResponse)
            {
                common.Meta.Title       = "Common resource data for " + Settings.OriginName;
                common.Meta.Description = "This resource contains common information for all resources (such as common links, implementation and owner details).";
            }

            Uri     projectsUri  = typeof(ProjectCollectionResource).CreateUri();
            Control projectsLink = MasonBuilderContext.NewLink(RelTypes.Projects, projectsUri, "List all projects");

            common.AddControl(projectsLink);

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

            Uri     projectsUrl            = typeof(ProjectCollectionResource).CreateUri();
            Uri     createProjectSchemaUrl = typeof(SchemaTypeResource).CreateUri(new { name = "create-project" });
            Control addProjectAction       = MasonBuilderContext.NewJsonAction(RelTypes.ProjectAdd, projectsUrl, "Create project", "Add new project to issue tracker.", schemaUrl: createProjectSchemaUrl);

            common.AddControl(addProjectAction);

            return(new ResourceCommonResource {
                Value = common
            });
        }
Exemplo n.º 9
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);
        }