/// <summary> /// 获取子节点 /// </summary> /// <param name="parentModule"></param> /// <param name="modules"></param> //public void GetChildren(NodeInfo parentModule, IList<Sys_Module> modules) //{ // int key = Int32.Parse(parentModule.id); // var childrenModule = modules.Where(c => c.ParentId == key && c.IsDel == 0 && c.ModuleLevel != 3).OrderBy(c => c.Sort); // NodeInfo childrenNode = null; // foreach (Sys_Module module in childrenModule) // { // childrenNode = new NodeInfo() // { // id = module.ModuleId.ToString(), // icon = module.Icon, // text = module.ModuleName, // level = module.ModuleLevel // }; // var children = modules.FirstOrDefault(c => c.ParentId == module.ModuleId && c.IsDel == 0 && c.ModuleLevel != 3); // if (children != null) // { // GetChildren(childrenNode, modules); // } // else // { // childrenNode.nodes = null; // } // parentModule.nodes.Add(childrenNode); // } //} #endregion #region 新增,编辑模块页面 /// <summary> /// 新增,编辑模块页面 /// </summary> /// <returns></returns> public ActionResult ModuleInfo() { var module = new SysModule(); ModuleViewMoudle viewModel = new ModuleViewMoudle(); string action = Request.QueryString["method"]; string moduleKey = Request.QueryString["moduleKey"]; if (moduleKey.IsNullOrEmpty()) { moduleKey = "0"; } ViewData["BtnIdList"] = ModuleServer.GetBtnSelectList(SysConfigEnum.BtnFunction); ViewData["BtnClassList"] = ModuleServer.GetBtnSelectList(SysConfigEnum.BtnClass); ViewData["BtnSizeList"] = ModuleServer.GetBtnSelectList(SysConfigEnum.BtnSize); ViewData["IsAuthorize"] = ModuleServer.GetBtnSelectList(SysConfigEnum.IsAuthorize); switch (action) { case "add": ViewBag.Title = "新增模块资源"; module.ParentId = moduleKey; module.IsDisplay = true; if (module.ParentId == "0") { module.ModuleLevel = 1; } else { var parentModule = db.SysModule.SingleOrDefault(a => a.ModuleId == module.ParentId); if (parentModule != null) { module.ModuleLevel = ++parentModule.ModuleLevel; } } break; case "edit": ViewBag.Title = "编辑模块"; module = db.SysModule.SingleOrDefault(a => a.ModuleId == moduleKey); if (!module.BtnClass.IsNullOrEmpty()) { var c = module.BtnClass.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); viewModel.BtnClass = String.Format("{0} {1}", c[0], c[1]); viewModel.BtnSize = c[2]; } break; } var m = db.SysModule.FirstOrDefault(c => c.ModuleId == module.ParentId); if (m != null) { viewModel.ParentModuleName = m.ModuleName; } else { viewModel.ParentModuleName = "模块资源"; } viewModel.SysModule = module; return(View(viewModel)); }
public string GetModuleTree() { ModuleServer server = new ModuleServer(); string parentId = Request.QueryString["id"]; if (parentId.IsNullOrEmpty()) { return(server.GetRootTree()); } return(server.GetNode(parentId)); }
protected override void OnCreate(Bundle savedInstanceState) { #region Android Stuff base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab); fab.Click += FabOnClick; #endregion consoleOutput = FindViewById <TextView>(Resource.Id.ConsoleOutput); titleLabel = FindViewById <TextView>(Resource.Id.titleLabel); CommandBar = FindViewById <EditText>(Resource.Id.CommandBar); // Sets up the base console system ClientServer = new ModuleServer(ref CommQueue); int id = ClientServer.ID; ConsoleClient = new ConsoleModule(ref CommQueue); id = ConsoleClient.ID; ConsoleClient.ConsolePostEvent += ConsoleClient_MessageRxEvent; ClientServer.Subscribe(ConsoleClient); // Sets up the networking and port system TCPClient = new NetworkingTCPClient(ref CommQueue); ClientServer.Subscribe(TCPClient); CommandBar.KeyPress += (object sender, View.KeyEventArgs e) => { e.Handled = false; if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter) { Toast.MakeText(this, "Message Transmitting!", ToastLength.Short).Show(); e.Handled = true; ClientServer.SendMessage("Post", new List <string>() { "Command: " + CommandBar.Text }, ConsoleClient.ID); // Updates the console List <string> arguments = CommandSyntaxInterpreter.ParseMessageBySpace(CommandBar.Text); // Finds the arguments based on the location of spaces string command = arguments[0]; // Extracts the actual command arguments.RemoveAt(0); // Removes the command from the list of arguments ClientServer.SendMessage(command, arguments); // Sends the command CommandBar.Text = ""; } }; }
/// <summary> /// Converts the string representation of a command to a Command object. /// A return value indicates whether the conversion succeded or not. /// </summary> /// <param name="s">A string containing the command to convert</param> /// <param name="localEndpoint">The remote endpoint source of the string</param> /// <param name="destination">The module which received the command</param> /// <param name="cmd">When this method returns, contains the Command equivalent to the command /// contained in s, if the conversion succeeded, or null if the conversion failed. /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format. /// This parameter is passed uninitialized</param> /// <param name="ex">When this method returns, contains the Exception generated during the parse operation, /// if the conversion failed, or null if the conversion succeeded. The conversion fails if the s parameter /// is a null reference (Nothing in Visual Basic) or is not of the correct format. /// This parameter is passed uninitialized</param> /// <returns>A command object that represents the command contained in s</returns> protected static bool TryParse(string s, System.Net.IPEndPoint localEndpoint, ModuleServer destination, out Command cmd, out Exception ex) { Regex rx; Match m; Prototype proto; //Module source; //Module destination; IModule src; IModule dest; string sCommand; string sParams; string sSrc; string sDest; string sId; int id; cmd = null; ex = null; // Regular Expresion Generation rx = rxCommandFromEndpoint; m = rx.Match(s); // Check if input string matchs Regular Expression if (!m.Success) { ex = new ArgumentException("Invalid String", "s"); return false; } // Extract Data sCommand = m.Result("${cmd}").ToLower(); if (!destination.SupportCommand(sCommand)) { ex = new Exception("Unsupported command provided"); return false; } sParams = m.Result("${params}"); sId = m.Result("${id}"); sSrc = m.Result("${src}"); sDest = m.Result("${dest}"); if ((sId == null) || (sId.Length < 1)) id = -1; else id = Int32.Parse(sId); // When at least one module is specified... if ((sSrc != null) && (sSrc.Length > 0)) { // If only one module is specified, there is two options: // the specified module is this (and we dont know the source module) or // the specified module is the source module if ((sDest == null) || (sDest.Length < 1)) { if (sSrc == destination.Name) dest = destination; else src = new Module(sSrc, localEndpoint.Address, localEndpoint.Port); } // If both, source and destination module are specified, since there is no // way of get the source module, a new one is created. // However its necesary to check if this is the apropiate destination module else { if (sDest != destination.Name) throw new Exception("Invalid destination module"); dest = destination; src = new Module(sSrc, localEndpoint.Address, localEndpoint.Port); } } // If no module is specified, then its set to null src = null; // Browse for an adequate prototype proto = destination.Prototypes[sCommand]; // Check if command matchs a prototype if ((proto != null) && proto.ParamsRequired && ((sParams == null) || (sParams.Length < 1))) { ex = new Exception("Invalid string. The Command requires parameters"); return false; } // Create the Command cmd = new Command(src, destination, sCommand, sParams, id); cmd.prototype = proto; cmd.sentTime = DateTime.Now; return true; }