public ExtensionManager(string valuePath) { Path = valuePath; foreach (string path in Directory.GetFiles(valuePath, "*.ini", SearchOption.AllDirectories)) { INI ini = new INI(path); string parentName = Directory.GetParent(path).FullName; string extensionPath = ini.GetValue("Assembly", "File").Replace("<%LOCAL%>", parentName); if (File.Exists(extensionPath)) { GExtension extension = LoadExtension(extensionPath); extension.Path = extensionPath; extension.Title = ini.GetValue("General", "Title"); extension.Author = ini.GetValue("General", "Author"); extension.Summary = ini.GetValue("General", "Summary"); string dependenciesDir = ini.GetValue("Assembly", "Dependencies").Replace("<%LOCAL%>", parentName); if (dependenciesDir.Length > 0 && Directory.Exists(dependenciesDir)) { extension.Dependencies = dependenciesDir; } Extensions.Add(extension); } } Extensions = (from extension in Extensions orderby extension.Title ascending select extension).ToList(); }
private void BtnCancel_Click(object sender, RoutedEventArgs e) { TextTitle.Clear(); TextAuthor.Clear(); TextSummary.Clear(); preview = null; manager = null; extension = null; compiler = null; StackResult.Visibility = Visibility.Collapsed; StackOpen.Visibility = Visibility.Visible; }
private void StackOpen_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { var openDialog = new OpenFileDialog { Filter = "라이브러리 파일 (*.dll)|*.dll" }; if (openDialog.ShowDialog() == false || !File.Exists(openDialog.FileName)) { return; } try { GridLoading.Visibility = Visibility.Visible; Task.Run(() => { manager = new ExtensionManager(); extension = manager.LoadExtension(openDialog.FileName); if (extension.Commands.Count <= 0 && extension.Controls.Count <= 0) { MessageBox.Show("해당 파일에는 사용 가능한 블럭이 없습니다.\n올바른 확장 파일을 선택해주시기 바랍니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error); return; } extension.Path = openDialog.FileName; Dispatcher.Invoke(() => { StackOpen.Visibility = Visibility.Collapsed; StackResult.Visibility = Visibility.Visible; LabelResult.Content = $"본 모듈은 {extension.Commands.Count}개의 블럭과 {extension.Controls.Count}개의 컨트롤을 포함하고 있습니다."; GridLoading.Visibility = Visibility.Collapsed; }); compiler = new GCompiler(); compiler.LoadReference(openDialog.FileName); }); } catch (Exception ex) { MessageBox.Show("해당 파일은 불러올 수 없습니다.\n" + ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// 모듈에 포함된 모든 함수를 블럭 배열로 변환합니다. /// </summary> /// <param name="target">블럭 배열로 변환할 모듈 객체입니다.</param> public BaseBlock[] ConvertToBlocks(GExtension target) { var blockList = new List <BaseBlock>(); foreach (var command in target.Commands) { switch (command.MethodType) { case GCommand.CommandType.Call: if (command.ObjectType == typeof(void)) { blockList.Add(new VoidCallBlock(command)); break; } blockList.Add(new ObjectCallBlock(command)); break; case GCommand.CommandType.Logic: blockList.Add(new ObjectCallBlock(command)); break; case GCommand.CommandType.Event: blockList.Add(new EventBlock(command)); break; case GCommand.CommandType.Property: blockList.Add(new PropertyBlock(command)); break; case GCommand.CommandType.Enum: blockList.Add(new EnumBlock(command)); break; } } return(blockList.ToArray()); }
private void StackOpen_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog { Filter = "라이브러리 파일 (*.dll)|*.dll" }; if (openDialog.ShowDialog() == true) { if (File.Exists(openDialog.FileName)) { try { manager = new ExtensionManager(); extension = manager.LoadExtension(openDialog.FileName); if (extension.Commands.Count > 0 || extension.Controls.Count > 0) { extension.Path = openDialog.FileName; StackOpen.Visibility = Visibility.Collapsed; StackResult.Visibility = Visibility.Visible; LabelResult.Content = $"본 모듈은 {extension.Commands.Count}개의 블럭과 {extension.Controls.Count}개의 컨트롤을 포함하고 있습니다."; compiler = new GCompiler(); compiler.LoadReference(openDialog.FileName); } else { MessageBox.Show("해당 파일에는 사용 가능한 블럭이 없습니다.\n올바른 확장 파일을 선택해주시기 바랍니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show("해당 파일은 불러올 수 없습니다.\n" + ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
/// <summary> /// 확장 모듈을 불러옵니다. /// </summary> /// <param name="pathValue">확장 모듈의 전체 경로입니다.</param> // TODO GEnumeration 부분도 번역 분석 필요 // TODO GView / GField 속성에 번역 구현 필요 public GExtension LoadExtension(string pathValue) { Assembly targetAssembly = Assembly.LoadFrom(pathValue); AssemblyName[] name = targetAssembly.GetReferencedAssemblies(); // 객체 생성 GExtension target = new GExtension(); target.Namespace = targetAssembly.GetName().Name; // 클래스 분석 foreach (Type value in targetAssembly.GetExportedTypes()) { List <GExport> controlExports = null; if (value.BaseType == typeof(GModule) || value.BaseType == typeof(GView)) { // 목록 생성 if (value.BaseType == typeof(GView)) { controlExports = new List <GExport>(); } // 속성 분석 foreach (PropertyInfo property in value.GetProperties()) { GCommandAttribute command = GetAttribute <GCommandAttribute>(property); GControlAttribute control = GetAttribute <GControlAttribute>(property); if (command != null || control != null) { if (command != null) { // 커멘드 목록 추가 target.Commands.Add( new GCommand ( target, value.FullName, property.Name, command.Name, property.GetMethod.ReturnType, GCommand.CommandType.Property, translations: command.Translated ? GetTranslations(property) : null ) ); } if (control != null) { // 컨트롤 목록 추가 controlExports.Add( new GExport ( value.FullName, property.Name, control.Name, property.GetMethod.ReturnType, translations: control.Translated ? GetTranslations(property) : null ) ); } } } // 이벤트 분석 foreach (EventInfo info in value.GetEvents()) { GCommandAttribute command = GetAttribute <GCommandAttribute>(info); GControlAttribute control = GetAttribute <GControlAttribute>(info); if (command != null || control != null) { // 대리자 검색 Type eventDelegate = null; MethodInfo eventDelegateMethod = null; foreach (Type typeDelegate in value.GetNestedTypes(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { if (typeDelegate == info.EventHandlerType) { eventDelegate = typeDelegate; break; } } if (eventDelegate != null) { eventDelegateMethod = eventDelegate.GetMethod("Invoke", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); } if (command != null) { // 커멘드 목록 추가 target.Commands.Add( new GCommand ( target, value.FullName, info.Name, command.Name, eventDelegateMethod != null ? eventDelegateMethod.ReturnType : typeof(void), GCommand.CommandType.Event, eventDelegateMethod != null ? GetParameters(eventDelegateMethod) : null, translations: command.Translated ? GetTranslations(info) : null ) ); } if (control != null) { // 컨트롤 목록 추가 controlExports.Add( new GExport ( value.FullName, info.Name, control.Name, eventDelegateMethod != null ? eventDelegateMethod.ReturnType : typeof(void), eventDelegateMethod != null ? GetParameters(eventDelegateMethod) : null, translations: control.Translated ? GetTranslations(info) : null ) ); } } } // 메소드 분석 foreach (MethodInfo info in value.GetMethods()) { GCommandAttribute command = GetAttribute <GCommandAttribute>(info); if (command != null) { // 커멘드 목록 추가 target.Commands.Add( new GCommand ( target, value.FullName, info.Name, command.Name, info.ReturnType, info.ReturnType == typeof(void) ? GCommand.CommandType.Call : GCommand.CommandType.Logic, GetParameters(info), translations: command.Translated ? GetTranslations(info) : null ) ); } } // 열거형 분석 foreach (Type enumeration in value.GetNestedTypes()) { GCommandAttribute command = GetAttribute <GCommandAttribute>(enumeration); if (command != null && enumeration.IsEnum) { // 열거형 필드 분석 List <GEnumeration> gEnumList = new List <GEnumeration>(); foreach (FieldInfo enumerationField in enumeration.GetFields()) { GFieldAttribute fieldCommand = GetAttribute <GFieldAttribute>(enumerationField); if (fieldCommand != null) { gEnumList.Add(new GEnumeration(enumerationField.Name, $"{value.FullName}.{enumeration.Name}.{enumerationField.Name}", fieldCommand.Name, enumerationField.FieldType)); } } // 커멘드 목록 추가 target.Commands.Add( new GCommand ( target, value.FullName, enumeration.Name, command.Name, enumeration, GCommand.CommandType.Enum, gEnumList.ToArray(), translations: command.Translated ? GetTranslations(enumeration) : null ) ); } } } if (value.BaseType == typeof(GView)) { // 뷰 이름 분석 GViewAttribute view = GetAttribute <GViewAttribute>(value); target.Controls.Add(new GControl(target, value, view != null ? view.Name : value.FullName, value.FullName, controlExports.ToArray())); } } target.Commands = (from command in target.Commands orderby command.MethodType descending, command.FriendlyName ascending select command).ToList(); return(target); }