void EnforceColumnPrefs() { try { if (GridPref != null) { foreach (var pair in GridPref.ColumnPrefs.OrderBy(p => p.Value.VisiblePosition)) { ColumnPref pref = pair.Value; ColumnBase cb = this.Grid.Columns[pair.Key]; if (cb == null) // no longer exists { continue; } if (pref.Width > 0) { cb.Width = pref.Width; } cb.VisiblePosition = pref.VisiblePosition; } GridPref.Completed = true; } } catch (Exception ex) { AbnakiLog.Exception(ex); } }
bool ReloadBounds() { bool changed = false; Prefs pref = Abnaki.Windows.Software.Wpf.Profile.Preference.ReadClassPrefs <MainWindow, Prefs>(); if (pref != null) { if (WpfScreenHelper.Screen.AllScreens.Any(sc => sc.WorkingArea.IntersectsWith(pref.Bounds))) { this.Hide(); // show later Top = pref.Bounds.Top; Left = pref.Bounds.Left; Width = pref.Bounds.Width; Height = pref.Bounds.Height; this.WindowState = pref.State; changed = true; } else { AbnakiLog.Comment(GetType().Name + " disregarded undisplayable bounds " + pref.Bounds); } } return(changed); }
static void CompleteSetup(Abnaki.Windows.GUI.IWindow mainWindow, IDockSystem ds) { if (ds == null) { AbnakiLog.Comment("IDockSystem null"); } else { ds.Defaults(); mainWindow.SavingPanelLayout += fi => ds.SerializeLayout(fi); mainWindow.RestoringPanelLayout += fi => ds.DeserializeLayout(fi); } }
static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) { string filepath = null; if (args.LoadedAssembly.IsDynamic) { // no file } else { filepath = args.LoadedAssembly.Location; } AbnakiLog.FileInfo(filepath, "Load " + args.LoadedAssembly.GetName()); }
/// <summary> /// Starts Application having Twindow as first thing user sees. /// </summary> /// <typeparam name="Tapp">System.Windows.Application, or subclass if necessary</typeparam> /// <typeparam name="Twindow">class of window</typeparam> /// <example> /// <code> /// [STAThread] /// public static int Main(string[] args) /// { return Starter.Start < YourApp,YourWin >(args); } /// </code> /// </example> public static int Start <Twindow, Tapp>(string[] args, Func <Twindow> initWindow = null) where Tapp : System.Windows.Application, new() where Twindow : System.Windows.Window, new() { //Process proc = System.Diagnostics.Process.GetCurrentProcess(); //ProcessStartInfo pistart = proc.StartInfo; // no use try { var starta = System.Reflection.Assembly.GetEntryAssembly(); AbnakiLog.Comment("Start", starta.Location); AbnakiLog.Comment("Version", starta.GetName().Version); AbnakiLog.Comment("Operating System", Environment.OSVersion); AbnakiLog.Comment("Culture", System.Globalization.CultureInfo.CurrentCulture); // reconcile FrameworkElement Language with CurrentCulture, which is independent by default FrameworkElement.LanguageProperty.OverrideMetadata( typeof(FrameworkElement), new FrameworkPropertyMetadata( System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); System.AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad; Tapp app = new Tapp(); app.DispatcherUnhandledException += Current_DispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Twindow mw; if (initWindow == null) { mw = new Twindow(); } else { mw = initWindow(); } return(app.Run(mw)); } catch (Exception ex) { Diplomat.Notifier.Error(ex); Diplomat.Troubleshooter.DialogSaveLog(); } return(1); // failed }
public void TestEntryOfEntries() { string f1 = "log1.xml"; AbnakiLog.Comment("Vote Labour"); AbnakiLog.Comment("Vote Tory"); AbnakiLog.Write(f1); AbnakiLog.Comment("Should be followed by EntryOfEntries"); AbnakiLog.Incorporate(f1); string f2 = "log2.xml"; AbnakiLog.Write(f2); Debug.WriteLine("Wrote logs in " + Environment.CurrentDirectory); }
void InvokeRestoringPanelLayout(FileInfo fi) { if (fi.Exists) { var h = RestoringPanelLayout; if (h != null) { using (new WaitCursor()) { h(fi); } } } else { AbnakiLog.FileInfo(fi, "Nonexistent, ignored"); } }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { // but in OnClosed(), note that RestoreBounds is Empty base.OnClosing(e); try { SaveBounds(); MessageTube.Publish(new FarewellMessage()); FileInfo fi = LayoutFileInfo(); InvokeSavingPanelLayout(fi); } catch (Exception ex) { AbnakiLog.Exception(ex); } }
public static Tpref ReadClassPrefs <Tclass, Tpref>() where Tpref : class { FileInfo fi = ClassPrefsFile <Tclass>(); if (fi.Exists) { try { using (StreamReader sr = new StreamReader(fi.FullName, PrefEncoding)) { XmlSerializer xs = new XmlSerializer(typeof(Tpref)); return((Tpref)xs.Deserialize(sr)); } } catch (Exception ex) { AbnakiLog.Exception(ex); } } return(null); }