Skip to content

Instantly share code, notes, and snippets.

@radu-matei
Created February 23, 2019 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radu-matei/e646b0e8c17ec7746cfb8e035b6feedb to your computer and use it in GitHub Desktop.
Save radu-matei/e646b0e8c17ec7746cfb8e035b6feedb to your computer and use it in GitHub Desktop.
using System;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using NUlid;
using Cnab.Bundle;
namespace Cnab.Runtime
{
public class Claim
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("revision")]
public string Revision { get; set; }
[JsonProperty("created")]
public DateTime Created { get; set; }
[JsonProperty("modified")]
public DateTime Modified { get; set; }
// TODO - it is really annoying to use Bundle.Bundle
[JsonProperty("bundle")]
public Bundle Bundle { get; set; }
[JsonProperty("result")]
public Result Result { get; set; }
// really cheap hack
// TODO - radu-matei - add IParameterValue
[JsonProperty("parameters")]
public Dictionary<string, object> Parameters { get; set; }
public Claim() { }
public Claim(string name)
{
var pattern = "^[a-zA-Z0-9_-]+$";
var rgx = new Regex(pattern);
if (!rgx.IsMatch(name))
{
throw new ArgumentException($"invalid name: {name}. Names must be [a-zA-Z0-9-_]+");
}
var now = DateTime.Now;
Name = name;
Revision = Ulid.NewUlid().ToString();
Created = now;
Modified = now;
Result = new Result()
{
Action = "unknown",
Status = "unknown"
};
Parameters = new Dictionary<string, object>();
}
public void Update(string action, string status)
{
this.Result.Action = action;
this.Result.Status = status;
this.Modified = DateTime.Now;
this.Revision = Ulid.NewUlid().ToString();
}
}
public class Result
{
[JsonProperty("message")]
public string Message { get; set; }
[JsonProperty("action")]
public string Action { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment