示例#1
0
 internal SqlAzManItem(NetSqlAzManStorageDataContext db, IAzManApplication application, int itemId, string name, string description, ItemType itemType, string bizRule, BizRuleSourceLanguage? bizRuleScriptLanguage, SqlAzManENS ens)
 {
     this.db = db;
     this.itemId = itemId;
     this.application = application;
     this.name = name;
     this.bizRuleSource = bizRule;
     this.bizRuleSourceLanguage = bizRuleScriptLanguage;
     this.description = description;
     this.itemType = itemType;
     this.ens = ens;
 }
示例#2
0
        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);
            }

            CompilerResults cr = null;
            MemoryStream ms = null;
            try
            {
                cp.CompilerOptions += " /filealign:4096 /optimize";
                cr = provider.CompileAssemblyFromSource(cp, bizRule);
                if (cr.Errors.Count > 0)
                {
                    throw SqlAzManException.GenericException("BizRule Compiler Error.", null);
                }
                compiledAssembly = cr.CompiledAssembly;
                int implementsIAzManBizRuleInterfaceCount = 0;
                foreach (Type t in compiledAssembly.GetTypes())
                {
                    Type[] interfaces = t.FindInterfaces(new TypeFilter(
                        delegate(Type typeObj, Object criteriaObj)
                        {
                            if (typeObj.ToString() == criteriaObj.ToString())
                                return true;
                            else
                                return false;
                        }), typeof(NetSqlAzMan.Interfaces.IAzManBizRule).FullName);
                    implementsIAzManBizRuleInterfaceCount += interfaces.Length;
                }
                if (implementsIAzManBizRuleInterfaceCount == 0)
                {
                    throw SqlAzManException.GenericException("There must be at least a type that implements NetSqlAzMan.Interfaces.IAzManBizRule interface", null);
                }
                else if (implementsIAzManBizRuleInterfaceCount > 1)
                {
                    throw SqlAzManException.GenericException("Too many types that implements NetSqlAzMan.Interfaces.IAzManBizRule interface. Maximum allowed is 1.", null);
                }
                string fullPathAssembly = compiledAssembly.Location;
                FileStream file = File.OpenRead(fullPathAssembly);
                FileInfo fi = new FileInfo(fullPathAssembly);
                byte[] buffer = new byte[(int)fi.Length];
                file.Read(buffer, 0, buffer.Length);
                file.Close();
                file.Dispose();
                return buffer;
            }
            catch (Exception ex)
            {
                StringBuilder outputMessages = new StringBuilder();
                foreach (string msg in cr.Output)
                {
                    outputMessages = outputMessages.AppendFormat("{0}\r\n", msg);
                }
                throw SqlAzManException.GenericException(String.Format("Biz Rule compile exception.\r\n{0}\r\nOutput:{1}\r\n", ex.Message, outputMessages), ex);
            }
            finally
            {
                if (ms != null)
                {
                    ms.Close();
                }
            }
        }
示例#3
0
 /// <summary>
 /// Reloads the biz rule.
 /// </summary>
 /// <param name="bizRule">The biz rule.</param>
 /// <param name="bizRuleLanguage">The biz rule language.</param>
 public void ReloadBizRule(string bizRule, BizRuleSourceLanguage bizRuleLanguage)
 {
     bool txBeginned = ((SqlAzManStorage)(this.application.Store.Storage)).internalBeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
     try
     {
         string oldBizRule = this.bizRuleSource;
         this.ClearBizRule();
         Assembly compiledAssembly;
         byte[] binaryAssembly = this.compileBizRuleAssembly(bizRule, bizRuleLanguage, out compiledAssembly);
         int id = this.db.BizRuleInsert(bizRule, (byte)bizRuleLanguage, binaryAssembly);
         int bizRuleId = id;
         this.db.ReloadBizRule(this.itemId, bizRuleId, this.application.ApplicationId);
         this.bizRuleSource = bizRule;
         this.bizRuleSourceLanguage = bizRuleLanguage;
         this.raiseBizRuleUpdated(this, oldBizRule);
         if (txBeginned) ((SqlAzManStorage)(this.application.Store.Storage)).internalCommitTransaction();
     }
     catch
     {
         if (txBeginned) ((SqlAzManStorage)(this.application.Store.Storage)).internalRollBackTransaction();
         throw;
     }
 }