/// <summary> /// Default constructor. /// </summary> /// <param name="connectionConfigKey">The database connection configuration key.</param> /// <param name="connectionType">The connection type.</param> /// <param name="connectionDataType">The connection data type.</param> /// <param name="dataAccessProvider">The data access provider.</param> public Product(string connectionConfigKey, Nequeo.Data.DataType.ConnectionContext.ConnectionType connectionType, Nequeo.Data.DataType.ConnectionContext.ConnectionDataType connectionDataType, Nequeo.Data.DataType.IDataAccess dataAccessProvider) : base(modelItem, connectionType, connectionDataType, dataAccessProvider) { OnCreated(); defaultDatabaseConnectionConfigurationKey = connectionConfigKey; _connectionType = connectionType; _connectionDataType = connectionDataType; }
/// <summary> /// Default constructor. /// </summary> /// <param name="connectionConfigKey">The database connection configuration key.</param> /// <param name="connectionType">The connection type.</param> /// <param name="connectionDataType">The connection data type.</param> /// <param name="dataAccessProvider">The data access provider.</param> public DataContext(string connectionConfigKey, Nequeo.Data.DataType.ConnectionContext.ConnectionType connectionType, Nequeo.Data.DataType.ConnectionContext.ConnectionDataType connectionDataType, Nequeo.Data.DataType.IDataAccess dataAccessProvider) : base(connectionConfigKey, connectionType, connectionDataType, dataAccessProvider) { OnCreated(); }
public string[] GetList(string prefixText, int count) { List <string> list = null; try { ConnectionStringExtensionElement[] items = ConnectionStringExtensionConfigurationManager.ConnectionStringExtensionElements(); if (items != null) { if (items.Count() > 0) { // For each service host configuration find // the corresponding service type. foreach (ConnectionStringExtensionElement item in items) { // Get the current type name // and create a instance of the type. Type typeName = Type.GetType(item.TypeName, true, true); object typeNameInstance = Activator.CreateInstance(typeName); if (WebServiceType == null) { WebServiceType = this; } if (WebServiceType != null) { if (WebServiceType.GetType().FullName.ToLower() == typeNameInstance.GetType().FullName.ToLower()) { Type dataAccessProviderType = Type.GetType(item.DataAccessProvider, true, true); ConnectionContext.ConnectionType connectionType = ConnectionContext.ConnectionTypeConverter.GetConnectionType(item.ConnectionType); ConnectionContext.ConnectionDataType connectionDataType = ConnectionContext.ConnectionTypeConverter.GetConnectionDataType(item.ConnectionDataType); // Build the current data object type and // the select data model generic type. Type dataType = Type.GetType(item.DataObjectTypeName, true, true); Type listGenericType = typeof(SelectDataGenericBase <>); // Create the generic type parameters // and create the genric type. Type[] typeArgs = { dataType }; Type listGenericTypeConstructor = listGenericType.MakeGenericType(typeArgs); // Create an instance of the data access provider Nequeo.Data.DataType.IDataAccess dataAccess = ((Nequeo.Data.DataType.IDataAccess)Activator.CreateInstance(dataAccessProviderType)); // Add the genric type contructor parameters // and create the generic type instance. object[] parameters = new object[] { item.ConnectionName, connectionType, connectionDataType, dataAccess }; object listGeneric = Activator.CreateInstance(listGenericTypeConstructor, parameters); PropertyInfo propertyInfo = dataType.GetProperty(item.DataObjectPropertyName); string name = propertyInfo.Name; // Get the current object. Object[] args = new Object[] { 0, count, name + " ASC", "(SqlQueryMethods.Like(" + name + ", \"" + prefixText + "%\"))" }; // Add the current data row to the // business object collection. object ret = listGeneric.GetType().InvokeMember("SelectData", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, listGeneric, args); // Cast the data object type as an enumerable object, // get the enumerator. System.Collections.IEnumerable itemsRet = (System.Collections.IEnumerable)ret; System.Collections.IEnumerator dataObjects = itemsRet.GetEnumerator(); // Iterate through the collection. while (dataObjects.MoveNext()) { // If the current index equals the // selected index then return // the data object type. // Get the property. PropertyInfo property = dataObjects.Current.GetType().GetProperty(name); // Get the current value of the property string v = property.GetValue(dataObjects.Current, null).ToString(); list.Add(v); } dataObjects.Reset(); break; } } } } } } catch (Exception ex) { string errorMessage = ex.Message; LogHandler.WriteTypeMessage(errorMessage, typeof(AutoComplete).GetMethod("GetList")); } return(list != null ? list.ToArray() : new string[0]); }
/// <summary> /// Validates a user to a SQL or integrated account. /// </summary> /// <param name="username">The user name.</param> /// <param name="password">The user password.</param> private void ValidateUser(string username, string password) { try { bool authResult = false; ConnectionStringExtensionElement[] items = ConnectionStringExtensionConfigurationManager.ConnectionStringExtensionElements(); if (items.Count() > 0) { // For each service host configuration find // the corresponding service type. foreach (ConnectionStringExtensionElement item in items) { // Get the current type name // and create a instance of the type. Type typeName = Type.GetType(item.TypeName, true, true); object typeNameInstance = Activator.CreateInstance(typeName); if (UserNamePasswordValidatorType == null) { UserNamePasswordValidatorType = this; } if (UserNamePasswordValidatorType != null) { if (UserNamePasswordValidatorType.GetType().FullName.ToLower() == typeNameInstance.GetType().FullName.ToLower()) { Type dataAccessProviderType = Type.GetType(item.DataAccessProvider, true, true); ConnectionContext.ConnectionType connectionType = ConnectionContext.ConnectionTypeConverter.GetConnectionType(item.ConnectionType); ConnectionContext.ConnectionDataType connectionDataType = ConnectionContext.ConnectionTypeConverter.GetConnectionDataType(item.ConnectionDataType); // Data table containing the data. DataTable dataTable = null; string sql = "SELECT [" + item.IndicatorColumnName + "] " + "FROM [" + (String.IsNullOrEmpty(item.DatabaseOwner) ? "" : item.DatabaseOwner + "].[") + item.TableName.Replace(".", "].[") + "] " + "WHERE ([" + item.ComparerColumnName + "] = '" + username + "')"; sql = Nequeo.Data.DataType.DataTypeConversion. GetSqlConversionDataTypeNoContainer(connectionDataType, sql); string providerName = null; string connection = string.Empty; string connectionString = string.Empty; // Get the current database connection string // from the configuration file through the // specified configuration key. using (DatabaseConnections databaseConnection = new DatabaseConnections()) connection = databaseConnection.DatabaseConnection(item.ConnectionName, out providerName); // If empty string is returned then // value should be the connection string. if (String.IsNullOrEmpty(connection)) { connectionString = item.ConnectionName; } else { connectionString = connection; } // Create an instance of the data access provider Nequeo.Data.DataType.IDataAccess dataAccess = ((Nequeo.Data.DataType.IDataAccess)Activator.CreateInstance(dataAccessProviderType)); // Get the connection type switch (connectionType) { // Get the permission data from the // database through the sql provider. case ConnectionContext.ConnectionType.SqlConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.PostgreSqlConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.OracleClientConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.OleDbConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.OdbcConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.MySqlConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; default: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; } // Permission data exists. if (dataTable != null) { if (dataTable.Rows.Count > 0) { string permissionValueItem = dataTable.Rows[0][item.IndicatorColumnName].ToString(); if (!String.IsNullOrEmpty(permissionValueItem)) { if (password.ToLower() == permissionValueItem.ToLower()) { authResult = true; break; } } } } } } } } // If the user has been validated // and autharised then allow connection. if (!authResult) { throw new FaultException("Unknown Username or Incorrect Password"); } } catch (Exception) { throw; } }
public string[] UserListService() { string[] userList = null; try { ConnectionStringExtensionElement[] items = ConnectionStringExtensionConfigurationManager.ConnectionStringExtensionElements(); if (items != null) { if (items.Count() > 0) { // For each service host configuration find // the corresponding service type. foreach (ConnectionStringExtensionElement item in items) { if (item.ServiceMethodName.ToLower() == "userlistservice") { // Get the current type name // and create a instance of the type. Type typeName = Type.GetType(item.TypeName, true, true); object typeNameInstance = Activator.CreateInstance(typeName); if (DynamicDataType == null) { DynamicDataType = this; } if (DynamicDataType != null) { if (DynamicDataType.GetType().FullName.ToLower() == typeNameInstance.GetType().FullName.ToLower()) { Type dataAccessProviderType = Type.GetType(item.DataAccessProvider, true, true); ConnectionContext.ConnectionType connectionType = ConnectionContext.ConnectionTypeConverter.GetConnectionType(item.ConnectionType); ConnectionContext.ConnectionDataType connectionDataType = ConnectionContext.ConnectionTypeConverter.GetConnectionDataType(item.ConnectionDataType); // Data table containing the data. DataTable dataTable = null; string sql = "SELECT [" + item.IndicatorColumnName + "], [" + item.DataObjectPropertyName + "] " + "FROM [" + (String.IsNullOrEmpty(item.DatabaseOwner) ? "" : item.DatabaseOwner + "].[") + item.TableName.Replace(".", "].[") + "] "; if ((!String.IsNullOrEmpty(item.ComparerColumnName)) && (!String.IsNullOrEmpty(item.ComparerValue))) { sql += "WHERE ([" + item.ComparerColumnName + "] = '" + item.ComparerValue + "')"; } sql = Nequeo.Data.DataType.DataTypeConversion. GetSqlConversionDataTypeNoContainer(connectionDataType, sql); string providerName = null; string connection = string.Empty; string connectionString = string.Empty; // Get the current database connection string // from the configuration file through the // specified configuration key. using (DatabaseConnections databaseConnection = new DatabaseConnections()) connection = databaseConnection.DatabaseConnection(item.ConnectionName, out providerName); // If empty string is returned then // value should be the connection string. if (String.IsNullOrEmpty(connection)) { connectionString = item.ConnectionName; } else { connectionString = connection; } // Create an instance of the data access provider Nequeo.Data.DataType.IDataAccess dataAccess = ((Nequeo.Data.DataType.IDataAccess)Activator.CreateInstance(dataAccessProviderType)); // Get the connection type switch (connectionType) { // Get the permission data from the // database through the sql provider. case ConnectionContext.ConnectionType.SqlConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.PostgreSqlConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.OracleClientConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.OleDbConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.OdbcConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; // Get the permission data from the // database through the oracle provider. case ConnectionContext.ConnectionType.MySqlConnection: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; default: dataAccess.ExecuteQuery(ref dataTable, sql, CommandType.Text, connectionString, true, null); break; } // Permission data exists. if (dataTable != null) { if (dataTable.Rows.Count > 0) { List <string> cols = new List <string>(); foreach (DataRow row in dataTable.Rows) { cols.Add("<a href=\"" + item.ServiceMethodRedirectionUrl + "?" + item.DataObjectPropertyName + "=" + row[item.DataObjectPropertyName].ToString() + "\">" + row[item.IndicatorColumnName].ToString() + "</a>"); } // Assign the collection. userList = cols.ToArray(); break; } } } } } } } } } catch (Exception ex) { string errorMessage = ex.Message; LogHandler.WriteTypeMessage(errorMessage, typeof(DynamicData).GetMethod("UserListService")); } // Return the list of users. return(userList == null ? new string[0] : userList); }
public string GetJSonDataTableService(int?iDisplayStart, int iDisplayLength, string sSearch, bool bEscapeRegex, int iColumns, int iSortingCols, int iSortCol_0, string sSortDir_0, string sEcho, string extensionName) { // Create a new json datatable service object. JSonDataTableService dataTableObject = new JSonDataTableService() { sEcho = Convert.ToInt32(sEcho).ToString() }; // Default data to send back. string jSonData = "{ \"sEcho\": " + sEcho + ", \"iTotalRecords\": 0, \"iTotalDisplayRecords\": 0, \"aaData\": [] }"; try { // Create a new json datatable service object. dataTableObject = new JSonDataTableService() { sEcho = Convert.ToInt32(sEcho).ToString() }; // Get the configuration data. ConnectionStringExtensionElement[] items = ConnectionStringExtensionConfigurationManager.ConnectionStringExtensionElements(); if (items != null) { if (items.Count() > 0) { // For each service host configuration find // the corresponding service type. foreach (ConnectionStringExtensionElement item in items) { if (item.Name.ToLower() == extensionName.ToLower()) { // Get the current type name // and create a instance of the type. Type typeName = Type.GetType(item.TypeName, true, true); object typeNameInstance = Activator.CreateInstance(typeName); if (DynamicDataType == null) { DynamicDataType = this; } if (DynamicDataType != null) { if (DynamicDataType.GetType().FullName.ToLower() == typeNameInstance.GetType().FullName.ToLower()) { Type dataAccessProviderType = Type.GetType(item.DataAccessProvider, true, true); ConnectionContext.ConnectionType connectionType = ConnectionContext.ConnectionTypeConverter.GetConnectionType(item.ConnectionType); ConnectionContext.ConnectionDataType connectionDataType = ConnectionContext.ConnectionTypeConverter.GetConnectionDataType(item.ConnectionDataType); // Build the current data object type and // the select data model generic type. Type dataType = Type.GetType(item.DataObjectTypeName, true, true); Type listGenericType = typeof(SelectDataGenericBase <>); // Create the generic type parameters // and create the genric type. Type[] typeArgs = { dataType }; Type listGenericTypeConstructor = listGenericType.MakeGenericType(typeArgs); // Create an instance of the data access provider Nequeo.Data.DataType.IDataAccess dataAccess = ((Nequeo.Data.DataType.IDataAccess)Activator.CreateInstance(dataAccessProviderType)); // Add the genric type contructor parameters // and create the generic type instance. object[] parameters = new object[] { item.ConnectionName, connectionType, connectionDataType, dataAccess }; object listGeneric = Activator.CreateInstance(listGenericTypeConstructor, parameters); // Get the current sorting column use this column as the // searc string[] columnNames = item.JsonDataTableColumnNames.Split(new char[] { '|' }, StringSplitOptions.None); PropertyInfo propertyInfo = dataType.GetProperty(columnNames[iSortCol_0]); string name = propertyInfo.Name; // Get the current object. Object[] args = null; Object[] countArgs = null; // If a search text exits. if (!String.IsNullOrEmpty(sSearch)) { args = new Object[] { (iDisplayStart != null ? (int)iDisplayStart : 0), iDisplayLength, name + (String.IsNullOrEmpty(sSortDir_0) ? " ASC" : " " + sSortDir_0.ToUpper()), "(SqlQueryMethods.Like(" + name + ", \"" + sSearch + "%\"))" }; // Get the current object. countArgs = new Object[] { name + " LIKE '" + sSearch + "%'" }; } else { args = new Object[] { (iDisplayStart != null ? (int)iDisplayStart : 0), iDisplayLength, name + (String.IsNullOrEmpty(sSortDir_0) ? " ASC" : " " + sSortDir_0.ToUpper()) }; } // Add the current data row to the // business object collection. object retCount = listGeneric.GetType().InvokeMember("GetRecordCount", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, listGeneric, countArgs); // Add the current data row to the // business object collection. object ret = listGeneric.GetType().InvokeMember("SelectData", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, listGeneric, args); // Cast the data object type as an enumerable object, // get the enumerator. System.Collections.IEnumerable itemsRet = (System.Collections.IEnumerable)ret; System.Collections.IEnumerator dataObjects = itemsRet.GetEnumerator(); // Create the data array. string[,] aaData = new string[ (iDisplayLength <= Convert.ToInt32((long)retCount) ? iDisplayLength : Convert.ToInt32((long)retCount)), columnNames.Length]; int z = 0; // Iterate through the collection. while (dataObjects.MoveNext()) { // If the current index equals the // selected index then return // the data object type. // Get the property. for (int i = 0; i < columnNames.Length; i++) { // Get the property info the current column string columnValue = string.Empty; PropertyInfo property = dataObjects.Current.GetType().GetProperty(columnNames[i]); try { // Get the current value of the property columnValue = property.GetValue(dataObjects.Current, null).ToString(); } catch { } // Add the value to the data two dimentinal array. aaData[z, i] = columnValue.Trim(); } // Increamnt the row count. z++; } dataObjects.Reset(); dataTableObject.iTotalRecords = Convert.ToInt32((long)retCount); dataTableObject.iTotalDisplayRecords = Convert.ToInt32((long)retCount); dataTableObject.aaData = aaData; // Serialse the data to a JSON format. jSonData = JavaObjectNotation.JSonCustomSerializer(dataTableObject); break; } } } } } } } catch (Exception ex) { string errorMessage = ex.Message; LogHandler.WriteTypeMessage(errorMessage, typeof(DynamicData).GetMethod("GetJSonDataTableService")); } // Return serialised json data. return(jSonData); }
public void ProcessRequest(HttpContext context) { try { // Get the collection of http handler configuration extensions HttpHandlerDataExtensionElement[] httpCollection = HttpHandlerDataConfigurationManager.HttpHandlerExtensionElements(); if (httpCollection != null) { // If http extensions exist if (httpCollection.Count() > 0) { // For each configuration foreach (HttpHandlerDataExtensionElement item in httpCollection) { // Get the current http handler type // and create a instance of the type. Type httpHandlerType = BuildManager.GetType(item.HttpHandlerTypeName, true, true); object httpHandlerTypeInstance = Activator.CreateInstance(httpHandlerType); if (HttpHandlerType == null) { HttpHandlerType = this; } if (HttpHandlerType != null) { if (HttpHandlerType.GetType().FullName.ToLower() == httpHandlerTypeInstance.GetType().FullName.ToLower()) { // Get the query string associated with this http handler string value = context.Request.QueryString[item.UrlQueryTextName]; // If a query string is assosicated with // this http handler then return the // data from the database and place this // data in the current session object. if (!String.IsNullOrEmpty(value)) { Type dataAccessProviderType = BuildManager.GetType(item.DataAccessProvider, true, true); ConnectionContext.ConnectionType connectionType = ConnectionContext.ConnectionTypeConverter.GetConnectionType(item.ConnectionType); ConnectionContext.ConnectionDataType connectionDataType = ConnectionContext.ConnectionTypeConverter.GetConnectionDataType(item.ConnectionDataType); // Build the current data object type and // the select data model generic type. Type dataType = BuildManager.GetType(item.DataObjectTypeName, true, true); Type listGenericType = typeof(SelectDataGenericBase <>); // Create the generic type parameters // and create the genric type. Type[] typeArgs = { dataType }; Type listGenericTypeConstructor = listGenericType.MakeGenericType(typeArgs); // Create an instance of the data access provider Nequeo.Data.DataType.IDataAccess dataAccess = ((Nequeo.Data.DataType.IDataAccess)Activator.CreateInstance(dataAccessProviderType)); // Add the genric tyoe contructor parameters // and create the generic type instance. object[] parameters = new object[] { item.ConnectionName, connectionType, connectionDataType, dataAccess }; object listGeneric = Activator.CreateInstance(listGenericTypeConstructor, parameters); PropertyInfo propertyInfo = dataType.GetProperty(item.DataObjectPropertyName); object valueType = Convert.ChangeType(value, propertyInfo.PropertyType); // Get the current object. Object[] args = new Object[] { (item.DataObjectPropertyName + " == @0"), item.ReferenceLazyLoading, new object[] { valueType } }; // Add the current data row to the // business object collection. object ret = listGeneric.GetType().InvokeMember("SelectDataEntitiesPredicate", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, listGeneric, args); // Assign the generic collection data // to the current session sate with // the unquie configuration name as the key. Nequeo.Caching.RuntimeCache.Set(item.Name, ret, (double)600.0); } } } else { break; } } if (HttpHandlerType != null) { // Redirect to the current request. context.Server.Execute(httpCollection[0].ChildPageGroupExecution); } } } } catch (Exception ex) { context.AddError(ex); LogHandler.WriteTypeMessage(ex.Message, typeof(GenericData).GetMethod("ProcessRequest")); } }