Skip to content

Commit

Permalink
-Moved enum ParameterType to internal
Browse files Browse the repository at this point in the history
-Fixed a bug wherein ResolveAddressParameters specified "false" to CustomParameters instead of "0"
-PrtgAPI.cmd will now import the PrtgAPI module regardless of the parent folder name
-Modified nuspec to include PrtgAPI.cmd in C# nupkg
-Fixed a bug wherein PrtgUrl construction would crash when Search Filters are null
  • Loading branch information
lordmilko committed Mar 10, 2018
1 parent fea4e09 commit 2b36abe
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 35 deletions.
6 changes: 3 additions & 3 deletions PrtgAPI.Tests.IntegrationTests/ActionTests/StateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ public void Action_State_PauseForDuration()

var sensor2 = GetSensor(Settings.UpSensor);

if (sensor2.Status == Status.Unknown)
if (sensor2.Status != Status.Up)
{
Logger.LogTestDetail($"Status was {Status.Unknown}. Waiting up to 5 minutes for sensor to go {Status.Up}");
Logger.LogTestDetail($"Status was {sensor2.Status}. Waiting up to 5 minutes for sensor to go {Status.Up}");

int attempts = 10;

do
{
sensor2 = GetSensor(Settings.UpSensor);

if (sensor2.Status == Status.Unknown)
if (sensor2.Status != Status.Up)
{
Thread.Sleep(30000);
attempts--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Data_Log_GetLogs_HasAnyResults()
[TestMethod]
public void Data_Log_GetLogs_SpecifiesStartDate()
{
var count = 5000;
var count = 6000;

var logs = client.GetLogs(null, DateTime.Now.AddDays(-1), count: count);

Expand All @@ -32,7 +32,7 @@ public void Data_Log_GetLogs_SpecifiesStartDate()
[TestMethod]
public void Data_Log_GetLogs_SpecifiesEndDate()
{
var logs = client.GetLogs(null, endDate: DateTime.Now.AddDays(-1), count: 5000);
var logs = client.GetLogs(null, endDate: DateTime.Now.AddDays(-1), count: 6000);

var first = logs.First();
var last = logs.Last();
Expand Down
2 changes: 1 addition & 1 deletion PrtgAPI/Enums/ParameterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PrtgAPI
/// <summary>
/// Specifies how <see cref="Parameter"/> values can be formatted when inserted in a <see cref="PrtgUrl"/>.
/// </summary>
public enum ParameterType
internal enum ParameterType
{
/// <summary>
/// <see cref="Parameter"/> is used with a single value under a single parameter instance, i.e. param=value.
Expand Down
Binary file modified PrtgAPI/Enums/Serialization/SensorTypeInternal.cs
Binary file not shown.
8 changes: 4 additions & 4 deletions PrtgAPI/Objects/Deserialization/XmlDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ internal class XmlDeserializer<T>

internal static XmlDeserializer<T> DeserializeList(XDocument doc)
{
return DeserializeInternal<XmlDeserializer<T>, T>(doc);
return DeserializeInternal<XmlDeserializer<T>>(doc);
}

internal static T DeserializeType(XDocument doc)
{
return DeserializeInternal<T, T>(doc);
return DeserializeInternal<T>(doc);
}

internal static void UpdateType(XDocument doc, T obj)
{
DeserializeInternal<T, T>(doc, obj);
DeserializeInternal<T>(doc, obj);
}

#pragma warning disable 693
private static T DeserializeInternal<T, TInner>(XDocument doc, object target = null)
private static T DeserializeInternal<T>(XDocument doc, object target = null)
#pragma warning restore 693
{
var deserializer = new XmlSerializer(typeof(T));
Expand Down
2 changes: 1 addition & 1 deletion PrtgAPI/Parameters/ObjectData/ResolveAddressParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public ResolveAddressParameters(string address)
{
this[Parameter.Custom] = new List<CustomParameter>
{
new CustomParameter("cache", false),
new CustomParameter("cache", 0),
new CustomParameter("dom", 0),
new CustomParameter("path", address)
};
Expand Down
1 change: 1 addition & 0 deletions PrtgAPI/PowerShell/Base/PrtgCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private void UnregisterEvents(bool resetState)
eventManager.RemoveEvent(eventManager.LogVerboseEventState, EventManager.LogVerboseEventStack, resetState);
}

[ExcludeFromCodeCoverage]
private void OnRetryRequest(object sender, RetryRequestEventArgs args)
{
var msg = args.Exception.Message.TrimEnd('.');
Expand Down
2 changes: 1 addition & 1 deletion PrtgAPI/PowerShell/Resources/PrtgAPI.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
start powershell -executionpolicy bypass -noexit -command "import-module '%~dp0..\PrtgAPI'; cd $env:userprofile"
start powershell -executionpolicy bypass -noexit -command "import-module '%~dp0\PrtgAPI.psd1'; cd $env:userprofile"
2 changes: 1 addition & 1 deletion PrtgAPI/Properties/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//0
//8
//-1
//0
//0
//
// This code was generated by a tool. Any changes made manually will be lost
Expand Down
2 changes: 1 addition & 1 deletion PrtgAPI/PrtgAPI.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ For more information and usage examples, please see the Project Site.</releaseNo
<tags>PSModule Prtg Sensor Device Group Probe Channel Notification Action Trigger Remove Pause Resume Check Acknowledge PowerShell Setting Property</tags>
</metadata>
<files>
<file src="bin\$configuration$\PrtgAPI\**\*.*" exclude="**\PrtgAPI.xml;**\*.dll;**\*.pdb;**\*.cmd" />
<file src="bin\$configuration$\PrtgAPI\**\*.*" exclude="**\PrtgAPI.xml;**\*.dll;**\*.pdb" />
</files>
</package>
35 changes: 19 additions & 16 deletions PrtgAPI/Request/PrtgUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,29 @@ private string FormatMultiParameter(IEnumerable enumerable, string description)

foreach (var val in enumerable)
{
string query;

if (description == Parameter.FilterXyz.GetDescription())
if (val != null)
{
var filter = (SearchFilter)val;
string query;

query = FormatMultiParameterFilter(filter, filter.Value);
}
else if(val.GetType().IsEnum) //If it's an enum other than FilterXyz
{
var result = FormatFlagEnum((Enum)val, v => SearchFilter.ToString(description, FilterOperator.Equals, v));
if (description == Parameter.FilterXyz.GetDescription())
{
var filter = (SearchFilter)val;

query = result ?? SearchFilter.ToString(description, FilterOperator.Equals, val);
}
else
{
query = FormatSingleParameterWithValEncode(description, val);
}
query = FormatMultiParameterFilter(filter, filter.Value);
}
else if (val.GetType().IsEnum) //If it's an enum other than FilterXyz
{
var result = FormatFlagEnum((Enum)val, v => SearchFilter.ToString(description, FilterOperator.Equals, v));

builder.Append(query + "&");
query = result ?? SearchFilter.ToString(description, FilterOperator.Equals, val);
}
else
{
query = FormatSingleParameterWithValEncode(description, val);
}

builder.Append(query + "&");
}
}

if(builder.Length > 0)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var client = new PrtgClient("prtg.mycoolsite.com", "username", "1234567890", Aut

#### Common Objects

[Sensors](https://github.com/lordmilko/PrtgAPI/wiki/Sensors), [Devices](https://github.com/lordmilko/PrtgAPI/wiki/Devices), [Groups](https://github.com/lordmilko/PrtgAPI/wiki/Groups), [Probes](https://github.com/lordmilko/PrtgAPI/wiki/Probes) and [Channels](https://github.com/lordmilko/PrtgAPI/wiki/Channels) can all be retrieved using their corresponding `Get<name>` methods
[Sensors](https://github.com/lordmilko/PrtgAPI/wiki/Sensors), [Devices](https://github.com/lordmilko/PrtgAPI/wiki/Devices), [Groups](https://github.com/lordmilko/PrtgAPI/wiki/Groups), [Probes](https://github.com/lordmilko/PrtgAPI/wiki/Probes) and [Channels](https://github.com/lordmilko/PrtgAPI/wiki/Channels) can all be retrieved using their corresponding `Get` methods

```c#
var devices = client.GetDevices();
Expand Down Expand Up @@ -264,10 +264,10 @@ Get all [devices](https://github.com/lordmilko/PrtgAPI/wiki/Devices) whose names
```powershell
C:\> Get-Device *dc*
Name Id Status Group Probe
---- -- ------ ----- -----
dc1 2001 Up Servers Local Probe
dc2 2002 Down Servers Local Probe
Name Id Status Host Group Probe
---- -- ------ ---- ----- -----
dc1 2001 Up 10.0.0.1 Servers Local Probe
dc2 2002 Down dc-2 Servers Local Probe
```

Expand Down

0 comments on commit 2b36abe

Please sign in to comment.