private void InitContext(CassandraConnectionInfo conn) { if (conn == null) throw new ArgumentNullException("conn", "conn is null."); Context = conn.CreateContext(); }
/// <summary>Returns the text to display in the root Schema Explorer node for a given connection info.</summary> public override string GetConnectionDescription(IConnectionInfo cxInfo) { var connInfo = CassandraConnectionInfo.Load(cxInfo); CacheDefinitionIfNessisary(connInfo); return(String.Format("{0}/{1} - {2}", connInfo.Host, connInfo.Port, connInfo.Keyspace)); }
public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo) { var connInfo = CassandraConnectionInfo.Load(cxInfo); CacheDefinitionIfNessisary(connInfo); return(new[] { new ParameterDescriptor("context", "FluentCassandra.CassandraContext") }); }
public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo) { var connInfo = CassandraConnectionInfo.Load(cxInfo); CacheDefinitionIfNessisary(connInfo); return(new[] { connInfo.CreateContext() }); }
public CassandraDriverContext(CassandraConnectionInfo connInfo) { if (connInfo == null) throw new ArgumentNullException("conn", "conn is null."); InitContext(connInfo); SetupLogWriting(); InitSession(); }
public ConnectionDialog(CassandraConnectionInfo conn) { if (conn == null) throw new ArgumentNullException("conn", "conn is null."); InitializeComponent(); DataContext = _connInfo = conn; PasswordValue.Password = conn.Password; }
public ConnectionDialog(CassandraConnectionInfo conn) { if (conn == null) { throw new ArgumentNullException("conn", "conn is null."); } InitializeComponent(); DataContext = _connInfo = conn; PasswordValue.Password = conn.Password; }
public override List <ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo cxInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName) { var connInfo = CassandraConnectionInfo.Load(cxInfo); CacheDefinitionIfNessisary(connInfo); return(SchemaBuilder.GetSchemaAndBuildAssembly( connInfo, GetDriverFolder(), assemblyToBuild, ref nameSpace, ref typeName)); }
internal static List <ExplorerItem> GetSchemaAndBuildAssembly(CassandraConnectionInfo info, string driverFolder, AssemblyName name, ref string nameSpace, ref string typeName) { var context = info.CreateContext(); var keyspace = context.Keyspace; var def = keyspace.GetSchema(); var code = GenerateCode(def, nameSpace, typeName); var schema = GetSchema(def); // Compile the code into the assembly, using the assembly name provided: BuildAssembly(code, driverFolder, name); return(schema); }
internal static List<ExplorerItem> GetSchemaAndBuildAssembly(CassandraConnectionInfo info, string driverFolder, AssemblyName name, ref string nameSpace, ref string typeName) { var context = info.CreateContext(); var keyspace = context.Keyspace; var def = keyspace.GetSchema(); var code = GenerateCode(def, nameSpace, typeName); var schema = GetSchema(def); // Compile the code into the assembly, using the assembly name provided: BuildAssembly(code, driverFolder, name); return schema; }
/// <summary>Displays a dialog prompting the user for connection details. The isNewConnection /// parameter will be true if the user is creating a new connection rather than editing an /// existing connection. This should return true if the user clicked OK. If it returns false, /// any changes to the IConnectionInfo object will be rolled back.</summary> public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { CassandraConnectionInfo connInfo; connInfo = isNewConnection ? new CassandraConnectionInfo { ConntectionInfo = cxInfo } : CassandraConnectionInfo.Load(cxInfo); var win = new ConnectionDialog(connInfo); var result = win.ShowDialog() == true; if (result) { connInfo.Save(); } CacheDefinitionIfNessisary(connInfo); return(result); }
public static CassandraConnectionInfo Load(IConnectionInfo connectionInfo) { XElement xe = connectionInfo.DriverData.Element(CassandraConnectionInfoKey); if (xe != null) { var connectionString = xe.Value; var builder = new ConnectionBuilder(connectionString); var info = new CassandraConnectionInfo(); info.ConntectionInfo = connectionInfo; info.Keyspace = builder.Keyspace; info.Host = builder.Servers[0].Host; info.Port = builder.Servers[0].Port; info.Timeout = builder.Servers[0].Timeout; info.Username = builder.Username; info.Password = builder.Password; return(info); } return(null); }
private void CacheDefinitionIfNessisary(CassandraConnectionInfo info) { }
private void CacheDefinitionIfNessisary(CassandraConnectionInfo info) { }
public static CassandraConnectionInfo Load(IConnectionInfo connectionInfo) { XElement xe = connectionInfo.DriverData.Element(CassandraConnectionInfoKey); if (xe != null) { var connectionString = xe.Value; var builder = new ConnectionBuilder(connectionString); var info = new CassandraConnectionInfo(); info.ConntectionInfo = connectionInfo; info.Keyspace = builder.Keyspace; info.Host = builder.Servers[0].Host; info.Port = builder.Servers[0].Port; info.Timeout = builder.Servers[0].Timeout; info.Username = builder.Username; info.Password = builder.Password; return info; } return null; }
public override string GetConnectionDescription(IConnectionInfo cxInfo) { _connInfo = CassandraConnectionInfo.Load(cxInfo); return string.Format("Cassandra: {0}", _connInfo.Host); }
internal static List<ExplorerItem> GetSchemaAndBuildAssembly(CassandraConnectionInfo info, string driverFolder, AssemblyName name, ref string nameSpace, ref string typeName) { var context = info.CreateContext(); var keyspace = context.Keyspace; var def = keyspace.GetSchema(); //var code = GenerateCode(def, nameSpace, typeName); var schema = GetSchema(def); CodeCompileUnit targetUnit = new CodeCompileUnit(); CodeNamespace codeNamespace = new CodeNamespace(nameSpace); codeNamespace.Imports.Add(new CodeNamespaceImport("System")); codeNamespace.Imports.Add(new CodeNamespaceImport("System.Numerics")); codeNamespace.Imports.Add(new CodeNamespaceImport("System.Linq")); codeNamespace.Imports.Add(new CodeNamespaceImport("FluentCassandra")); codeNamespace.Imports.Add(new CodeNamespaceImport("FluentCassandra.Connections")); codeNamespace.Imports.Add(new CodeNamespaceImport("FluentCassandra.Types")); CodeTypeDeclaration contextClass = new CodeTypeDeclaration(typeName); contextClass.IsClass = true; contextClass.TypeAttributes = TypeAttributes.Public; contextClass.BaseTypes.Add(typeof (IDisposable)); #region Constructor CodeConstructor codeConstructor = new CodeConstructor(); codeConstructor.Attributes = MemberAttributes.Public; codeConstructor.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(CassandraContext)), "context")); codeConstructor.Statements.Add( new CodeSnippetStatement( @"if (context == null) throw new ArgumentNullException(""context"", ""context is null.""); _context_9e94d563_59a5_4e31_8919_fd15298559d9 = context; _session_9e94d563_59a5_4e31_8919_fd15298559d9 = new CassandraSession(Context.ConnectionBuilder);")); contextClass.Members.Add(codeConstructor); #endregion #region IDisposable CodeMemberMethod disposeMethod = new CodeMemberMethod(); disposeMethod.Attributes = MemberAttributes.Public; disposeMethod.Name = "Dispose"; disposeMethod.ReturnType = new CodeTypeReference(typeof(void)); disposeMethod.Statements.Add(new CodeSnippetStatement(@"if (Session != null) Session.Dispose(); if (Context != null && !Context.WasDisposed) Context.Dispose();")); contextClass.Members.Add(disposeMethod); #endregion #region CreateSessionProperty CreatePropertyWithBackingField(contextClass, typeof(CassandraSession), "Session"); #endregion #region CreateContextProperty CreatePropertyWithBackingField(contextClass, typeof(CassandraContext), "Context"); #endregion #region Create Column Family Accessors foreach (CassandraColumnFamilySchema cassandraColumnFamilySchema in def.ColumnFamilies) { //create property accessor if (cassandraColumnFamilySchema.Columns.Count >= 1) { //generate a type based on the static column family schema CodeTypeDeclaration generatedClass = new CodeTypeDeclaration(cassandraColumnFamilySchema.FamilyName); generatedClass.IsClass = true; generatedClass.TypeAttributes = TypeAttributes.Public; //add properties based on schema foreach (CassandraColumnSchema column in cassandraColumnFamilySchema.Columns) { CodeMemberField newProperty = new CodeMemberField(); newProperty.Attributes = MemberAttributes.Public; newProperty.Name = column.Name; if(column.ValueType == CassandraType.UTF8Type) { newProperty.Type = new CodeTypeReference(typeof(string)); } generatedClass.Members.Add(newProperty); } codeNamespace.Types.Add(generatedClass); } CodeMemberField field = new CodeMemberField(); field.Attributes = MemberAttributes.Private; field.Type = new CodeTypeReference(typeof(CassandraColumnFamily)); field.Name = "_" + cassandraColumnFamilySchema.FamilyName.ToLower(); contextClass.Members.Add(field); string statementTemplate = @"if (_{0} == null) _{0} = Context.GetColumnFamily(""{1}""); return _{0};"; CodeMemberProperty property = new CodeMemberProperty(); property.Attributes = MemberAttributes.Public; property.Type = new CodeTypeReference(typeof(CassandraColumnFamily)); property.HasGet = true; property.GetStatements.Add(new CodeSnippetStatement(string.Format(statementTemplate, cassandraColumnFamilySchema.FamilyName.ToLower(), cassandraColumnFamilySchema.FamilyName))); property.HasSet = false; property.Name = cassandraColumnFamilySchema.FamilyName; contextClass.Members.Add(property); //create a type for each static column family } #endregion codeNamespace.Types.Add(contextClass); targetUnit.Namespaces.Add(codeNamespace); //compile CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"); CodeGeneratorOptions options = new CodeGeneratorOptions(); options.BracingStyle = "C"; CompilerParameters parameters = new CompilerParameters(); provider.CompileAssemblyFromDom(parameters, targetUnit); using (StreamWriter sourceWriter = new StreamWriter(@"C:\temp\GeneratedCode.cs")) { provider.GenerateCodeFromCompileUnit(targetUnit, sourceWriter, options); } // Compile the code into the assembly, using the assembly name provided: BuildAssembly(targetUnit, driverFolder, name); return schema; }