//fill this method in with code which will execute once //when the module is added, when "initialize" is selected from the context menu, //or when the engine restart button is pressed public override void Initialize() { ModuleView mv = MainWindow.theNeuronArray.FindModuleByLabel("Robot"); if (mv == null) { return; } base.mv.Height = mv.Height; if (mv != null) { for (int i = 0; i < mv.Height; i++) { base.mv.GetNeuronAt(0, i).Label = mv.GetNeuronAt(0, i).Label; if (base.mv.GetNeuronAt(0, i).Label != ".") { base.mv.GetNeuronAt(1, i).Label = " <<"; base.mv.GetNeuronAt(2, i).Label = " <"; base.mv.GetNeuronAt(3, i).Label = " --"; base.mv.GetNeuronAt(4, i).Label = " >"; base.mv.GetNeuronAt(5, i).Label = " >>"; } } } MainWindow.Update(); }
public RakunModuleViewModel(RakunNodeBase Module, RakunViewerUserControl _View, ModuleView _Root) { ModuleInfo = Module.Clone() as RakunNodeBase; Parent = _View; Root = _Root; if (Module.NodeType == RakunNodeBase.RakunNodeType.For) { _ModuleValues.Add(new RakunValueNodeViewModel(new RakunNode() { NodeName = "index", type = RakunType.ValueName }, Root, _View, this)); } if (Module.NodeType == RakunNodeBase.RakunNodeType.If) { //_ModuleValues.Add(new RakunValueNodeViewModel(new RakunNode() { NodeName = "Condition", type = RakunType.ValueName }, Root, _View, this)); } if (ModuleInfo.rootNode != null) { foreach (RakunNode node in ModuleInfo.rootNode.Rakunlist) { _ModuleValues.Add(new RakunValueNodeViewModel(node, Root, _View, this)); } } }
//did the neuron associated with a thing fire? //firing at least minPastCycles but not more than maxPastCycles ago public bool Fired(Thing t, long maxPastCycles = 1, bool firedInput = true, long minPastCycles = 0) { int i = UKS.IndexOf(t); ModuleView naModule = na; if (!firedInput) { naModule = GetOutputModule(); if (naModule == null) { return(false); } } Neuron n = naModule.GetNeuronAt(i); if (n == null) { return(false); } long timeSinceLastFire = MainWindow.theNeuronArray.Generation - n.LastFired; bool retVal = timeSinceLastFire <= maxPastCycles; if (retVal) { retVal = timeSinceLastFire >= minPastCycles; } return(retVal); }
/// <summary> /// 获取模块权限列表 /// </summary> protected void BindModules() { if (TID.Text != "") { BLL.BASE_MODULE Mbll = new BLL.BASE_MODULE(); DataSet ds = Mbll.GetModuleList2(TID.Text); ModuleView.DataSource = ds; ModuleView.DataBind(); if (ds.Tables[0].Rows.Count == 0) { btn_AllSave.Visible = false; } else { btn_AllSave.Visible = true; } } else { btn_AllSave.Visible = false; ModuleView.DataSource = null; ModuleView.DataBind(); } }
public void SecondDataReadWrite() { var modview = new ModuleView() { name = "test", code = @" function default(uid, data) if data != nil then setdata(""myval"", data) end return getdata(""myval"") end" }; var mod = service.UpdateModule(modview); var result = service.RunCommand("test", "something", new Requester() { userId = 8 }); Assert.Equal("something", result); result = service.RunCommand("test", null, new Requester() { userId = 8 }); Assert.Equal("something", result); }
public void ArgTyping(string type, string data, string expected) { //The subcommands variable exists but is the wrong type, the module system shouldn't care var modview = new ModuleView() { name = "test", code = @" subcommands = {[""wow""]={[""arguments""]={""first_" + type + @"""}} } function command_wow(uid, data) return type(data) end" }; userService.WriteAsync(new UserViewFull() { username = "******" }, new Requester() { system = true }).Wait(); var mod = service.UpdateModule(modview); var result = service.RunCommand("test", "wow " + data, new Requester() { userId = 8 }); Assert.Equal(expected, result); }
//fill this method in with code which will execute //once for each cycle of the engine public override void Fire() { Init(); //be sure to leave this here ModuleView naSource = theNeuronArray.FindModuleByLabel("UKS"); if (naSource == null) { return; } uks = (ModuleUKS)naSource.TheModule; Thing mentalModel = uks.GetOrAddThing("MentalModel", "Visual"); Thing wordParent = uks.GetOrAddThing("Word", "Audible"); Thing attn = uks.GetOrAddThing("ATTN", "Thing"); Thing attnVisualTarget = attn.GetReferenceWithAncestor(mentalModel); Thing attnAudibleTarget = attn.GetReferenceWithAncestor(wordParent); AssociateWordsWithVisuals(attnAudibleTarget); //if you want the dlg to update, use the following code whenever any parameter changes if (dlg != null && !((ModuleAssociationDlg)dlg).busy) { UpdateDialog(); } }
public void PrntDbg(params string[] allmessages) { var modview = new ModuleView() { name = "test", code = @" function default(uid, data) prntdbg(""Logging here!"") end" }; var mod = service.UpdateModule(modview); foreach (var message in allmessages) { service.RunCommand("test", message, new Requester() { userId = 8 }); } Assert.Equal(allmessages.Length, mod.debug.Count); for (int i = 0; i < allmessages.Length; i++) { Assert.Equal($"[8:default|{allmessages[i]}] Logging here!", mod.debug.ElementAt(i).Substring(0, mod.debug.ElementAt(i).IndexOf("(") - 1)); } }
[InlineData(3600 * 24 * 365 * 8 + 50, "8 years ago")] //Ah boy, years public void TimeSinceTimestamp(double subtractSeconds, string expected) { //The subcommands variable exists but is the wrong type, the module system shouldn't care var modview = new ModuleView() { name = "test", code = @" function default(uid, time) return timesincetimestamp(time) end" }; userService.WriteAsync(new UserViewFull() { username = "******" }, new Requester() { system = true }).Wait(); var mod = service.UpdateModule(modview); var result = service.RunCommand("test", DateTime.Now.Subtract(TimeSpan.FromSeconds(subtractSeconds)).ToString(), new Requester() { userId = 8 }); Assert.Equal(expected, result); }
public void SetGetData_Arbitrary(string data) { //The subcommands variable exists but is the wrong type, the module system shouldn't care var modview = new ModuleView() { name = "test", code = @" function default(uid, data) setdata(""key"", data) return getdata(""key"") end" }; userService.WriteAsync(new UserViewFull() { username = "******" }, new Requester() { system = true }).Wait(); var mod = service.UpdateModule(modview); var result = service.RunCommand("test", data, new Requester() { userId = 8 }); Assert.Equal(data, result); }
public void SubcommandArguments_User() { //The subcommands variable exists but is the wrong type, the module system shouldn't care var modview = new ModuleView() { name = "test", code = @" subcommands = {[""wow""]={[""arguments""]={""first_user"",""second_user""}} } function command_wow(uid, user1, user2) return ""Id: "" .. uid .. "" User1: "" .. user1 .. "" User2: "" .. user2 end" }; //Fragile test, should inject a fake user service that always says the user is good. oh well userService.WriteAsync(new UserViewFull() { username = "******" }, new Requester() { system = true }).Wait(); userService.WriteAsync(new UserViewFull() { username = "******" }, new Requester() { system = true }).Wait(); var mod = service.UpdateModule(modview); var result = service.RunCommand("test", "wow 1 2(lol_username!)", new Requester() { userId = 8 }); Assert.Equal("Id: 8 User1: 1 User2: 2", result); }
public void SubcommandArguments_Mixed() { //The subcommands variable exists but is the wrong type, the module system shouldn't care var modview = new ModuleView() { name = "test", code = @" subcommands = {[""wow""]={[""arguments""]={""first_user"",""second_word"",""third_freeform""}} } function command_wow(uid, user, word, freeform) return ""Id: "" .. uid .. "" User: "" .. user .. "" Word: "" .. word .. "" Freeform: "" .. freeform end" }; userService.WriteAsync(new UserViewFull() { username = "******" }, new Requester() { system = true }).Wait(); var mod = service.UpdateModule(modview); var result = service.RunCommand("test", "wow 1(somebody) kills a lot of people", new Requester() { userId = 8 }); Assert.Equal("Id: 8 User: 1 Word: kills Freeform: a lot of people", result); }
private void HandleSpeechIn1() { ModuleView naIn = MainWindow.theNeuronArray.FindModuleByLabel("ModuleSpeechIn"); if (naIn == null) { return; } naIn.BeginEnum(); for (Neuron n = naIn.GetNextNeuron(); n != null; n = naIn.GetNextNeuron()) { if (!n.InUse()) { break; } if (n.LastCharge == 1) { if (theInPhrase != "") { theInPhrase += " "; } theInPhrase += n.Label; return; } } if (theInPhrase != "") { phraseIsComplete = true; } }
public override void DeleteThing(Thing t) { int i = UKS.IndexOf(t); base.DeleteThing(t); //because we removed a node, any external synapses to related neurons need to be adjusted to point to the right place //on any neurons which might have shifted. if (i > -1) { for (int j = i + 1; j < na.NeuronCount; j++) { Neuron targetNeuron = na.GetNeuronAt(j - 1); Neuron sourceNeuron = na.GetNeuronAt(j); MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron); } //repeat this process for the output array ModuleView naModule = theNeuronArray.FindAreaByLabel("KBOut"); if (naModule != null) { for (int j = i + 1; j < naModule.NeuronCount; j++) { Neuron targetNeuron = naModule.GetNeuronAt(j - 1); Neuron sourceNeuron = naModule.GetNeuronAt(j); MainWindow.thisWindow.theNeuronArrayView.MoveOneNeuron(sourceNeuron, targetNeuron); } } } UpdateNeuronLabels(); }
//fill this method in with code which will execute //once for each cycle of the engine public override void Fire() { Init(); //be sure to leave this here ModuleView naSource = theNeuronArray.FindModuleByLabel("UKS"); if (naSource == null) { return; } uks = (ModuleUKS)naSource.TheModule; GetSegmentsFromUKS(); if (boundaries.Count > 120) { return; //TODO startup hack } FindCorners(); ConnectCorners(); FindAreas(); GetAreaGreatesLengths(); GetAreaCentroids(); GetAreaColors(); SetAreasToUKS(); //if you want the dlg to update, use the following code whenever any parameter changes // UpdateDialog(); }
/// <summary> /// 获取模块权限列表 /// </summary> protected void BindModules() { if (Rid.Text != "") { BLL.BASE_MODULE Mbll = new BLL.BASE_MODULE(); DataSet ds = Mbll.GetModuleList2(ModuleTypeList.SelectedValue); ModuleView.DataSource = ds; ModuleView.DataBind(); if (ds.Tables[0].Rows.Count == 0) { btn_AllSave.Visible = false; } else { if (Code.UserHandle.ValidationHandle(Code.Tag.Grant)) { btn_AllSave.Visible = true; } else { btn_AllSave.Visible = false; } } } else { btn_AllSave.Visible = false; ModuleView.DataSource = null; ModuleView.DataBind(); } }
private void HandleSpeechIn1() { ModuleView naIn = MainWindow.theNeuronArray.FindModuleByLabel("ModuleSpeechIn"); if (naIn == null) { return; } foreach (Neuron n in naIn.Neurons) { if (!n.InUse()) { break; } if (n.LastCharge == 1) { if (theInPhrase != "") { theInPhrase += " "; } theInPhrase += n.Label; return; } } if (theInPhrase != "") { phraseIsComplete = true; } }
public void SecondDataReadWrite() { var modview = new ModuleView() { name = "test", code = @" function command_wow(uid, data) setdata(""myval"", ""something"") return getdata(""myval"") end function command_wow2(uid, data) return getdata(""myval"") end" }; var mod = service.UpdateModule(modview); var result = service.RunCommand("test", "wow", "whatever", new Requester() { userId = 8 }); Assert.Equal("something", result); result = service.RunCommand("test", "wow2", "whatever", new Requester() { userId = 8 }); Assert.Equal("something", result); }
Point GetStrokeMiddle(int x1, int y1, double direction, out float length) { //TODO add improved boundary detection to replace == backgroundColor int maxSearch = 20; Point retVal = new Point(0, 0); length = -1; ModuleView naSourceImage = theNeuronArray.FindAreaByLabel("ModuleImageFile"); if (naSourceImage == null) { return(retVal); } double dx = Cos(direction); double dy = Sin(direction); int start = 0; int end = 0; double x = x1; double y = y1; for (int i = 1; i < maxSearch; i++) { x += dx; y += dy; Neuron n = naSourceImage.GetNeuronAt((int)x, (int)y); if (n != null && n.LastChargeInt == backgroundColor) { end = i; break; } if (i == maxSearch - 1) { return(retVal); } } x = x1; y = y1; for (int i = 1; i < maxSearch; i++) { x -= dx; y -= dy; Neuron n = naSourceImage.GetNeuronAt((int)x, (int)y); if (n != null && n.LastChargeInt == backgroundColor) { start = -i; break; } if (i == maxSearch - 1) { return(retVal); } } double midPoint = (start + end) / 2f; retVal = new Point(x1 + midPoint * dx, y1 + midPoint * dy); length = end - start; return(retVal); }
public RakunValueNodeViewModel(RakunNode _Module, ModuleView _Root, RakunViewerUserControl _Parent, RakunModuleViewModel _ModuleViewModle) { Parent = _Parent; Module = _Module; Root = _Root; ModuleViewModle = _ModuleViewModle; ChangedName = ValueName; }
//display history of KB public override void Fire() { Init(); //be sure to leave this here string tempString = ""; ModuleView naKB = theNeuronArray.FindModuleByLabel("Module2DKB"); if (naKB == null) { return; } for (int x = 0; x < naKB.Width; x += 2) { for (int y = 0; y < naKB.Height; y++) { Neuron n = naKB.GetNeuronAt(x, y); if (n.Fired()) { tempString += " " + n.Label; } } } if (tempString != "" && tempString != history.LastOrDefault()) { lock (history) { history.Add(tempString); } } tempString = ">>>>"; for (int x = 1; x < naKB.Width; x += 2) { for (int y = 0; y < naKB.Height; y++) { Neuron n = naKB.GetNeuronAt(x, y); if (n.Fired()) { Neuron n1 = naKB.GetNeuronAt(x - 1, y); tempString += " " + n1.Label; } } } if (tempString != ">>>>") { lock (history) { history.Add(tempString); } } lock (history) { while (history.Count > maxLength) { history.RemoveAt(0); } } UpdateDialog(); }
public ModuleView CreateModuleView(ModuleView moduleView) { using var context = new DeviserDbContext(_dbOptions); var dbModuleView = _mapper.Map <Entities.ModuleView>(moduleView); var result = context.ModuleView.Add(dbModuleView).Entity; context.SaveChanges(); return(_mapper.Map <ModuleView>(result)); }
private void ExecuteClose(object sender, ExecutedRoutedEventArgs e) { TabItem tab = (TabItem)ContentView.Items[ContentView.SelectedIndex]; ModuleView modView = (ModuleView)tab.Tag; modView.Module.DestroyView(); ContentView.Items.Remove(tab); e.Handled = true; }
//display history of KB public override void Fire() { Init(); //be sure to leave this here string tempString = ""; ModuleView naKB = theNeuronArray.FindAreaByLabel("Module2DKB"); if (naKB == null) { return; } for (int i = 0; i < naKB.NeuronCount; i++) { Neuron n = naKB.GetNeuronAt(i); if (n.Fired()) { tempString += " " + n.Label; } } if (tempString != "" && tempString != history.LastOrDefault()) { lock (history) { history.Add(tempString); } } tempString = ">>>>"; ModuleView naKBOut = theNeuronArray.FindAreaByLabel("KBOut"); if (naKBOut == null) { return; } for (int i = 0; i < naKBOut.NeuronCount; i++) { Neuron n = naKBOut.GetNeuronAt(i); if (n.Fired()) { tempString += " " + n.Label; } } if (tempString != ">>>>") { lock (history) { history.Add(tempString); } } lock (history) { while (history.Count > maxLength) { history.RemoveAt(0); } } UpdateDialog(); }
public void BasicCreate() { var modview = new ModuleView() { name = "test", code = "--wow" }; var mod = service.UpdateModule(modview); Assert.True(mod.script != null); }
//maintain a list of objects in the current visual field public void FireVisibleObjects() { ModuleView naUKS = theNeuronArray.FindAreaByLabel("Module2DUKS"); if (naUKS == null) { return; } ModuleUKSN UKS = (ModuleUKSN)naUKS.TheModule; if (UKSSegments == null) { return; } //Thing tVisible = UKS.Labeled("Visible"); //clear all visiblility references //for (int i = 0; i < UKSSegments.Count; i++) // UKSSegments[i].RemoveReference(tVisible); ModuleView naVision = theNeuronArray.FindAreaByLabel("Module2DVision"); if (naVision == null) { return; } int possibleViewAngles = naVision.Width; float deltaTheta = Module2DVision.fieldOfView / possibleViewAngles; for (int i = 0; i < possibleViewAngles; i++) { float theta = (float)-Module2DVision.fieldOfView / 2 + (i * deltaTheta); PointPlus P = new PointPlus { R = 10, Theta = theta }; foreach (Thing t in UKSSegments) { Segment s = SegmentFromUKSThing(t); if (s == null) { continue; } Utils.FindIntersection(new Point(0, 0), P.P, s.P1.P, s.P2.P, out bool lines_intersect, out bool segments_intersect, out Point intersection, out Point close_p1, out Point closep2, out double collisionAngle); if (segments_intersect) { //TODO...only fire the closest at each point UKS.Fire(t); // t.AddReference(tVisible); } } } }
/// <summary> /// 获取发起页面的菜单权限 /// </summary> /// <returns>System.String.</returns> public string LoadAuthorizedMenus(string modulecode) { AuthStrategyContext user = _authUtil.GetCurrentUser(); ModuleView module = user.Modules.FirstOrDefault(u => u.Code == modulecode); if (module != null) { return(JsonHelper.Instance.Serialize(module.Elements)); } return(""); }
public override void Fire() { Init(); //be sure to leave this here to enable use of the na variable if (commands == null) { return; } if (line >= commands.Length) { return; } string[] commandLine = commands[line].Split(' '); if (commandLine.Length > 0 && commandLine[0].IndexOf("//") != 0) { for (int i = 0; i < commandLine.Length; i++) { string currentCommand = commandLine[i]; if (currentCommand == "Stop") { line = commands.Length; return; } if (currentCommand == "Loop") { line = 0; return; } if (currentCommand == "Wait-for") { SetCurrentModule(commandLine[i + 1]); ModuleView na1 = theNeuronArray.FindAreaByLabel(currentModule); Neuron n = na1.GetNeuronAt(commandLine[i + 2]); if (n != null && !n.Fired()) { return; } } SetCurrentModule(currentCommand); ModuleView na = theNeuronArray.FindAreaByLabel(currentModule); if (na != null && currentCommand != "") { Neuron n = na.GetNeuronAt(currentCommand); if (n != null) { n.CurrentCharge = 1; } } } } line++; UpdateDialog(); }
private void SetTheNeuron(int x0, int y0) { ModuleView naSource = theNeuronArray.FindModuleByLabel("ModuleImageFile"); //Set neuron int theHeight = naSource.Height; int theWidth = naSource.Width; int x = (int)(x0 * na.Width / (float)theWidth); int y = (int)(y0 * na.Height / (float)theHeight); na.GetNeuronAt(x, y).SetValue(1); }
public static ModuleView ConverToModuleView(this Module module) { ModuleView moduleView = new ModuleView(); moduleView.ModuleId = module.Id; moduleView.Number = module.Number; moduleView.Name = module.Name; moduleView.Description = module.Description; return(moduleView); }