Utility Methods API for PubNub C# SDK
The methods on this page are utility methods that don't fit into other categories.
Destroy
Description
Destroy frees up the threads and allows for clean exit.
Method(s)
destroy()
Basic Usage
pubnub.Destroy();
Returns
None
Encrypt
Description
This function allows to encrypt
the data.
Method(s)
To encrypt
the data you can use the following method(s) in C# V4 SDK.
pubnub.Encrypt(inputString, cipherKey)
Parameter | Type | Required | Description |
---|---|---|---|
inputString | String | Yes | The data to encrypt . |
cipherKey | String | Optional | If it's not provided, the cipher key from config will be used. |
Basic Usage
Encrypt part of message
string stringToEncrypt = "hello world";
string cipherKey = "testCipher";
string payload = pubnub.Encrypt(stringToEncrypt, cipherKey);
Encrypt File
Description
This function allow to encrypt
the file content/data.
Method(s)
To encrypt
the file you can use the following method(s) in C# V4 SDK.
pubnub.EncryptFile(sourceFile, destinationFile) pubnub.EncryptFile(sourceFile, destinationFile, cipherKey)
Parameter | Type | Required | Description |
---|---|---|---|
sourceFile | String | Yes | File to be encrypted. |
destinationFile | String | Yes | Path of the encrypted file to be saved. |
cipherKey | String | Optional | Cipher Key to use for encryption. If no key is provided, CipherKey provided in PNConfiguration will be considered. |
byte[] outputBytes = pubnub.EncryptFile(sourceBytes) byte[] outputBytes = pubnub.EncryptFile(sourceBytes, cipherKey)
Parameter | Type | Required | Description |
---|---|---|---|
sourceBytes | byte[] | Yes | byte array of the file. |
cipherKey | String | Optional | Cipher Key to use for encryption. If no key is provided, CipherKey provided in PNConfiguration will be considered. |
Basic Usage
string source_file = "cat_picture.jpg"; // checks bin folder if no path is provided
string destination_file = "destination_cat_pic.jpg"; // checks bin folder if no path is provided
pn.EncryptFile(source_file, destination_file, "enigma");
byte[] sourceBytes = System.IO.File.ReadAllBytes("cat_picture.jpg"); // checks bin folder if no path is provided
byte[] outputBytes = pn.EncryptFile(sourceBytes, "enigma");
System.IO.File.WriteAllBytes("destination_cat_pic.jpg", outputBytes); // checks bin folder if no path is provided
Decrypt
Description
This function allows to decrypt
the data.
Method(s)
To decrypt
the data you can use the following method(s) in C# V4 SDK.
pubnub.Decrypt(inputString, cipherKey)
Parameter | Type | Required | Description |
---|---|---|---|
inputString | String | Yes | The data to decrypt . |
cipherKey | String | Optional | If it's not provided, the cipher key from config will be used. |
Basic Usage
Decrypt part of message
string encryptedString = "9qR0Q4TuDUwiLTcxtIY3mA==";
string cipherKey = "testCipher";
string decryptedMessage = pubnub.Decrypt(encryptedString, cipherKey);
Decrypt File
Description
This function allow to decrypt
the file content/data.
Method(s)
To decrypt
the file you can use the following method(s) in C# V4 SDK.
pubnub.DecryptFile(sourceFile, destinationFile); pubnub.DecryptFile(sourceFile, destinationFile, cipherKey);
Parameter | Type | Required | Description |
---|---|---|---|
sourceFile | String | Yes | File to be decrypted. |
destinationFile | String | Yes | Path of the decrypted file to be saved. |
cipherKey | String | Optional | Cipher Key to use for decryption. If no key is provided, CipherKey provided in PNConfiguration will be considered. |
byte[] outputBytes = pubnub.DecryptFile(sourceBytes) byte[] outputBytes = pubnub.DecryptFile(sourceBytes, cipherKey)
Parameter | Type | Required | Description |
---|---|---|---|
sourceBytes | byte[] | Yes | byte array of the file. |
cipherKey | String | Optional | Cipher Key to use for decryption. If no key is provided, CipherKey provided in PNConfiguration will be considered. |
Basic Usage
string source_file = "encrypted_cat_pic.jpg"; // checks bin folder if no path is provided
string destination_file = "cat_pic_original.jpg"; // checks bin folder if no path is provided
pn.DecryptFile(source_file, destination_file, "enigma");
byte[] sourceBytes = System.IO.File.ReadAllBytes("encrypted_cat_pic.jpg"); // checks bin folder if no path is provided
byte[] outputBytes = pn.DecryptFile(sourceBytes, "enigma");
System.IO.File.WriteAllBytes("cat_pic_original.jpg", outputBytes); // checks bin folder if no path is provided
Disconnect
Description
Call the Disconnect
method to force the SDK to stop all requests to PubNub server when there are active subscribe channels.
Method(s)
To disconnect
the data you can use the following method(s) in C# V4 SDK.
Disconnect<T>()
This method doesn't take any arguments.
Basic Usage
pubnub.Disconnect<string>();
Get Subscribed Channel Groups
Description
Returns all the subscribed channel groups in a List of type String
.
Method(s)
To Get Subscribe Channel Groups
you can use the following method(s) in the C# V4 SDK:
List<string> GetSubscribedChannelGroups()
Basic Usage
Get Subscribed Channel Groups
List<string> groups = pubnub.GetSubscribedChannelGroups();
Response
List<String>
["channelGroup1", "channelGroup2"]
Get Subscribed Channels
Description
Returns all the subscribed channels in a List of type String
.
Method(s)
To Get Subscribed Channels
you can use the following method(s) in the C# V4 SDK:
List<string> GetSubscribedChannels()
Basic Usage
Get Subscribed Channels
List<string> channels = pubnub.GetSubscribedChannels();
Response
List<String>
["channel1", "channel2"]
Reconnect
Description
Call the reconnect
method to force the SDK to try and reach out PubNub.
Method(s)
To reconnect
the data you can use the following method(s) in C# V4 SDK.
Reconnect<T>(bool resetSubscribeToken)
Parameter | Type | Required | Description |
---|---|---|---|
resetSubscribeToken | bool | Optional | Passing true will send zero timetoken upon reconnect. |
Basic Usage
pubnub.Reconnect<string>();
Time
Description
This function will return a 17 digit precision Unix epoch.
Algorithm constructing the timetoken
timetoken = (Unix epoch time in seconds) * 10000000
Example of creating a timetoken for a specific time and date:
08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000
Method(s)
To fetch Time
you can use the following method(s) in C# V4 SDK:
pubnub.QueryParam(Dictionary<string,object>).Time()
Parameter | Type | Required | Description |
---|---|---|---|
QueryParam | Dictionary<string, object> | Optional | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
Async | PNCallback | Deprecated | PNCallback of type PNTimeResult . |
Execute | PNCallback | Yes | PNCallback of type PNTimeResult . |
Basic Usage
Get PubNub Timetoken
pubnub.Time()
.Execute(new PNTimeResultExt(
(result, status) => {
// handle time result.
}
));
Returns
The Time
operation returns a PNTimeResult
which contains the following property:
Property Name | Type | Description |
---|---|---|
Timetoken | long | Returns a long representation of current timetoken. |