/* * private void PopulateScreens() * { * settings.Screens = Screen.AllScreens.Select(s => * { * string friendlyName = s.DeviceName; * if (settings.ScreenFriendlyName) * { * try * { * string friendlyNameStr = s.DeviceFriendlyName(); * if (!String.IsNullOrEmpty(friendlyNameStr)) * { * friendlyName = friendlyNameStr; * } * } * catch { } * } * return new ScreenInfo(s.DeviceName, friendlyName); * }).ToList(); * * if (string.IsNullOrWhiteSpace(settings.Screen) && settings.Screens.Count > 0) * { * settings.Screen = settings.Screens[0].DeviceName; * } * Logger.Instance.LogMessage(TracingLevel.INFO, $"Populated {settings.Screens.Count} screens"); * }*/ private async Task MoveApplication() { if (String.IsNullOrWhiteSpace(settings.Screen)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"Screen not specified."); await Connection.ShowAlert(); return; } if (settings.AppSpecific && String.IsNullOrWhiteSpace(settings.ApplicationName)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"Application not specified."); await Connection.ShowAlert(); return; } if (String.IsNullOrWhiteSpace(settings.XPosition) || String.IsNullOrWhiteSpace(settings.YPosition)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"X or Y position not specified."); await Connection.ShowAlert(); return; } if (!int.TryParse(settings.XPosition, out int xPosition)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid X position: {settings.XPosition}"); await Connection.ShowAlert(); return; } if (!int.TryParse(settings.YPosition, out int yPosition)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid Y position: {settings.YPosition}"); await Connection.ShowAlert(); return; } WindowSize windowSize = null; WindowResize windowResize = WindowResize.NoResize; if (settings.ResizeWindow) { windowResize = WindowResize.ResizeWindow; if (String.IsNullOrWhiteSpace(settings.Height) || String.IsNullOrWhiteSpace(settings.Width)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"Height or Width position not specified."); await Connection.ShowAlert(); return; } if (!int.TryParse(settings.Height, out int height)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid height: {settings.Height}"); await Connection.ShowAlert(); return; } if (!int.TryParse(settings.Width, out int width)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid width: {settings.Width}"); await Connection.ShowAlert(); return; } windowSize = new WindowSize(height, width); } else if (settings.MaximizeWindow) { windowResize = WindowResize.Maximize; } else if (settings.MinimizeWindow) { windowResize = WindowResize.Minimize; } else if (settings.OnlyTopmost) { windowResize = WindowResize.OnlyTopmost; } Screen screen = MonitorManager.Instance.GetScreenFromUniqueValue(settings.Screen); if (screen == null) { Logger.Instance.LogMessage(TracingLevel.ERROR, $"Could not find screen {settings.Screen}"); await Connection.ShowAlert(); return; } var processCount = WindowPosition.MoveProcess(new MoveProcessSettings() { AppSpecific = settings.AppSpecific, Name = settings.ApplicationName, DestinationScreen = screen, Position = new System.Drawing.Point(xPosition, yPosition), WindowResize = windowResize, WindowSize = windowSize, MakeTopmost = settings.TopmostWindow, LocationFilter = settings.ShouldFilterLocation ? settings.LocationFilter : null, TitleFilter = settings.ShouldFilterTitle ? settings.TitleFilter : null }); if (processCount > 0) { tmrRetryProcess.Stop(); } else if (processCount == 0 && !tmrRetryProcess.Enabled) { if (!Int32.TryParse(settings.RetryAttempts, out retryAttempts)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid RetryAttempts: {settings.RetryAttempts}"); return; } tmrRetryProcess.Start(); } }