internal string Create(TracebackDelegate traceFunc) { string result = String.Empty; try { m_pe = new PythonEngine(); m_Engine = m_pe.engine; m_Scope = m_pe.scope; var pc = Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_Engine) as PythonContext; PythonDictionary hooks = (PythonDictionary)pc.SystemState.Get__dict__()["path_hooks"]; hooks.Clear(); if (traceFunc != null) { m_Engine.SetTrace(traceFunc); } result = "Created"; } catch (Exception ex) { result = ex.Message; } return(result); }
/// <summary> /// Update the script vars /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bUpdate_Click(object sender, EventArgs e) { //Create variable bridge from C# to IronPython engine pe.ExecuteCommand("interface_val = 0"); pe.ExecuteCommand("user_val = {}"); //Set the IronPython bridge variables... ScriptDomainManager.CurrentManager.Host.DefaultModule.SetVariable("interface_val", cbMinLength.SelectedItem); pe.ExecuteCommand("i.MINLENGTH = interface_val"); ScriptDomainManager.CurrentManager.Host.DefaultModule.SetVariable("interface_val", cbMaxLength.SelectedItem); pe.ExecuteCommand("i.MAXLENGTH = interface_val"); ScriptDomainManager.CurrentManager.Host.DefaultModule.SetVariable("interface_val", cbCaps.SelectedItem); pe.ExecuteCommand("i.CAPLENGTH = interface_val"); ScriptDomainManager.CurrentManager.Host.DefaultModule.SetVariable("interface_val", cbGencount.SelectedItem); pe.ExecuteCommand("i.GENCOUNT = interface_val"); ScriptDomainManager.CurrentManager.Host.DefaultModule.SetVariable("interface_val", cdAddCount.SelectedItem); pe.ExecuteCommand("i.ADDCOUNT = interface_val"); ScriptDomainManager.CurrentManager.Host.DefaultModule.SetVariable("interface_val", tbInsertionChars.Text.Trim()); pe.ExecuteCommand("i.ADDCHAR = interface_val"); //This was the only way I could succesfully update the SWAP PythonDictionary from a string SWAPS.Clear(); try { SWAPS = (PythonDictionary)pe.EvaluateAs <PythonDictionary>(tbSwapSet.Text.Trim()).Clone(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\nInvalid SwapSet. Autofixing to an empty swapset {}"); //Fix for user... tbSwapSet.Text = "{}"; SWAPS = (PythonDictionary)pe.EvaluateAs <PythonDictionary>(tbSwapSet.Text.Trim()).Clone(); } //Now set the SWAP bridge ScriptDomainManager.CurrentManager.Host.DefaultModule.SetVariable("user_val", SWAPS); pe.ExecuteCommand("i.SWAPS = user_val"); //Set the C# password GENCOUNT GENCOUNT = (int)cbGencount.SelectedItem; //Notify user... tbDisplay.AppendText("Password options successfully UPDATED!\r\n"); bUpdate.Enabled = false; bSavesettings.Enabled = true; }