I have this problem with using Fluent Cassandra in a test application. All I want to do is set the IsOnline field to true inside the SignIn method, but I keep getting the exception supercolumn parameter is not optional for super CF. I've tried many things, but haven't been able to get it to work. All the data is created and inserted into my Cassandra Keyspace, but to change it again to IsOnline after insertion is failing me.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentCassandra;
using FluentCassandra.Connections;
using FluentCassandra.Types;
using FluentCassandra.Operations;
using FluentCassandra.ObjectSerializer;
using FluentCassandra.Linq;
namespace CassandraTryTwo
{
class Program
{
private static void CreateDatabase()
{
using (var context = new CassandraContext(keyspace: "RadiumNet", host: "localhost"))
{
if (context.KeyspaceExists("RadiumNet"))
{
context.DropKeyspace("RadiumNet");
}
var keyspace = new CassandraKeyspace("RadiumNet", context);
keyspace.TryCreateSelf();
keyspace.TryCreateColumnFamily(
new CassandraColumnFamilySchema
{
FamilyName = "Accounts",
FamilyType = ColumnType.Super,
KeyValueType = CassandraType.UTF8Type,
SuperColumnNameType = CassandraType.UTF8Type,
ColumnNameType = CassandraType.UTF8Type,
DefaultColumnValueType = CassandraType.UTF8Type
}
);
}
return;
}
private static void SignUp(String email, String password, String name, String surname, String age)
{
using (var context = new CassandraContext(keyspace: "RadiumNet", host: "localhost"))
{
var accountFamily = context.GetSuperColumnFamily("Accounts");
var accountColumn = accountFamily.Get(email).First();
if (accountColumn.Count() > 0)
{
Console.WriteLine("User {0} already registered", email);
}
else
{
dynamic account = accountColumn;
account = accountFamily.CreateRecord(key: email);
dynamic details = account.CreateSuperColumn();
details.Password = password;
details.Name = name;
details.Surname = surname;
details.Age = age;
dynamic flags = account.CreateSuperColumn();
flags.IsBlocked = "False";
flags.IsBanned = "False";
flags.IsOnline = "False";
account.Details = details;
account.Flags = flags;
context.Attach(account);
context.SaveChanges();
}
}
return;
}
private static void SignIn(String email, String password)
{
using (var context = new CassandraContext(keyspace: "RadiumNet", host: "localhost"))
{
var accountFamily = context.GetSuperColumnFamily("Accounts");
var accountColumn = accountFamily.Get(email).First();
if (accountColumn.Count() == 0)
{
Console.WriteLine("User {0} did not register", email);
}
else
{
dynamic account = accountColumn;
dynamic details = account.Details;
dynamic flags = account.Flags;
if (details.Password != password)
{
Console.WriteLine("User {0} provided an invalid password", email);
}
else
{
flags.IsOnline = "True";
Console.WriteLine("Welcome {0} {1}", details.Name, details.Surname);
context.Attach(account);
context.SaveChanges();
}
}
}
return;
}
private static void SetupConsole()
{
Console.Title = "Cassandra Test";
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
Console.SetWindowSize(120, 40);
Console.Clear();
}
private static void Pause()
{
Console.WriteLine();
Console.WriteLine("Press ENTER to continue...");
Console.ReadLine();
}
private static void Main(string[] args)
{
SetupConsole();
CreateDatabase();
SignUp("foo@bar.com", "BooBab", "Wynand", "Pieterse", "22");
SignUp("gee@wiz.com", "GreenBab", "Henk", "Pieterse", "27");
SignIn("foo@bar.com", "BooBab");
SignIn("bla@gmail.com", "Grrr");
SignIn("gee@wiz.com", "Breezer");
Pause();
}
}
}