Skip to content

Commit 24f0f60

Browse files
throw exception when uuid is not set (#125)
* throw exception when uuid is not set * added UUID check in ChangeUUID method
1 parent 01c0470 commit 24f0f60

40 files changed

+352
-564
lines changed

.pubnub.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: c-sharp
2-
version: "5.4.0"
2+
version: "6.0.0"
33
schema: 1
44
scm: github.com/pubnub/c-sharp
55
changelog:
6+
- date: 2022-01-12
7+
version: v6.0.0
8+
changes:
9+
- type: improvement
10+
text: "BREAKING CHANGES: UUID is mandatory to use SDK."
611
- date: 2021-12-16
712
version: v5.4.0
813
changes:
@@ -621,7 +626,7 @@ features:
621626
- QUERY-PARAM
622627
supported-platforms:
623628
-
624-
version: Pubnub 'C#' 5.4.0
629+
version: Pubnub 'C#' 6.0.0
625630
platforms:
626631
- Windows 10 and up
627632
- Windows Server 2008 and up
@@ -631,7 +636,7 @@ supported-platforms:
631636
- .Net Framework 4.5
632637
- .Net Framework 4.6.1+
633638
-
634-
version: PubnubPCL 'C#' 5.4.0
639+
version: PubnubPCL 'C#' 6.0.0
635640
platforms:
636641
- Xamarin.Android
637642
- Xamarin.iOS
@@ -650,7 +655,7 @@ supported-platforms:
650655
- .Net Standard 2.1
651656
- .Net Core
652657
-
653-
version: PubnubUWP 'C#' 5.4.0
658+
version: PubnubUWP 'C#' 6.0.0
654659
platforms:
655660
- Windows Phone 10
656661
- Universal Windows Apps
@@ -672,9 +677,9 @@ sdks:
672677
distributions:
673678
-
674679
distribution-type: source
675-
distribution-repository: Github
680+
distribution-repository: GitHub
676681
package-name: Pubnub
677-
location: https://github.com/pubnub/c-sharp/releases/tag/v5.4.0.0
682+
location: https://github.com/pubnub/c-sharp/releases/tag/v6.0.0.0
678683
requires:
679684
-
680685
name: ".Net"
@@ -971,7 +976,7 @@ sdks:
971976
distribution-type: source
972977
distribution-repository: GitHub
973978
package-name: PubNubPCL
974-
location: https://github.com/pubnub/c-sharp/releases/tag/v5.4.0.0
979+
location: https://github.com/pubnub/c-sharp/releases/tag/v6.0.0.0
975980
requires:
976981
-
977982
name: ".Net Core"
@@ -1342,9 +1347,9 @@ sdks:
13421347
distributions:
13431348
-
13441349
distribution-type: source
1345-
distribution-repository: Github
1350+
distribution-repository: GitHub
13461351
package-name: PubnubUWP
1347-
location: https://github.com/pubnub/c-sharp/releases/tag/v5.4.0.0
1352+
location: https://github.com/pubnub/c-sharp/releases/tag/v6.0.0.0
13481353
requires:
13491354
-
13501355
name: "Universal Windows Platform Development"

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v6.0.0 - January 12 2022
2+
-----------------------------
3+
- BREAKING CHANGES: UUID is mandatory to use SDK.
4+
15
v5.4.0 - December 16 2021
26
-----------------------------
37
- Fixed: replaced BouncyCastle lib with System.Security.Cryptography.Algorithms.

src/Api/PubnubApi/PNConfiguration.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ public string Uuid
102102
public bool UseRandomInitializationVector { get; set; }
103103
public int FileMessagePublishRetryLimit { get; set; }
104104

105-
public PNConfiguration()
105+
public PNConfiguration(string uuid)
106106
{
107+
if (string.IsNullOrEmpty(uuid) || string.IsNullOrEmpty(uuid.Trim()))
108+
{
109+
throw new ArgumentException("Missing or Incorrect uuid value");
110+
}
111+
107112
this.Origin = "ps.pndsn.com";
108113
this.presenceHeartbeatTimeout = 300;
109-
this.uuid = string.Format("pn-{0}", Guid.NewGuid().ToString());
110114
this.NonSubscribeRequestTimeout = 10;
111115
this.SubscribeTimeout = 310;
112116
this.LogVerbosity = PNLogVerbosity.NONE;
@@ -124,6 +128,7 @@ public PNConfiguration()
124128
this.SuppressLeaveEvents = false;
125129
this.UseRandomInitializationVector = true;
126130
this.FileMessagePublishRetryLimit = 5;
131+
this.Uuid = uuid;
127132
}
128133

129134
public PNConfiguration SetPresenceTimeoutWithCustomInterval(int timeout, int interval)

src/Api/PubnubApi/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
[assembly: AssemblyProduct("Pubnub C# SDK")]
1212
[assembly: AssemblyCopyright("Copyright © 2021")]
1313
[assembly: AssemblyTrademark("")]
14-
[assembly: AssemblyVersion("5.4.0.0")]
15-
[assembly: AssemblyFileVersion("5.4.0.0")]
14+
[assembly: AssemblyVersion("6.0.0.0")]
15+
[assembly: AssemblyFileVersion("6.0.0.0")]
1616
// Setting ComVisible to false makes the types in this assembly not visible
1717
// to COM components. If you need to access a type in this assembly from
1818
// COM, set the ComVisible attribute to true on that type.

src/Api/PubnubApi/Pubnub.cs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -412,27 +412,35 @@ public Guid GenerateGuid()
412412
return Guid.NewGuid();
413413
}
414414

