### Configuring PubNub C# SDK Source: https://github.com/pubnub/c-sharp/blob/master/README.md This snippet shows the minimum configuration required to initialize the PubNub SDK in C#. It demonstrates how to create a PNConfiguration object, set the UserId, SubscribeKey, and PublishKey, and instantiate the Pubnub client. This setup is essential before performing any PubNub operations. ```csharp using PubnubApi; PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")); pnConfiguration.SubscribeKey = "mySubscribeKey"; pnConfiguration.PublishKey = "myPublishKey"; Pubnub pubnub = new Pubnub(pnConfiguration); ``` -------------------------------- ### Publishing and Subscribing with PubNub C# SDK Source: https://github.com/pubnub/c-sharp/blob/master/README.md This snippet illustrates the basic publish and subscribe flow. It shows how to create a message dictionary, subscribe to a specific channel, and then asynchronously publish the message to that channel. It also demonstrates how to retrieve the publish result and status. ```csharp Dictionary message = new Dictionary(); message.Add("msg", "Hello world!"); pubnub.Subscribe() .Channels(new string[]{ "my_channel" }).Execute(); PNResult publishResponse = await pubnub.Publish() .Message(message) .Channel("my_channel") .ExecuteAsync(); PNPublishResult publishResult = publishResponse.Result; PNStatus status = publishResponse.Status; Console.WriteLine("pub timetoken: " + publishResult.Timetoken.ToString()); Console.WriteLine("pub status code : " + status.StatusCode.ToString()); ``` -------------------------------- ### Loading Typeface from Android Asset in C# Source: https://github.com/pubnub/c-sharp/blob/master/src/Examples/mono-for-android/PubNubMessaging.Example/Assets/AboutAssets.txt Shows how to load a font file (e.g., "fonts/samplefont.ttf") directly from the application's assets directory using the `Typeface.CreateFromAsset` method, which is a common pattern for functions that automatically utilize assets. ```C# Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); ``` -------------------------------- ### Adding PubNub Subscribe Event Listeners (C#) Source: https://github.com/pubnub/c-sharp/blob/master/README.md This code demonstrates how to add event listeners to the Pubnub client using SubscribeCallbackExt. It includes delegates to handle incoming messages (PNMessageResult) and presence events (PNPresenceEventResult), showing how to access data like channel, publisher, timetoken, and message content. ```csharp pubnub.AddListener(new SubscribeCallbackExt( delegate (Pubnub pnObj, PNMessageResult pubMsg) { if (pubMsg != null) { Debug.WriteLine("In Example, SubscribeCallback received PNMessageResult"); Debug.WriteLine("In Example, SubscribeCallback messsage channel = " + pubMsg.Channel); Debug.WriteLine("In Example, SubscribeCallback messsage channelGroup = " + pubMsg.Subscription); Debug.WriteLine("In Example, SubscribeCallback messsage publishTimetoken = " + pubMsg.Timetoken); Debug.WriteLine("In Example, SubscribeCallback messsage publisher = " + pubMsg.Publisher); string jsonString = pubMsg.Message.ToString(); Dictionary msg = pubnub.JsonPluggableLibrary.DeserializeToObject>(jsonString); Debug.WriteLine("msg: " + msg["msg"]); } }, delegate (Pubnub pnObj, PNPresenceEventResult presenceEvnt) { if (presenceEvnt != null) { Debug.WriteLine("In Example, SubscribeCallback received PNPresenceEventResult"); Debug.WriteLine(presenceEvnt.Channel + " " + presenceEvnt.Occupancy + " " + presenceEvnt.Event); } } )) ``` -------------------------------- ### Opening Android Asset File in C# Source: https://github.com/pubnub/c-sharp/blob/master/src/Examples/mono-for-android/PubNubMessaging.Example/Assets/AboutAssets.txt Demonstrates how to open a raw asset file (e.g., "my_asset.txt") from the application's assets directory using the `Assets.Open` method within an Android Activity's `OnCreate` method. This provides an `InputStream` to read the file content. ```C# public class ReadAsset : Activity { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); InputStream input = Assets.Open ("my_asset.txt"); } } ``` -------------------------------- ### Generated R Class for Android Resources (C#) Source: https://github.com/pubnub/c-sharp/blob/master/src/Examples/mono-for-android/PubNubMessaging.Example/Resources/AboutResources.txt This C# code snippet shows the structure of the automatically generated 'R' class. This class contains nested classes (e.g., 'drawable', 'layout', 'strings') with constant integer fields representing the unique IDs assigned to each resource item during the build process. These IDs are used by native Android APIs to reference resources instead of file paths. ```csharp public class R { public class drawable { public const int icon = 0x123; } public class layout { public const int main = 0x456; } public class strings { public const int first_string = 0xabc; public const int second_string = 0xbcd; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.