Beispiel #1
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="dataObjectTypeName">The data object type name.</param>
 /// <param name="configurationKeyDatabaseConnection">The database connection string or the connection configuration key.</param>
 /// <param name="connectionType">The database connection type.</param>
 /// <param name="connectionDataType">The database connection data type.</param>
 /// <param name="dataAccessProvider">The data access provider.</param>
 public ConnectionTypeModel(string dataObjectTypeName, string configurationKeyDatabaseConnection,
                            ConnectionContext.ConnectionType connectionType, ConnectionContext.ConnectionDataType connectionDataType, string dataAccessProvider)
 {
     _dataObjectTypeName = dataObjectTypeName;
     _configurationKeyDatabaseConnection = configurationKeyDatabaseConnection;
     _connectionType     = connectionType;
     _connectionDataType = connectionDataType;
     _dataAccessProvider = dataAccessProvider;
 }
Beispiel #2
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified
        /// context and culture information.
        /// </summary>
        /// <param name="context">An System.ComponentModel.ITypeDescriptorContext that provides a format context.</param>
        /// <param name="culture">The System.Globalization.CultureInfo to use as the current culture.</param>
        /// <param name="value">The System.Object to convert.</param>
        /// <returns>An System.Object that represents the converted value.</returns>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                // If the value is null then return
                // the ConnectionTypeModel type.
                return(new ConnectionTypeModel());
            }

            // If the value is a string type
            // then attempt to convert to
            // a ConnectionTypeModel type.
            if (value is string)
            {
                string s = (string)value;
                if (s.Length == 0)
                {
                    // If no string value then return default
                    // ConnectionTypeModel type.
                    return(new ConnectionTypeModel());
                }

                string[] parts = s.Split(',');

                // If there are no parts or more than 5 parts then
                // throw exception, can not convert to ConnectionTypeModel type.
                if ((parts.Length < 1) || (parts.Length > 5))
                {
                    throw new ArgumentException(
                              "Connection type must have 5 parts.", "value");
                }

                // Get the connection type enums from the string value passed.
                ConnectionContext.ConnectionType     connectionType     = ConnectionContext.ConnectionTypeConverter.GetConnectionType(parts[2]);
                ConnectionContext.ConnectionDataType connectionDataType = ConnectionContext.ConnectionTypeConverter.GetConnectionDataType(parts[3]);
                string dataAccessProvider = parts[4];

                // Return the ConnectionTypeModel type with values.
                return(new ConnectionTypeModel(parts[0], parts[1], connectionType, connectionDataType, dataAccessProvider));
            }
            return(base.ConvertFrom(context, culture, value));
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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"));
            }
        }