Understanding the hierarchy system

Feb 22, 2010 at 5:33 PM
Edited Feb 23, 2010 at 8:50 AM

Hi Andrea, I'm looking into your terrific project for my company, and I've got some preliminary questions:

1. The point of the operations / tasks hierarchy is to encapsulate operations permissions with the higher-level task permissions? I mean, the intention is to put several operations under a task so I can grant access to related operations together, rather than individually for each one?
  The intention is NOT, from my understanding, to do something like this:

Operation: Read
Operation: Add
Operation: Remove
Operation: Update

Task: EditDocument --> Operations: Read, Add, Remove, Update
Task: EditMailingList --> Operations: Read, Add, Remove, Update

 

Right? The above was not your intention, I guess, as that doesn't seem to work.

Is there any elegant way that you can think of, to apply Read/Add/Remove/Update operations to a large number of tasks, then give one role full control (all operations) to all tasks, and another role only read-access to all tasks (only the Read operation for each task)?

 

2. I cannot find anything in the documentation about how to add business rules, other than how to get to the relevant part in the snapin. I would like to understand how the "new business rule" code should be implemented:

 

public sealed class BizRule : IAzManBizRule
{
public BizRule()
{ }

public bool Execute(Hashtable contextParameters, IAzManSid identity, IAzManItem ownerItem, ref AuthorizationType authorizationType)
{
//Insert your code here
//Assign authorizationType to some AuthorizationType value to force CheckAccess result for this item.
return true;
}
}

 

Can you give any hints, or perhaps an example, as to how to implement the Execute method?

 

Thanks for the amazing product,

Joni

Feb 23, 2010 at 10:24 AM

Also I'm interested to know if it is possible to apply the same Business Rule to multiple roles/tasks/operations?

 

Joni

Feb 24, 2010 at 8:08 AM

Hi,

Operation names must all be distinct.

You should do something like this:

Task: EditDocument -> Operations: ReadDocument, AddDocument, RemoveDocument, UpdateDocument

Task: EditMailingList -> Operations: ReadMailingList, AddMailingList, RemoveMailingList, UpdateMailingList

In thos way if you want to create a role that can only read:

Role: Reader -> Task: ReadAll -> Operations: ReadDocument, ReadMailingList

Regards,

Andrea.

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator  
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com

Feb 24, 2010 at 8:16 AM

Hi,

yes you can.

Just put your business rule into a separate assembly (MyAssembly.Myclass.MyBusinessRule) and invoke it from the netsqlazman biz rule source:

using System;

using System.Security.Principal;

using System.IO;

using System.Data;

using System.Collections;

using System.Collections.Specialized;

using System.Collections.Generic;

using System.Text;

using NetSqlAzMan;

using NetSqlAzMan.Interfaces;

using MyAssembly;

namespace Consegne.BizRules

{

    public sealed class BizRule : IAzManBizRule

    {

        public BizRule()

        { }

        public bool Execute(Hashtable contextParameters, IAzManSid identity, IAzManItem ownerItem, ref AuthorizationType authorizationType)

        {

           return MyAssembly.Myclass.MyBusinessRule(contextParameters, identity, ownerItem, ref authorizationType);

        }

    }

}

Regards,

Andrea.

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator  
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com

Feb 24, 2010 at 9:52 AM

Hi Andrea, yeah, I've figured out the system with the operations. It's very convenient.

About the business rules, if I add logic from my own assembly do I have to also add that assembly to SQL?

 

Thanks

Joni

Feb 24, 2010 at 10:17 AM

No need.

NetSqlAzMan Snap-in do all by itself … compiling for you the assembly and serializing it into a blob field.

The assembly is added to SQL has a binary array without involving SQL 2005 CLR assemblies.

Regards,

Andrea.

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator  
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com

Feb 26, 2010 at 11:53 AM

I guess I'll have to try it out. But I don't understand how it will find the assembly that I reference. Does it have to be in the GAC then?

 

Joni

Feb 26, 2010 at 1:04 PM

You can use “dynamic assembly loading” (load at runtime).

Here an example:

        private void LoadAssembly()

        {

            Assembly a = Assembly.LoadFile(filename);

            System.Type[] sts = a.GetTypes();

            foreach (System.Type st in sts)

            {

                Object o = Activator.CreateInstance(st);

                if (o != null)

                {

                    Console.WriteLine(st.FullName + " Instantiated\n");

                    //proceed with type conversion here

                }

                else

                {

                    Console.WriteLine(st.FullName + " NOT Instantiated\n");

                }

            }                       

        }

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator  
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com

Mar 23, 2010 at 7:57 PM
Edited Mar 23, 2010 at 7:57 PM

NetSqlAzMan Snap-in cant find reference, because it has fixed number of recerenced assembiles system.* + netsqlazman.dll no dynamic loading can fix this snap-in problem.

maybe it snap-in could have configuration, where to look for external assemblies... 

look at SqlAzManItem.cs : 

private byte[] compileBizRuleAssembly(string bizRule, BizRuleSourceLanguage bizRuleLanguage, out Assembly compiledAssembly)
        {
            CodeDomProvider provider = null;
            if (bizRuleLanguage == NetSqlAzMan.BizRuleSourceLanguage.CSharp)
                provider = new Microsoft.CSharp.CSharpCodeProvider();
            else
                provider = new Microsoft.VisualBasic.VBCodeProvider();
            CompilerParameters cp = new CompilerParameters();
            cp.GenerateInMemory = false;
            cp.GenerateExecutable = false;
            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Data.dll");
            cp.ReferencedAssemblies.Add("System.Data.OracleClient.dll");
            cp.ReferencedAssemblies.Add("System.DirectoryServices.dll");
            cp.ReferencedAssemblies.Add("System.Messaging.dll");
            cp.ReferencedAssemblies.Add("System.Security.dll");
            cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            cp.ReferencedAssemblies.Add("System.Xml.dll");
            Assembly netsqlazmanAassembly = this.GetType().Assembly;
            if (netsqlazmanAassembly.CodeBase.StartsWith("file:///"))
            {
                cp.ReferencedAssemblies.Add(netsqlazmanAassembly.CodeBase.Substring(8).Replace('/','\\'));
            }
            else
            {
                cp.ReferencedAssemblies.Add(netsqlazmanAassembly.Location);
            }
            
......

greetings M.

Mar 24, 2010 at 5:44 PM

Hi,

I mean Assembly Dynamic Loading from your custom code (not from Snap-In):

Type a code like this into your business rule code:

Assembly assembly = Assembly.LoadFrom("MyNice.dll");

Type type = assembly.GetType("MyType");

object instanceOfMyType = Activator.CreateInstance(type);

Look at this web resource for more details:

http://stackoverflow.com/questions/465488/c-load-assemblies-at-runtime

Regards,

Andrea.

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator  
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com