public IList <RuleTemplateProxy> GetAllByPageBySearch(int pageIndex, int pageSize, string searchTerm) { IEnumerable <RuleTemplate> queryOnRule = null; IList <RuleTemplate> ruleTemplates = new List <RuleTemplate>(); IList <DesignedRule> designedRules = new BDesignedRules().GetAll(); try { if (string.IsNullOrEmpty(searchTerm.Trim())) { queryOnRule = _ruleRep.Find(ruleTmp => ruleTmp.UserDefined); } else { queryOnRule = NHSession.QueryOver <RuleTemplate>() .Where(rule => rule.UserDefined && rule.Name.Contains(searchTerm) || rule.Name.Contains(searchTerm) || rule.IdentifierCode.ToString(CultureInfo.InvariantCulture).Contains(searchTerm)) .List <RuleTemplate>(); } queryOnRule = queryOnRule .Skip(pageIndex * pageSize) .Take(pageSize); ruleTemplates = queryOnRule.ToList <RuleTemplate>(); } catch (Exception ex) { LogException(ex, "GTS.Clock.Business.Rules.BRule", "GetAllByPageBySearch"); throw ex; } foreach (RuleTemplate item in ruleTemplates) { DesignedRule desinedRuleObj = designedRules.FirstOrDefault(d => d.RuleTemplate.ID == item.ID); item.DesignedRule = desinedRuleObj; } var RuleTemplateProxyList = ruleTemplates.Select(ruleTemplate => new RuleTemplateProxy(ruleTemplate) { Type = RuleTypeList[ruleTemplate.TypeId] }).ToList(); return(RuleTemplateProxyList); }
public string GenerateAndCompile() { #region Source Main Text string sourceTextMain = @" using System; using System.Collections.Generic; using System.Linq; using GTS.Clock.ModelEngine; using GTS.Clock.ModelEngine.ELE; using GTS.Clock.ModelEngine.Concepts; using GTS.Clock.ModelEngine.Concepts.Operations; using GTS.Clock.Infrastructure.Utility; namespace GTS.Clock.Business.DesignedCalculator { public static class DesignedRuleCalculator { //#region Rules ###RULES### //#endregion } public static class DesignedConceptCalculator { #region Concepts ###CONCEPTS### #endregion } }"; #endregion #region CONCEPTS string sourceTextConcepts = @" /// <summary> /// ###SUMMARY### /// </summary> /// <param name=""MyRule""></param> public static void ###IDENTIFIER###(this GTS.Clock.Business.Calculator.ConceptCalculator calculator, BaseScndCnpValue Result, SecondaryConcept MyConcept) { ###CSHARPSOURCE### } "; var Conceptsource = new EntityRepository <SecondaryConcept>().GetAll().Where(x => x.UserDefined) .Select(cnp => new RuleConceptCompileProxy() { Identifier = cnp.IdentifierCode.ToString(CultureInfo.InvariantCulture), CSharpCode = cnp.CSharpCode, Summery = cnp.FnName, }) .ToList(); string strConcepts = string.Empty; foreach (var ruleConceptCompileProxy in Conceptsource) { var tt = sourceTextConcepts.Replace("###SUMMARY###", " C" + ruleConceptCompileProxy.Summery + "Summary"); tt = tt.Replace("###IDENTIFIER###", "C" + ruleConceptCompileProxy.Identifier); tt = tt.Replace("###CSHARPSOURCE###", ruleConceptCompileProxy.CSharpCode); strConcepts += tt; } sourceTextMain = sourceTextMain.Replace("###CONCEPTS###", strConcepts); #endregion #region RULES string sourceTextMethods = @" /// <summary> /// ##SUMMARY### /// </summary> /// <param name=""MyRule""></param> public static void ###IDENTIFIER###(this GTS.Clock.Business.Calculator.RuleCalculator calculator, AssignedRule MyRule) { ###CSHARPSOURCE### } "; //var Rulesource = new EntityRepository<DesignedRule>() // //var Rulesource = new EntityRepository<RuleTemplate>() // //.GetAll().Where(x => x.UserDefined) // .GetAll().Select(cnp => new RuleConceptCompileProxy() // { // //Identifier = cnp.RuleTemplateID.IdentifierCode.ToString(CultureInfo.InvariantCulture), // //CSharpCode = cnp.CSharpCode, // //Summery = cnp.RuleTemplateID.Name // Identifier = cnp.RuleTemplate.IdentifierCode.ToString(CultureInfo.InvariantCulture), // CSharpCode = cnp.CSharpCode, // Summery = cnp.RuleTemplate.Name // }) // .ToList(); IList <RuleConceptCompileProxy> Rulesource = new List <RuleConceptCompileProxy>(); DesignedRule designedRuleAlias = null; RuleTemplate RuleTemplateAlias = null; IList <DesignedRule> designedRuleList = this.NHSession.QueryOver <DesignedRule>(() => designedRuleAlias) .JoinAlias(() => designedRuleAlias.RuleTemplate, () => RuleTemplateAlias) .List <DesignedRule>(); if (designedRuleList != null && designedRuleList.Count > 0) { designedRuleList.ToList <DesignedRule>().ForEach(x => { Rulesource.Add(new RuleConceptCompileProxy() { Identifier = x.RuleTemplate.IdentifierCode.ToString(CultureInfo.InvariantCulture), CSharpCode = x.CSharpCode, Summery = x.RuleTemplate.Name }); }); } string strMethods = string.Empty; foreach (var ruleConceptCompileProxy in Rulesource) { var tt = sourceTextMethods.Replace("###SUMMARY###", "R" + ruleConceptCompileProxy.Summery + "Summary"); tt = tt.Replace("###IDENTIFIER###", "R" + ruleConceptCompileProxy.Identifier); tt = tt.Replace("###CSHARPSOURCE###", ruleConceptCompileProxy.CSharpCode); strMethods += tt; } sourceTextMain = sourceTextMain.Replace("###RULES###", strMethods); #endregion var providerOptions = new Dictionary <string, string> { { "CompilerVersion", "v4.0" } }; CSharpCodeProvider provider = new CSharpCodeProvider(providerOptions); CompilerParameters compilerParams = new CompilerParameters { OutputAssembly = OutputDLLFullPath, GenerateInMemory = false, GenerateExecutable = false }; #region ReferencedAssemblies compilerParams.ReferencedAssemblies.Add("mscorlib.dll"); compilerParams.ReferencedAssemblies.Add("System.dll"); compilerParams.ReferencedAssemblies.Add("System.Core.dll"); compilerParams.ReferencedAssemblies.Add("System.Data.dll"); compilerParams.ReferencedAssemblies.Add("System.Data.DataSetExtensions.dll"); compilerParams.ReferencedAssemblies.Add("System.Xml.dll"); compilerParams.ReferencedAssemblies.Add("System.Xml.Linq.dll"); var refDlls = new List <string>() { "GTS.Clock.Business.dll", "GTS.Clock.Infrastructure.dll", "GTS.Clock.Infrastructure.RepositoryEngine.dll", "GTS.Clock.ModelEngine.dll", "log4net.dll", "GTS.Clock.Business.Calculator.dll", "GTS.Clock.Business.GeneralCalculator.dll" }; foreach (var refDll in refDlls) { var dllPath = string.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory + "RuleGenerator\\bin", refDll); if (System.IO.File.Exists(dllPath)) { compilerParams.ReferencedAssemblies.Add(dllPath); } } #endregion CompilerResults results = provider.CompileAssemblyFromSource(compilerParams, sourceTextMain); var message = string.Empty; if (results.Errors.Count == 0) { using (StreamWriter streamWriter = new StreamWriter(OutputCSharpCodeFullPath)) { streamWriter.Write(sourceTextMain); } } else { using (StreamWriter streamWriter = new StreamWriter(OutputCSharpCodeFullPath + ".LOG")) { for (int index = 0; index < results.Errors.Count; index++) { CompilerError err = results.Errors[index]; streamWriter.Write(err.ErrorText); message += "\r\n" + err.ErrorText; } } } return(message); }
public string[] UpdateRuleGenerator_RuleGeneratorPage( string state, string ID, string VariablesObject, string ParameterObject, string RuleStateObject, string CSharpCode, //string RuleObject, string PersionScript, string RuleTemplateID, string DesignedRuleID) { this.InitializeCulture(); string[] retMessage = new string[4]; try { AttackDefender.CSRFDefender(this.Page); decimal RuleGeneratorID = 0; //decimal iID = Convert.ToDecimal(this.StringBuilder.CreateString(ID)); decimal designedRuleID = Convert.ToDecimal(DesignedRuleID); VariablesObject = this.StringBuilder.CreateString(VariablesObject, StringGeneratorExceptionType.ConceptRuleManagement); ParameterObject = this.StringBuilder.CreateString(ParameterObject, StringGeneratorExceptionType.ConceptRuleManagement); RuleStateObject = this.StringBuilder.CreateString(RuleStateObject, StringGeneratorExceptionType.ConceptRuleManagement); CSharpCode = this.StringBuilder.CreateString(CSharpCode, StringGeneratorExceptionType.ConceptRuleManagement); PersionScript = this.StringBuilder.CreateString(PersionScript, StringGeneratorExceptionType.ConceptRuleManagement); BDesignedRules bDesignedRule = new BDesignedRules(); bool CheckPageState = bDesignedRule.CheckToExistRuleCSharpCode(Convert.ToDecimal(RuleTemplateID)); UIActionType uam = (UIActionType)Enum.Parse(typeof(UIActionType), this.StringBuilder.CreateString(state).ToUpper()); if (CheckPageState) { uam = (UIActionType)Enum.Parse(typeof(UIActionType), "EDIT"); } else { uam = (UIActionType)Enum.Parse(typeof(UIActionType), "ADD"); } DesignedRule designedrule = new DesignedRule(); List <RuleGeneratorRuleParameterProxy> ParameterList = GetListOfParameterObject(ParameterObject); if (uam != UIActionType.DELETE) { designedrule.VariablesObject = VariablesObject; designedrule.ParameterObject = ParameterObject; designedrule.RuleStateObject = RuleStateObject; designedrule.CSharpCode = CSharpCode; designedrule.PersionScript = PersionScript; List <RuleTemplateParameter> ruleTemplateParameterList = new List <RuleTemplateParameter>(); designedrule.RuleTemplate = new RuleTemplate { ID = Convert.ToInt32(RuleTemplateID) }; foreach (RuleGeneratorRuleParameterProxy item in ParameterList) { RuleTemplateParameter ruleTemplateParameter = new RuleTemplateParameter(); ruleTemplateParameter.Name = item.Parametername; ruleTemplateParameter.RuleTemplateId = Convert.ToInt32(RuleTemplateID); ruleTemplateParameter.Title = item.Parametername; switch (Convert.ToInt32(item.Parametertype)) { case 0: ruleTemplateParameter.Type = RuleParamType.Numeric; break; case 1: ruleTemplateParameter.Type = RuleParamType.Time; break; case 2: ruleTemplateParameter.Type = RuleParamType.Date; break; } ruleTemplateParameterList.Add(ruleTemplateParameter); } designedrule.RuleTemplateParameterList = ruleTemplateParameterList; designedrule.RuleRgisterDate = DateTime.Now; } switch (uam) { case UIActionType.ADD: designedrule.RuleEstate = (int)UIActionType.ADD; RuleGeneratorID = this.DesignedRuleBusiness.InsertDesignedRule(designedrule, uam); break; case UIActionType.EDIT: designedrule.RuleEstate = (int)UIActionType.EDIT; designedrule.ID = designedRuleID; RuleGeneratorID = this.DesignedRuleBusiness.UpdateDesignedRule(designedrule, uam); break; case UIActionType.DELETE: //if (selectedRuleGeneratorID == 0) //{ // retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.UIValidationExceptions, new Exception(GetLocalResourceObject("NoRuleforEdit").ToString()), retMessage); // return retMessage; //} RuleGeneratorID = this.DesignedRuleBusiness.InsertDesignedRule(designedrule, uam); break; } retMessage[0] = GetLocalResourceObject("RetSuccessType").ToString(); string SuccessMessageBody = string.Empty; switch (uam) { case UIActionType.ADD: SuccessMessageBody = GetLocalResourceObject("AddComplete").ToString(); break; case UIActionType.EDIT: SuccessMessageBody = GetLocalResourceObject("EditComplete").ToString(); break; case UIActionType.DELETE: SuccessMessageBody = GetLocalResourceObject("DeleteComplete").ToString(); break; default: break; } retMessage[1] = SuccessMessageBody; retMessage[2] = "success"; retMessage[3] = RuleGeneratorID.ToString(); return(retMessage); } catch (UIValidationExceptions ex) { retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.UIValidationExceptions, ex, retMessage); return(retMessage); } catch (UIBaseException ex) { retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.UIBaseException, ex, retMessage); return(retMessage); } catch (Exception ex) { retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.Exception, ex, retMessage); return(retMessage); } }