private void btnSave_Click(object sender, EventArgs e) { if (CheckSave()) { bool retValue = true; FunctionController controler = new FunctionController(); FunctionEntity fun = new FunctionEntity(); fun.OID = hdfOID.Value; fun.FUNCTIONPARENTID = hfParentOID.Value; fun.FUNCTIONKEY = txtFuncCode.Text.Trim(); fun.FUNCTIONLEVEL = Convert.ToInt32(txtFuncLevel.Text.Trim()); fun.FUNCTIONNAME = txtFuncName.Text.Trim(); fun.FUNCTIONORDER = Convert.ToInt32(txtFuncOrder.Text.Trim()); fun.FUNCTIONSTATUS = drpFuncStatus.SelectedValue; fun.FUNCTIONTYPE = 0; fun.FUNCTIONURL = txtFuncUrl.Text.Trim(); fun.MEMO = txtFuncMemo.Text.Trim(); fun.CUSER = AppCenter.CurrentPersonAccount; fun.MUSER = AppCenter.CurrentPersonAccount; if (string.IsNullOrEmpty(fun.OID)) { fun.OID = Guid.NewGuid().ToString(); retValue = controler.InsertFunction(fun); } else { retValue = controler.UpdateFunction(fun); } if (retValue) { base.ShowMessage(CommonMessage.SaveSuccess); this.ClearAllControls(); this.BindTree(); } else { base.ShowMessage(CommonMessage.SaveFailed); } } }
private FunctionEntity Datarow2Entity(DataRow dr) { if (dr != null) { FunctionEntity fun = new FunctionEntity(); fun.OID = Convert.ToString(dr["OID"]); fun.FUNCTIONKEY = Convert.ToString(dr["FUNCTIONKEY"]); fun.FUNCTIONLEVEL = Convert.ToInt32(dr["FUNCTIONLEVEL"]); fun.FUNCTIONNAME = Convert.ToString(dr["FUNCTIONNAME"]); fun.FUNCTIONORDER = Convert.ToInt32(dr["FUNCTIONORDER"]); fun.FUNCTIONPARENTID = Convert.ToString(dr["FUNCTIONPARENTID"]); fun.FUNCTIONSTATUS = Convert.ToString(dr["FUNCTIONSTATUS"]); fun.FUNCTIONTYPE = Convert.ToInt32(dr["FUNCTIONTYPE"]); fun.FUNCTIONURL = Convert.ToString(dr["FUNCTIONURL"]); fun.MEMO = Convert.ToString(dr["MEMO"]); return(fun); } else { return(null); } }
public async Task <string> Handle(UpdateParticipationSessionFunctionCommand request, CancellationToken cancellationToken) { var participation = await _repository.FindByIdAsync(new ParticipationId(request.ParticipationId)); if (participation is null) { throw new NotFoundException(request.ParticipationId.ToString(), "ParticipationSession"); } var function = new FunctionEntity( new FunctionId(request.FunctionId), _userService.UserId, request.Code, _timeService.Now(), request.Order ); participation.UpdateFunction(function, _userService.UserId); await _repository.SetAsync(participation); return(function.Id.ToString()); }
public void UpdateFunction(FunctionEntity function, UserId userId) { if (!Team.UserIds.Contains(userId)) { throw new DomainException( $"Function {function.Id} cannot be added by user : {userId} not in participation team"); } ValidateFunction(function); var existingFunction = _functions.FirstOrDefault(f => f.Id == function.Id); if (existingFunction is null) { throw new DomainException($"Function {function.Id} not in participation functions"); } var otherFunctionWithSameOrder = _functions.FirstOrDefault(f => f.Order == function.Order && function.Order != null); if (otherFunctionWithSameOrder is not null && existingFunction.Order is not null) { otherFunctionWithSameOrder.Order = existingFunction.Order; RegisterEvent(new ParticipationFunctionsReordered(Id, new List <FunctionId> { otherFunctionWithSameOrder.Id, function.Id })); } if (existingFunction.Order is null && function.Order is not null) { ShiftExistingFunctionsOrder(function.Order.Value); } existingFunction.Order = function.Order; existingFunction.Code = function.Code; existingFunction.LastModificationDate = function.LastModificationDate; existingFunction.UserId = function.UserId; ReorderFunctions(); RegisterEvent(new ParticipationFunctionUpdated(Id, function.Id)); }
/// <summary> /// 加载数据 /// </summary> private void InitData() { this.hidPid.Value = functionID.ToString(); this.hidfun.Value = Master.fun.ToString(); List <FunctionEntity> funcList = bllFunc.QueryFirstLevelList(); foreach (FunctionEntity item in funcList) { this.selFunctionLevel.Items.Add(new ListItem(item.Function_Name, item.Function_ID.ToString())); } if (functionID == 0) { //首次加载设置 this.txtFunctionUrl.Disabled = true; this.txtFunctionOrder.Value = "1000"; } else { FunctionEntity entity = bllFunc.QueryFunction(functionID); this.selFunctionLevel.Value = entity.Function_ParentID.ToString(); this.txtFunctionName.Value = entity.Function_Name; this.txtFunctionOrder.Value = entity.Function_Order.ToString(); if (entity.Function_Level == 1) { this.txtFunctionUrl.Disabled = true; this.txtFunctionUrl.Value = ""; } else { this.txtFunctionUrl.Value = entity.Function_URL_New; } } }
/// <summary> /// 根据查询前三级分类 /// </summary> /// <param name="kid"></param> /// <returns></returns> public List <FunctionEntity> SelectAllFunctions() { string cache_key = "BB__AllFunction"; object o = MyCache <List <FunctionEntity> > .Get(cache_key); if (o == null) { DataTable dt = functiondao.GetAllFunction().Tables[0]; List <FunctionEntity> functions = new List <FunctionEntity>(); foreach (DataRow dr in dt.Rows) { FunctionEntity f = new FunctionEntity(); f.Function_URL_New = dr[7].ToString(); f.Function_ID = int.Parse(dr["Function_ID"].ToString()); f.Function_IsNew = int.Parse(dr["Function_IsNew"].ToString()); f.Function_isValid = int.Parse(dr["Function_isValid"].ToString()); f.Function_Level = int.Parse(dr["Function_Level"].ToString()); f.Function_Name = dr["Function_Name"].ToString(); f.Function_Order = dr["Function_Order"].ToString(); f.Function_ParentID = int.Parse(dr["Function_ParentID"].ToString()); f.Function_URL = dr["Function_URL"].ToString(); functions.Add(f); } if (functions.Count > 0) { MyCache <List <FunctionEntity> > .Insert(cache_key, functions); } return(functions); } else { return(o as List <FunctionEntity>); } }
public FunctionEntity Parse(TypedEntity typedEntity, string name, IEnumerable <XElement> elements) { FunctionEntity functionEntity = new FunctionEntity(); XElement declarationElement = (from el in elements where el.Name == "div" && el.Attribute("class") != null && el.Attribute("class").Value == "declaration_indent" select el).FirstOrDefault(); declarationElement = declarationElement ?? (from el in elements where el.Name == "pre" select el).FirstOrDefault(); XElement parameterElement = (from el in elements where el.Name == "div" && el.Attribute("class") != null && el.Attribute("class").Value == "param_indent" select el).FirstOrDefault(); XElement returnValueElement = (from el in elements where el.Name == "h5" && el.Value.Trim() == "Return Value" select el).FirstOrDefault(); //XElement discussionElement = (from el in elements // where el.Name == "h5" && el.Value.Trim() == "Discussion" // select el).FirstOrDefault(); XElement availabilityElement = (from el in elements let term = el.Descendants("dt").FirstOrDefault() let definition = el.Descendants("dd").FirstOrDefault() where el.Name == "dl" && term != null && term.Value.Trim() == "Availability" select definition).FirstOrDefault(); functionEntity.Name = name; String signature = declarationElement.TrimAll(); if (signature.StartsWith("#define")) { this.Logger.WriteLine("SKIPPING define statement: " + name); return(null); } functionEntity.Signature = signature; // Extract abstract IEnumerable <XElement> abstractElements = elements.SkipWhile(el => el.Name != "p").TakeWhile(el => el.Name == "p"); foreach (XElement element in abstractElements) { String line = element.TrimAll(); if (!String.IsNullOrEmpty(line)) { functionEntity.Summary.Add(line); } } //// Extract discussion //if (discussionElement != null) //{ // IEnumerable<XElement> discussionElements = discussionElement.ElementsAfterSelf().TakeWhile(el => el.Name == "p"); // foreach (XElement element in discussionElements) // { // String line = element.TrimAll(); // if (!String.IsNullOrEmpty(line)) // { // methodEntity.Summary.Add(line); // } // } //} // Parse signature signature = signature.Replace("extern", String.Empty).Trim(); int pos = signature.IndexOf(name); if (pos == -1) { this.Logger.WriteLine("MISMATCH between name and declaration: " + name); return(null); } String returnType = signature.Substring(0, pos).Trim(); String parameters = signature.Substring(pos + name.Length).Trim(); parameters = parameters.Trim(';', '(', ')'); if (parameters != "void") { foreach (string parameter in parameters.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { String parameterType = "NOTYPE"; String parameterName = "NONAME"; Match r = PARAMETER_REGEX.Match(parameter); if (r.Success) { parameterType = r.Groups [2].Value.Trim(); parameterName = r.Groups [3].Value.Trim(); } else if (parameter.Trim() == "...") { parameterType = "params Object[]"; parameterName = "values"; } else { this.Logger.WriteLine("FAILED to parse parameter: " + parameter); return(null); } MethodParameterEntity parameterEntity = new MethodParameterEntity(); bool isOut, isByRef, isBlock; parameterEntity.Type = this.TypeManager.ConvertType(parameterType, out isOut, out isByRef, out isBlock, this.Logger); parameterEntity.IsOut = isOut; parameterEntity.IsByRef = isByRef; parameterEntity.IsBlock = isBlock; parameterEntity.Name = TypeManager.ConvertName(parameterName); functionEntity.Parameters.Add(parameterEntity); } } // Extract return type functionEntity.ReturnType = this.TypeManager.ConvertType(returnType, this.Logger); if (functionEntity.Parameters.Count > 0 && parameterElement != null) { XElement termList = parameterElement.Descendants("dl").FirstOrDefault(); if (termList != null) { IEnumerable <XElement> dtList = from el in termList.Elements("dt") select el; IEnumerable <XElement> ddList = from el in termList.Elements("dd") select el; if (dtList.Count() == ddList.Count()) { // Iterate over definitions for (int i = 0; i < dtList.Count(); i++) { String term = dtList.ElementAt(i).TrimAll(); //String summary = ddList.ElementAt(i).TrimAll(); IEnumerable <String> summaries = ddList.ElementAt(i).Elements("p").Select(p => p.Value.TrimAll()); // Find the parameter MethodParameterEntity parameterEntity = functionEntity.Parameters.Find(p => String.Equals(p.Name, term)); if (parameterEntity != null) { //parameterEntity.Summary.Add(summary); foreach (string sum in summaries) { parameterEntity.Summary.Add(sum); } } } } } } // Fix the name only after looking for the documentation for (int i = 0; i < functionEntity.Parameters.Count; i++) { functionEntity.Parameters [i].Name = this.TypeManager.ConvertName(functionEntity.Parameters [i].Name); } // Get the summary for return type if (!String.Equals(functionEntity.ReturnType, "void", StringComparison.OrdinalIgnoreCase) && returnValueElement != null) { IEnumerable <XElement> returnTypeElements = returnValueElement.ElementsAfterSelf().TakeWhile(el => el.Name == "p"); functionEntity.ReturnsDocumentation = String.Empty; foreach (XElement element in returnTypeElements) { String line = element.TrimAll(); if (!String.IsNullOrEmpty(line)) { functionEntity.ReturnsDocumentation += line; } } } // Get the availability if (availabilityElement != null) { functionEntity.MinAvailability = CommentHelper.ExtractAvailability(availabilityElement.TrimAll()); } return(functionEntity); }
/// <summary> /// 保存数据 /// </summary> private void SaveFunctionBySubmit() { if (ValidForm()) { if (functionID > 0) { #region 修改 FunctionEntity updateEntity = bllFunc.QueryFunction(functionID); if (updateEntity != null) { int selFunLevel = int.Parse(this.selFunctionLevel.Value); if (selFunLevel == 0) { #region 修改成为一级菜单 updateEntity.Function_Name = this.txtFunctionName.Value.Trim(); updateEntity.Function_Order = this.txtFunctionOrder.Value.Trim(); updateEntity.Function_URL_New = string.Empty; updateEntity.Function_ParentID = 0; updateEntity.Function_Level = 1; bool isSuccess = bllFunc.Update(updateEntity); if (isSuccess) { RetrunPageAlert(enumPageAlert.Success); } else { RetrunPageAlert(enumPageAlert.Fail); } #endregion } else { #region 修改二级菜单 updateEntity.Function_Name = this.txtFunctionName.Value.Trim(); updateEntity.Function_URL_New = this.txtFunctionUrl.Value.Trim(); updateEntity.Function_Order = this.txtFunctionOrder.Value.Trim(); updateEntity.Function_Level = 2; updateEntity.Function_ParentID = selFunLevel; bool isSuccess = bllFunc.Update(updateEntity); if (isSuccess) { RetrunPageAlert(enumPageAlert.Success); } else { RetrunPageAlert(enumPageAlert.Fail); } #endregion } } else { this.RetrunPageAlert(enumPageAlert.NoExists); } #endregion } else { #region 保存 FunctionEntity funEntity = new FunctionEntity(); funEntity.Function_IsNew = 1; funEntity.Function_isValid = 1; funEntity.Function_Order = this.txtFunctionOrder.Value.Trim(); funEntity.Function_Name = this.txtFunctionName.Value.Trim(); funEntity.CreateDate = DateTime.Now; int selFunLevel = int.Parse(this.selFunctionLevel.Value); if (selFunLevel == 0) { #region 新建一级菜单 funEntity.Function_URL_New = string.Empty; funEntity.Function_ParentID = 0; funEntity.Function_Level = 1; bool isSuccess = bllFunc.Insert(funEntity); if (isSuccess) { RetrunPageAlert(enumPageAlert.Success); } else { RetrunPageAlert(enumPageAlert.Fail); } #endregion } else { #region 新建二级菜单 funEntity.Function_URL_New = this.txtFunctionUrl.Value.Trim(); funEntity.Function_Level = 2; funEntity.Function_ParentID = selFunLevel; bool isSuccess = bllFunc.Insert(funEntity); if (isSuccess) { RetrunPageAlert(enumPageAlert.Success); } else { RetrunPageAlert(enumPageAlert.Fail); } #endregion } #endregion } } }
/// <summary> /// 新建功能菜单 /// 默认给管理员角色添加该权限菜单 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Insert(FunctionEntity entity) { bool isSuccess = false; SqlTransaction trans = null; StringBuilder sbSql = new StringBuilder(); sbSql.Append(" INSERT INTO M_System_Function"); sbSql.Append(" (Function_Name,Function_URL,Function_ParentID,Function_Order,Function_isValid,Function_Level,Function_URL_New,Function_IsNew,CreateDate)"); sbSql.Append(" VALUES("); sbSql.Append(" @Function_Name,@Function_URL,@Function_ParentID,@Function_Order,@Function_isValid,@Function_Level,@Function_URL_New,@Function_IsNew,@CreateDate"); sbSql.Append(" );"); sbSql.Append(" SELECT @@IDENTITY;"); SqlParameter[] prms = { new SqlParameter("@Function_Name", SqlDbType.NVarChar, 20), new SqlParameter("@Function_URL", SqlDbType.NText), new SqlParameter("@Function_ParentID", SqlDbType.Int), new SqlParameter("@Function_Order", SqlDbType.NVarChar, 20), new SqlParameter("@Function_isValid", SqlDbType.Int), new SqlParameter("@Function_Level", SqlDbType.Int), new SqlParameter("@Function_URL_New", SqlDbType.NVarChar, 200), new SqlParameter("@Function_IsNew", SqlDbType.Int), new SqlParameter("@CreateDate", SqlDbType.DateTime) }; prms[0].Value = entity.Function_Name; prms[1].Value = entity.Function_URL; prms[2].Value = entity.Function_ParentID; prms[3].Value = entity.Function_Order; prms[4].Value = entity.Function_isValid; prms[5].Value = entity.Function_Level; prms[6].Value = entity.Function_URL_New; prms[7].Value = entity.Function_IsNew; prms[8].Value = entity.CreateDate; try { using (SqlConnection conn = new SqlConnection(SQlHelper.MyConnectStr)) { conn.Open(); trans = conn.BeginTransaction(); object result = SQlHelper.ExecuteScalar(trans, CommandType.Text, sbSql.ToString(), prms); int functionID = Convert.ToInt32(result); SqlParameter[] rolePrms = { new SqlParameter("@FunctionID", functionID), new SqlParameter("@RoleID", 100) //100是管理员角色ID }; //管理员添加该菜单权限 string insertRoleFunRelSql = "INSERT INTO M_System_Role_Fun_Rel(RFRel_FunctionID, RFRel_RoleID) VALUES(@FunctionID, @RoleID)"; int effectline = SQlHelper.ExecuteNonQuery(trans, CommandType.Text, insertRoleFunRelSql, rolePrms); string searchUserRoleRelSql = "SELECT [User_ID] FROM M_System_User_Role_Rel WHERE User_RoleID=@RoleID"; DataTable table = SQlHelper.ExecuteDataset(trans, CommandType.Text, searchUserRoleRelSql, rolePrms).Tables[0]; if (table != null && table.Rows.Count > 0) { string insertUserFunRelSql = "INSERT INTO M_System_User_Fun_Rel(UFRel_FunctionID, UFRel_UserID) VALUES(@FunctionID,@UserID)"; List <int> userIdList = table.AsEnumerable().Select(row => int.Parse(row.Field <string>("User_ID"))).ToList(); foreach (int userid in userIdList) { SqlParameter[] userPrms = { new SqlParameter("@FunctionID", functionID), new SqlParameter("@UserID", userid) }; int resultnum = SQlHelper.ExecuteNonQuery(trans, CommandType.Text, insertUserFunRelSql, userPrms); } } isSuccess = true; trans.Commit(); } } catch (Exception ex) { if (trans != null) { trans.Rollback(); } LogUtil.WriteLog(ex); return(false); } return(isSuccess); }
/// <summary> /// Parses the specified method element. /// </summary> /// <param name = "functionElement">The function element.</param> /// <returns></returns> public FunctionEntity Parse(TypedEntity typedEntity, XElement functionElement) { FunctionEntity functionEntity = new FunctionEntity(); // Extract name String name = functionElement.TrimAll(); functionEntity.Name = name; this.Logger.WriteLine(" Function '" + name + "'"); // Extract abstract XElement abstractElement = (from el in functionElement.ElementsAfterSelf("p") where (String)el.Attribute("class") == "abstract" select el).FirstOrDefault(); functionEntity.Summary.Add(abstractElement.TrimAll()); // Extract declaration XElement declarationElement = (from el in functionElement.ElementsAfterSelf("pre") where (String)el.Attribute("class") == "declaration" select el).FirstOrDefault(); String signature = declarationElement.TrimAll(); if (signature.StartsWith("#define")) { this.Logger.WriteLine("SKIPPING define statement: " + name); return(null); } if (signature.StartsWith("typedef")) { this.Logger.WriteLine("SKIPPING define statement: " + name); return(null); } if (!signature.Contains("(")) // e.g. NS_DURING { this.Logger.WriteLine("SKIPPING non-function statement: " + name); return(null); } // Trim down signature while (signature.IndexOf(" ") != -1) { signature = signature.Replace(" ", " "); } functionEntity.Signature = signature; //Console.WriteLine("signature='" + signature + "'"); // Parse signature int pos = signature.IndexOf(name); if (pos == -1) { this.Logger.WriteLine("MISMATCH between name and declaration: " + name); return(null); } String returnType = signature.Substring(0, pos).Trim(); int paramsIndex = pos + name.Length; int paramsLength = signature.IndexOf(')') + 1 - paramsIndex; // Stop before getting to function body String parameters = signature.Substring(paramsIndex, paramsLength).Trim(); parameters = parameters.Trim(';', '(', ')').Trim(); if (parameters != "void") { foreach (string parameter in parameters.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { String parameterType = "NOTYPE"; String parameterName = "NONAME"; //Console.WriteLine("parameter='" + parameter + "'"); Match r = PARAMETER_REGEX.Match(parameter); if (r.Success) { parameterType = r.Groups [2].Value.Trim(); parameterName = r.Groups [3].Value.Trim(); } else if (parameter.Trim() == "...") { parameterType = "params Object[]"; parameterName = "values"; } else { this.Logger.WriteLine("FAILED to parse parameter: " + parameter); return(null); } parameterType = parameterType.Trim(); MethodParameterEntity parameterEntity = new MethodParameterEntity(); bool isOut, isByRef, isBlock; parameterEntity.Type = this.TypeManager.ConvertType(parameterType, out isOut, out isByRef, out isBlock, this.Logger); parameterEntity.IsOut = isOut; parameterEntity.IsByRef = isByRef; parameterEntity.IsBlock = isBlock; parameterEntity.Name = TypeManager.ConvertName(parameterName); functionEntity.Parameters.Add(parameterEntity); } } // Extract return type functionEntity.ReturnType = this.TypeManager.ConvertType(returnType, this.Logger); // Extract parameter documentation if (functionEntity.Parameters.Count > 0) { XElement termList = (from el in functionElement.Elements("div").Elements("dl") where (String)el.Parent.Attribute("class") == "api parameters" && (String)el.Attribute("class") == "termdef" select el).FirstOrDefault(); if (termList != null) { IEnumerable <XElement> dtList = from el in termList.Elements("dt") select el; IEnumerable <XElement> ddList = from el in termList.Elements("dd") select el; if (dtList.Count() == ddList.Count()) { // Iterate over definitions for (int i = 0; i < dtList.Count(); i++) { String term = dtList.ElementAt(i).TrimAll(); IEnumerable <String> summaries = ddList.ElementAt(i).Elements("p").Select(p => p.Value.TrimAll()); // Find the parameter MethodParameterEntity parameterEntity = functionEntity.Parameters.Find(p => String.Equals(p.Name, term)); if (parameterEntity != null) { foreach (string sum in summaries) { parameterEntity.Summary.Add(sum); } } } } } } // Fix the name only after looking for the documentation for (int i = 0; i < functionEntity.Parameters.Count; i++) { functionEntity.Parameters [i].Name = this.TypeManager.ConvertName(functionEntity.Parameters [i].Name); } // Get the summary for return type if (!String.Equals(functionEntity.ReturnType, "void", StringComparison.OrdinalIgnoreCase)) { XElement returnValueElement = (from el in functionElement.ElementsAfterSelf("div") where (String)el.Attribute("class") == "return_value" select el).FirstOrDefault(); if (returnValueElement != null) { IEnumerable <String> documentations = returnValueElement.Elements("p").Select(p => p.Value.TrimAll()); functionEntity.ReturnsDocumentation = String.Join(String.Empty, documentations.ToArray()); } } //// Extract discussion //XElement discussionElement = (from el in functionElement.ElementsAfterSelf("div") // where (String) el.Attribute("class") == "api discussion" // select el).FirstOrDefault(); //if (discussionElement != null) //{ // foreach (XElement paragraph in discussionElement.Elements("p")) // { // functionEntity.Summary.Add(paragraph.TrimAll()); // } //} // Get the availability XElement availabilityElement = (from el in functionElement.ElementsAfterSelf("div") where (String)el.Attribute("class") == "api availability" select el).FirstOrDefault(); String minAvailability = availabilityElement.Elements("ul").Elements("li").FirstOrDefault().TrimAll(); functionEntity.MinAvailability = CommentHelper.ExtractAvailability(minAvailability); return(functionEntity); }
/// <summary> /// Returns a set of possible roots of a function, e. g. /// sin(x) = a => /// x = arcsin(a) + 2 pi n /// x = pi - arcsin(a) + 2 pi n /// </summary> /// <param name="func"></param> /// <param name="value"></param> /// <param name="x"></param> /// <returns></returns> public static Set InvertFunctionEntity(FunctionEntity func, Entity value, Entity x) { Entity a = func.Children[0]; Entity b = func.Children.Count == 2 ? func.Children[1] : null; int arg = func.Children.Count == 2 && func.Children[1].FindSubtree(x) != null ? 1 : 0; var n = Utils.FindNextIndex(func + value, "n"); var res = new Set(); var pi = MathS.pi; Set GetNotNullEntites(Set set) { return(set.FiniteWhere(el => el.entType != Entity.EntType.NUMBER || el.GetValue().IsDefinite())); } switch (func.Name) { // Consider case when sin(sin(x)) where double-mention of n occures case "sinf": { // sin(x) = value => x = arcsin(value) + 2pi * n res.AddRange(GetNotNullEntites(FindInvertExpression(a, MathS.Arcsin(value) + 2 * pi * n, x))); // sin(x) = value => x = pi - arcsin(value) + 2pi * n res.AddRange(GetNotNullEntites(FindInvertExpression(a, pi - MathS.Arcsin(value) + 2 * pi * n, x))); return(res); } case "cosf": { // cos(x) = value => x = arccos(value) + 2pi * n res.AddRange(GetNotNullEntites(FindInvertExpression(a, MathS.Arccos(value) + 2 * pi * n, x))); // cos(x) = value => x = -arccos(value) + 2pi * n res.AddRange(GetNotNullEntites(FindInvertExpression(a, -MathS.Arccos(value) - 2 * pi * n, x))); return(res); } case "tanf": { var inverted = FindInvertExpression(a, MathS.Arctan(value) + pi * n, x); // tan(x) = value => x = arctan(value) + pi * n res.AddRange(GetNotNullEntites(inverted)); return(res); } case "cotanf": { var inverted = FindInvertExpression(a, MathS.Arccotan(value) + pi * n, x); // cotan(x) = value => x = arccotan(value) res.AddRange(GetNotNullEntites(inverted)); return(res); } case "arcsinf": // arcsin(x) = value => x = sin(value) if (EntityInBounds(value, ArcsinFrom, ArcsinTo)) { return(GetNotNullEntites(FindInvertExpression(a, MathS.Sin(value), x))); } else { return(Empty); } case "arccosf": // arccos(x) = value => x = cos(value) if (EntityInBounds(value, ArccosFrom, ArccosTo)) { return(GetNotNullEntites(FindInvertExpression(a, MathS.Cos(value), x))); } else { return(Empty); } case "arctanf": // arctan(x) = value => x = tan(value) return(GetNotNullEntites(FindInvertExpression(a, MathS.Tan(value), x))); case "arccotanf": // arccotan(x) = value => x = cotan(value) return(GetNotNullEntites(FindInvertExpression(a, MathS.Cotan(value), x))); case "logf": if (arg != 0) { // log(x, a) = value => x = a ^ value return(GetNotNullEntites(FindInvertExpression(b, MathS.Pow(a, value), x))); } else { // log(a, x) = value => a = x ^ value => x = a ^ (1 / value) return(GetNotNullEntites(FindInvertExpression(a, MathS.Pow(b, 1 / value), x))); } default: throw new SysException("Unknown function"); } }
private static string GetFunctionInvocation(TypedEntity typedEntity, FunctionEntity functionEntity, FunctionEntity innerFunctionEntity, String suffix = null) { // Strip name if the prefix is the same String name = functionEntity.Name; if (name.StartsWith(typedEntity.Name)) { name = name.Substring(typedEntity.Name.Length); } StringBuilder builder = new StringBuilder(); builder.AppendFormat("{0}{1}(", name, suffix ?? String.Empty); builder.Append(GetMessageParameterList(functionEntity, innerFunctionEntity, false)); builder.Append(");"); return(builder.ToString()); }
protected void GenerateFunctionBody(int indent, TypedEntity typedEntity, FunctionEntity methodEntity, FunctionEntity innerMethodEntity, bool needStorage, String suffix = null) { bool hasReturn = !String.Equals(methodEntity.ReturnType, "void"); bool mixed = (innerMethodEntity != null); bool mixedReturnType = mixed && !String.Equals(methodEntity.ReturnType, innerMethodEntity.ReturnType); this.GenerateLocalsAllocation(indent, methodEntity, innerMethodEntity); this.GenerateLocalsMarshalling(indent, methodEntity, innerMethodEntity); String invocation = GetFunctionInvocation(typedEntity, methodEntity, innerMethodEntity, suffix); if (hasReturn) { if (needStorage) { String prefix = methodEntity.ReturnType + " __result = "; if (mixedReturnType) { prefix += "(" + methodEntity.ReturnType + ") "; } invocation = prefix + invocation; } else { String prefix = "return "; if (mixedReturnType) { prefix += "(" + methodEntity.ReturnType + ") "; } invocation = prefix + invocation; } } this.Writer.WriteLineFormat(indent, invocation); this.GenerateLocalsUnmarshalling(indent, methodEntity, innerMethodEntity); this.GenerateLocalsDeallocation(indent, methodEntity, innerMethodEntity); if (hasReturn && needStorage) { this.Writer.WriteLineFormat(indent, "return __result;"); } }
private void GenerateWrapperFunction(TypedEntity typedEntity, FunctionEntity functionEntity, FunctionEntity functionEntity32, FunctionEntity functionEntity64, bool needStorage) { bool useMixedInvocation = functionEntity32 != null && functionEntity64 != null; // Strip name if the prefix is the same String name = functionEntity.Name; if (name.StartsWith(typedEntity.Name)) { name = name.Substring(typedEntity.Name.Length); } StringBuilder signature = new StringBuilder(); signature.AppendFormat("public static {0} {1}(", functionEntity.ReturnType, name); // Append parameters List <String> parameters = new List <String> (); foreach (MethodParameterEntity methodParameterEntity in functionEntity.Parameters.Where(p => p.Generate)) { parameters.Add(GetTypeSignature(methodParameterEntity)); } signature.Append(String.Join(", ", parameters.ToArray())); signature.Append(")"); this.Writer.WriteLineFormat(2, signature.ToString()); this.Writer.WriteLineFormat(2, "{{"); if (useMixedInvocation) { #if MIXED_MODE this.Writer.WriteLineFormat(3, "if (ObjectiveCRuntime.Is64Bits)"); this.Writer.WriteLineFormat(3, "{{"); this.GenerateFunctionBody(4, typedEntity, functionEntity, functionEntity64, needStorage, SUFFIX_64); this.Writer.WriteLineFormat(3, "}}"); this.Writer.WriteLineFormat(3, "else"); this.Writer.WriteLineFormat(3, "{{"); #endif this.GenerateFunctionBody(4, typedEntity, functionEntity, functionEntity32, needStorage, SUFFIX_32); #if MIXED_MODE this.Writer.WriteLineFormat(3, "}}"); #endif } else { this.GenerateFunctionBody(3, typedEntity, functionEntity, null, needStorage, SUFFIX_INNER); } this.Writer.WriteLineFormat(2, "}}"); this.Writer.WriteLine(); }
private static Function ToFunctionModel(FunctionEntity function) => new()
private void createEntity(object sender, EventArgs e) { cGUID thisID = Utilities.GenerateGUID(DateTime.Now.ToString("G")); if (createDatatypeEntity.Checked) { //Make the DatatypeEntity DatatypeEntity newEntity = new DatatypeEntity(thisID); newEntity.type = (CathodeDataType)entityVariant.SelectedIndex; newEntity.parameter = Utilities.GenerateGUID(textBox1.Text); //Make the parameter to give this DatatypeEntity a value (the only time you WOULDN'T want this is if the val is coming from a linked entity) CathodeParameter thisParam = null; switch (newEntity.type) { case CathodeDataType.POSITION: thisParam = new CathodeTransform(); break; case CathodeDataType.FLOAT: thisParam = new CathodeFloat(); break; case CathodeDataType.FILEPATH: case CathodeDataType.STRING: thisParam = new CathodeString(); break; case CathodeDataType.SPLINE_DATA: thisParam = new CathodeSpline(); break; case CathodeDataType.ENUM: thisParam = new CathodeEnum(); ((CathodeEnum)thisParam).enumID = new cGUID("4C-B9-82-48"); //ALERTNESS_STATE is the first alphabetically break; case CathodeDataType.SHORT_GUID: thisParam = new CathodeResource(); ((CathodeResource)thisParam).resourceID = new cGUID("00-00-00-00"); break; case CathodeDataType.BOOL: thisParam = new CathodeBool(); break; case CathodeDataType.DIRECTION: thisParam = new CathodeVector3(); break; case CathodeDataType.INTEGER: thisParam = new CathodeInteger(); break; } newEntity.parameters.Add(new CathodeLoadedParameter(newEntity.parameter, thisParam)); //Add to flowgraph & save name flow.datatypes.Add(newEntity); if (NodeDB.GetCathodeName(newEntity.parameter) == newEntity.parameter.ToString()) { NodeDBEx.AddNewParameterName(newEntity.parameter, textBox1.Text); } NewEntity = newEntity; } else if (createFunctionEntity.Checked) { //Create FunctionEntity FunctionEntity newEntity = new FunctionEntity(thisID); switch (entityVariant.Text) { //TODO: find a nicer way of auto selecting this (E.G. can we reflect to class names?) case "CAGEAnimation": newEntity = new CAGEAnimation(thisID); break; case "TriggerSequence": newEntity = new TriggerSequence(thisID); break; } newEntity.function = CathodeEntityDatabase.GetEntityAtIndex(entityVariant.SelectedIndex).guid; //TODO: auto populate params here //Add to flowgraph & save name flow.functions.Add(newEntity); NodeDBEx.AddNewNodeName(thisID, textBox1.Text); NewEntity = newEntity; } else if (createFlowgraphEntity.Checked) { //Create FunctionEntity FunctionEntity newEntity = new FunctionEntity(thisID); CathodeFlowgraph selectedFlowgraph = availableFlows.FirstOrDefault(o => o.name == entityVariant.Text); if (selectedFlowgraph == null) { MessageBox.Show("Failed to look up flowgraph!\nPlease report this issue on GitHub.\n\n" + entityVariant.Text, "Could not find flowgraph!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } newEntity.function = selectedFlowgraph.nodeID; //Add to flowgraph & save name flow.functions.Add(newEntity); NodeDBEx.AddNewNodeName(thisID, textBox1.Text); NewEntity = newEntity; } this.Close(); }
/// <summary> /// 创建日期:2016/11/2 /// 功能介绍:根据当前用户加载左侧导航菜单方法 /// </summary> /// <param name="context"></param> public void LoadLeftMenu(HttpContext context) { var currentUserID = context.Session["UserID"].ToString(); var sessionUserID = ""; if (context.Session["CurrentUserID"] != null) { sessionUserID = context.Session["CurrentUserID"].ToString(); } if (context.Session["SecondMenu"] != null && context.Session["FirstMenu"] != null && sessionUserID == currentUserID) { var tempSecondMenu = context.Session["SecondMenu"] as List <FunctionService.FunctionEntity>; var tempFirstMenu = context.Session["FirstMenu"] as List <FunctionService.FunctionEntity>; context.Response.Write(JsonConvert.SerializeObject(new { secondMenu = tempSecondMenu, firstMenu = tempFirstMenu })); context.Response.End(); } var loginName = Common.GetSessionValue("loginName", context); if (loginName == null) { return; } var EnterpriseCode = Common.GetSessionValue("EnterpriseCode", context); if (EnterpriseCode == null) { return; } var us = MgrServices.UserAddService.GetEntityInfo(loginName, EnterpriseCode); //根据当前登录用户名获取当前登录用户信息 List <int> lThirdFunID = MgrServices.FunctionService.GetRoleFun(Convert.ToInt32(us._r_id)); //得到当前用户的三级权限ID List <FunctionService.FunctionEntity> lThirdFun = new List <FunctionService.FunctionEntity>(); List <FunctionService.FunctionEntity> secondMenu = new List <FunctionService.FunctionEntity>(); //实例化一个二级菜单集合 DataRow[] WD_DTR; DataTable dt = MgrServices.FunctionService.GetFunByFID(); for (int i = 0; i < lThirdFunID.Count; i++)//循环查找三级权限父ID的二级权限 { //var funEntity = MgrServices.FunctionService.GetEntity(lThirdFunID[i]); //var secondFunEntity = MgrServices.FunctionService.GetEntity(funEntity.Fun_ParentID); FunctionEntity model = new FunctionEntity(); WD_DTR = dt.Select(" Fun_ID ='" + lThirdFunID[i] + "' "); if (WD_DTR.Length > 0) { var SenconfunID = WD_DTR[0]["Fun_ParentID"]; var WD_DTRs = dt.Select(" Fun_ID ='" + SenconfunID + "' "); model.Fun_ID = Convert.ToInt32(WD_DTRs[0]["Fun_ID"]); model.Fun_Name = WD_DTRs[0]["Fun_Name"].ToString(); model.Fun_ParentID = Convert.ToInt32(WD_DTRs[0]["Fun_ParentID"]); model.Fun_Type = Convert.ToInt32(WD_DTRs[0]["Fun_Type"]); model.Fun_Url = WD_DTRs[0]["Fun_Url"].ToString(); } secondMenu.Add(model); } //去除二级权限重复数据 for (int i = 0; i < secondMenu.Count; i++) //外循环是循环的次数 { for (int j = secondMenu.Count - 1; j > i; j--) //内循环是 外循环一次比较的次数 { if (secondMenu[i].Fun_ID == secondMenu[j].Fun_ID) { secondMenu.RemoveAt(j); } } } secondMenu = secondMenu.OrderBy(x => x.Fun_ID).ToList();; List <FunctionService.FunctionEntity> firstMenu = new List <FunctionService.FunctionEntity>(); //实例化一级菜单 for (int i = 0; i < secondMenu.Count; i++) //循环二级菜单Fun_ID得到一级菜单 { FunctionEntity funEntity = new FunctionEntity(); //var funEntitys = MgrServices.FunctionService.GetEntity(secondMenu[i].Fun_ParentID); var WD_DTRs = dt.Select("Fun_ID ='" + secondMenu[i].Fun_ParentID + "' "); if (WD_DTRs.Length > 0) { funEntity.Fun_ID = Convert.ToInt32(WD_DTRs[0]["Fun_ID"]); funEntity.Fun_Name = WD_DTRs[0]["Fun_Name"].ToString(); if (WD_DTRs[0]["Fun_ParentID"].ToString().Length > 0) { funEntity.Fun_ParentID = Convert.ToInt32(WD_DTRs[0]["Fun_ParentID"]); } funEntity.Fun_Type = Convert.ToInt32(WD_DTRs[0]["Fun_Type"]); funEntity.Fun_Url = WD_DTRs[0]["Fun_Url"].ToString(); } if (funEntity != null) { firstMenu.Add(funEntity); } } //去除一级权限重复值 for (int i = 0; i < firstMenu.Count; i++) //外循环是循环的次数 { for (int j = firstMenu.Count - 1; j > i; j--) //内循环是 外循环一次比较的次数 { if (firstMenu[i].Fun_ID == firstMenu[j].Fun_ID) { firstMenu.RemoveAt(j); } } } context.Session["SecondMenu"] = secondMenu; context.Session["FirstMenu"] = firstMenu; context.Session["CurrentUserID"] = context.Session["UserID"]; context.Response.Write(JsonConvert.SerializeObject(new { secondMenu = secondMenu, firstMenu = firstMenu })); }
/// <summary> /// Parses the function interpreting "Math.Sqr" as sqr /// TODO /// </summary> /// <param name="linq"></param> /// <returns></returns> private static Entity InnerParse(Expression linq) { var unary = linq as UnaryExpression; var binary = linq as BinaryExpression; switch (linq.NodeType) { case ExpressionType.Lambda: return(InnerParse((linq as LambdaExpression).Body)); case ExpressionType.Constant: return(new NumberEntity(new Number((linq as ConstantExpression).Value))); case ExpressionType.Parameter: return(new VariableEntity((linq as ParameterExpression).Name)); case ExpressionType.Negate: return(-1 * InnerParse(unary.Operand)); case ExpressionType.UnaryPlus: return(1 * InnerParse(unary.Operand)); case ExpressionType.Add: return(InnerParse(binary.Left) + InnerParse(binary.Right)); case ExpressionType.Subtract: return(InnerParse(binary.Left) - InnerParse(binary.Right)); case ExpressionType.Multiply: return(InnerParse(binary.Left) * InnerParse(binary.Right)); case ExpressionType.Divide: return(InnerParse(binary.Left) / InnerParse(binary.Right)); case ExpressionType.Power: return(MathS.Pow(InnerParse(binary.Left), InnerParse(binary.Right))); case ExpressionType.Call: var method = linq as MethodCallExpression; var children = method.Arguments.Select(InnerParse).ToList(); var methodInfo = method.Method; var name = methodInfo.Name.ToLower() + "f"; if (name == "powf") // The only operator that acts as function { var op = new OperatorEntity(name, Const.PRIOR_POW) { Children = children }; return(op); } else if (SynonymFunctions.SynFunctions.ContainsKey(name)) { return(SynonymFunctions.SynFunctions[name](children)); } else { var func = new FunctionEntity(name) { Children = children }; return(func); } default: throw new ParseException("Parse error"); } }