Click here to Skip to main content
11,584,556 members (64,457 online)

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy except programming questions.

Technical discussions are encouraged, but click here to ask your programming question.

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, no programming questions and please don't post ads.
 
GeneralRe: What technique do you use to persist state? Pin
leppie4-Mar-13 2:32
memberleppie4-Mar-13 2:32 
GeneralRe: What technique do you use to persist state? Pin
Ravi Bhavnani4-Mar-13 2:40
memberRavi Bhavnani4-Mar-13 2:40 
GeneralRe: What technique do you use to persist state? Pin
Marc Clifton4-Mar-13 4:04
protectorMarc Clifton4-Mar-13 4:04 
GeneralRe: What technique do you use to persist state? Pin
harold aptroot4-Mar-13 2:41
memberharold aptroot4-Mar-13 2:41 
GeneralRe: What technique do you use to persist state? Pin
CPallini4-Mar-13 2:53
mvpCPallini4-Mar-13 2:53 
GeneralRe: What technique do you use to persist state? Pin
Nagy Vilmos4-Mar-13 2:59
memberNagy Vilmos4-Mar-13 2:59 
GeneralRe: What technique do you use to persist state? Pin
ChrisElston4-Mar-13 3:14
memberChrisElston4-Mar-13 3:14 
GeneralRe: What technique do you use to persist state? Pin
Marc Clifton4-Mar-13 4:10
protectorMarc Clifton4-Mar-13 4: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? Pin
Forogar4-Mar-13 4:33
memberForogar4-Mar-13 4:33 
GeneralRe: What technique do you use to persist state? Pin
Marc Clifton4-Mar-13 4:46
protectorMarc Clifton4-Mar-13 4:46 
GeneralRe: What technique do you use to persist state? Pin
Marco Bertschi4-Mar-13 3:20
memberMarco Bertschi4-Mar-13 3:20 
GeneralRe: What technique do you use to persist state? Pin
OriginalGriff4-Mar-13 3:32
mvpOriginalGriff4-Mar-13 3:32 
GeneralRe: What technique do you use to persist state? Pin
Ennis Ray Lynch, Jr.4-Mar-13 3:53
memberEnnis Ray Lynch, Jr.4-Mar-13 3:53 
GeneralRe: What technique do you use to persist state? Pin
Marc Clifton4-Mar-13 4:18
protectorMarc Clifton4-Mar-13 4:18 
GeneralRe: What technique do you use to persist state? Pin
Ravi Bhavnani4-Mar-13 6:32
memberRavi Bhavnani4-Mar-13 6:32 
GeneralRe: What technique do you use to persist state? Pin
Kabwla.Phone5-Mar-13 6:06
memberKabwla.Phone5-Mar-13 6:06 
GeneralRe: What technique do you use to persist state? Pin
Klaus-Werner Konrad4-Mar-13 4:05
memberKlaus-Werner Konrad4-Mar-13 4:05 
GeneralRe: What technique do you use to persist state? Pin
Marc Clifton4-Mar-13 4:17
protectorMarc Clifton4-Mar-13 4:17 
GeneralRe: What technique do you use to persist state? Pin
Klaus-Werner Konrad4-Mar-13 5:07
memberKlaus-Werner Konrad4-Mar-13 5:07 
GeneralRe: What technique do you use to persist state? Pin
wizardzz4-Mar-13 4:13
memberwizardzz4-Mar-13 4:13 
GeneralRe: What technique do you use to persist state? Pin
Eddy Vluggen4-Mar-13 5:00
mvpEddy Vluggen4-Mar-13 5:00 
GeneralRe: What technique do you use to persist state? Pin
Marc Clifton4-Mar-13 6:04
protectorMarc Clifton4-Mar-13 6:04 
GeneralRe: What technique do you use to persist state? Pin
S Houghtelin4-Mar-13 5:11
memberS Houghtelin4-Mar-13 5:11 
GeneralRe: What technique do you use to persist state? Pin
PIEBALDconsult4-Mar-13 5:19
memberPIEBALDconsult4-Mar-13 5:19 
GeneralRe: What technique do you use to persist state? Pin
BobJanova4-Mar-13 6:42
memberBobJanova4-Mar-13 6: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
Web03 | 2.8.150707.1 | Last Updated 8 Jul 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid