Getting errors after creating an Application in the Store

Topics: General Topic, MMC SnapIn, NetSqlAzMan Core
Oct 8, 2014 at 2:30 PM
NetSqlAzMan version 3.6.0.15
NetSqlAzMan installed products MMC SnapIn, RoleProvider
Windows 7, VB, .Net 4.5
Platform x64
SQL Server version 2012 Enterprise

I’m trying to implement NetSQLAzMan for a web application. The application manages events like meetings, trade shows, & conventions. The target market is small to mid-sized non-profit organizations. NetSQLAzman is a potential role provider solution because of the item inheritance it includes.
There are two “sides” to this application, the client/private facing website that allows a customer to add an event, configure it by adding program content (seminars, workshops and such), and open the event up for registration. The public facing site allows people to register for the event.
A key factor for the client facing site is custom role configuration. Client A1 may give access to two people who have complete access to configure any number of events. Client B2 may give access to a set of people on an event by event basis. Team1 may have access to Event1 and Event2 is only accessible to Team2. It could be more complex in that for Event2, there is a larger team managing the event with one person managing onsite seminars, another planning offsite activities, a third person handling transportation requirements for the offsite activities and a fourth person managing food and beverage activities. Roles are not needed for the public facing site.
The basic hierarchy for the application needs to be something like this:
Administrator (Access to everything)
Organization (Client) Manager (Access to everything for an Organization/Client)
  Event Manager (Access to one or more specific events for an Organization/Client)
     Staff Manager (Access to Specific Event Agenda [seminars, workshops] Content)
        Staff Edit (Access to Add/Edit/Delete)
        Staff View (Access to View Only)
The key here is that a client, on an event by event basis may have custom roles below Event Manager.
Seminar Manager
Seminar Edit
Seminar View
Workshop Manager
Seminar Edit
Seminar View
Food And Beverage Manager
Food And Beverage Edit
NetSQLAzMan seems to allow me to enable this functionality but to implement it I need to create an Application in the Store for each client with their custom Roles in that Application. Short term I don’t need Task or Operation functionality but using NetSQLAzMan leaves the door open to implementing it down the road.

I installed the provider and created an instance of the role provider in my database. I added a Store and a “placeholder” Application using the Snap In so I don’t get an error on startup. I create a second Application for the Administrator/Site Configuration users.
I wrote code that adds a client to the website. It performs several actions. It creates the Organization entry in the Organization table. It adds a primary user and their data to the appropriate tables. Then it creates a NetSQLAzMan Application for the Organization. It creates five basic Roles in the Application. The Client can change these down the road as needed if they need customized roles. It adds the primary user to the OrganizationManager Role.

This is the code used:

Dim SecurityStorage As IAzManStorage = New SqlAzManStorage(SecurityConnectionString)
Dim SecurityStore As IAzManStore = SecurityStorage.GetStore("ConferenceManagement")
Dim ApplicationName As String = CreateApplicationName(OrganizationName, OrganizationID)
SecurityStore.CreateApplication(ApplicationName, OrganizationName)
Dim SecurityApplication As IAzManApplication = SecurityStore.GetApplication(ApplicationName)
Dim AdministratorRole = SecurityApplication.CreateItem("Administrators", "Administrators", ItemType.Role)
Dim OrganizationManagerRole = SecurityApplication.CreateItem("OrganizationManager", "Organization Manager", ItemType.Role)
Dim EventManagerRole = SecurityApplication.CreateItem("EventManager", "Event Manager", ItemType.Role)
Dim StaffManagerRole = SecurityApplication.CreateItem("StaffManager", "Staff Manager", ItemType.Role)
Dim rp As NetSQLAzManRoleProvider = DirectCast(Roles.Provider, NetSQLAzManRoleProvider)
rp.ApplicationName = ApplicationName
AdministratorRole.AddMember(OrganizationManagerRole)
OrganizationManagerRole.AddMember(EventManagerRole)
EventManagerRole.AddMember(StaffManagerRole)
StaffManagerRole.AddMember(StaffEditRole)
StaffManagerRole.AddMember(StaffViewRole)
StaffManagerRole.AddMember(StaffReportsRole)
rp.AddUsersToRoles({"Administrator"}, {"Administrators"})
If OrganizationManagerUserName <> String.Empty Then
rp.AddUsersToRoles({OrganizationManagerUserName}, {OrganizationManagerUserName})
End If

The function named CreateApplicationName creates a unique name for the Application with only alphanumeric characters.

This is where I run into problems. If I have the Snap In open, I can stop the code and exit after I create the application. I can refresh the Store content and I can see the newly created Application in the tree. If I exit the Snap In, it throws errors when I restart it. It doesn’t matter where I stop the code, after any of this code executes the Snap In won’t start so I can’t validate the code results.
When I set the Application Name on the Role Provider it throws an error saying the Application isn’t found.

I can call

SecurityApplication = Nothing
SecurityApplication As IAzManApplication = SecurityStore.GetApplication(ApplicationName)

And it doesn’t throw an Error. So the code finds the Application that way but not through the Role Provider. I thought that I screwed up something with the calls to CreateItem, but as I said, even if I just create the Application and nothing else as shown below I have the same errors. The Snap In won’t start and setting the Role provider ApplicationName throws an error.

Dim SecurityStorage As IAzManStorage = New SqlAzManStorage(SecurityConnectionString)
Dim SecurityStore As IAzManStore = SecurityStorage.GetStore("ConferenceManagement")
Dim ApplicationName As String = CreateApplicationName(OrganizationName, OrganizationID)
SecurityStore.CreateApplication(ApplicationName, OrganizationName)
Dim SecurityApplication As IAzManApplication = SecurityStore.GetApplication(ApplicationName)
Dim rp As NetSQLAzManRoleProvider = DirectCast(Roles.Provider, NetSQLAzManRoleProvider)
rp.ApplicationName = ApplicationName

I’m not sure where to head at this point, using direct calls to implement the Add/Delete Role/User To/From Roles functionality in the role provider or try to figure out why the errors occur.
Thanks
Oct 9, 2014 at 8:39 AM
Hi dcioffi,
I see in your code that you did not the operations inside a transaction (storage.BeginTransaction/Commit) so the only thing that comes in my mind is that during these operations there was some dirty writing (the writing process was interrupted unexpected ?).
I suggest you to remove first all applications from NetSqlAzMan repository and do it again the writing operations (using VB code) but inside transaction.
If you want you should perform before a little analysis on the data to see if the integrity is corrupted or not.

Let me know.
Andrea.