Exemplo n.º 1
0
        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]);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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);
        }