/// <summary> /// Gets the application attribute. /// </summary> /// <param name="key">The key.</param> /// <returns></returns> public IAzManAttribute<IAzManApplication> GetAttribute(string key) { ApplicationAttributesResult aa; if ((aa = (from t in this.db.ApplicationAttributes() where t.ApplicationId == this.applicationId && t.AttributeKey == key select t).FirstOrDefault()) != null) { IAzManAttribute<IAzManApplication> result = new SqlAzManApplicationAttribute(this.db, this, aa.ApplicationAttributeId.Value, aa.AttributeKey, aa.AttributeValue, this.ens); if (this.ens != null) this.ens.AddPublisher(result); return result; } else { throw SqlAzManException.AttributeNotFoundException(key, this.store.Name, this.name, null); } }
/// <summary> /// Gets the application attributes. /// </summary> /// <returns></returns> public IAzManAttribute<IAzManApplication>[] GetAttributes() { IAzManAttribute<IAzManApplication>[] attributes; var ds = (from tf in this.db.ApplicationAttributes() where tf.ApplicationId == this.applicationId select tf).ToList(); attributes = new SqlAzManApplicationAttribute[ds.Count]; int index = 0; foreach (var row in ds) { attributes[index] = new SqlAzManApplicationAttribute(this.db, this, row.ApplicationAttributeId.Value, row.AttributeKey, row.AttributeValue, this.ens); if (this.ens != null) this.ens.AddPublisher(attributes[index]); index++; } return attributes; }
/// <summary> /// Creates an application attribute. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <returns></returns> public IAzManAttribute<IAzManApplication> CreateAttribute(string key, string value) { try { int applicationAttributeId = this.db.ApplicationAttributeInsert(this.applicationId, key, value); IAzManAttribute<IAzManApplication> result = new SqlAzManApplicationAttribute(this.db, this, applicationAttributeId, key, value, this.ens); this.raiseApplicationAttributeCreated(this, result); if (this.ens != null) this.ens.AddPublisher(result); return result; } catch (System.Data.SqlClient.SqlException sqlex) { if (sqlex.Number == 2601) //Index Duplicate Error throw SqlAzManException.AttributeDuplicateException(key, this, sqlex); else throw SqlAzManException.GenericException(sqlex); } }