415-
public void ChangeUUID(string newUUID)
416-
{
415+
public void ChangeUUID(string newUUID)
416+
{
417+
if (newUUID != null && string.IsNullOrEmpty(newUUID.Trim()))
418+
{
419+
if (pubnubLog != null && pubnubConfig != null)
420+
{
421+
LoggingMethod.WriteToLog(pubnubLog, string.Format("DateTime: {0}, UUID cannot be null/empty.", DateTime.Now.ToString(CultureInfo.InvariantCulture)), pubnubConfig.LogVerbosity);
422+
}
423+
throw new MissingMemberException("UUID cannot be null/empty");
424+
}
417425
EndPoint.OtherOperation endPoint = new EndPoint.OtherOperation(pubnubConfig, JsonPluggableLibrary, pubnubUnitTest, pubnubLog, telemetryManager, tokenManager, this);
418426
endPoint.CurrentPubnubInstance(this);
419427
endPoint.ChangeUUID(newUUID);
420-
}
428+
}
421429

422-
public static long TranslateDateTimeToPubnubUnixNanoSeconds(DateTime dotNetUTCDateTime)
423-
{
424-
return EndPoint.OtherOperation.TranslateDateTimeToPubnubUnixNanoSeconds(dotNetUTCDateTime);
425-
}
430+
public static long TranslateDateTimeToPubnubUnixNanoSeconds(DateTime dotNetUTCDateTime)
431+
{
432+
return EndPoint.OtherOperation.TranslateDateTimeToPubnubUnixNanoSeconds(dotNetUTCDateTime);
433+
}
426434

427-
public static DateTime TranslatePubnubUnixNanoSecondsToDateTime(long unixNanoSecondTime)
428-
{
429-
return EndPoint.OtherOperation.TranslatePubnubUnixNanoSecondsToDateTime(unixNanoSecondTime);
430-
}
435+
public static DateTime TranslatePubnubUnixNanoSecondsToDateTime(long unixNanoSecondTime)
436+
{
437+
return EndPoint.OtherOperation.TranslatePubnubUnixNanoSecondsToDateTime(unixNanoSecondTime);
438+
}
431439

432-
public static DateTime TranslatePubnubUnixNanoSecondsToDateTime(string unixNanoSecondTime)
433-
{
434-
return EndPoint.OtherOperation.TranslatePubnubUnixNanoSecondsToDateTime(unixNanoSecondTime);
435-
}
440+
public static DateTime TranslatePubnubUnixNanoSecondsToDateTime(string unixNanoSecondTime)
441+
{
442+
return EndPoint.OtherOperation.TranslatePubnubUnixNanoSecondsToDateTime(unixNanoSecondTime);
443+
}
436444

