/// <summary> /// Gets the TMDb API configuration either from the TMdbEasy client or /// deserialized from a XML document if the document is newer than 7 days old and the XML document exists. /// </summary> /// <param name="easy">An instance to a TMdbEasy client.</param> /// <param name="configPath">The configuration path.</param> /// <returns>A Configurations class instance.</returns> public static Configurations GetConfigurations(EasyClient easy, string configPath) { // construct a XML file name for serialization / deserialization.. string configFileName = Path.Combine(configPath, "TMDbConfig.xml"); if (File.Exists(configFileName)) // if the XML file exists.. { // ..read the XML file's information.. FileInfo fileInfo = new FileInfo(configFileName); // if the file is newer than 7 days.. if ((DateTime.Now - fileInfo.LastWriteTimeUtc).TotalDays < 7) { // create an instance of a XmlDocument class.. XmlDocument xmlDocument = new XmlDocument(); // load the XML file into the XmlDocument class instance.. xmlDocument.Load(configFileName); // deserialize the XML document to a Configurations class instance and return it.. return((Configurations)ObjectSerialization.DeserializeObject(typeof(Configurations), xmlDocument)); } else // too old XML file.. { // ..so re-get the configuration and save it to a XML file and return a Configurations class instance.. return(GetApiConfig(easy, configFileName)); } } else // file doesn't exist.. { // ..so get the configuration and save it to a XML file and return a Configurations class instance.. return(GetApiConfig(easy, configFileName)); } }