public WhoisResult ToWhoisResult(OrganizationResult organization) { WhoisResult result = new WhoisResult(); result.Name = new WhoisResult_Name(); result.Name.Firstname = this.Firstname; result.Name.Nickname = this.Nickname; result.Name.Lastname = this.Lastname; result.Stats = new WhoisResult_Stats(); result.Stats.Level = this.Level; result.Stats.Breed = this.Breed; result.Stats.Gender = this.Gender; result.Stats.Faction = organization.Faction; result.Stats.Profession = this.Profession; result.Stats.Title = null; result.Stats.DefenderRank = this.DefenderRank; result.Stats.DefenderLevel = this.DefenderLevel; result.Organization = new WhoisResult_Organization(); result.Organization.ID = organization.ID; result.Organization.Name = organization.Name; result.Organization.Rank = this.Rank; result.Organization.RankID = this.RankID; result.PictureURL = this.PictureUrl; result.SmallPictureURL = this.SmallPictureUrl; result.LastUpdated = organization.LastUpdated; return(result); }
private static OrganizationResult GetCachedOrganization(Int32 organizationID, Server server, bool ignoreDate) { OrganizationResult result = null; try { string path = XmlCachePath + Path.DirectorySeparatorChar + OrganizationPath; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = path + Path.DirectorySeparatorChar + (int)server + "." + organizationID + ".xml"; if (File.Exists(file)) { TimeSpan time = DateTime.Now - File.GetLastWriteTime(file); if (time.TotalHours > CacheDuration && ignoreDate == false) { return(null); } FileStream stream = null; StreamReader reader = null; try { stream = File.OpenRead(file); reader = new StreamReader((Stream)stream); string xml = reader.ReadToEnd(); OrganizationCache cache = new OrganizationCache(); cache = ParseOrganizationCache(xml); result = cache.ToOrganizationResult(server); } catch { } finally { if (reader != null) { reader.Close(); reader.Dispose(); } if (stream != null) { stream.Close(); stream.Dispose(); } } } } catch { } return(result); }
public void FromOrganizationResult(OrganizationResult result) { this.ID = result.ID; this.Name = result.Name; this.Faction = result.Faction; this.LastUpdated = result.LastUpdated; this.Members = new string[result.Members.Items.Length]; int i = 0; foreach (OrganizationMember member in result.Members.Items) { this.Members[i] = member.Nickname; i++; } }
public OrganizationResult ToOrganizationResult(Net.Server server) { OrganizationResult result = new OrganizationResult(); result.ID = this.ID; result.Name = this.Name; result.Faction = this.Faction; result.LastUpdated = this.LastUpdated; result.Members = new OrganizationMembers(); result.Members.Items = new OrganizationMember[this.Members.Length]; for (int i = 0; i < this.Members.Length; i++) { result.Members.Items[i] = new OrganizationMember(); result.Members.Items[i].FromWhoisResult(XML.GetWhois(this.Members[i], server, true, true, true)); } return(result); }
public static OrganizationResult GetOrganization(Int32 organizationID, Server server, bool readCache, bool writeCache, Int32 timeout) { if (server == Server.Test) { return(null); } OrganizationResult result = null; if (readCache) { result = GetCachedOrganization(organizationID, server, false); } if (result != null) { Output("Retrieved {0}@{1} from organization cache", result.Name, server.ToString()); return(result); } result = GetOrganization(String.Format(URL_OfficialOrganization, (int)server, organizationID), timeout); if (result != null) { if (writeCache) { SetCachedOrganization(result, server); } Output("Retrieved {0}@{1} from funcom's organization server", result.Name, server.ToString()); return(result); } result = GetCachedOrganization(organizationID, server, true); if (result != null) { Output("Retrieved {0}@{1} from old organization cache", result.Name, server.ToString()); return(result); } Output("Unable to retrieve organization data for ID:{0}@{1}", organizationID, server.ToString()); return(null); }
private static string OrganizationToXml(OrganizationResult whois) { string xml = null; MemoryStream stream = null; try { XmlSerializer serializer = new XmlSerializer(typeof(OrganizationResult)); stream = new MemoryStream(); serializer.Serialize(stream, whois); xml = Encoding.UTF8.GetString(stream.ToArray()); } catch { } finally { if (stream != null) { stream.Close(); stream.Dispose(); } } return(xml); }
public static OrganizationResult ParseOrganization(string xml) { MemoryStream stream = null; try { stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)); XmlSerializer serializer = new XmlSerializer(typeof(OrganizationResult)); OrganizationResult result = (OrganizationResult)serializer.Deserialize(stream); stream.Close(); stream.Dispose(); return(result); } catch { } finally { if (stream != null) { stream.Close(); stream.Dispose(); } } return(null); }
private static void SetCachedOrganization(OrganizationResult organization, Server server) { if (organization.ID < 1) { return; } if (organization.Name == null || organization.Name == string.Empty) { return; } if (organization.Members == null || organization.Members.Items == null || organization.Members.Items.Length == 0) { return; } OrganizationCache cache = new OrganizationCache(); cache.FromOrganizationResult(organization); string xml = OrganizationCacheToXml(cache); if (xml == null || xml == String.Empty) { return; } FileStream stream = null; StreamWriter writer = null; try { string path = XmlCachePath + Path.DirectorySeparatorChar + OrganizationPath; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = path + Path.DirectorySeparatorChar + (int)server + "." + organization.ID + ".xml"; if (File.Exists(file)) { File.Delete(file); } stream = File.Create(file); writer = new StreamWriter((Stream)stream); writer.Write(xml); foreach (OrganizationMember member in organization.Members.Items) { WhoisResult whois = member.ToWhoisResult(organization); SetCachedWhois(whois, server); } } catch { } finally { if (writer != null) { writer.Close(); writer.Dispose(); } if (stream != null) { stream.Close(); stream.Dispose(); } } }