public MainViewModel(IImageLoaderService imageLoaderService, IImageProcessingService imageProcessingService) { this.imageLoaderService = imageLoaderService; this.imageProcessingRoutine = imageProcessingService.Current; this.imageProcessingLog = new ImageProcessingLog(); }
// Collect available image processing routines in the specified assembly private void CollectImageProcessingRoutines(string fname) { Type typeIImageProcessingRoutine = typeof(IImageProcessingRoutine); Assembly assembly = null; try { // try to load assembly assembly = Assembly.LoadFrom(fname); // get types of the assembly Type[] types = assembly.GetTypes( ); // check all types foreach (Type type in types) { // get interfaces ot the type Type[] interfaces = type.GetInterfaces( ); // check, if the type is inherited from IImageProcessingRoutine if (Array.IndexOf(interfaces, typeIImageProcessingRoutine) != -1) { IImageProcessingRoutine ipRoutine = null; try { // create an instance of the type ipRoutine = (IImageProcessingRoutine)Activator.CreateInstance(type); // add routine to collection if (!processingRoutines.ContainsKey(ipRoutine.Name)) { processingRoutines.Add(ipRoutine.Name, ipRoutine); } } catch (Exception) { // something failed during instance creatinion } } } } catch (Exception) { } }
// Item is clicked in modules' menu private void module_Click( object sender, EventArgs e ) { ipRoutineToUse = processingRoutines[( (ToolStripMenuItem) sender ).Text]; ProcessSelectedImage( ); }
// On form loading private void MainForm_Load( object sender, EventArgs e ) { // collect available modules in application's directory CollectModules( Path.GetDirectoryName( Application.ExecutablePath ) ); // add modules' name to application's menu foreach ( string routineName in processingRoutines.Keys ) { ToolStripItem item = modulesToolStripMenuItem.DropDownItems.Add( routineName ); item.Click += new System.EventHandler( this.module_Click ); if ( ipRoutineToUse == null ) { ipRoutineToUse = processingRoutines[routineName]; } } // load configuratio Configuration config = Configuration.Instance; if ( config.Load( ) ) { try { bool windowPositionIsValid = false; // get window location/size Size windowSize = new Size( int.Parse( config.GetConfigurationOption( mainFormWidthOption ) ), int.Parse( config.GetConfigurationOption( mainFormHeightOption ) ) ); System.Drawing.Point windowTopLeft = new System.Drawing.Point( int.Parse( config.GetConfigurationOption( mainFormXOption ) ), int.Parse( config.GetConfigurationOption( mainFormYOption ) ) ); System.Drawing.Point windowTopRight = new System.Drawing.Point( windowTopLeft.X + windowSize.Width, windowTopLeft.Y ); // check if window location is within of the displays foreach ( Screen screen in Screen.AllScreens ) { if ( ( screen.WorkingArea.Contains( windowTopLeft ) ) || ( screen.WorkingArea.Contains( windowTopRight ) ) ) { windowPositionIsValid = true; break; } } if ( windowPositionIsValid ) { Location = windowTopLeft; Size = windowSize; WindowState = (FormWindowState) Enum.Parse( typeof( FormWindowState ), config.GetConfigurationOption( mainFormStateOption ) ); mainSplitContainer.SplitterDistance = int.Parse( config.GetConfigurationOption( splitter1Option ) ); splitContainer1.SplitterDistance = int.Parse( config.GetConfigurationOption( splitter2Option ) ); splitContainer2.SplitterDistance = int.Parse( config.GetConfigurationOption( splitter3Option ) ); } // get size mode of picture box SetPictureBoxSizeMode( (PictureBoxSizeMode) Enum.Parse( typeof( PictureBoxSizeMode ), config.GetConfigurationOption( pictureSizeModeOption ) ) ); // get recent folders for ( int i = 0; i < 7; i++ ) { string rf = config.GetConfigurationOption( recentFolderOption + i ); if ( rf != null ) recentFolders.Add( rf ); } RebuildRecentFoldersList( ); bool openLast = bool.Parse( config.GetConfigurationOption( openLastOption ) ); openLastFolderOnStartToolStripMenuItem.Checked = openLast; if ( ( openLast ) && ( recentFolders.Count > 0 ) ) { OpenFolder( recentFolders[0] ); } } catch { } } }
// On form loading private void MainForm_Load(object sender, EventArgs e) { // collect available modules in application's directory CollectModules(Path.GetDirectoryName(Application.ExecutablePath)); // add modules' name to application's menu foreach (string routineName in processingRoutines.Keys) { ToolStripItem item = modulesToolStripMenuItem.DropDownItems.Add(routineName); item.Click += new System.EventHandler(this.module_Click); if (ipRoutineToUse == null) { ipRoutineToUse = processingRoutines[routineName]; } } // load configuratio Configuration config = Configuration.Instance; if (config.Load( )) { try { // get window location/size Location = new Point( int.Parse(config.GetConfigurationOption(mainFormXOption)), int.Parse(config.GetConfigurationOption(mainFormYOption))); Size = new Size( int.Parse(config.GetConfigurationOption(mainFormWidthOption)), int.Parse(config.GetConfigurationOption(mainFormHeightOption))); WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), config.GetConfigurationOption(mainFormStateOption)); mainSplitContainer.SplitterDistance = int.Parse(config.GetConfigurationOption(splitter1Option)); splitContainer1.SplitterDistance = int.Parse(config.GetConfigurationOption(splitter2Option)); splitContainer2.SplitterDistance = int.Parse(config.GetConfigurationOption(splitter3Option)); // get size mode of picture box SetPictureBoxSizeMode((PictureBoxSizeMode)Enum.Parse(typeof(PictureBoxSizeMode), config.GetConfigurationOption(pictureSizeModeOption))); // get recent folders for (int i = 0; i < 7; i++) { string rf = config.GetConfigurationOption(recentFolderOption + i); if (rf != null) { recentFolders.Add(rf); } } RebuildRecentFoldersList( ); bool openLast = bool.Parse(config.GetConfigurationOption(openLastOption)); openLastFolderOnStartToolStripMenuItem.Checked = openLast; if ((openLast) && (recentFolders.Count > 0)) { OpenFolder(recentFolders[0]); } } catch { } } }
// Item is clicked in modules' menu private void module_Click(object sender, EventArgs e) { ipRoutineToUse = processingRoutines[((ToolStripMenuItem)sender).Text]; ProcessSelectedImage( ); }
// On form loading private void MainForm_Load( object sender, EventArgs e ) { // collect available modules in application's directory CollectModules( Path.GetDirectoryName( Application.ExecutablePath ) ); // add modules' name to application's menu foreach ( string routineName in processingRoutines.Keys ) { ToolStripItem item = modulesToolStripMenuItem.DropDownItems.Add( routineName ); item.Click += new System.EventHandler( this.module_Click ); if ( ipRoutineToUse == null ) { ipRoutineToUse = processingRoutines[routineName]; } } // load configuratio Configuration config = Configuration.Instance; if ( config.Load( ) ) { try { // get window location/size Location = new Point( int.Parse( config.GetConfigurationOption( mainFormXOption ) ), int.Parse( config.GetConfigurationOption( mainFormYOption ) ) ); Size = new Size( int.Parse( config.GetConfigurationOption( mainFormWidthOption ) ), int.Parse( config.GetConfigurationOption( mainFormHeightOption ) ) ); WindowState = (FormWindowState) Enum.Parse( typeof( FormWindowState ), config.GetConfigurationOption( mainFormStateOption ) ); mainSplitContainer.SplitterDistance = int.Parse( config.GetConfigurationOption( splitter1Option ) ); splitContainer1.SplitterDistance = int.Parse( config.GetConfigurationOption( splitter2Option ) ); splitContainer2.SplitterDistance = int.Parse( config.GetConfigurationOption( splitter3Option ) ); // get size mode of picture box pictureBox.SizeMode = (PictureBoxSizeMode) Enum.Parse( typeof( PictureBoxSizeMode ), config.GetConfigurationOption( pictureSizeModeOption ) ); // get recent folders for ( int i = 0; i < 5; i++ ) { string rf = config.GetConfigurationOption( recentFolderOption + i ); if ( rf != null ) recentFolders.Add( rf ); } RebuildRecentFoldersList( ); bool openLast = bool.Parse( config.GetConfigurationOption( openLastOption ) ); openLastFolderOnStartToolStripMenuItem.Checked = openLast; if ( ( openLast ) && ( recentFolders.Count > 0 ) ) { OpenFolder( recentFolders[0] ); } } catch { } } }
// On form loading private void MainForm_Load(object sender, EventArgs e) { // collect available modules in application's directory CollectModules(Path.GetDirectoryName(Application.ExecutablePath)); // add modules' name to application's menu foreach (var routineName in processingRoutines.Keys) { var item = modulesToolStripMenuItem.DropDownItems.Add(routineName); item.Click += new System.EventHandler(this.module_Click); if (ipRoutineToUse == null) { ipRoutineToUse = processingRoutines[routineName]; } } // load configuratio var config = Configuration.Instance; if (config.Load()) { try { var windowPositionIsValid = false; // get window location/size var windowSize = new Size( int.Parse(config.GetConfigurationOption(mainFormWidthOption)), int.Parse(config.GetConfigurationOption(mainFormHeightOption))); var windowTopLeft = new System.Drawing.Point( int.Parse(config.GetConfigurationOption(mainFormXOption)), int.Parse(config.GetConfigurationOption(mainFormYOption))); var windowTopRight = new System.Drawing.Point( windowTopLeft.X + windowSize.Width, windowTopLeft.Y); // check if window location is within of the displays foreach (var screen in Screen.AllScreens) { if ((screen.WorkingArea.Contains(windowTopLeft)) || (screen.WorkingArea.Contains(windowTopRight))) { windowPositionIsValid = true; break; } } if (windowPositionIsValid) { Location = windowTopLeft; Size = windowSize; WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), config.GetConfigurationOption(mainFormStateOption)); mainSplitContainer.SplitterDistance = int.Parse(config.GetConfigurationOption(splitter1Option)); splitContainer1.SplitterDistance = int.Parse(config.GetConfigurationOption(splitter2Option)); splitContainer2.SplitterDistance = int.Parse(config.GetConfigurationOption(splitter3Option)); } // get size mode of picture box SetPictureBoxSizeMode((PictureBoxSizeMode)Enum.Parse(typeof(PictureBoxSizeMode), config.GetConfigurationOption(pictureSizeModeOption))); // get recent folders for (var i = 0; i < 7; i++) { var rf = config.GetConfigurationOption(recentFolderOption + i); if (rf != null) { recentFolders.Add(rf); } } RebuildRecentFoldersList(); var openLast = bool.Parse(config.GetConfigurationOption(openLastOption)); openLastFolderOnStartToolStripMenuItem.Checked = openLast; if ((openLast) && (recentFolders.Count > 0)) { OpenFolder(recentFolders[0]); } } catch { } } }