Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert attribute decorated POCO's to Points #64

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

joakimhew
Copy link
Contributor

@joakimhew joakimhew commented Oct 17, 2017

This feature adds an extension method allowing users to convert attribute decorated POCO's following certain rules into Points.

The following attributes must be present in the POCO:

Attribute name Mandatory? Maximum in one type
[Measurement] Yes 1
[Timestamp] No 1
[Tag] No
[Field] Yes

Example:

Please notice how one of the tag and field names are explicitly set using the attribute and name argument

public class MyType 
{
     [Timestamp]
     public DateTime Time { get; set; }

     [Measurement]
     public string MyMeasurement { get; set; }

     [Tag]
     public string Tag1 { get; set; }

     [Tag(name: "newtagname")] // <- Explicitly set tag name
     public string Tag2 { get; set; }

     [Field]
     public string Field1 { get; set; }

     [Field(name: "newfieldname")] // <- Explicitly set field name
     public bool Field2 { get; set; }

     [Field]
     public float Field2 { get; set; }
}

MyType myType = new MyType
{
    Time = DateTime.Now,
    Measurement = "TestMeasurement",
    Tag1 = "FirstTag",
    Tag2 = "SecondTag",
    Field1 = "FirstField",
    Field2 = True,
    Field3 = 2324
};

var point = myType.ToPoint();

This will produce the following point object:

point = 
{
    "Timestamp" : "2017-10-17 10:18:00",
    "Name" : "TestMeasurement",
    "Tags" : [
          "Tag1" : "FirstTag",
          "newtagname`" : "SecondTag" // <- explicitly set tag name
    ],
    "Fields" : [
          "Field1" : "FirstField",
          "newfieldname" : True, // <- explicitly set field name
          "Field3" : 2324
     ]
}

The following validations are implemented and will return detailed exceptions:

@tihomir-kit
Copy link
Owner

tihomir-kit commented Oct 17, 2017

Lol! Dude.. this is a sick feature. Just awesome. :)

I'll try to publish it over the weekend.

Thanks!

@joakimhew joakimhew changed the title Convert attribute decorated types to Points Convert attribute decorated POCOto Points Oct 17, 2017
@joakimhew joakimhew changed the title Convert attribute decorated POCOto Points Convert attribute decorated POCO's to Points Oct 17, 2017
@joakimhew
Copy link
Contributor Author

@pootzko Glad I can help! I just added the option to explicitly set the names for tags and fields using a name argument in the attributes. Updated my original comment.

I found out at work today that this would be nice to have so figured I could make a proper implementation!

@joakimhew
Copy link
Contributor Author

Have you had the chance to look more into this 😄 ?

@tihomir-kit
Copy link
Owner

Hey man, sorry for the delay. I haven't yet, I've been very busy the last 2 weeks. I'll try to look at it this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants