private static Profile Load(IContentStorage storage, string profileFolder, Guid id, string file) { Profile profile = null; var path = storage.CombinePath(profileFolder, file); if (storage.IsFileExist(path)) { var document = new XmlDocument(); using (var stream = storage.OpenForRead(path)) { document.Load(stream); } var rootElement = document.DocumentElement; var name = rootElement.GetChildElementText(NameElementName) ?? file; var passwordHash = rootElement.GetChildElementText(PasswordHashElementName); profile = new Profile(id, name, passwordHash); profile.WorldName = rootElement.GetChildElementText(WorldElemenName); var activeData = rootElement.GetChildElementText(LastActiveElementName); DateTime lastActive; if (!string.IsNullOrEmpty(activeData) && DateTime.TryParse(activeData, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out lastActive)) { profile.LastActive = lastActive; } else { profile.LastActive = DateTime.MinValue; } } return(profile); }
public static XmlElement LoadXml(this IContentStorage storage, string path) { XmlElement element = null; if (storage.IsFileExist(path)) { using (var stream = storage.OpenForRead(path)) { var document = new XmlDocument(); document.Load(stream); element = document.DocumentElement; } } return(element); }