/// <summary> /// Creates the specified application name. /// </summary> /// <param name="applicationName">Name of the application.</param> /// <param name="applicationDescription">The application description.</param> /// <returns></returns> public IAzManApplication CreateApplication(string applicationName, string applicationDescription) { try { int applicationId = this.db.ApplicationInsert(this.storeId, applicationName, applicationDescription); IAzManApplication applicationCreated = new SqlAzManApplication(this.db, this, applicationId, applicationName, applicationDescription, this.netsqlazmanFixedServerRole, this.ens); this.raiseApplicationCreated(this, applicationCreated); if (this.ens != null) { this.ens.AddPublisher(applicationCreated); } this.applications = null; //Force cache refresh return(applicationCreated); } catch (System.Data.SqlClient.SqlException sqlex) { if (sqlex.Number == 2601) //Index Duplicate Error { throw SqlAzManException.ApplicationDuplicateException(applicationName, this, sqlex); } else { throw SqlAzManException.GenericException(sqlex); } } }
/// <summary> /// Gets the applications. /// </summary> /// <returns></returns> public IAzManApplication[] GetApplications() { var ds = (from tf in this.db.Applications() where tf.StoreId == this.storeId orderby tf.Name select tf).ToList(); List <IAzManApplication> applications = new List <IAzManApplication>(); foreach (var row in ds) { byte netsqlazmanFixedServerRole = 0; if (this.IAmAdmin) { netsqlazmanFixedServerRole = 3; } else { var r1 = this.db.CheckApplicationPermissions(row.ApplicationId.Value, 2); var r2 = this.db.CheckApplicationPermissions(row.ApplicationId.Value, 1); if (r1.HasValue && r1.Value) { netsqlazmanFixedServerRole = 2; } else if (r2.HasValue && r2.Value) { netsqlazmanFixedServerRole = 1; } } IAzManApplication app = new SqlAzManApplication(this.db, this, row.ApplicationId.Value, row.Name, row.Description, netsqlazmanFixedServerRole, this.ens); applications.Add(app); this.raiseApplicationOpened(app); if (this.ens != null) { this.ens.AddPublisher(app); } } return(applications.ToArray()); }
/// <summary> /// Opens the application. /// </summary> /// <param name="applicationName">Name of the application.</param> /// <returns></returns> public IAzManApplication GetApplication(string applicationName) { ApplicationsResult app; if ((app = (from t in this.db.Applications() where t.StoreId == this.storeId && t.Name == applicationName select t).FirstOrDefault()) != null) { byte netsqlazmanFixedServerRole = 0; if (this.IAmAdmin) { netsqlazmanFixedServerRole = 3; } else { var r1 = this.db.CheckApplicationPermissions(app.ApplicationId, 2); var r2 = this.db.CheckApplicationPermissions(app.ApplicationId, 1); if (r1.HasValue && r1.Value) { netsqlazmanFixedServerRole = 2; } else if (r2.HasValue && r2.Value) { netsqlazmanFixedServerRole = 1; } } IAzManApplication application = new SqlAzManApplication(this.db, this, app.ApplicationId.Value, applicationName, app.Description, netsqlazmanFixedServerRole, this.ens); this.raiseApplicationOpened(application); if (this.ens != null) { this.ens.AddPublisher(application); } return(application); } else { throw SqlAzManException.ApplicationNotFoundException(applicationName, this, null); } }