437445
public List<string> GetSubscribedChannels()
438446
{
@@ -825,6 +833,15 @@ public Pubnub(PNConfiguration config)
825833
LoggingMethod.WriteToLog(pubnubLog, string.Format("DateTime: {0}, WARNING: The PresenceTimeout cannot be less than 20, defaulting the value to 20. Please update the settings in your code.", DateTime.Now.ToString(CultureInfo.InvariantCulture)), config.LogVerbosity);
826834
}
827835
}
836+
if (config != null && (string.IsNullOrEmpty(config.Uuid) || string.IsNullOrEmpty(config.Uuid.Trim())))
837+
{
838+
if (pubnubLog != null)
839+
{
840+
LoggingMethod.WriteToLog(pubnubLog, string.Format("DateTime: {0}, PNConfiguration.Uuid is required to use the SDK.", DateTime.Now.ToString(CultureInfo.InvariantCulture)), config.LogVerbosity);
841+
}
842+
throw new MissingMemberException("PNConfiguration.Uuid is required to use the SDK");
843+
}
844+
828845
}
829846

830847
private void CheckRequiredConfigValues()

src/Api/PubnubApi/PubnubApi.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313

1414
<PropertyGroup>
1515
<PackageId>Pubnub</PackageId>
16-
<PackageVersion>5.4.0.0</PackageVersion>
16+
<PackageVersion>6.0.0.0</PackageVersion>
1717
<Title>PubNub C# .NET - Web Data Push API</Title>
1818
<Authors>Pandu Masabathula</Authors>
1919
<Owners>PubNub</Owners>
2020
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2121
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
2222
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2323
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
24-
<PackageReleaseNotes>Replaced BouncyCastle lib with System.Security.Cryptography.Algorithms.
25-
Added try/catch for publish operation to catch exceptions.</PackageReleaseNotes>
24+
<PackageReleaseNotes>BREAKING CHANGES: UUID is mandatory to use SDK.</PackageReleaseNotes>
2625
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
2726
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
2827
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>

src/Api/PubnubApiPCL/PubnubApiPCL.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414

1515
<PropertyGroup>
1616
<PackageId>PubnubPCL</PackageId>
17-
<PackageVersion>5.4.0.0</PackageVersion>
17+
<PackageVersion>6.0.0.0</PackageVersion>
1818
<Title>PubNub C# .NET - Web Data Push API</Title>
1919
<Authors>Pandu Masabathula</Authors>
2020
<Owners>PubNub</Owners>
2121
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2222
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
2323
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2424
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
25-
<PackageReleaseNotes>Replaced BouncyCastle lib with System.Security.Cryptography.Algorithms.
26-
Added try/catch for publish operation to catch exceptions.</PackageReleaseNotes>
25+
<PackageReleaseNotes>BREAKING CHANGES: UUID is mandatory to use SDK.</PackageReleaseNotes>
2726
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
2827
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
2928
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>

src/Api/PubnubApiUWP/PubnubApiUWP.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515

1616
<PropertyGroup>
1717
<PackageId>PubnubUWP</PackageId>
18-
<PackageVersion>5.4.0.0</PackageVersion>
18+
<PackageVersion>6.0.0.0</PackageVersion>
1919
<Title>PubNub C# .NET - Web Data Push API</Title>
2020
<Authors>Pandu Masabathula</Authors>
2121
<Owners>PubNub</Owners>
2222
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2323
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
2424
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2525
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
26-
<PackageReleaseNotes>Replaced BouncyCastle lib with System.Security.Cryptography.Algorithms.
27-
Added try/catch for publish operation to catch exceptions.</PackageReleaseNotes>
26+
<PackageReleaseNotes>BREAKING CHANGES: UUID is mandatory to use SDK.</PackageReleaseNotes>
2827
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
2928
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
3029
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>

