public void RemoveConfigurationTest() { string path = Path.Combine(provider.UserDataFolderPath, TestLayoutFile); foreach (string file in Directory.EnumerateFiles(provider.UserDataFolderPath)) { if (file.IndexOf(path) == 0 && file.Contains(".bak")) { File.Delete(file); } } AppLayout al = new AppLayout(10, 11); al.SerializeInJSON(path); ConfigurationBase.RemoveConfiguration(path); Assert.IsFalse(File.Exists(path)); bool bakExists = false; foreach (string file in Directory.EnumerateFiles(provider.UserDataFolderPath)) { if (file.IndexOf(path) == 0 && file.Contains(".bak")) { bakExists = true; File.Delete(file); break; } } Assert.IsTrue(bakExists); }
public void LoadDefaultAppLayoutTest() { string path = Path.Combine(provider.UserDataFolderPath, TestLayoutFile); AppLayout al = new AppLayout(10, 11); al.LayoutLive.Height = 800; al.LayoutSnapshot.RowPropertiesHeight = 500; al.SerializeInJSON(path); AppLayout loadedAl = AppLayout.LoadFromJSON <AppLayout>(path); loadedAl.LoadLayoutIfPrevVersion(2, 2); System.IO.File.Delete(path); Assert.AreEqual(460, loadedAl.LayoutLive.Width); Assert.AreEqual(800, loadedAl.LayoutLive.Height); Assert.AreEqual(46 * 7, loadedAl.LayoutLive.RowPropertiesHeight); Assert.AreEqual(0, loadedAl.LayoutLive.RowTestHeight); Assert.AreEqual(870, loadedAl.LayoutSnapshot.Width); Assert.AreEqual(720, loadedAl.LayoutSnapshot.Height); Assert.AreEqual(410, loadedAl.LayoutSnapshot.ColumnSnapWidth); Assert.AreEqual(500, loadedAl.LayoutSnapshot.RowPropertiesHeight); Assert.AreEqual(260, loadedAl.LayoutSnapshot.RowTestHeight); Assert.AreEqual(AppLayout.CurrentVersion, loadedAl.Version); Assert.AreEqual(10, loadedAl.Top); Assert.AreEqual(11, loadedAl.Left); }
public void CreateAppLayout() { AppLayout appLayout = new AppLayout(); appLayout.ApplicationName = ApplicationName; File.WriteAllText(AppPath + "\\Views\\Shared\\_Layout.cshtml", appLayout.TransformText()); }
/// <summary> /// Update main window layout. /// </summary> private void UpdateMainWindowLayout() { AppLayout layout = ConfigurationManager.GetDefaultInstance().AppLayout; EnsureWindowIsInVirtualScreen(layout); this.Top = layout.Top; this.Left = layout.Left; this.Width = layout.Width; this.Height = layout.Height; this.WindowState = layout.WinState; }
internal static void EnsureWindowIsInVirtualScreenWithInjection(AppLayout layout, double windowTop, double windowLeft, double virtualLeft, double virtualTop, double virtualWidth, double virtualHeight) { double virtualRight = virtualLeft + virtualWidth; double virtualBottom = virtualTop + virtualHeight; if (layout != null) { const double fallbackWindowPosition = 200.0; layout.Top = GetFirstDefinedNumber(new double[] { layout.Top, windowTop, fallbackWindowPosition }); layout.Left = GetFirstDefinedNumber(new double[] { layout.Left, windowLeft, fallbackWindowPosition }); double top = layout.Top; double left = layout.Left; double right = left + layout.Width; double bottom = top + layout.Height; // If the window is completely offscreen, open it in default location if ((right <= virtualLeft) || (bottom <= virtualTop) || (left >= virtualRight) || (top >= virtualBottom)) { top = layout.Top = windowTop; left = layout.Left = windowLeft; } // Adjust the window extents to keep it fully within the virtual screen layout.Width = Math.Min(layout.Width, virtualWidth); layout.Height = Math.Min(layout.Height, virtualHeight); right = left + layout.Width; bottom = top + layout.Height; if (right > virtualRight) { layout.Left = virtualRight - layout.Width; } else if (left < virtualLeft) { layout.Left = virtualLeft; } if (bottom > virtualBottom) { layout.Top = virtualBottom - layout.Height; } else if (top < virtualTop) { layout.Top = virtualTop; } } }
/// <summary> /// Deserialize saved A11yElement /// </summary> /// <param name="path"></param> /// <returns></returns> public static AppLayout FromJson(string path) { AppLayout element = null; string exactPath = Path.GetFullPath(".../Resources"); var x = Directory.EnumerateDirectories(".."); if (File.Exists(path)) { var json = File.ReadAllText(path); element = JsonConvert.DeserializeObject <AppLayout>(json); } return(element); }
public void AppLayoutTest() { AppLayout al = new AppLayout(10, 11); Assert.AreEqual(460, al.LayoutLive.Width); Assert.AreEqual(500, al.LayoutLive.Height); Assert.AreEqual(410, al.LayoutLive.ColumnSnapWidth); Assert.AreEqual(0, al.LayoutLive.RowTestHeight); Assert.AreEqual(46 * 7, al.LayoutLive.RowPropertiesHeight); Assert.AreEqual(870, al.LayoutSnapshot.Width); Assert.AreEqual(720, al.LayoutSnapshot.Height); Assert.AreEqual(410, al.LayoutSnapshot.ColumnSnapWidth); Assert.AreEqual(260, al.LayoutSnapshot.RowTestHeight); Assert.AreEqual(46 * 7, al.LayoutLive.RowPropertiesHeight); Assert.AreEqual(10, al.Top); Assert.AreEqual(11, al.Left); }
private AppLayout GetInitialConfig(double?top = null, double?left = null, double?height = null, double?width = null) { var layout = new AppLayout(double.NaN, double.NaN); if (top.HasValue) { layout.Top = top.Value; } if (left.HasValue) { layout.Left = left.Value; } if (height.HasValue) { layout.Height = height.Value; } if (width.HasValue) { layout.Width = width.Value; } return(layout); }
static void Main(string [] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //Must call MgPlatform.Initialize() before we can work with anything from the MapGuide API try { #if PROFILE using (new CallMeasure("MgdPlatform.Initialize")) { MgdPlatform.Initialize("Platform.ini"); } #else MgdPlatform.Initialize("Platform.ini"); #endif } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error"); return; } AppLayout layout = null; var ser = new XmlSerializer(typeof(AppLayout)); if (args.Length == 1) { using (var file = File.OpenRead(args[0])) { layout = (AppLayout)ser.Deserialize(file); } }/* * else * { * layout = AppLayout.CreateDefault("MapGuide Desktop App Layout Example", "Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition"); * using (var file = File.OpenWrite("Sheboygan.AppLayout")) * { * ser.Serialize(file, layout); * } * }*/ var mdfId = new MgResourceIdentifier(layout.Map.MapDefinition); var provider = new MgDesktopMapViewerProvider(null); var resSvc = (MgResourceService)provider.CreateService(MgServiceType.ResourceService); if (resSvc.ResourceExists(mdfId)) { #if PROFILE using (new CallMeasure("MgdMap constructor (cold start)")) { var mapCold = new MgdMap(mdfId); } MgdMap map = null; using (new CallMeasure("MgdMap constructor (warm start)")) { map = new MgdMap(mdfId); } using (new CallMeasure("MgMapViewerProvider.LoadMap")) { provider.LoadMap(map); } #else provider.LoadMap(new MgdMap(mdfId)); #endif } var frm = Shell.Instance; ((Shell)frm).Initialize(layout, provider); Application.Run((Shell)frm); MgdPlatform.Terminate(); }
/// <summary> /// Make sure that the app layout is fully within the virtual screen, including resizing it /// if necessary. /// </summary> /// <param name="layout">The layout. Its position will be modified only if necessary</param> private void EnsureWindowIsInVirtualScreen(AppLayout layout) { EnsureWindowIsInVirtualScreenWithInjection(layout, this.Top, this.Left, SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight); }