/// <summary> /// Takes PlaceDirectory b and traveses thru each key, /// If key not found, PlaceDirectory will add that key and the contents of said key from PlaceDirectory b to 'this' PlaceDir. /// </summary> public void Merge(PlaceDirectory b) { if (b != null && b.Dir.Count > 0) { foreach (string k in b.Dir.Keys) { //Check if file still exist if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\voreadventure\\custom\\places\\" + k)) { if (MessageBox.Show("The place \"" + k + "\" does not exits, but there was a reference in the pass session,\n would you like to keep the data of this place?", "Missing place referd - Previous session", MessageBoxButtons.YesNo) == DialogResult.No) { continue; } } //Mergin missing keys if (!Dir.ContainsKey(k)) { Dir.Add(k, b.Dir[k]); } //If key is not missing, Load the entierty of the list* //* only if it has more or the same as to avoid data lost else { if (b.Dir[k].Count >= Dir[k].Count) { Dir[k] = b.Dir[k]; } } } } }
//From Program to xml public void SaveSession(PlaceDirectory a) { string path = Environment.CurrentDirectory + "\\session.xml"; SessionSeriasable session = new SessionSeriasable(a); StreamWriter writer = new StreamWriter(path); XmlSerializer serializer = new XmlSerializer(session.GetType()); serializer.Serialize(writer, session); writer.Close(); }
/// <summary> /// Get's all session data and translate it into a seriasable form. /// </summary> /// <param name="placeDirectory"></param> void GetSessionFrom(PlaceDirectory placeDirectory) { foreach (string k in placeDirectory.Dir.Keys) { List <NodeSeria> nl = new List <NodeSeria>(); foreach (Node item in placeDirectory.Dir[k]) { nl.Add(new NodeSeria(item)); } keys.Add(k); NSerias.Add(nl); } }
public void LoadSession() { log.Info("Loading intizialided"); prevSession = lSe.LoadPreviousSession().ToPlaceDirectory(); //Merge already loaded PlaceDir with prev session list PlaceDir.Merge(prevSession); foreach (string key in PlaceDir.Dir.Keys) { foreach (Node n in PlaceDir.Dir[key]) { n.RelateOptions(PlaceDir.Dir[key]); } } UpdateWorkspace(); }
public PlaceDirectory ToPlaceDirectory() { PlaceDirectory pd = new PlaceDirectory(); pd.Dir = new Dictionary <string, List <Node> >(); for (int i = 0; i < keys.Count; i++) { string k = keys[i]; //Create nodes and add them to the list pd.Dir.Add(k, new List <Node>()); foreach (NodeSeria node in NSerias[i])//for each node in the list of sernodes { pd.Dir[k].Add(node.ToNode()); } } return(pd); }
public List <List <NodeSeria> > NSerias = new List <List <NodeSeria> >(); //NodesFromPlaces [index of key related][list of node][node] public SessionSeriasable(PlaceDirectory a) { GetSessionFrom(a); }