public Welcome() { InitializeComponent(); MainForm.RoundedControl(Btn_AddFolder); MyResources.ConfigFolderBrowserDialog(openFolder); }
internal static Image GenerateDefaultImage(string typeName, bool bigIcon) { string back_fileName = bigIcon ? @"plain_big.png" : @"plain.png"; float x = 0; float y = bigIcon ? 6 : 3; float size = bigIcon ? 36 : 17; string label = ""; for (int i = 0; i < typeName.Length; i++) { if (Char.IsUpper(typeName[i])) { label += typeName[i]; if (label.Length == 2) { break; } } } if (label.Length < 2) { label = typeName.Substring(0, 2); } Image background = MyResources.GetImage(back_fileName); Graphics g = Graphics.FromImage(background); g.DrawString(label, new Font(new FontFamily("Consolas"), 17, FontStyle.Bold), Brushes.White, x, y); return(background); }
private static IEnumerable <Type> GetBrainSimUIExtensionTypes() { var ret = new List <Type>(); foreach (FileInfo assemblyFile in MyConfiguration.ListModules()) { try { Assembly assembly = Assembly.LoadFrom(assemblyFile.FullName); string xml; if (MyResources.TryGetTextFromAssembly(assembly, MyModuleConfig.MODULE_CONFIG_FILE, out xml)) { continue; } MyLog.INFO.WriteLine("UI module loaded: " + assemblyFile.Name); ret.AddRange(assembly.GetTypes().Where(IsUIExtension)); } catch (Exception ex) { MyLog.DEBUG.WriteLine("Error when looking for UI modules: " + ex.Message); } } return(ret); }
public static void LoadModules() { MyLog.INFO.WriteLine("Loading system modules..."); AddModuleFromAssembly(new FileInfo(MyResources.GetEntryAssemblyPath() + "\\" + CORE_MODULE_NAME), true); MyLog.INFO.WriteLine("Loading custom modules..."); foreach (string modulePath in ModulesSearchPath) { FileInfo info = new FileInfo(modulePath); if ((info.Attributes & FileAttributes.Directory) > 0) { info = new FileInfo(Path.Combine(info.FullName, info.Name + ".dll")); } if (info.Exists) { AddModuleFromAssembly(info); } else { MyLog.ERROR.WriteLine("Module assembly not found: " + info); } } }
/// <summary> /// 在绘制该控件之前,为控件注册为需要回发处理 /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); // 为控件注册为需要回发处理 this.Page.RegisterRequiresPostBack(this); // 注册客户端脚步包含文件 if (!this.Page.ClientScript.IsClientScriptBlockRegistered(SCRIPT_ID)) { this.Page.ClientScript.RegisterClientScriptBlock(typeof(void), SCRIPT_ID, String.Format(SCRIPT, MyResources.GetResourcesURL("WebTextPaneJS"))); } // 注册 CSS 样式表文件 if (!this.Page.ClientScript.IsClientScriptBlockRegistered(CSS_ID)) { this.Page.ClientScript.RegisterClientScriptBlock(typeof(void), CSS_ID, String.Format(CSS, MyResources.GetResourcesURL("WebTextPaneCSS"))); } // 注册 OnSubmit 语句,在页面提交时同步文本模型控件中文本值 this.Page.ClientScript.RegisterOnSubmitStatement(typeof(bool), SCRIPT_ON_SUBMIT_ID, SCRIPT_ON_SUBMIT); // 调用自定义控件绘制前准备函数 this.MyOnPreRender(e); // 设置设计器的内置 HTML 为用户指定的文本 this.m_spanDesigner.InnerHtml = this.XMLNText; // 设置隐藏字段文本 this.m_textModel.InnerHtml = this.XMLNText; }
public static MyModuleConfig LoadModuleConfig(FileInfo assemblyFile) { Assembly assembly = Assembly.LoadFrom(assemblyFile.FullName); string xml = MyResources.GetTextFromAssembly(assembly, MODULE_CONFIG_FILE); if (string.IsNullOrEmpty(xml)) { throw new FileNotFoundException("Module config not found (resource \"nodes.xml\" missing for module " + assemblyFile.Name + ")."); } YAXSerializer serializer = new YAXSerializer(typeof(MyModuleConfig), YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Warning); MyModuleConfig moduleConfig = (MyModuleConfig)serializer.Deserialize(xml); if (moduleConfig == null) { throw new YAXException("Module config parsing failed: " + serializer.ParsingErrors); } moduleConfig.Assembly = assembly; moduleConfig.File = assemblyFile; moduleConfig.LoadConversionClass(); moduleConfig.FinalizeNodeConfigs <MyNodeConfig>(moduleConfig.NodeConfigList); moduleConfig.FinalizeNodeConfigs <MyWorldConfig>(moduleConfig.WorldConfigList); return(moduleConfig); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MyResources.Init(); Application.Run(MyResources.Main); }
static MyConfiguration() { GlobalPTXFolder = MyResources.GetEntryAssemblyPath() + @"\modules\GoodAI.BasicNodes\ptx\"; KnownNodes = new Dictionary <Type, MyNodeConfig>(); KnownWorlds = new Dictionary <Type, MyWorldConfig>(); Modules = new List <MyModuleConfig>(); ModulesSearchPath = new List <string>(); AssemblyLookup = new Dictionary <Assembly, MyModuleConfig>(); }
public Settings() { InitializeComponent(); MyResources.ConfigFolderBrowserDialog(openFolder); MainForm.RoundedControl(Btn_AddFolder); MainForm.RoundedControl(Btn_ReloadFolder); MainForm.RoundedControl(Lb_Num, 3); MainForm.RoundedControl(Lb_Dir, 3); }
/// <summary> /// 建立工具条分隔符控件 /// </summary> public void AddSeparator() { // 建立 HTML 图片控件 HtmlImage image = new HtmlImage(); // 设置图片文件的源 image.Src = MyResources.GetResourcesURL("ToolbarSeparator"); // 加入分隔符 this.AddMyControl(image); }
/// <summary> /// 建立工具条手柄控件 /// </summary> /// <returns>HTML 图片控件</returns> private void CreateHandlerControl() { // 建立 HTML 图片控件 HtmlImage image = new HtmlImage(); // 设置图片文件的源 image.Src = MyResources.GetResourcesURL("ToolbarHandler"); // 加入工具条手柄 this.AddMyControl(image); }
public static void SetupModuleSearchPath() { var modulesPath = Path.Combine(MyResources.GetEntryAssemblyPath(), MODULES_PATH); if (Directory.Exists(modulesPath)) { foreach (string modulePath in Directory.GetDirectories(modulesPath)) { ModulesSearchPath.Add(modulePath); } } }
internal void InitIcons(Assembly assembly) { if (!String.IsNullOrEmpty(SmallIcon)) { SmallImage = MyResources.GetImageFromAssembly(assembly, SmallIcon); } if (SmallImage == null) { SmallImage = MyNodeConfig.GenerateDefaultImage(Name, false); } }
public static void SetupModuleSearchPath() { //SearchPath.Add(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); //add bs folder name if (Directory.Exists(MyResources.GetEntryAssemblyPath() + "\\" + MODULES_PATH)) { foreach (string modulePath in Directory.GetDirectories(MyResources.GetEntryAssemblyPath() + "\\" + MODULES_PATH)) { ModulesSearchPath.Add(modulePath); } } }
void CreateGameObjectView(string resPath) { var res = MyResources.Load(resPath); var ins = GameObject.Instantiate(res) as GameObject; u3dView = ins.GetComponent <U3DGameObjectView>(); if (u3dView == null) { u3dView = ins.AddComponent <U3DGameObjectView>(); } View = u3dView as IGameObjectView; View.HostObject = this; }
private void UpdateLearningTaskDescription() { if (learningTaskList.SelectedItem == null) { learningTaskDescription.Url = null; } else { const string HTML_DIRECTORY = @"Resources\html"; string htmlFileName = (learningTaskList.SelectedItem as LearningTaskListItem).HTMLFileName; string fullPath = MyResources.GetMyAssemblyPath() + "\\" + HTML_DIRECTORY + "\\" + htmlFileName; learningTaskDescription.Navigate(fullPath); } }
public static void LoadModules() { MyLog.INFO.WriteLine("Loading system modules..."); AddModuleFromAssembly( new FileInfo(Path.Combine(MyResources.GetEntryAssemblyPath(), CORE_MODULE_NAME)), basicNode: true); if (ModulesSearchPath.Count == 0) { throw new InvalidOperationException("ModulesSearchPath must not be empty."); } MyLog.INFO.WriteLine("Loading custom modules..."); ListModules().ForEach(moduleFileInfo => AddModuleFromAssembly(moduleFileInfo)); }
/// <summary> /// 建立新的工具条按钮 /// </summary> /// <param name="imgSrc">按钮图片源</param> /// <param name="commandName">命令名称</param> /// <returns>工具条图片按钮对象</returns> public ToolbarImageButton CreateImageButton(string resID, string commandName) { // 获取工具提示字符串 string toolTipString = ToolTips.TheInstance.GetString(commandName); // 建立工具条图片按钮控件 ToolbarImageButton imageButton = new ToolbarImageButton(MyResources.GetResourcesURL(resID), commandName); // 设置提示字符串 imageButton.Alt = toolTipString; // 设置标题提示信息 imageButton.Attributes.Add("title", toolTipString); return(imageButton); }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { if (this.MdiChildren.Count() > 0) { foreach (Form form in this.MdiChildren) { form.Dispose(); } } Resources.Dispose(); MyResources.Dispose(); Inventory.Dispose(); Environment.Exit(0); }
public MyProjectRunner(MyLogLevel level = MyLogLevel.DEBUG) { // why not to directly ask for TypeMap.GetInstance<MySimulation> ? // because in Typemap configuration, MySimulation is set to be singleton - this causes problems when MyProjectRunner // is instantiated multiple times - second and following instances obtain an instance of MySimulation from the first // MyProjectRunner instance. If the first MyProjectRunner instance was Shutdown-ed, the MySimulation instance is also // cleared and any following Shutdown on other MyProjectRunner instances will cause freeze/inifnite hang. // This code creates new MySimulation instance for each MyProjectRunner instance. // Other solution could be to not have a MySimulation as a singleton in TypeMap configuration - and it could work just OK, // because in BrainSim, the TypeMap's GetInstance on MySimulation is only on one place in MainForm. However, this may change // in future or the change itself may have other consequences, so for now I pick this solution, as it is safer. MySimulation simulation = new MyLocalSimulation(TypeMap.GetInstance <MyValidator>(), TypeMap.GetInstance <IMyExecutionPlanner>()); SimulationHandler = new MySimulationHandler(simulation); m_resultIdCounter = 0; SimulationHandler.ProgressChanged += SimulationHandler_ProgressChanged; SimulationHandler.StepPerformed += SimulationHandler_StepPerformed; m_monitors = new List <Tuple <int, uint, MonitorFunc> >(); m_results = new Hashtable(); Project = new MyProject(); var path = MyResources.GetEntryAssemblyPath(); if (MyConfiguration.ModulesSearchPath.Count == 0) { MyConfiguration.SetupModuleSearchPath(); } MyConfiguration.ProcessCommandParams(); try { if (MyConfiguration.Modules.Count == 0) { MyConfiguration.LoadModules(); } } catch (Exception e) { MyLog.WARNING.WriteLine(e.Message); throw; } MyLog.Level = level; }
private void LoadLicensesList() { // first add our own license var eulaFile = Path.Combine(MyResources.GetEntryAssemblyPath(), @"EULA.rtf"); if (File.Exists(eulaFile)) { licenseList.Items.Add(new LicenseItem(eulaFile, "GoodAI Brain Simulator")); } // add licenses for 3rd party libs var licensesDirInfo = new DirectoryInfo(Path.Combine(MyResources.GetEntryAssemblyPath(), @"licenses")); foreach (var file in licensesDirInfo.GetFiles("*.txt")) { licenseList.Items.Add(new LicenseItem(file.FullName)); } }
public void LoadXMLDoc(Assembly assembly) { try { string src = MyResources.GetTextFromAssembly(assembly, XMLDOC_FILENAME); XDocument xml = XDocument.Parse(src); IEnumerable <XElement> members = xml.Root.Element("members").Elements("member"); foreach (XElement member in members) { m_docTable[member.Attribute("name").Value] = member; } } catch (Exception ex) { MyLog.WARNING.WriteLine("XML documentation loading failed for assembly: " + assembly.FullName + "\n\t" + ex.Message); } }
/// <summary> /// Loads a bitmap from a file and stores it in a dictionary. Checks for ARGB color format (e.g. 32bit png). /// Implementation same as in MyMastermindWorld (TODO: refactor once TetrisWorld gets moved to BasicNodes). /// </summary> /// <param name="path"></param> /// <param name="textureType"></param> protected void LoadBitmap(TextureType textureType, string path) { if (!m_bitmapTable.ContainsKey(textureType)) { try { Bitmap bitmap = (Bitmap)Image.FromFile(MyResources.GetMyAssemblyPath() + "\\" + path, true); m_bitmapTable[textureType] = bitmap; if (bitmap.PixelFormat != PixelFormat.Format32bppArgb) { throw new ArgumentException("The specified image is not in the required RGBA format."); // note: alpha must not be premultiplied } } catch (Exception ex) { MyLog.WARNING.WriteLine(ex.Message); } } }
private int LoadAndGetBitmapSize(string path) { if (!m_bitmapTable.ContainsKey(path)) { try { Bitmap bitmap = (Bitmap)Image.FromFile(MyResources.GetMyAssemblyPath() + "\\" + path, true); m_bitmapTable[path] = bitmap; return(bitmap.Width * bitmap.Height); } catch (Exception ex) { m_errorMessage = ex.Message; return(0); } } else { return(m_bitmapTable[path].Width * m_bitmapTable[path].Height); } }
internal void InitIcons(Assembly assembly) { if (!String.IsNullOrEmpty(BigIcon)) { BigImage = MyResources.GetImageFromAssembly(assembly, BigIcon); } if (BigImage == null) { BigImage = GenerateDefaultImage(NodeType, true); } if (!String.IsNullOrEmpty(SmallIcon)) { SmallImage = MyResources.GetImageFromAssembly(assembly, SmallIcon); } if (SmallImage == null) { SmallImage = GenerateDefaultImage(NodeType, false); } }
public MyProjectRunner(MyLogLevel level = MyLogLevel.DEBUG) { MySimulation simulation = TypeMap.GetInstance <MySimulation>(); SimulationHandler = new MySimulationHandler(simulation); m_resultIdCounter = 0; SimulationHandler.ProgressChanged += SimulationHandler_ProgressChanged; SimulationHandler.StepPerformed += SimulationHandler_StepPerformed; m_monitors = new List <Tuple <int, uint, MonitorFunc> >(); m_results = new Hashtable(); Project = new MyProject(); var path = MyResources.GetEntryAssemblyPath(); if (MyConfiguration.ModulesSearchPath.Count == 0) { MyConfiguration.SetupModuleSearchPath(); } MyConfiguration.ProcessCommandParams(); try { if (MyConfiguration.Modules.Count == 0) { MyConfiguration.LoadModules(); } } catch (Exception e) { MyLog.WARNING.WriteLine(e.Message); throw; } MyLog.Level = level; }
public static float[] LoadDigits() { Image charactersTexture = MyResources.GetImage("plot_char.png"); // = Image.FromFile("res/plot_char.png"); int width = charactersTexture.Width; int height = charactersTexture.Height; int size = width * height; BitmapData bitmapData = new Bitmap(charactersTexture).LockBits( new Rectangle(0, 0, charactersTexture.Width, charactersTexture.Height), ImageLockMode.ReadOnly, charactersTexture.PixelFormat); byte[] bytes = new byte[size * 4]; float[] alphaValues = new float[size]; Marshal.Copy(bitmapData.Scan0, bytes, 0, size * 4); for (int i = 0; i < size; i++) { alphaValues[i] = (float)bytes[i * 4 + 3] / 255; } return(alphaValues); }
public void ProcessRequest(HttpContext context) { string propName = context.Request["ResID"]; if (propName == null) { return; } // 获取资源类型 Type type = typeof(MyResources); // 获取属性信息 PropertyInfo propInfo = type.GetProperty(propName, BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic); if (propInfo == null) { return; } // 获取资源文件对象 MyResources myRes = new MyResources(); // 获取资源值 object value = propInfo.GetValue(myRes, null); if (value == null) { return; } switch (value.GetType().ToString()) { #if DEBUG case "System.Drawing.Bitmap": // 设置输出流的 MIME 类型 context.Response.ContentType = "image/gif"; // 获取位图图像 Bitmap bitmap = (System.Drawing.Bitmap)value; // 将位图图像保存到页面输出流 bitmap.Save(context.Response.OutputStream, bitmap.RawFormat); break; case "System.String": // 设置输出流的 MIME 类型 context.Response.ContentType = "text/css"; // 设置字符集 context.Response.ContentEncoding = Encoding.UTF8; switch (propName) { case "CssWebTextPane": // 输出 CSS 样式表 context.Response.Write(Bincess_Resource.CssWebTextPane); break; case "ScriptWebTextPane": // 输出 JavaScript 脚步文件 context.Response.Write(Bincess_Resource.ScriptWebTextPane); break; default: break; } break; #else case "System.Drawing.Bitmap": // 获取位图图像 Bitmap bitmap = (System.Drawing.Bitmap)value; // 将位图图像保存到页面输出流 bitmap.Save(context.Response.OutputStream, bitmap.RawFormat); break; case "System.String": // 输出文本值 context.Response.Write(value); break; #endif default: break; } }
/// <summary> /// 在绘制控件之前,为控件注册客户端脚本 /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (!this.Page.ClientScript.IsClientScriptBlockRegistered(SCRIPT_ID)) { // 为控件注册客户端脚本 this.Page.ClientScript.RegisterClientScriptBlock(typeof(void), SCRIPT_ID, String.Format(SCRIPT, MyResources.GetResourcesURL("WebGroupListJS"))); } }
public override void Init(int nGPU) { Owner.MNISTManager = new MyMNISTManager(MyResources.GetMyAssemblyPath() + @"\res\", TrainingExamplesPerDigit, TestExamplesPerDigit, false, AfterLastImage); }