IEnumerator WaitForFlightGlobals() { while (!FlightGlobals.ready || (FlightGlobals.ActiveVessel == null)) { yield return(new WaitForSeconds(0.1f)); } ConfigNode node = savedNode; node = node.GetNode(PERSISTENT_NODE_NAME); vesselProfiles = new VesselTable(); var guidStrings = node.nodes.DistinctNames(); foreach (var strGuid in guidStrings) { try { Guid guid = new Guid(strGuid); // could throw an exception if string is malformed if (!FlightGlobals.fetch.vessels.Any(v => v.id == guid)) { continue; } if (vesselProfiles.ContainsKey(guid)) { continue; } ConfigNode profileNode = node.GetNode(strGuid); Profile p = new Profile(profileNode); if (p.modified) { vesselProfiles.Add(guid, p); } else { Profile storedProfile = FindStoredProfile(p.name); if (HaveStoredProfile(storedProfile)) { vesselProfiles.Add(guid, storedProfile.Clone()); } else { p.modified = true; vesselProfiles.Add(guid, p); } } } catch (Exception e) { Log.Error("ProfileManager: Exception while loading '{0}': {1}", strGuid, e); } } Ready = true; }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (!node.HasNode(PERSISTENT_NODE_NAME)) { Log.Warning("Persistent save has no saved profiles"); vesselProfiles = new VesselTable(); Ready = true; return; } node = node.GetNode(PERSISTENT_NODE_NAME); vesselProfiles = new VesselTable(); var guidStrings = node.nodes.DistinctNames(); foreach (var strGuid in guidStrings) { try { Guid guid = new Guid(strGuid); // could throw an exception if string is malformed if (!FlightGlobals.Vessels.Any(v => v.id == guid)) { continue; } if (vesselProfiles.ContainsKey(guid)) { continue; } ConfigNode profileNode = node.GetNode(strGuid); Profile p = new Profile(profileNode); if (p.modified) { vesselProfiles.Add(guid, p); } else { if (HaveStoredProfile(p.name)) { vesselProfiles.Add(guid, FindStoredProfile(p.name).Clone()); } else { p.modified = true; vesselProfiles.Add(guid, p); } } } catch (Exception e) { Log.Error("ProfileManager: Exception while loading '{0}': {1}", strGuid, e); } } Ready = true; }
public void Insert(string VesselName,byte[] Ts) { VesselTable item = new VesselTable(); item.VesselName = VesselName; item.Ts = Ts; item.Save(UserName); }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (!node.HasNode(PERSISTENT_NODE_NAME)) { Log.Warning("Persistent save has no saved profiles"); vesselProfiles = new VesselTable(); Ready = true; return; } savedNode = node.CreateCopy(); StartCoroutine(WaitForFlightGlobals()); }
//end btnadd click #endregion #region crud events protected void insert_vessel_name(string vesselname) { try { VesselTable _tbl = new VesselTable(); _tbl.VesselName = vesselname; _tbl.Save(); } catch (Exception ex) { string _ex = ex.Message.ToString(); this.dxlblErr.Text = _ex; this.dxpnlErr.Visible = true; } }
/// <summary> /// Load vessel-specific ConfigNodes from the persistent file /// </summary> /// <param name="node"></param> public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (!node.HasNode(PERSISTENT_NODE_NAME)) { Log.Warning("Persistent save has no saved profiles"); vesselProfiles = new VesselTable(); Ready = true; return; } else { node = node.GetNode(PERSISTENT_NODE_NAME); } //List<string> errors = new List<string>(); vesselProfiles = new VesselTable(); var guidStrings = node.nodes.DistinctNames(); Log.Verbose("ProfileManager: {0} vessel profile nodes found", guidStrings.Length); foreach (var strGuid in guidStrings) { Log.Debug("Loading node with name '{0}'", strGuid); try { Guid guid = new Guid(strGuid); // could throw an exception if string is malformed Log.Debug("Guid created: {0}", guid.ToString()); // confirm a vessel with this Guid exists if (!FlightGlobals.Vessels.Any(v => v.id == guid)) { Log.Warning("Did not find a vessel that matches {0}; check destruction event code", guid.ToString()); continue; } // confirm that we don't have duplicate entries if (vesselProfiles.ContainsKey(guid)) { Log.Error("ProfileManager: Duplicate profile for vessel {0} found!", VesselIdentifier(guid), FlightGlobals.Vessels.Find(v => v.id == guid).vesselName); continue; } // grab the node with this info ConfigNode profileNode = node.GetNode(strGuid); // create a profile out of the data stored in this node Profile p = new Profile(profileNode); // if modified is true => use the modified profile // if modified is false THEN // if a stored profile of same name exists THEN // clone the stored profile // Else // add to missing profile list // clone default profile // end // end if (p.modified) { Log.Verbose("Vessel {0} has a modified profile '{1}' stored.", VesselIdentifier(guid), p.name); vesselProfiles.Add(guid, p); } else { if (HaveStoredProfile(p.name)) { Log.Verbose("Vessel {0} has stored profile '{1}'", VesselIdentifier(guid), p.name); // use the stored profile vesselProfiles.Add(guid, FindStoredProfile(p.name).Clone()); } else { Log.Warning("Vessel {0} refers to a stored profile '{1}' which was not found. Existing data has been converted to a vessel profile.", VesselIdentifier(guid), p.name); p.modified = true; vesselProfiles.Add(guid, p); //// add to missing profile list and clone default //errors.Add(string.Format("Stored profile '{0}' not found for {1}", p.name, VesselIdentifier(guid))); //Log.Error("Could not find profile '{0}' for vessel {1}. Will use default.", p.name, VesselIdentifier(guid)); //// note to self: this isn't the same as Profile.MakeDefault(); //// that is used for a truly default, totally unmodified profile. //// DefaultProfile will locate a profile called "default" instead, //// which may be custom-made by the user if they overwrite the //// standard one //vesselProfiles.Add(guid, DefaultProfile.Clone()); } } } catch (Exception e) { Log.Error("ProfileManager: Exception while loading '{0}': {1}", strGuid, e); } } //if (errors.Count > 0) //{ // string message = "Errors while loading profiles:\n\n"; // errors.ForEach(err => message += err + "\n"); // message += "\nVessel(s) have been assigned the \"default\" profile."; // Log.Debug("Errors encountered during profile load: {0}", message); // PopupDialog.SpawnPopupDialog("ScienceAlert: Profile Manager", message, "Okay", false, HighLogic.Skin); //} Ready = true; }
public void Update(int VesselID,string VesselName,byte[] Ts) { VesselTable item = new VesselTable(); item.MarkOld(); item.IsLoaded = true; item.VesselID = VesselID; item.VesselName = VesselName; item.Ts = Ts; item.Save(UserName); }
//end btnadd click #endregion #region crud events protected void insert_vessel_name(string vesselname) { try { VesselTable _tbl = new VesselTable(); _tbl.VesselName = vesselname; _tbl.Save(); } catch(Exception ex) { string _ex = ex.Message.ToString(); this.dxlblErr.Text = _ex; this.dxpnlErr.Visible = true; } }