-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from pyrocumulus/post-system-service
Add PostSystem request
- Loading branch information
Showing
16 changed files
with
677 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
src/PVOutput.Net/Builders/ExtendedDataDefinitionBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Dawn; | ||
using PVOutput.Net.Enums; | ||
using PVOutput.Net.Objects; | ||
using PVOutput.Net.Objects.Modules.Implementations; | ||
|
||
namespace PVOutput.Net.Builders | ||
{ | ||
/// <summary> | ||
/// Builder for creating extended data definitions, used to update systems. | ||
/// </summary> | ||
public sealed class ExtendedDataDefinitionBuilder | ||
{ | ||
internal ExtendedDataDefinition _definition; | ||
|
||
/// <summary> | ||
/// Creates a new builder. | ||
/// </summary> | ||
public ExtendedDataDefinitionBuilder() | ||
{ | ||
_definition = new ExtendedDataDefinition(); | ||
} | ||
|
||
/// <summary> | ||
/// The index that specifies which extended data value to update. | ||
/// </summary> | ||
/// <param name="index">The index of the extended data value.</param> | ||
/// <returns>The builder.</returns> | ||
public ExtendedDataDefinitionBuilder SetIndex(ExtendedDataIndex index) | ||
{ | ||
_definition.Index = index; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the label of the extended data value. | ||
/// </summary> | ||
/// <param name="label">The label to set.</param> | ||
/// <returns>The builder.</returns> | ||
public ExtendedDataDefinitionBuilder SetLabel(string label) | ||
{ | ||
Guard.Argument(label).MaxLength(20); | ||
|
||
_definition.Label = label; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the unit of the extended data value. | ||
/// </summary> | ||
/// <param name="unit">The unit to set.</param> | ||
/// <returns>The builder.</returns> | ||
public ExtendedDataDefinitionBuilder SetUnit(string unit) | ||
{ | ||
Guard.Argument(unit).MaxLength(10); | ||
|
||
_definition.Unit = unit; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the displayed colour of the extended data value. | ||
/// </summary> | ||
/// <param name="colour">Hexadecimal colour to display <c>6 hexadecimal characters</c>.</param> | ||
/// <returns>The builder.</returns> | ||
public ExtendedDataDefinitionBuilder SetColour(string colour) | ||
{ | ||
Guard.Argument(colour).Length(6); | ||
Guard.Argument(colour).Require(IsHexadecimalString, m => "Colour should be a hexadecimal string."); | ||
|
||
_definition.Colour = colour; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the axis used to display the extended data value on. | ||
/// </summary> | ||
/// <param name="axis">The axis to display the extended data value on.</param> | ||
/// <returns>The builder</returns> | ||
public ExtendedDataDefinitionBuilder SetAxis(int axis) | ||
{ | ||
Guard.Argument(axis).InRange(0, 5); | ||
|
||
_definition.Axis = axis; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the graph type used to display the extended data value. | ||
/// </summary> | ||
/// <param name="displayType">Display type to use.</param> | ||
/// <returns>The builder.</returns> | ||
public ExtendedDataDefinitionBuilder SetDisplayType(ExtendedDataDisplayType displayType) | ||
{ | ||
_definition.DisplayType = displayType; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Uses information within the builder to return the built data definition. | ||
/// </summary> | ||
/// <returns>The extended data definition.</returns> | ||
public IExtendedDataDefinition Build() | ||
{ | ||
return _definition; | ||
} | ||
|
||
/// <summary> | ||
/// Uses information within the builder to return the built data definition. | ||
/// Resets the builder to it's default state after building. | ||
/// </summary> | ||
/// <returns>The extended data definition.</returns> | ||
public IExtendedDataDefinition BuildAndReset() | ||
{ | ||
var result = _definition; | ||
_definition = new ExtendedDataDefinition(); | ||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Resets the builder to it's default state. Ready to build a new definition. | ||
/// </summary> | ||
/// <returns>The builder in it's default state.</returns> | ||
public ExtendedDataDefinitionBuilder Reset() | ||
{ | ||
_definition = new ExtendedDataDefinition(); | ||
return this; | ||
} | ||
|
||
internal static bool IsHexadecimalString(string colour) | ||
{ | ||
foreach (char character in colour.ToUpperInvariant()) | ||
{ | ||
if (!IsHexadecimalCharacter(character)) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
internal static bool IsHexadecimalCharacter(char character) | ||
{ | ||
if (character >= '0' && character <= '9') | ||
{ | ||
return true; | ||
} | ||
|
||
if (character >= 'A' && character <= 'F') | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace PVOutput.Net.Enums | ||
{ | ||
/// <summary> | ||
/// Defines how to display the extended value. | ||
/// </summary> | ||
public enum ExtendedDataDisplayType | ||
{ | ||
/// <summary> | ||
/// Display as line in graph. | ||
/// </summary> | ||
Line, | ||
|
||
/// <summary> | ||
/// Display as area in graph. | ||
/// </summary> | ||
Area | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Text; | ||
|
||
namespace PVOutput.Net.Enums | ||
{ | ||
/// <summary> | ||
/// Describes the index of an extended data value. | ||
/// </summary> | ||
public enum ExtendedDataIndex | ||
{ | ||
/// <summary> | ||
/// Extended data value v7. | ||
/// </summary> | ||
v7, | ||
|
||
/// <summary> | ||
/// Extended data value v8. | ||
/// </summary> | ||
v8, | ||
|
||
/// <summary> | ||
/// Extended data value v9. | ||
/// </summary> | ||
v9, | ||
|
||
/// <summary> | ||
/// Extended data value v10. | ||
/// </summary> | ||
v10, | ||
|
||
/// <summary> | ||
/// Extended data value v11. | ||
/// </summary> | ||
v11, | ||
|
||
/// <summary> | ||
/// Extended data value v12. | ||
/// </summary> | ||
v12 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using PVOutput.Net.Enums; | ||
|
||
namespace PVOutput.Net.Objects | ||
{ | ||
/// <summary> | ||
/// Defines an extended data value for a system. | ||
/// </summary> | ||
public interface IExtendedDataDefinition | ||
{ | ||
/// <summary> | ||
/// The index of the extended data value (v7-v12). | ||
/// </summary> | ||
ExtendedDataIndex Index { get; set; } | ||
|
||
/// <summary> | ||
/// The label of the extended data value. | ||
/// </summary> | ||
string Label { get; set; } | ||
|
||
/// <summary> | ||
/// The unit of the extended data value. | ||
/// </summary> | ||
string Unit { get; set; } | ||
|
||
/// <summary> | ||
/// The hexadecimal colour (ffffff) used to display the extended data value. | ||
/// </summary> | ||
string Colour { get; set; } | ||
|
||
/// <summary> | ||
/// The axis on which to display the extended data value. | ||
/// </summary> | ||
int? Axis { get; set; } | ||
|
||
/// <summary> | ||
/// The type of graph to display the extended data value with. | ||
/// </summary> | ||
ExtendedDataDisplayType? DisplayType { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/PVOutput.Net/Objects/Modules/Implementations/ExtendedDataDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using PVOutput.Net.Enums; | ||
|
||
namespace PVOutput.Net.Objects.Modules.Implementations | ||
{ | ||
internal class ExtendedDataDefinition : IExtendedDataDefinition | ||
{ | ||
public ExtendedDataIndex Index { get; set; } | ||
public string Label { get; set; } | ||
public string Unit { get; set; } | ||
public string Colour { get; set; } | ||
public int? Axis { get; set; } | ||
public ExtendedDataDisplayType? DisplayType { get; set; } | ||
} | ||
} |
Oops, something went wrong.