private void insertButton_Click(object sender, EventArgs e) { try { IPisnickaGateway pisnickagateway = new PisnickaGateway(); IAlbumGateway albumGateway = new AlbumGateway(); IZanrGateway zanrgateway = new ZanrGateway(); IInterpretGateway interpretgateway = new InterpretGateway(); pisnickagateway.Nazev = nazevBox.Text; pisnickagateway.Delka = delkaBox.Text; zanrgateway.Id = Int32.Parse(zanrBox.Text); interpretgateway.Id = Int32.Parse(interpretBox.Text); albumGateway.Id = Int32.Parse(albumBox.Text); Pisnicka p = new Pisnicka(pisnickagateway); Interpret i = new Interpret(interpretgateway); Zanr z = new Zanr(zanrgateway); Album a = new Album(albumGateway); PisnickaService.InsertPisnicku(p, i, z, a); infoLabel.Text = "pisnicka vložena"; } catch (Exception ex) { infoLabel.Text = "Něco je špatně"; Console.WriteLine(ex); } }
private void insertButton_Click(object sender, EventArgs e) { try { InterpretGateway interpretgateway = new InterpretGateway(); interpretgateway.UmeleckeJmeno = umeleckeBox.Text; interpretgateway.Jmeno = jmenoBox.Text; interpretgateway.Zeme = zemeBox.Text; //interpretgateway.DatumNarozeni = DateTime.ParseExact(datumnarozeniBox.Text, "yyy-MM-dd",System.Globalization.CultureInfo.InvariantCulture); DateTime date = new DateTime(1994, 02, 02); interpretgateway.DatumNarozeni = date; Interpret i = new Interpret(interpretgateway); InterpretService intSer = new InterpretService(); intSer.InsertInterpreta(i); infoLabel.Text = "interpret vložen"; } catch (Exception ex) { infoLabel.Text = "Něco je špatně"; Console.WriteLine(ex); } }
private void btnSave_Click(object sender, EventArgs e) { int n; bool isNumeric = int.TryParse(edFoundationYear.Text, out n); FunctionController fc = new FunctionController(); if (edName.Text == "") { edName.BackColor = ColorTranslator.FromHtml("#ff6666"); MessageBox.Show("Kein Name wurde angegeben.", "Eingabe nicht vollständig", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!isNumeric || edFoundationYear.Text.Length > 4) { edName.BackColor = Color.White; edFoundationYear.BackColor = ColorTranslator.FromHtml("#ff6666"); MessageBox.Show("Das angegebene Gründungsjahr ist nicht gültig.", "Eingabe nicht vollständig", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (fc.objectAlreadyExists(edName.Text, "Interpret")) { edFoundationYear.BackColor = Color.White; edName.BackColor = ColorTranslator.FromHtml("#ff6666"); MessageBox.Show("Interpret existiert bereits.", "Fehlerhafte Eingabe", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Interpret i = new Interpret(edName.Text, edFoundationYear.Text, edLand.Text); i.create(); Close(); } }
public Interpret getInterpreta(int param) { //InterpretGateway InterpretGateway = new InterpretFinder().SelectId(param); IInterpretGateway InterpretGateway = finder.SelectId(param); Interpret interpret = new Interpret(InterpretGateway); return(interpret); }
/// <summary> /// Initializes the AnimationManager class /// </summary> public AnimationManager() { _interpreter = new Interpret(); _animationsCollection = new AnimationsCollection(); _soundPlayer = null; _currentScreen = null; _player = null; _variables = new Variables(); }
public ActionResult NovyPrispevek(Prispevek prispevek) { using (ModelContainer db = new ModelContainer()) { int idUzivatel = int.Parse(Session["uzivatelID"].ToString()); //vyhledám potřebné informace - aktuálně přihlášený uživatel a interpreta ke kterému potřebuji vložit příspěvek Uzivatel aktualnePrihlaseny = db.Uzivatele.Where(x => x.Id == idUzivatel).First(); String nazevInterpreta = Session["interpretNazev"].ToString(); Interpret aktualniInterpret = db.Interpreti.Where(x => x.Nazev == nazevInterpreta).First(); //doplnim vyhledané informace prispevek.DatumPridani = DateTime.Now; prispevek.Interpret = aktualniInterpret; prispevek.Autor = aktualnePrihlaseny; prispevek.Schvalen = false; //vyhledám uživatele který je správcem interpreta int idSpravce = db.SpravciInterpretu.Where(x => x.Interpret.Nazev == nazevInterpreta).Select(x => x.UzivatelId).First(); Uzivatel spravceInterpreta = db.Uzivatele.Where(x => x.Id == idSpravce).First(); prispevek.Obsah = System.Net.WebUtility.HtmlEncode(prispevek.Obsah); //vytvořím žádost Zadost novaZadost = new Zadost(); novaZadost.Interpret = aktualniInterpret; novaZadost.Prispevek = prispevek; novaZadost.StavZadosti = StavZadosti.Cekajici; novaZadost.ZadostOd = aktualnePrihlaseny; novaZadost.ZadostKomu = spravceInterpreta; novaZadost.TypZadosti = TypZadosti.ZadostPisen; //pokud uživatel který vkládá příspěvek je zároveň správcem daného interpreta pak se nemusí čekat na schválení žádosti a příspěvek bude přidán if (spravceInterpreta.Prezdivka.Equals(aktualnePrihlaseny.Prezdivka)) { novaZadost.StavZadosti = StavZadosti.Schvalena; prispevek.Schvalen = true; } //vložím nový příspěvek db.Prispevky.Add(prispevek); //vložím novou žádost db.Zadosti.Add(novaZadost); //uložím změny db.SaveChanges(); //vrátit view které zobrazí odeslání žádosti o příspěvku a vysvětlení co dál return(View("NovyPrispevekPotvrzeni")); } }
/// <summary> /// Invoke the specified method /// </summary> /// <param name="callerInterpreter">The caller interpreter (usually a block)</param> /// <param name="invokeExpression">The invoke expression</param> /// <param name="argumentValues">The list of argument values</param> /// <param name="parentMethodInterpreter">The parent method interpret from where the invocation happened</param> /// <param name="callStackService">The user call stack service</param> /// <returns>Returns the result of the method</returns> internal object InvokeMethod(Interpret callerInterpreter, AlgorithmExpression invokeExpression, Collection <object> argumentValues, MethodInterpreter parentMethodInterpreter, CallStackService callStackService) { var methodName = invokeExpression._methodName.ToString(); var method = Methods.FirstOrDefault(m => m.MethodDeclaration._name.ToString() == methodName); if (method == null) { callerInterpreter.ChangeState(this, new AlgorithmInterpreterStateEventArgs(new Error(new MethodNotFoundException(methodName, $"The method '{methodName}' does not exists in the current class or is not accessible."), ClassDeclaration), callerInterpreter.GetDebugInfo())); return(null); } if (!method.MethodDeclaration._isAsync && invokeExpression._await) { callerInterpreter.ChangeState(this, new AlgorithmInterpreterStateEventArgs(new Error(new MethodNotAwaitableException(methodName), method.MethodDeclaration), callerInterpreter.GetDebugInfo())); return(null); } Guid stackTraceId; var isAsync = method.MethodDeclaration._isAsync; if (parentMethodInterpreter == null) { stackTraceId = Guid.Empty; } else { stackTraceId = parentMethodInterpreter.StacktraceId; if (DebugMode) { var callStack = callStackService.CallStacks.Single(cs => cs.TaceId == stackTraceId); var call = callStack.Stack.Pop(); if (call != null) { call.Variables = callerInterpreter.GetAllAccessibleVariable().DeepClone(); callStack.Stack.Push(call); } } } method = new MethodInterpreter(method.MethodDeclaration, DebugMode); method.StateChanged += ChangeState; method.OnGetParentInterpreter += new Func <ClassInterpreter>(() => this); method.OnDone += new Action <MethodInterpreter>((met) => { met.Dispose(); met.StateChanged -= ChangeState; }); method.Initialize(); method.Run(invokeExpression._await, argumentValues, stackTraceId); if (isAsync && !invokeExpression._await) { return(null); } return(method.ReturnedValue); }
public static Object Call(this Function function, Object[] arguments) { var scope = new Scope(); for (var i = 0; i < function.Arguments.Count; i++) { scope[function.Arguments[i].Item1] = arguments[i]; } return(Interpret.Evaluate(function.Body, scope)); }
/// <summary> /// Evaluates the given sample. Runs the program on inputs given by the sample and stores outputs of the program in sample.RealOutputs. /// </summary> /// <param name="sample"></param> /// <param name="interpret"></param> /// <returns></returns> public void evaluate(TrainingSample sample, Interpret interpret) { interpret.reset(); interpret.numericInputs = sample.inputs.ToList(); this.execute(interpret); for (int i = 0; i < sample.outputsCount; i++) { sample.realOutputs[i] = interpret.outputs[i]; } }
public void execute(Interpret interpreter) { DirectiveNode currentDir = mainEntryPoint; while (currentDir != null) { currentDir.execute(interpreter); currentDir = currentDir.getNextDirective(); } }
/// <summary> /// Initializes the AnimationManager class /// </summary> public AnimationManager() { _interpreter = new Interpret(); _animationsCollection = new AnimationsCollection(); _soundPlayer = null; _currentPanel = null; _player = null; IsSwitchActive = false; _variables = new Variables(); resetSwitchEventStates(); }
/// <summary> /// from YAML to CLI_Commands /// </summary> /// <param name="text">The text.</param> /// <returns>CLI_Commands</returns> public static CLI_Commands DeSerialize(string text) { var i = new Interpret(); text = i.InterpretText(text); var serializer = new DeserializerBuilder() //.WithNamingConvention(CamelCaseNamingConvention.Instance) .Build(); return(serializer.Deserialize <CLI_Commands>(text)); }
public void InsertInterpreta(Interpret interpret) { Interpret i = interpret; IInterpretGateway ig = new InterpretGateway(); ig.UmeleckeJmeno = i.umeleckeJmeno; ig.Jmeno = i.Jmeno; ig.DatumNarozeni = i.DatumNarozeni; ig.Zeme = i.Zeme; ig.Insert(); }
public static void InsertPisnicku(Pisnicka pisnicka, Interpret interpret, Zanr zanr, Album album) { Pisnicka p = pisnicka; Zanr z = zanr; Interpret i = interpret; Album a = album; IPisnickaGateway pg = new PisnickaGateway(); IZanrGateway zg = new ZanrGateway(); IAlbumGateway ag = new AlbumGateway(); IInterpretGateway ig = new InterpretGateway(); pg.Insert(); }
public void InterpretTextNone() { #region arrange string textToInterpret = RandomString(22); #endregion #region act var i = new Interpret(); var str = i.InterpretText(textToInterpret); #endregion #region assert Assert.AreEqual(textToInterpret, str); #endregion }
// 构造函数 public MainPage() { InitializeComponent(); string bmobId = "2bf438a29c5411c813e6e50a1aedfd0c"; JYCaoZuo.getCaoZuo().page = this; JYCaoZuo.getCaoZuo().init(bmobId); // 用于本地化 ApplicationBar 的示例代码 //BuildLocalizedApplicationBar(); string daiMa = "int i = 0;while(i<100){ i = i+1;write(i);}"; //使用方法 //1语义分析 LexicalAnalysis la = new LexicalAnalysis(); string outStr = la.Analyze(daiMa); List <object> errList = la.errlist; Debug.WriteLine(outStr); Analysis ciFaFenXi = new Analysis(); //判断语义是否有误 if (ciFaFenXi.syntaxAalysis(la)) { } else { Debug.WriteLine(ciFaFenXi.errInfo.ToString()); } //2 执行算法 MidCode m0 = new MidCode(ciFaFenXi); m0.Scan(); Interpret runner = new Interpret(); runner.GetRun(m0.c); //得到结果 string jieGuo = runner.jieGuo; Debug.WriteLine(jieGuo); m0.clear(); }
private int OnExecute() { Console.WriteLine($"processing files accordingly to settings from {Name}"); var i = new Interpret(); var text = i.InterpretText(File.ReadAllText(Name)); var rewrite = RewriteAction.UnSerializeMe(text); rewrite.Rewrite(); return(0); //for (var i = 0; i < Count; i++) //{ // Console.WriteLine($"Hello {Name}!"); //} //return 0; }
/// <summary> /// Evaluates given solution program using given samplesGenerator. Prints a comparison of desiredOutputs to realOutputs and computes success rate. /// </summary> /// <param name="generator"></param> /// <param name="p"></param> /// <param name="samplesCount"></param> public static void runEvaluation(TrainingSamplesGenerator generator, SolutionProgram p, int samplesCount, bool quiet = false) { Interpret i = new Interpret(); int currectCount = 0; foreach (var sample in generator.generateSamples(samplesCount)) { p.evaluate(sample, i); Printing.PrintMsg(sample.ToString() + "\treal output: " + sample.realOutputs2String + " " + (sample.isCorrectlyAnswered ? "OK" : "WRONG"), quiet); if (sample.isCorrectlyAnswered) { currectCount++; } } Console.WriteLine($"Success rate: {currectCount} out of {samplesCount} ({((double)(currectCount*100) / samplesCount).ToString("0.##")}%)"); }
/// <summary> /// Handles when the connected descriptor sends input /// </summary> /// <param name="e">the events of the message</param> public override void OnMessage(string message) { if (_currentPlayer == null) { OnError(new Exception("Invalid character; please reload the client and try again.")); return; } IEnumerable <string> errors = Interpret.Render(message, _currentPlayer); //It only sends the errors if (errors.Any(str => !string.IsNullOrWhiteSpace(str))) { SendOutput(errors); } }
public void InterpretDateTimeUtcNow() { #region arrange string textToInterpret = "this is from #utcnow:yyyyMMddHHmmss#"; #endregion #region act var i = new Interpret(); i.TwoSlashes = false; var str = i.InterpretText(textToInterpret); #endregion #region assert Console.WriteLine("interpreted: " + str); str.Should().Contain($"this is from {DateTime.UtcNow.ToString("yyyyMMdd")}"); #endregion }
/// <summary> /// Handles when the connected descriptor sends input /// </summary> /// <param name="e">the events of the message</param> protected override void OnMessage(MessageEventArgs e) { if (_currentPlayer == null) { SendWrapper("Invalid character; please reload the client and try again."); this.Context.WebSocket.Close(CloseStatusCode.Abnormal, "connection aborted - no player");; } var errors = Interpret.Render(e.Data, _currentPlayer); //It only sends the errors if (errors.Any(str => !string.IsNullOrWhiteSpace(str))) { SendWrapper(errors); } }
/// <summary> /// Handles initial connection /// </summary> protected override void OnOpen() { var authTicketValue = Context.CookieCollection[".AspNet.ApplicationCookie"].Value; GetUserIDFromCookie(authTicketValue); UserManager = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext())); var authedUser = UserManager.FindById(_userId); var currentCharacter = authedUser.GameAccount.Characters.FirstOrDefault(ch => ch.ID.Equals(authedUser.GameAccount.CurrentlySelectedCharacter)); if (currentCharacter == null) { Send("<p>No character selected</p>"); return; } //Try to see if they are already live _currentPlayer = LiveCache.Get <Player>(currentCharacter.ID); //Check the backup if (_currentPlayer == null) { var hotBack = new HotBackup(System.Web.Hosting.HostingEnvironment.MapPath("/HotBackup/")); _currentPlayer = hotBack.RestorePlayer(currentCharacter.AccountHandle, currentCharacter.ID); } //else new them up if (_currentPlayer == null) { _currentPlayer = new Player(currentCharacter); } _currentPlayer.Descriptor = this; //We need to barf out to the connected client the welcome message. The client will only indicate connection has been established. var welcomeMessage = new List <String>(); welcomeMessage.Add(string.Format("Welcome to alpha phase twinMUD, {0}", currentCharacter.FullName())); welcomeMessage.Add("Please feel free to LOOK around."); _currentPlayer.WriteTo(welcomeMessage); //Send the look command in Interpret.Render("look", _currentPlayer); }
private void löschenToolStripMenuItem_Click(object sender, EventArgs e) { string name = treeMain.SelectedNode.Text; string typeOfObject = getTypeOfNode(treeMain.SelectedNode); if (typeOfObject.Equals("interpret")) { Interpret i = new Interpret(name, "", ""); i.delete(name); } else if (typeOfObject.Equals("album")) { Album a = new Album(name, "", "", "", ""); a.delete(name); } prepareTree(); }
private void Button_Click(object sender, RoutedEventArgs e) { //执行结果 //使用方法 //1语义分析 string daiMa = txtForDaiMa.Text; JYCaoZuo.getCaoZuo().addaoZuo("点击了执行代码:" + daiMa); LexicalAnalysis la = new LexicalAnalysis(); string outStr = la.Analyze(daiMa); List <object> errList = la.errlist; Debug.WriteLine(outStr); Analysis ciFaFenXi = new Analysis(); //判断语义是否有误 if (ciFaFenXi.syntaxAalysis(la)) { } else { txtForJieGuo.Text = ciFaFenXi.errInfo.ToString() + "\n" + outStr; Debug.WriteLine(ciFaFenXi.errInfo.ToString()); return; } //2 执行算法 MidCode m0 = new MidCode(ciFaFenXi); m0.Scan(); Interpret runner = new Interpret(); runner.GetRun(m0.c); //得到结果 string jieGuo = runner.jieGuo; Debug.WriteLine(jieGuo); txtForJieGuo.Text = jieGuo + "\n" + outStr; m0.clear(); JYCaoZuo.getCaoZuo().addaoZuo("点击了执行代码:" + daiMa + ",结果:" + txtForJieGuo.Text); }
public async Task <AuthorizationResult> AuthorizeEntityChangeAsync(IIdentity user, DbEntityEntry ent) { if (ent.State == EntityState.Unchanged || ent.State == EntityState.Detached) { return(AuthorizationResult.Success()); } if (ent.Entity is T) { var casted = ent.Cast <T>(); switch (ent.State) { case EntityState.Added: var interpreted = Interpret.BeforeCreate(casted.Entity, GetContextInfo(user)); return((await Authorize.CreateAsync(interpreted, GetContextInfo(user))).CreateAggregateResult()); case EntityState.Modified: var original = CreateWithValues(casted.OriginalValues); var modified = CreateWithValues(casted.CurrentValues); var modifiedInterpreted = Interpret.BeforeModify((T)original, (T)modified, GetContextInfo(user)); foreach (var field in ent.CurrentValues.PropertyNames) { ent.CurrentValues[field] = modifiedInterpreted.GetType().GetProperty(field) .GetValue(modifiedInterpreted, null); } return((await Authorize.ModifyAsync((T)original, modifiedInterpreted, GetContextInfo(user))) .CreateAggregateResult()); case EntityState.Deleted: return((await Authorize.RemoveAsync( (T)CreateWithValues(casted.OriginalValues, casted.Entity.GetType()), GetContextInfo(user))) .CreateAggregateResult()); default: return(AuthorizationResult.Fail("The entity state is invalid", casted.Entity)); } } else { return(await GetChildRepositoryFor(ent).AuthorizeEntityChangeAsync(user, ent)); } }
public void InterpretSettingsFile() { #region arrange string textToInterpret = "this is from #file:SqlServerConnectionString#"; #endregion #region act var i = new Interpret(); var str = i.InterpretText(textToInterpret); #endregion #region assert Console.WriteLine("interpreted: " + str); Assert.IsFalse(str.Contains("#"), "should be interpreted"); Assert.IsTrue(str.Contains("this is from"), "should contain first chars"); //Assert.IsTrue(str.Contains("atabase"),"should contain database"); Assert.IsTrue(str.Contains("rusted"), "should containt trusted connection"); #endregion }
public void InterpretStaticParameterString() { #region arrange string textToInterpret = "this is @static:System.IO.Path.GetFileNameWithoutExtension(#env:solutionPath#)@"; Environment.SetEnvironmentVariable("solutionPath", "a.sln"); #endregion #region act var i = new Interpret(); i.TwoSlashes = false; var str = i.InterpretText(textToInterpret); #endregion #region assert str.Should().Be($"this is a"); #endregion }
public void InterpretGuid() { #region arrange string textToInterpret = "#guid:n#"; #endregion #region act var i = new Interpret(); i.TwoSlashes = false; var str = i.InterpretText(textToInterpret); #endregion #region assert Console.WriteLine("interpreted: " + str); str.Should().HaveLength(32); var g = new Guid(str); //g should exists without error #endregion }
static void Main2(string[] args) { //SolutionProgram p = getProgram0(); //SolutionProgram p = getProgram1(); SolutionProgram p = getProgram2(); Interpret i = new Interpret(); i.numericInputs = new List <int>() { 97 }; Console.WriteLine(p.ToString()); p.execute(i); new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(p)); Console.WriteLine("inputs: " + string.Join(" ", i.numericInputs)); Console.WriteLine("outputs: " + string.Join(" ", i.outputs)); }
public void InterpretStaticOneParameter() { #region arrange string textToInterpret = "this is from #static:DateTime.Today#"; textToInterpret += " and #static:Directory.GetCurrentDirectory()#"; #endregion #region act var i = new Interpret(); i.TwoSlashes = false; var str = i.InterpretText(textToInterpret); #endregion #region assert Console.WriteLine("interpreted: " + str); str.Should().Be($"this is from {DateTime.Today.ToString()} and {Directory.GetCurrentDirectory()}"); #endregion }