Skip to content

module created per README.md#53

Open
ess-charles wants to merge 1 commit intorobert-tridium:mainfrom
ess-charles:myFile-rt-edit
Open

module created per README.md#53
ess-charles wants to merge 1 commit intorobert-tridium:mainfrom
ess-charles:myFile-rt-edit

Conversation

@ess-charles
Copy link
Copy Markdown

Create a new Niagara component named BFile with the following:

A Property named fileName with a type of String
A Property named path with a type of String
A Property named size with a type of int
A Property named createdDate with a type of BAbsTime
A Property named modifiedDate with a type of BAbsTime
An Action named touch that updates the modifiedDate Property to the current time
An Action named print that prints a summary of the Properties to stdout.

Copy link
Copy Markdown
Owner

@robert-tridium robert-tridium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@NiagaraProperty(name = "fileName", type = "BString", defaultValue = "BString.DEFAULT")
@NiagaraProperty(name = "path", type = "BString", defaultValue = "BString.DEFAULT")
@NiagaraProperty(name = "size", type = "BInteger", defaultValue = "BInteger.DEFAULT")
@NiagaraProperty(name = "createdDate", type = "BAbsTime", defaultValue = "BAbsTime.now()")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to be careful using a defaultValue of BAbsTime.now() because this defaultValue is used to initialize the static Property field on line 105. Since that field is static, every instance of this class will share it. What that ultimately means is every new copy of this component that gets added to a station will have the same default value for the createdDate property and it won't be the time at which that particular component got created, but it will be the time that this class got loaded in the JVM.

If you want the value of the createdDate to be when the component got added to the station, it would be better to use a defaultValue of BAbsTime.DEFAULT like you're doing for modifiedDate and then override the started() callback to see if the component is starting for the first time and, if so, update the createdDate Property to BAbsTime.now(). Maybe something like:

@Override
public void started()
{
  if (getCreatedDate().equals(BAbsTime.DEFAULT))
  {
    setCreatedDate(BAbsTime.now());
  }
}

@ess-charles
Copy link
Copy Markdown
Author

ess-charles commented Mar 26, 2026 via email

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