public static TwUser LoadCredentials() { TwUser twiUser = new TwUser(); if (!File.Exists(s_configFile)) { Console.WriteLine("Enter Twitter username..."); twiUser.Username = Console.ReadLine(); Console.WriteLine("Enter Twitter password..."); twiUser.Password = Console.ReadLine(); } else { twiUser = Deserialize(); } if (string.IsNullOrEmpty(twiUser.OAuthToken) || string.IsNullOrEmpty(twiUser.OAuthTokenSecret)) twiUser.SetOAuthCredentials(); return twiUser; }
static TwUser Deserialize() { TwUser twiUser = null; try { using (FileStream file = File.Open(s_configFile, FileMode.Open)) { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(TwUser)); twiUser = (TwUser)jsonSerializer.ReadObject(file); } } catch (SerializationException) { XmlSerializer deserializer = new XmlSerializer(typeof(TwUser)); using (StreamReader reader = new StreamReader(s_configFile)) twiUser = (TwUser)deserializer.Deserialize(reader); twiUser.Serialize(); } return(twiUser); }
public static TwUser LoadCredentials() { TwUser twiUser = new TwUser(); if (!File.Exists(s_configFile)) { Console.WriteLine("Enter Twitter username..."); twiUser.Username = Console.ReadLine(); Console.WriteLine("Enter Twitter password..."); twiUser.Password = Console.ReadLine(); } else { twiUser = Deserialize(); } if (string.IsNullOrEmpty(twiUser.OAuthToken) || string.IsNullOrEmpty(twiUser.OAuthTokenSecret)) { twiUser.SetOAuthCredentials(); } return(twiUser); }