src/Examples/PubnubApi.ConsoleExample/PubnubAsyncAwaitExample.cs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ static public async Task MainAsync()
6262
string EnvSubscribeKey = System.Environment.GetEnvironmentVariable("PN_SUB_KEY", EnvironmentVariableTarget.Machine);
6363
string EnvSecretKey = System.Environment.GetEnvironmentVariable("PN_SEC_KEY", EnvironmentVariableTarget.Machine);
6464

65-
66-
PNConfiguration config = new PNConfiguration();
6765
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
6866

6967
StringBuilder hintStringBuilder = new StringBuilder();
@@ -94,6 +92,20 @@ static public async Task MainAsync()
9492
Console.ResetColor();
9593
Console.WriteLine();
9694

95+
Console.WriteLine("ENTER Custom Session UUID. Without it, you cannot consume Pubnub SDK");
96+
string sessionUUID = Console.ReadLine();
97+
if (string.IsNullOrEmpty(sessionUUID) || sessionUUID.Trim().Length == 0)
98+
{
99+
Console.WriteLine("Invalid UUID. Random GUID value will be set for this example");
100+
sessionUUID = "pn-" + Guid.NewGuid().ToString();
101+
}
102+
Console.ForegroundColor = ConsoleColor.Blue;
103+
Console.WriteLine("Accepted Custom Session UUID.");
104+
Console.ResetColor();
105+
Console.WriteLine();
106+
107+
PNConfiguration config = new PNConfiguration(sessionUUID);
108+
97109
Console.WriteLine("Enable SSL? ENTER Y for Yes, else N. (Default N)");
98110
string enableSSL = Console.ReadLine();
99111
Console.ForegroundColor = ConsoleColor.Blue;
@@ -172,31 +184,6 @@ static public async Task MainAsync()
172184
Console.ResetColor();
173185
Console.WriteLine();
174186

175-
Console.WriteLine("Use Custom Session UUID? ENTER Y for Yes, else N");
176-
string enableCustomUUID = Console.ReadLine();
177-
if (enableCustomUUID.Trim().ToLowerInvariant() == "y")
178-
{
179-
Console.WriteLine("ENTER Session UUID.");
180-
string sessionUUID = Console.ReadLine();
181-
if (string.IsNullOrEmpty(sessionUUID) || sessionUUID.Trim().Length == 0)
182-
{
183-
Console.WriteLine("Invalid UUID. Default value will be set.");
184-
}
185-
else
186-
{
187-
config.Uuid = sessionUUID;
188-
}
189-
Console.ForegroundColor = ConsoleColor.Blue;
190-
Console.WriteLine("Accepted Custom Session UUID.");
191-
Console.ResetColor();
192-
}
193-
else
194-
{
195-
Console.ForegroundColor = ConsoleColor.Blue;
196-
Console.WriteLine("Default Session UUID opted.");
197-
Console.ResetColor();
198-
}
199-
Console.WriteLine();
200187

201188
Console.WriteLine("Enter Auth Key. If you don't want to use Auth Key, Press ENTER Key");
202189
authKey = Console.ReadLine();
@@ -1188,11 +1175,18 @@ static public async Task MainAsync()
11881175
break;
11891176
case "17":
11901177
Console.WriteLine("ENTER UUID.");
1191-
string sessionUUID = Console.ReadLine();
1192-
pubnub.ChangeUUID(sessionUUID);
1193-
Console.ForegroundColor = ConsoleColor.Blue;
1194-
Console.WriteLine("UUID = {0}", config.Uuid);
1195-
Console.ResetColor();
1178+
string newsessionUUID = Console.ReadLine();
1179+
try
1180+
{
1181+
pubnub.ChangeUUID(newsessionUUID);
1182+
Console.ForegroundColor = ConsoleColor.Blue;
1183+
Console.WriteLine("UUID = {0}", config.Uuid);
1184+
Console.ResetColor();
1185+
}
1186+
catch (Exception ex)
1187+
{
1188+
Console.WriteLine(ex.ToString());
1189+
}
11961190
break;
11971191
case "18":
11981192
Console.WriteLine("Disconnect");

0 commit comments

Comments
 (0)