/// <summary> /// Authenticate Method /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public string Authenticate(string username, string password, bool useCookies) { Logger techLogger = LogManager.GetCurrentClassLogger(); var includes = new List <string> { "UserRoleItems.Role", "UserGroupItems.Group.GroupRoleItems" }; username = username.TrimEnd(' ').TrimEnd('/').TrimEnd('\\'); var existingUser = DataFacade.GOUserDataProvider.GetCollection(filterPredicate: $"UserName == \"{username}\"", includes: includes, skipSecurity: true).SingleOrDefault(); GOUserDataObject currentUser; if (existingUser == null) { techLogger.Debug($"User with username={username} doen't exist => create a new One."); // new user provided by SOLID : create it currentUser = CreateNewUser(username, null, null, username, Guid.NewGuid().ToString(), true, true); techLogger.Info($"SOLID - connect: Creation new user {currentUser.EmailAddress} ({currentUser.FullName})"); } else { currentUser = existingUser; } var token = SetAuthenticationToken(currentUser, useCookies: true, solidToken: password); techLogger.Info($"SOLID - OK - connection user {currentUser.EmailAddress} ({currentUser.FullName})"); var userUri = DataProviderHelper.GetWebIdRootURL(username); DataProviderHelper.EnsurePublicTypeRegistration(userUri, "goapp-visitedplaces", "http://schema.org/TextDigitalDocument", "myvisitedplaces.ttl"); return(token); }
private DataProvider() { _helper = new DataProviderHelper(WebConfigurationManager.ConnectionStrings["Main"].ConnectionString); }
protected override void Init() { if (Initialized) { return; } HashSet <String> passedRelationNames = new HashSet <string>(); HashSet <String> passedSchemas = new HashSet <string>(); HashSet <String> excludedOwners = new HashSet <string>(); excludedOwners.Add("System".ToUpper()); if (Connection.State != ConnectionState.Open) { Connection.Open(); } NuoDbCommand command; try { DataTable views = null; DataTable tables = null; if ((SupportedElementTypes & DbConnectionElementTypes.Table) != 0) { tables = (Connection as NuoDbConnection).GetSchema("Tables"); DataProviderHelper.LogDataTableStructure(Logger, tables); } if ((SupportedElementTypes & DbConnectionElementTypes.View) != 0) { views = (Connection as NuoDbConnection).GetSchema("Views"); DataProviderHelper.LogDataTableStructure(Logger, views); } Connection.Close(); for (int pass = 0; pass < 2; pass++) { DataTable currentTable; switch (pass) { case 0: currentTable = views; break; case 1: currentTable = tables; break; default: Debug.Assert(false); currentTable = null; break; } if (currentTable == null) { continue; } foreach (DataRow dr in currentTable.Rows) { string schema = dr["TABLE_SCHEMA"].ToString(); string name = dr["TABLE_NAME"].ToString(); if (SuppressAddTableOrRelation(name, schema)) { continue; } if (excludedOwners.Contains(schema)) { continue; } // Get schema from connection string NuoDbConnection connection = (NuoDbConnection)Connection; NuoDbConnectionStringBuilder _parsedConnectionString = new NuoDbConnectionStringBuilder(Connection.ConnectionString); string usedSchema; if (Connection.ConnectionString.Contains("schema")) { usedSchema = _parsedConnectionString.Schema; } else { usedSchema = String.Empty; } // If no schema is specified in the connectionString, get all tables of all schemas, // otherwise just get the tables of the specified schema if ((schema != usedSchema.ToUpper()) && !String.IsNullOrEmpty(usedSchema)) { continue; } // No schema specified, add them to list, to build relations if (!passedSchemas.Contains(schema)) { passedSchemas.Add(schema); } ICloneable cloneable = (ICloneable)Connection; Debug.Assert(cloneable != null); if (cloneable != null) { NuoDbConnection newConnection = (NuoDbConnection)cloneable.Clone(); command = new NuoDbCommand("Select * From " + (String.IsNullOrEmpty(schema) ? name + "" : schema + "." + "\"" + name) + "\"", newConnection); AddCommand(command, name, "\"{0}\"", "?"); } else { throw new LL_BadDatabaseStructure_Exception("The passed connection doesn't implement the ICloneable interface. Contact NuoDB support for an updated version."); } } } //get relations string commandText = String.Format(CultureInfo.InvariantCulture, "Select Distinct b.Tablename as PrimaryTable, c.Field as PrimaryField, " + " b2.Tablename as ForeignTable, c2.Field as ForeignField, a.Numberkeys as NumberKeys, b.schema, b2.schema " + "From System.Foreignkeys a " + "Left outer join System.Tables b " + "on a.PrimaryTableId =b.Tableid " + "Left outer join System.Fields c " + "on a.PrimaryFieldId = c.FieldId " + "Left outer join System.Tables b2 " + "on a.ForeignTableid =b2.TableId " + "Left outer join System.Fields c2 " + "on a.ForeignFieldId =c2.FieldId " + "where b.Tablename =c.Tablename " + "and " + "b2.Tablename = c2.Tablename "); using (command = new NuoDbCommand(commandText, Connection as NuoDbConnection)) { string lastRelationChildColumnName = ""; string lastRelationParentColumnName = ""; int counter = 0; Connection.Open(); DbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { if (!reader.IsDBNull(0) && !reader.IsDBNull(1)) { string childColumnName = reader.GetString(3); string parentColumnName = reader.GetString(1); string childTableName = reader.GetString(2); string parentTableName = reader.GetString(0); string parentSchema = reader.GetString(5); string childSchema = reader.GetString(6); if (excludedOwners.Contains(parentSchema) || excludedOwners.Contains(childSchema)) { continue; } if (SuppressAddTableOrRelation(parentTableName, parentSchema) || SuppressAddTableOrRelation(childTableName, childSchema)) { continue; } //check whether shared primary key if (reader.GetInt16(4) > 1) { ++counter; //first time i am empty if (counter == 1) { lastRelationParentColumnName = parentColumnName; lastRelationChildColumnName = childColumnName; } else { lastRelationChildColumnName += '\t' + childColumnName; lastRelationParentColumnName += '\t' + parentColumnName; } if (counter == reader.GetInt16(4)) { parentColumnName = lastRelationParentColumnName; childColumnName = lastRelationChildColumnName; counter = 0; } else { continue; } } string relationName = parentTableName + "2" + childTableName; int relationIndex = 1; string formatString = relationName + "{0}"; while (passedRelationNames.Contains(relationName)) { relationName = String.Format(CultureInfo.InvariantCulture, formatString, relationIndex); relationIndex++; } passedRelationNames.Add(relationName); AddRelation(relationName, parentTableName, childTableName, parentColumnName, childColumnName); } } reader.Close(); } } finally { Connection.Close(); Initialized = true; } }
protected override void Init() { if (Initialized) { return; } HashSet <String> passedRelationNames = new HashSet <string>(); Connection.Open(); try { bool containsViews = false; DataTable dtTables; if ((SupportedElementTypes & DbConnectionElementTypes.Table) != 0) { dtTables = (Connection as NpgsqlConnection).GetSchema("Tables"); } else { dtTables = new DataTable(); } //Getschema ("Tables") supplies only the tables lately, so a merge is performed. if ((SupportedElementTypes & DbConnectionElementTypes.View) != 0) { try { DataTable dtViews = (Connection as NpgsqlConnection).GetSchema("Views"); //merge the datatables if (dtViews.Rows.Count > 0) { dtViews.Columns["check_option"].ColumnName = "table_type"; dtViews.Columns.Remove("is_updatable"); //uptdate the table_type column var changeColumnName = dtViews.AsEnumerable() .Select (row => { row["table_type"] = "VIEW"; return(row); }); dtViews = changeColumnName.CopyToDataTable(); //We conclude that sometime Getschema gets the views again and we have the double. if (dtTables.AsEnumerable().Any(row => "VIEW" == row.Field <String>("table_type"))) { containsViews = true; } //merge with tables dt dtTables.Merge(dtViews); //if there are duplicates (views) remove if (containsViews) { var uniqueTables = dtTables.AsEnumerable() .GroupBy(row => row.Field <string>("TABLE_NAME")) .Select(row => row.First()); dtTables = uniqueTables.CopyToDataTable(); } } } catch (Exception ex) { LoggingHelper.LogExceptionDetails(ex, Logger); } } DataProviderHelper.LogDataTableStructure(Logger, dtTables); Connection.Close(); Provider.PrefixTableNameWithSchema = PrefixTableNameWithSchema; foreach (DataRow dr in dtTables.Rows) { string tableSchema = dr["TABLE_SCHEMA"].ToString(); if (tableSchema != "information_schema" && tableSchema != "pg_catalog") { string tableType = dr["TABLE_TYPE"].ToString(); string parentTableName = dr["TABLE_NAME"].ToString(); if (SuppressAddTableOrRelation(parentTableName, tableSchema)) { continue; } switch (tableType) { case "BASE TABLE": if ((SupportedElementTypes & DbConnectionElementTypes.Table) == 0) { continue; } break; case "VIEW": if ((SupportedElementTypes & DbConnectionElementTypes.View) == 0) { continue; } break; default: continue; } // pass table NpgsqlConnection newConnection; if (Connection is ICloneable) // Npgsql < 3.0.0 { newConnection = (NpgsqlConnection)((Connection as ICloneable).Clone()); } else // Npgsql >= 3.0.0 { newConnection = new NpgsqlConnection(Connection.ConnectionString); } string txt; if (String.IsNullOrEmpty(tableSchema)) { txt = String.Format("Select * From \"{0}\"", parentTableName); } else { txt = String.Format("Select * From \"{0}\".\"{1}\"", tableSchema, parentTableName); } AddCommand(new NpgsqlCommand(txt, newConnection), parentTableName, "\"{0}\"", ":{0}"); } } string commandText = "SELECT a.table_name AS pk_table_name, a.column_name AS pk_colum_name, b.table_name AS fk_table_name, b.column_name AS fk_colum_name, a.table_schema, b.table_schema FROM information_schema.referential_constraints LEFT JOIN information_schema.key_column_usage AS a ON referential_constraints.constraint_name = a.constraint_name LEFT JOIN information_schema.key_column_usage AS b ON referential_constraints.unique_constraint_name= b.constraint_name"; using (NpgsqlCommand cmd = new NpgsqlCommand(commandText, Connection as NpgsqlConnection)) { Connection.Open(); NpgsqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string childTableName = reader.GetString(0); string childColumnName = reader.GetString(1); string parentTableName = reader.GetString(2); string parentColumnName = reader.GetString(3); string parentSchema = reader.GetString(4); string childSchema = reader.GetString(5); ////check whether tables exist otherwise continue without adding relation if (!dtTables.AsEnumerable().Any(row => childTableName == row.Field <String>("TABLE_NAME")) || !dtTables.AsEnumerable().Any(row => parentTableName == row.Field <String>("TABLE_NAME"))) { continue; } if (SuppressAddTableOrRelation(parentTableName, null) || SuppressAddTableOrRelation(childTableName, null)) { continue; } string relName = parentTableName + "2" + childTableName; int relationIndex = 1; string formatString = relName + "{0}"; while (passedRelationNames.Contains(relName)) { relName = String.Format(CultureInfo.InvariantCulture, formatString, relationIndex); relationIndex++; } passedRelationNames.Add(relName); AddRelation(relName, parentTableName, childTableName, parentColumnName, childColumnName, parentSchema, childSchema); } reader.Close(); } } finally { Connection.Close(); Initialized = true; } }
public List <PatientMetaData> GetAllByPatientId(int patientId) { var pStoreId = DataProviderHelper.GetInt32Parameter("StoreId", patientId); return(_context.EntityFromSql <PatientMetaData>("sp_GetAll_Patient_ByPatientId", pStoreId).ToList()); }