I haven't used .net in years and when I did it was vb.net. I'm trying to set up a simple pubnub proof of concept in C# and I'm really struggling. I've created a new forms application (I want to be able to control the feed with buttons, start/stop/etc). I then open program.cs
which gives me the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace feedtest
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
I've installed pubnub using nuget package manager and I've added the using
reference, but that's where things go sour. The first step in the documentation says to "initialize the API" using the following line:
Pubnub pubnub = new Pubnub("demo", "demo");
I finally figured out I put that in Static Void Main()
but now it's like I'm going down the rabbit hole. After modifying a few things from the documentation and ignoring others, I'm at the following point:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using PubNubMessaging.Core;
namespace feedtest
{
static class Program
{
private static string result;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Pubnub pubnub = new Pubnub("demo", "demo");
pubnub.Subscribe<string>(
"my_channel",
DisplaySubscribeReturnMessage,
DisplaySubscribeConnectStatusMessage,
DisplayErrorMessage
);
}
static void DisplayErrorMessage(PubnubClientError obj)
{
throw new NotImplementedException();
}
static void DisplaySubscribeConnectStatusMessage(string obj)
{
throw new NotImplementedException();
}
static void DisplaySubscribeReturnMessage(string obj)
{
Console.WriteLine("SUBSCRIBE REGULAR CALLBACK:");
Console.WriteLine(result);
if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
{
List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
if (deserializedMessage != null && deserializedMessage.Count > 0)
{
object subscribedObject = (object)deserializedMessage[0];
if (subscribedObject != null)
{
//IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
string resultActualMessage = pubnub.JsonPluggableLibrary.SerializeToJsonString(subscribedObject);
}
}
}
}
}
}
The current error is
The name 'pubnub' does not exist in the current context
How can I fix this error? Should I? Am I even close? Did I pick the wrong starting point? Does anyone know of any good, simple, pubnub tutorials?