Click here to Skip to main content

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy.
The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct and please don't post ads.

Technical discussions are welcome, but if you need specific help please use the programming forums.


 
GeneralRe: What technique do you use to persist state? Pinmemberleppie4-Mar-13 3:32 
GeneralRe: What technique do you use to persist state? PinmemberRavi Bhavnani4-Mar-13 3:40 
GeneralRe: What technique do you use to persist state? PinprotectorMarc Clifton4-Mar-13 5:04 
GeneralRe: What technique do you use to persist state? Pinmemberharold aptroot4-Mar-13 3:41 
GeneralRe: What technique do you use to persist state? PinmvpCPallini4-Mar-13 3:53 
GeneralRe: What technique do you use to persist state? PinmemberNagy Vilmos4-Mar-13 3:59 
GeneralRe: What technique do you use to persist state? PinmemberChrisElston4-Mar-13 4:14 
GeneralRe: What technique do you use to persist state? PinprotectorMarc Clifton4-Mar-13 5:10 
Nagy Vilmos wrote:
Dang Marc, have you been reading my hard drive again?

 
Who, me? Unsure | :~
 
Nagy Vilmos wrote:
I need to work out an article for just this

 
That would be great. The impetus, partly, for my survey'ish question is because I've been adding state/configuration persistence to an app, and I was wondering what sort of "best practices" there might be out there. The .NET class seems not configurable enough - I'd like to leave it open to the developer as to how to persist the state information. On the other hand, it also seems to closely coupled to "the Microsoft way", what with all the binding support, not that one needs to use it.
 
At the moment, I've decided to go for an interface-less, more functional approach, resulting in this raw usage example:
 
public ApplicationFormController()
{
	Program.AppState.Register("Form", () =>
		{
			return new List<State>()
				{
					new State("X", View.Location.X),
					new State("Y", View.Location.Y),
					new State("W", View.Size.Width),
					new State("H", View.Size.Height),
					new State("WindowState", View.WindowState.ToString()),
				};
 
		},
		state =>
		{
			// Silently handle exceptions for when we add state items that are part of the state file until we 
			// save the state.  This allows me to add new state information without crashing the app on startup.
			Program.Try(() => View.Location = new Point(state.Single(t => t.Key == "X").Value.to_i(), state.Single(t => t.Key == "Y").Value.to_i()));
			Program.Try(() => View.Size = new Size(state.Single(t => t.Key == "W").Value.to_i(), state.Single(t => t.Key == "H").Value.to_i()));
			Program.Try(() => View.WindowState = state.Single(t => t.Key == "WindowState").Value.ToEnum<FormWindowState>());
		});
}
 
public override void EndInit()
{
	Program.AppState.RestoreState("appState.xml");
}
 
Marc

GeneralRe: What technique do you use to persist state? PinmemberForogar4-Mar-13 5:33 
GeneralRe: What technique do you use to persist state? PinprotectorMarc Clifton4-Mar-13 5:46 
GeneralRe: What technique do you use to persist state? PinmemberMarco Bertschi4-Mar-13 4:20 
GeneralRe: What technique do you use to persist state? PinmvpOriginalGriff4-Mar-13 4:32 
GeneralRe: What technique do you use to persist state? PinmemberEnnis Ray Lynch, Jr.4-Mar-13 4:53 
GeneralRe: What technique do you use to persist state? PinprotectorMarc Clifton4-Mar-13 5:18 
GeneralRe: What technique do you use to persist state? PinmemberRavi Bhavnani4-Mar-13 7:32 
GeneralRe: What technique do you use to persist state? PinmemberKabwla.Phone5-Mar-13 7:06 
GeneralRe: What technique do you use to persist state? PinmemberKlaus-Werner Konrad4-Mar-13 5:05 
GeneralRe: What technique do you use to persist state? PinprotectorMarc Clifton4-Mar-13 5:17 
GeneralRe: What technique do you use to persist state? PinmemberKlaus-Werner Konrad4-Mar-13 6:07 
GeneralRe: What technique do you use to persist state? Pinmemberwizardzz4-Mar-13 5:13 
GeneralRe: What technique do you use to persist state? PinmvpEddy Vluggen4-Mar-13 6:00 
GeneralRe: What technique do you use to persist state? PinprotectorMarc Clifton4-Mar-13 7:04 
GeneralRe: What technique do you use to persist state? PinmemberS Houghtelin4-Mar-13 6:11 
GeneralRe: What technique do you use to persist state? PinmemberPIEBALDconsult4-Mar-13 6:19 
GeneralRe: What technique do you use to persist state? PinmemberBobJanova4-Mar-13 7:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 18 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid