ssteenkiste / nettiers

Automatically exported from code.google.com/p/nettiers
1 stars 0 forks source link

Multiple CustomProcedureStartsWith #420

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This is an extension to the templates that I aslways make. It allwos me to use 
multiple Custom procedure prefixes. This is handy in that our administrative 
application and main application share the same database, but there are certain 
procs that we would never want a normal enduser to run, therefore we build the 
datalayers in two sets of assemblies. The administrative datalayer uses a 
semicolon seperated list for its CustomProcedureStartsWith parameter.

Please consider this for inclusion into the project, I believe it could be very 
helpful for everyone.

This is in the CommonSqlCode.cs file.
//original procedure renamed
public IDictionary GetCustomProceduresSinglePrefix(string objectName, 
CommandSchemaCollection allCommands)
        {
            string customPrefix = string.Format(CustomProcedureStartsWith, objectName, ProcedurePrefix);
            IDictionary procs = new Hashtable();
            string customName;
            bool discover = true;
            System.Collections.ArrayList invalids = new System.Collections.ArrayList();
            string current = string.Empty;

            while (discover)
            {
                try
                {
                    procs.Clear();
                    foreach (CommandSchema proc in allCommands)
                    {
                        if (proc == null)
                            continue;

                        current = proc.Name;
                        if (invalids.Contains(proc.Name))
                            continue;

                        if (proc.Name.ToLower().StartsWith(customPrefix.ToLower()))
                        {
                            customName = proc.Name.Substring(customPrefix.Length);
                            procs.Add(customName, proc);
                        }
                    }
                    discover = false;
                }
                catch
                {
                    System.Diagnostics.Debug.WriteLine("Stored Procedure Command Failed: " + current);
                    invalids.Add(current);
                }
            }

            return procs;
        }

        public IDictionary GetCustomProcedures(string objectName, CommandSchemaCollection allCommands)
        {
            string customPrefix = string.Format(CustomProcedureStartsWith, objectName, ProcedurePrefix);
            IDictionary procs = new Hashtable();
            string customName;
            bool discover = true;
            System.Collections.ArrayList invalids = new System.Collections.ArrayList();
            string current = string.Empty;

            if (CustomProcedureStartsWith.Contains(";"))
            {
                string[] prefixes = CustomProcedureStartsWith.Split(';');

                while (discover)
                {
                    try
                    {
                        procs.Clear();
                        foreach (String prefix in prefixes)
                        {
                            customPrefix = string.Format(prefix, objectName, ProcedurePrefix);
                            foreach (CommandSchema proc in allCommands)
                            {
                                if (proc == null)
                                    continue;

                                current = proc.Name;
                                if (invalids.Contains(proc.Name))
                                    continue;

                                if (proc.Name.ToLower().StartsWith(customPrefix.ToLower()))
                                {
                                    customName = proc.Name.Substring(customPrefix.Length);
                                    procs.Add(customName, proc);
                                }
                            }
                        }
                        discover = false;
                    }
                    catch
                    {
                        System.Diagnostics.Debug.WriteLine("Stored Procedure Command Failed: " + current);
                        invalids.Add(current);
                    }
                }
            }
            else
            {
                return GetCustomProceduresSinglePrefix(objectName, allCommands);
            }

            return procs;
        }

Original issue reported on code.google.com by ryan.piw...@gmail.com on 5 Mar 2012 at 8:03