public void DeletePersistentVariable(int dataSourceId, string variableName = null) { IDal dal = new DataAccessLayer(EyediaCoreConfigurationSection.CurrentConfig.Database.DatabaseType).Instance; IDbConnection connection = dal.CreateConnection(_ConnectionString); connection.Open(); IDbCommand command = dal.CreateCommand(); command.Connection = connection; if (!string.IsNullOrEmpty(variableName)) { command.CommandText = "DELETE from [IdpePersistentVariable] WHERE [DataSourceId] = @DataSourceId AND [Name] = @Name"; command.AddParameterWithValue("DataSourceId", dataSourceId); command.AddParameterWithValue("Name", variableName); } else { command.CommandText = "DELETE from [IdpePersistentVariable] WHERE [DataSourceId] = @DataSourceId"; command.AddParameterWithValue("DataSourceId", dataSourceId); } command.ExecuteNonQuery(); }
/// <summary> /// Gets the missing relationships. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public IEnumerable <RelationshipEntry> GetMissingRelationships(IProcessingContext context) { long tenantId = CallData <long> .GetValue("TargetTenantId"); Dictionary <Guid, CardinalityEnum_Enumeration> typeCardinalities = TypeCardinalities; ///// // Query entities that are part of the solution ///// const string sql = @"SELECT TypeUid, FromUid, ToUid FROM AppDeploy_Relationship WHERE AppVerUid = @appVer AND TenantId = @tenantId"; using (IDbCommand command = CreateCommand( )) { command.CommandText = sql; command.AddParameterWithValue("@appVer", AppVerId); command.AddParameterWithValue("@tenantId", tenantId); using (IDataReader reader = command.ExecuteReader( )) { while (reader.Read( )) { Guid typeId = reader.GetGuid(0); Guid fromId = reader.GetGuid(1); Guid toId = reader.GetGuid(2); CardinalityEnum_Enumeration cardinality; RelationshipEntry entry = typeCardinalities.TryGetValue(typeId, out cardinality) ? new RelationshipEntry(typeId, fromId, toId, cardinality) : new RelationshipEntry(typeId, fromId, toId); yield return(entry); } } } }
/// <summary> /// Gets the missing field data. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public IEnumerable <DataEntry> GetMissingFieldData(IProcessingContext context) { long tenantId = CallData <long> .GetValue("TargetTenantId"); ///// // Query entities that are part of the solution ///// const string sql = @"select EntityUid, FieldUid from AppDeploy_Field d where d.AppVerUid = @appVer AND TenantId = @tenantId"; using (IDbCommand command = CreateCommand( )) { command.CommandText = sql; command.AddParameterWithValue("@appVer", AppVerId); command.AddParameterWithValue("@tenantId", tenantId); using (IDataReader reader = command.ExecuteReader( )) { while (reader.Read( )) { var entry = new DataEntry { EntityId = reader.GetGuid(0), FieldId = reader.GetGuid(1), }; yield return(entry); } } } }
/// <summary> /// Gets the binary data. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public IEnumerable <BinaryDataEntry> GetBinaryData(IProcessingContext context) { Func <string, byte[]> loadBinaryData = token => FileRepositoryUtils.LoadFileData(Factory.AppLibraryFileRepository, token, context); using (IDbCommand command = CreateCommand( )) { command.CommandType = CommandType.Text; command.CommandText = CommandText.AppLibraryGetBinaryData; command.AddParameterWithValue("@appVer", AppVerId); command.AddParameterWithValue("@isOfTypeId", Helpers.IsOfTypeRelationshipUpgradeId); command.AddParameterWithValue("@inheritsId", Helpers.InheritsRelationshipUpgradeId); command.AddParameterWithValue("@fileDataHashFieldId", Helpers.FileDataHashFieldUpgradeId); command.AddParameterWithValue("@imageFileTypeId", Helpers.ImageFileTypeUpgradeId); using (IDataReader reader = command.ExecuteReader( )) { while (reader.Read( )) { var binaryDataEntry = new BinaryDataEntry { DataHash = reader.GetString(0), LoadDataCallback = loadBinaryData }; yield return(binaryDataEntry); } } } }
public List <AccountPosition> LoadAccountPositions(string accountNumber, TradeDate tradeDate) { List <AccountPosition> positions = new List <AccountPosition>(); using (IDbConnection con = this.GetConnection()) { con.Open(); using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = $"{SQL} WHERE p.AccountNumber = @AccountNumber AND p.TradeDate = @TradeDate"; cmd.AddParameterWithValue("@AccountNumber", accountNumber); cmd.AddParameterWithValue("@TradeDate", tradeDate.Date); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { var position = this.DecodeRow(reader); positions.Add(position); } } } } return(positions); }
public int GetSreKeyId(IDal myDal, IDbConnection conn, IDbTransaction transaction, int dataSourceId, string keyName) { int keyId = 0; string commandText = "select k.keyId, [Name], [Value] from idpekey k "; commandText += "inner join IdpeKeyDataSource ka on k.keyId = ka.keyId "; commandText += "where ka.dataSourceId = @DataSourceId and Name = @Name"; IDbCommand command = myDal.CreateCommand(commandText, conn); command.Transaction = transaction; command.AddParameterWithValue("DataSourceId", dataSourceId); command.AddParameterWithValue("Name", keyName); IDataReader reader = command.ExecuteReader(); if (reader.Read()) { keyId = int.Parse(reader[0].ToString()); } reader.Close(); reader.Dispose(); command.Dispose(); return(keyId); }
/// <summary> /// Load relationships. /// </summary> /// <param name="context"></param> /// <returns></returns> IEnumerable <RelationshipEntry> IDataSource.GetRelationships(IProcessingContext context) { if (_relationshipCache == null) { WellKnownAliases aliases = WellKnownAliases.CurrentTenant; var cardinality = new Dictionary <long, CardinalityEnum_Enumeration>( ); ///// // Cache the various types of cardinality. ///// using (new TenantAdministratorContext(TenantId)) { cardinality [aliases.OneToOne] = CardinalityEnum_Enumeration.OneToOne; cardinality [aliases.OneToMany] = CardinalityEnum_Enumeration.OneToMany; cardinality [aliases.ManyToOne] = CardinalityEnum_Enumeration.ManyToOne; cardinality [aliases.ManyToMany] = CardinalityEnum_Enumeration.ManyToMany; } var dict = new Dictionary <RelationshipEntryKey, RelationshipEntry>( ); var toOne = new Dictionary <RelationshipEntryCardinalityKey, RelationshipEntry>( ); var fromOne = new Dictionary <RelationshipEntryCardinalityKey, RelationshipEntry>( ); ///// // Query entities that are part of the solution ///// using (IDbCommand command = CreateCommand( )) { command.CommandText = "spGetTenantAppRelationships"; command.CommandType = CommandType.StoredProcedure; command.AddParameterWithValue("@solutionId", SolutionId); command.AddParameterWithValue("@tenant", TenantId); using (IDataReader reader = command.ExecuteReader( )) { ///// // Read the base relationships ///// ReadRelationships(context, reader, cardinality, dict, toOne, fromOne, false); ///// // Move to the discarded install relationships (if there are any) ///// if (reader.NextResult( )) { ///// // Read discarded relationships ///// ReadRelationships(context, reader, cardinality, dict, toOne, fromOne, true); } } } _relationshipCache = dict.Values.ToList( ); } return(_relationshipCache); }
public void RefreshAttributePositions(int dataSourceId) { IDal myDal = null; IDbConnection conn = null; IDbTransaction transaction = null; IDataReader reader = null; IDbCommand command = null; try { myDal = new DataAccessLayer(Information.EyediaCoreConfigurationSection.Database.DatabaseType).Instance; conn = myDal.CreateConnection(_ConnectionString); conn.Open(); transaction = myDal.CreateTransaction(conn); command = myDal.CreateCommand(); command.CommandText = "select AttributeDataSourceId, a.[AttributeId],a.[Name],aes.[IsAcceptable],AttributeDataSourceId,Position,es.Name as [DataSourceName] "; command.CommandText += "from idpeAttribute a Inner join idpeAttributeDataSource aes on a.AttributeId = aes.AttributeId "; command.CommandText += "inner join idpeDataSource es on aes.DataSourceId = es.Id where es.Id = " + dataSourceId + " and aes.IsAcceptable = 1 order by aes.Position"; command.Connection = conn; command.Transaction = transaction; reader = command.ExecuteReader(); List <int> attributeDataSourceIds = new List <int>(); while (reader.Read()) { attributeDataSourceIds.Add((int)reader["AttributeDataSourceId"].ToString().ParseInt()); } reader.Close(); int position = 1; foreach (int attributeDataSourceId in attributeDataSourceIds) { IDbCommand updateCommand = myDal.CreateCommand(); updateCommand.Connection = conn; updateCommand.Transaction = transaction; updateCommand.CommandText = "UPDATE [IdpeAttributeDataSource] SET [Position] = @Position WHERE [AttributeDataSourceId] = @AttributeDataSourceId"; updateCommand.AddParameterWithValue("Position", position); updateCommand.AddParameterWithValue("AttributeDataSourceId", attributeDataSourceId); updateCommand.ExecuteNonQuery(); position++; } transaction.Commit(); conn.Close(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { reader.Dispose(); command.Dispose(); conn.Dispose(); } }
public void RemoveCardFromDeck(Deck deck, Card card) { IDbCommand command = connector.CreateCommand(); command.CommandText = "DELETE TOP(1) FROM Decklist WHERE deckID = @deckID AND cardID = @cardID;"; command.AddParameterWithValue("deckID", deck.GetID()); command.AddParameterWithValue("cardID", card.GetID()); connector.ExecuteNonQuery(command); }
public void AddCardToDeck(Deck deck, Card card) { IDbCommand command = connector.CreateCommand(); command.CommandText = "INSERT INTO deckList (deckID, cardID) VALUES (@deck, @card);"; command.AddParameterWithValue("deck", deck.GetID()); command.AddParameterWithValue("card", card.GetID()); connector.ExecuteNonQuery(command); }
public void DeleteDeck(Deck deck) { IDbCommand command = connector.CreateCommand(); command.CommandText = "UPDATE Deck SET active=@active WHERE ID=@id;"; command.AddParameterWithValue("active", false); command.AddParameterWithValue("id", deck.GetID()); connector.ExecuteNonQuery(command); }
public void Add(Election t) { IDbCommand command = _connector.CreateCommand(); command.CommandText = "INSERT INTO [Verkiezing] ([Naam], [AantalZetels]) VALUES (@name, @seats);"; command.AddParameterWithValue("name", t.Name); command.AddParameterWithValue("seats", t.Seats); _connector.ExecuteNonQuery(command); }
public void SetComplete(Deck deck, bool set) { IDbCommand command = connector.CreateCommand(); command.CommandText = "UPDATE [DECK] SET [Completed]=@complete WHERE [ID]=@id;"; command.AddParameterWithValue("complete", set); command.AddParameterWithValue("id", deck.GetID()); connector.ExecuteNonQuery(command); }
public void Save(Group group) { IDal myDal = new DataAccessLayer(EyediaCoreConfigurationSection.CurrentConfig.Database.DatabaseType).Instance; IDbConnection conn = myDal.CreateConnection(_ConnectionString); conn.Open(); IDbTransaction transaction = myDal.CreateTransaction(conn); IDbCommand command = myDal.CreateCommand(); command.Connection = conn; command.Transaction = transaction; try { if (group.Id == 0) { command.CommandText = "INSERT INTO [Group] (Name, Description) "; command.CommandText += " VALUES (@Name, @Description)"; command.AddParameterWithValue("Name", group.Name); command.AddParameterWithValue("Description", group.Description); command.ExecuteNonQuery(); //Deb: I know dirty coding, need to be changed. OUTPUT INSERTED.Id not working @SQL CE command.Parameters.Clear(); command.CommandText = "SELECT max(Id) from [Group]"; int newCodeSetId = (Int32)command.ExecuteScalar(); } else { command.CommandText = "UPDATE [Group] SET [Name] = @Name,[Description] = @Description "; command.CommandText += "WHERE [Id] = @Id"; command.AddParameterWithValue("Name", group.Name); command.AddParameterWithValue("Description", group.Description); command.AddParameterWithValue("Id", group.Id); command.ExecuteNonQuery(); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.Message, ex); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); transaction.Dispose(); } }
public override void OnSave(PersistentObject obj) { var informationTypeIdAttr = obj["InformationTypeId"]; var sensitivityLabelIdAttr = obj["SensitivityLabelId"]; if (!CheckRules(obj)) { return; } var entity = LoadEntity(obj); var informationTypeId = (string)informationTypeIdAttr ?? string.Empty; var informationTypeName = informationTypeId.Length > 0 ? informationTypeIdAttr.Options.First(o => o.StartsWith(informationTypeId + "=")).Split('=')[1] : string.Empty; var sensitivityLabelId = (string)sensitivityLabelIdAttr ?? string.Empty; var sensitivityLabelName = sensitivityLabelId.Length > 0 ? sensitivityLabelIdAttr.Options.First(o => o.StartsWith(sensitivityLabelId + "=")).Split('=')[1] : string.Empty; var ids = obj.ObjectId.Split(';'); var columnName = ids[0]; var schemaName = ids[1]; var tableName = ids[2]; var sql = $@"use [{obj.Parent.ObjectId}]; {upsertExtendedProperty}"; if (Context.Database.Connection.State == ConnectionState.Closed) { Context.Database.Connection.Open(); } foreach (var extendedproperty in new[] { new { name = "sys_information_type_id", value = informationTypeId }, new { name = "sys_information_type_name", value = informationTypeName }, new { name = "sys_sensitivity_label_id", value = sensitivityLabelId }, new { name = "sys_sensitivity_label_name", value = sensitivityLabelName } }) { using (IDbCommand cmd = Context.Database.Connection.CreateCommand()) { cmd.CommandText = sql; cmd.AddParameterWithValue("@name", extendedproperty.name); cmd.AddParameterWithValue("@value", extendedproperty.value); cmd.AddParameterWithValue("@schemaname", schemaName); cmd.AddParameterWithValue("@tablename", tableName); cmd.AddParameterWithValue("@columnname", columnName); cmd.ExecuteNonQuery(); } } Manager.Current.QueueClientOperation(new RefreshOperation("ClassifyData.Database", obj.Parent.ObjectId)); }
public void Add(Coalition t) { IDbCommand command = _connector.CreateCommand(); command.CommandText = "INSERT INTO [Coalitie] ([Naam], [Premier], [Zetels]) VALUES (@name, @primeminister, @seats);"; command.AddParameterWithValue("name", t.Name); command.AddParameterWithValue("primeminister", t.PrimeMinister); command.AddParameterWithValue("seats", t.Seats); _connector.ExecuteNonQuery(command); }
public void InsertDeck(Deck deck) { IDbCommand command = connector.CreateCommand(); command.CommandText = "INSERT INTO [Deck] (name, active, completed) VALUES (@deck, @active, @complete);"; command.AddParameterWithValue("deck", deck.ToString()); command.AddParameterWithValue("active", true); command.AddParameterWithValue("complete", false); connector.ExecuteNonQuery(command); }
public void Add(Results t) { IDbCommand command = _connector.CreateCommand(); command.CommandText = "INSERT INTO [Uitslag] ([VerkiezingID], [Naam], [TotaalStemmen]) VALUES (@electionid, @name, @votes);"; command.AddParameterWithValue("electionid", 1); command.AddParameterWithValue("name", t.Name); command.AddParameterWithValue("votes", t.TotalVotes); _connector.ExecuteNonQuery(command); }
public void RemovePartyFromCoalition(Coalition coalition, Party party) { IDbCommand command = _connector.CreateCommand(); command.CommandText = "VerwijderPartijUitCoalitie(@coalitienaam, @partijnaam);"; command.AddParameterWithValue("coalitienaam", coalition.Name); command.AddParameterWithValue("partijnaam", party.Name); command.CommandType = CommandType.StoredProcedure; _connector.ExecuteNonQuery(command); }
public void Add(Party t) { IDbCommand command = _connector.CreateCommand(); command.CommandText = "INSERT INTO [Partij] ([Naam], [Lijsttrekker], [AantalLeden]) VALUES (@name, @partyleader, @members);"; command.AddParameterWithValue("name", t.Name); command.AddParameterWithValue("primeminister", t.PartyLeader); command.AddParameterWithValue("members", t.AmountOfMembers); _connector.ExecuteNonQuery(command); }
public void AddPartyToCoalition(Coalition coalition, Party party) { IDbCommand command = _connector.CreateCommand(); command.CommandText = "VoegPartijToeAanCoalitie(@coalitienaam, @partijnaam);"; command.AddParameterWithValue("coalitienaam", coalition.Name); command.AddParameterWithValue("partijnaam", party.Name); command.CommandType = CommandType.StoredProcedure; _connector.ExecuteNonQuery(command); }
public void Delete(Party t) { IDbCommand command = _connector.CreateCommand(); command.CommandText = "DELETE FROM [CoalitiePartij] WHERE [PartijID] = (SELECT ID FROM Partij WHERE Naam=@naam)"; command.AddParameterWithValue("naam", t.Name); _connector.ExecuteNonQuery(command); command.CommandText = "DELETE FROM [Partij] WHERE [Naam]=@naam"; command.AddParameterWithValue("naam", t.Name); _connector.ExecuteNonQuery(command); }
public int SaveLog(string fileName, string subFileName, int dataSourceId, int totalRecords, int totalValidRecords, DateTime started, DateTime finished, string sreEnvironment) { IDal myDal = new DataAccessLayer(EyediaCoreConfigurationSection.CurrentConfig.Database.DatabaseType).Instance; IDbConnection conn = myDal.CreateConnection(_ConnectionString); conn.Open(); IDbCommand command = myDal.CreateCommand(); command.Connection = conn; int id = 0; try { command.CommandText = "insert into [IdpeLog] ([FileName],[SubFileName],[DataSourceId],[TotalRecords],[TotalValidRecords],[Started],[Finished],[Environment]) "; command.CommandText += " values(@FileName, @SubFileName, @DataSourceId,@TotalRecords,@TotalValidRecords,@Started, @Finished, @Environment)"; command.AddParameterWithValue("FileName", fileName); if (string.IsNullOrEmpty(subFileName)) { command.AddParameterWithValue("SubFileName", DBNull.Value); } else { command.AddParameterWithValue("SubFileName", subFileName); } command.AddParameterWithValue("DataSourceId", dataSourceId); command.AddParameterWithValue("TotalRecords", totalRecords); command.AddParameterWithValue("TotalValidRecords", totalValidRecords); command.AddParameterWithValue("Started", started); command.AddParameterWithValue("Finished", finished); command.AddParameterWithValue("Environment", sreEnvironment); command.ExecuteNonQuery(); //Deb: I know dirty coding, need to be changed. OUTPUT INSERTED.Id not working @SQL CE command.Parameters.Clear(); command.CommandText = "SELECT max(Id) from IdpeLog"; id = (Int32)command.ExecuteScalar(); } catch (Exception ex) { Trace.TraceError(ex.ToString()); throw new Exception(ex.Message, ex); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } return(id); }
/// <summary> /// Gets the binary data. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> IEnumerable <BinaryDataEntry> IDataSource.GetBinaryData(IProcessingContext context) { if (_binaryCache == null) { var data = new List <BinaryDataEntry>( ); Func <string, byte[]> loadBinaryData = token => FileRepositoryUtils.LoadFileData(Factory.BinaryFileRepository, token, context); using (IDbCommand command = CreateCommand( )) { command.CommandType = CommandType.Text; command.CommandText = CommandText.TenantSourceGetBinaryDataCommandText; command.AddParameterWithValue("@tenant", TenantId); using (IDataReader reader = command.ExecuteReader( )) { while (reader.Read( )) { var binaryDataEntry = new BinaryDataEntry { DataHash = reader.GetString(0), LoadDataCallback = loadBinaryData }; data.Add(binaryDataEntry); } } } _binaryCache = data; } return(_binaryCache); }
public void DeleteAttribute(int attributeId, bool ignoreException = true) { string cmdText = string.Empty; IDal myDal = new DataAccessLayer(Information.EyediaCoreConfigurationSection.Database.DatabaseType).Instance; IDbConnection conn = myDal.CreateConnection(_ConnectionString); IDbCommand command = myDal.CreateCommand(cmdText, conn); conn.Open(); try { cmdText = "DELETE from [IdpeAttribute] WHERE [AttributeId] = @AttributeId"; command.CommandText = cmdText; command.AddParameterWithValue("AttributeId", attributeId); command.ExecuteNonQuery(); } catch (Exception ex) { if (!ignoreException) { Trace.TraceError(ex.ToString()); throw new Exception(ex.Message, ex); } } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } }
//obsolete - dont use public bool DisassociateAttributeFromDataSource(int attributeDataSourceId) { string cmdText = string.Empty; IDal myDal = new DataAccessLayer(Information.EyediaCoreConfigurationSection.Database.DatabaseType).Instance; IDbConnection conn = myDal.CreateConnection(_ConnectionString); IDbCommand command = myDal.CreateCommand(cmdText, conn); conn.Open(); try { cmdText = "DELETE FROM [IdpeAttributeDataSource] WHERE [AttributeDataSourceId] = @AttributeDataSourceId"; command.CommandText = cmdText; command.AddParameterWithValue("AttributeDataSourceId", attributeDataSourceId); command.ExecuteNonQuery(); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } return(true); }
public List <CashFlow> LoadAllAccountCashFlows(string accountNumber) { List <CashFlow> cashFlows = new List <CashFlow>(); using (IDbConnection con = new ProfiledDbConnection( new SqlConnection(_connectionString), MiniProfiler.Current)) { con.Open(); using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = $"{SQL} WHERE f.AccountNumber = @AccountNumber"; cmd.AddParameterWithValue("@accountNumber", accountNumber); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { var cashFlow = this.DecodeRow(reader); cashFlows.Add(cashFlow); } } } } return(cashFlows); }
public List <SecurityPrice> LoadSecurityPrices(TradeDate date) { List <SecurityPrice> prices = new List <SecurityPrice>(); using (IDbConnection con = this.GetConnection()) { con.Open(); using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = $"{SQL} WHERE p.TradeDate = @TradeDate"; cmd.AddParameterWithValue("@TradeDate", date.Date); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { var price = this.DecodeRow(reader); prices.Add(price); } } } } return(prices); }
public List <CashFlow> LoadExternalCashFlows(string accountNumber) { List <CashFlow> cashFlows = new List <CashFlow>(); using (IDbConnection con = this.GetConnection()) { con.Open(); using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = $"{SQL} WHERE f.AccountNumber = @AccountNumber AND ft.ExternalFlow = 1"; cmd.AddParameterWithValue("@accountNumber", accountNumber); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { var cashFlow = this.DecodeRow(reader); cashFlows.Add(cashFlow); } } } } return(cashFlows); }
public IEnumerable <InvestmentAccount> LoadInvestmentAccounts(TradeDate tradeDate) { List <InvestmentAccount> accounts = new List <InvestmentAccount>(); using (IDbConnection con = this.GetConnection()) { con.Open(); using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = SQL; cmd.AddParameterWithValue("@TradeDate", tradeDate.Date); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { var account = this.DecodeRow(reader); accounts.Add(account); } } } } return(accounts); }