// Public Methods (2) public static void LoadConfig() { try { string ConfigFile = Path.Combine(ClientSettings.AppPath, "App.config"); XmlDocument oXml = new XmlDocument(); AppSettings = new NameValueCollection(); Accounts = new System.Collections.Generic.List<Yedda.Twitter.Account>(); if (File.Exists(ConfigFile)) { oXml.Load(ConfigFile); XmlNodeList oList = oXml.SelectNodes("//appSettings/add"); foreach (XmlNode oNode in oList) { AppSettings.Add(oNode.Attributes["key"].Value, oNode.Attributes["value"].Value); } oList = oXml.SelectNodes("//accounts/add"); foreach (XmlNode oNode in oList) { Yedda.Twitter.Account a = new Yedda.Twitter.Account(); a.UserName = oNode.Attributes["user"].Value; a.Password = oNode.Attributes["password"].Value; if (oNode.Attributes["servername"] != null) { string ServerName = oNode.Attributes["servername"].Value; a.ServerURL = Yedda.Servers.ServerList[ServerName]; } if (oNode.Attributes["server"] != null) { a.Server = (Yedda.Twitter.TwitterServer)Enum.Parse(typeof(Yedda.Twitter.TwitterServer), oNode.Attributes["server"].Value, true); } a.Enabled = bool.Parse(oNode.Attributes["enabled"].Value); Accounts.Add(a); } } } catch { } }
private void ResetDictionaries() { FollowingDictionary.Clear(); TwitterConnections.Clear(); foreach (Yedda.Twitter.Account a in ClientSettings.AccountsList) { Twitter.Account AccountInfo = new Twitter.Account { ServerURL = a.ServerURL, UserName = a.UserName, Password = a.Password, OAuth_token = a.OAuth_token, OAuth_token_secret = a.OAuth_token_secret, Enabled = a.Enabled }; Twitter TwitterConn = Servers.CreateConnection(AccountInfo); TwitterConnections.Add(TwitterConn); Following f = new Following(TwitterConn); FollowingDictionary.Add(TwitterConn, f); } SetConnectedMenus(); Manager = new TimelineManagement(); Manager.Progress += Manager_Progress; Manager.CompleteLoaded += Manager_CompleteLoaded; Manager.Startup(TwitterConnections); Manager.FriendsUpdated += Manager_FriendsUpdated; Manager.MessagesUpdated += Manager_MessagesUpdated; Manager.SearchesUpdated += Manager_SearchesUpdated; foreach (Following f in FollowingDictionary.Values) { f.LoadFromTwitter(); } }
private bool DoPost(PicturePostObject postData, Twitter.Account account, bool successEvent) { this.account = account; #region Argument check this.account = account; //Check for empty path if (string.IsNullOrEmpty(postData.Filename)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } //Check for empty credentials if (string.IsNullOrEmpty(account.OAuth_token) || string.IsNullOrEmpty(account.OAuth_token_secret)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } #endregion using (System.IO.FileStream file = new FileStream(postData.Filename, FileMode.Open, FileAccess.Read)) { try { postData.PictureStream = file; XmlDocument uploadResult = UploadPicture(API_UPLOAD, postData, account); if (uploadResult == null) // occurs in the event of an error return false; string URL = uploadResult.SelectSingleNode("//url").InnerText; postData.URL = URL; if(successEvent) { OnUploadFinish(new PictureServiceEventArgs(PictureServiceErrorLevel.OK, URL, string.Empty, postData.Filename)); } } catch (Exception /*ex*/) { // could do with catching a SocketException here, so we can give more useful information to the user OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); return false; } } return true; }
/// <summary> /// Fetch a picture /// </summary> /// <param name="pictureURL"></param> public override void FetchPicture(string pictureURL, Twitter.Account account) { #region Argument check this.account = account; //Need a url to read from. if (string.IsNullOrEmpty(pictureURL)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, "", API_ERROR_DOWNLOAD)); } #endregion try { workerPPO = new PicturePostObject(); workerPPO.Message = pictureURL; if (workerThread == null) { workerThread = new System.Threading.Thread(new System.Threading.ThreadStart(ProcessDownload)); workerThread.Name = "PictureUpload"; workerThread.Start(); } else { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.NotReady, "", "A request is already running.")); } } catch (Exception) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, "", API_ERROR_DOWNLOAD)); } }
/// <summary> /// Post a picture /// </summary> /// <param name="postData"></param> public override bool PostPicture(PicturePostObject postData, Twitter.Account account) { #region Argument check //Check for empty path if (string.IsNullOrEmpty(postData.Filename)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } //Check for empty credentials if (string.IsNullOrEmpty(account.OAuth_token) || string.IsNullOrEmpty(account.OAuth_token_secret)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } #endregion _account = account; using (postData.PictureStream = new FileStream(postData.Filename, FileMode.Open, FileAccess.Read)) { try { XmlDocument uploadResult = UploadPicture(API_UPLOAD, postData, account); if (uploadResult == null) { return false; } string URL = uploadResult.SelectSingleNode("//url").InnerText; postData.URL = URL; OnUploadFinish(new PictureServiceEventArgs(PictureServiceErrorLevel.OK, URL, string.Empty, postData.Filename)); return true; } catch { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); return false; } } }
private bool DoPost(PicturePostObject postData, Twitter.Account account, bool successEvent) { #region Argument check this._account = account; //Check for empty path if (string.IsNullOrEmpty(postData.Filename)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } //Check for empty credentials if (string.IsNullOrEmpty(account.OAuth_token) || string.IsNullOrEmpty(account.OAuth_token_secret)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } #endregion using (System.IO.FileStream file = new FileStream(postData.Filename, FileMode.Open, FileAccess.Read)) { try { #region async //if (postData.UseAsync) //{ // workerPPO = (PicturePostObject) postData.Clone(); // workerPPO.PictureData = incoming; // if (workerThread == null) // { // workerThread = new System.Threading.Thread(new System.Threading.ThreadStart(ProcessUpload)); // workerThread.Name = "PictureUpload"; // workerThread.Start(); // } // else // { // OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.NotReady, string.Empty, "A request is already running.")); // } //} //else //{ #endregion //use sync. postData.PictureStream = file; XmlDocument uploadResult = UploadPicture(API_UPLOAD_V2, postData); //if (File.Exists("mobyresult.txt")) //{ // File.Delete("mobyresult.txt"); //} //XmlTextWriter xm = new XmlTextWriter("mobyresult.txt", Encoding.UTF8); //uploadResult.Save(xm); //XmlDocument uploadResult = new XmlDocument(); //uploadResult.Load("mobyresult.txt"); if (uploadResult == null) // occurs in the event of an error { return false; } if (successEvent) { string URL = uploadResult.SelectSingleNode("//mediaurl").InnerText; postData.URL = URL; OnUploadFinish(new PictureServiceEventArgs(PictureServiceErrorLevel.OK, URL, string.Empty, postData.Filename)); } } catch (Exception) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); return false; } } return true; }
//�Public�Methods�(2) public static void LoadConfig() { try { string ConfigFile = Path.Combine(ClientSettings.AppPath, "App.config"); XmlDocument oXml = new XmlDocument(); AppSettings = new NameValueCollection(); Accounts = new System.Collections.Generic.List<Yedda.Twitter.Account>(); if (File.Exists(ConfigFile)) { oXml.Load(ConfigFile); XmlNodeList oList = oXml.SelectNodes("//appSettings/add"); foreach (XmlNode oNode in oList) { AppSettings.Add(oNode.Attributes["key"].Value, oNode.Attributes["value"].Value); } oList = oXml.SelectNodes("//accounts/add"); foreach (XmlNode oNode in oList) { Yedda.Twitter.Account a = new Yedda.Twitter.Account(); a.UserName = oNode.Attributes["user"].Value; a.Password = oNode.Attributes["password"].Value; try { a.OAuth_token = oNode.Attributes["oauth_token"].Value; a.OAuth_token_secret = oNode.Attributes["oauth_token_secret"].Value; } catch (Exception) { } try { a.OAuth_token_secure = oNode.Attributes["oauth_token_secure"].Value; a.OAuth_token_secret_secure = oNode.Attributes["oauth_token_secret_secure"].Value; } catch (Exception) { } //if tokens are not saved secure yet, create them if (string.IsNullOrEmpty(a.OAuth_token_secure)) { a.OAuth_token_secure = ICSettings.Encryption.Encrypt(a.OAuth_token); a.OAuth_token_secret_secure = ICSettings.Encryption.Encrypt(a.OAuth_token_secret); } //if tokens aren't read from config (which is good), create tokens from secrets. if (string.IsNullOrEmpty(a.OAuth_token)) { a.OAuth_token = ICSettings.Encryption.Decrypt(a.OAuth_token_secure); a.OAuth_token_secret = ICSettings.Encryption.Decrypt(a.OAuth_token_secret_secure); } if (oNode.Attributes["servername"] != null) { string ServerName = oNode.Attributes["servername"].Value; a.ServerURL = Yedda.Servers.ServerList[ServerName]; } if (oNode.Attributes["server"] != null) { a.Server = (Yedda.Twitter.TwitterServer)Enum.Parse(typeof(Yedda.Twitter.TwitterServer), oNode.Attributes["server"].Value, true); } a.Enabled = bool.Parse(oNode.Attributes["enabled"].Value); Accounts.Add(a); } } } catch { } }
public static void LoadSettings() { ConfigurationSettings.LoadConfig(); IFormatProvider format = new System.Globalization.CultureInfo(1033); AccountsList = new List<Yedda.Twitter.Account>(); Yedda.Twitter.Account LegacySettingsAccount = new Yedda.Twitter.Account(); try { if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["AutoCompleteAddressBook"])) { AutoCompleteAddressBook = Boolean.Parse(ConfigurationSettings.AppSettings["AutoCompleteAddressBook"]); } else { AutoCompleteAddressBook = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["UseDIB"])) { UseDIB = Boolean.Parse(ConfigurationSettings.AppSettings["UseDIB"]); } else { UseDIB = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["ZoomPreview"])) { ZoomPreview = Boolean.Parse(ConfigurationSettings.AppSettings["ZoomPreview"]); } else { ZoomPreview = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["AutoScrollToTop"])) { AutoScrollToTop = Boolean.Parse(ConfigurationSettings.AppSettings["AutoScrollToTop"]); } else { AutoScrollToTop = false; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["CacheDir"])) { CacheDir = ConfigurationSettings.AppSettings["CacheDir"]; } else { CacheDir = AppPath; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["MediaService"])) { PreviousMediaService = ConfigurationSettings.AppSettings["MediaService"]; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["SelectedMediaService"])) { SelectedMediaService = ConfigurationSettings.AppSettings["SelectedMediaService"]; } else { SelectedMediaService = "TweetPhoto"; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["SendMessageToMediaService"])) { SendMessageToMediaService = bool.Parse(ConfigurationSettings.AppSettings["SendMessageToMediaService"]); } else { SendMessageToMediaService = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["FontSize"])) { FontSize = int.Parse(ConfigurationSettings.AppSettings["FontSize"]); } else { FontSize = 9; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["SearchItems"])) { SearchItems = new Queue<string>(ConfigurationSettings.AppSettings["SearchItems"].Split('|')); } else { SearchItems = new Queue<string>(); } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["AutoTranslate"])) { AutoTranslate = bool.Parse(ConfigurationSettings.AppSettings["AutoTranslate"]); } else { AutoTranslate = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["UILanguage"])) { PockeTwit.Localization.XmlBasedResourceManager.CultureInfo = new System.Globalization.CultureInfo(ConfigurationSettings.AppSettings["UILanguage"]); } else { PockeTwit.Localization.XmlBasedResourceManager.CultureInfo = System.Globalization.CultureInfo.CurrentUICulture; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["TranslationLanguage"])) { TranslationLanguage = ConfigurationSettings.AppSettings["TranslationLanguage"]; } else { TranslationLanguage = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.ToLower(); } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["UpdateMinutes"])) { UpdateMinutes = int.Parse(ConfigurationSettings.AppSettings["UpdateMinutes"], format); } else { UpdateMinutes = 5; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["ThemeName"])) { ThemeName = ConfigurationSettings.AppSettings["ThemeName"]; } else { ThemeName = "Sunny"; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["HighQualityAvatars"])) { HighQualityAvatars = bool.Parse(ConfigurationSettings.AppSettings["HighQualityAvatars"]); } else { HighQualityAvatars = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["UseClickables"])) { UseClickables = bool.Parse(ConfigurationSettings.AppSettings["UseClickables"]); } else { UseClickables = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["ShowAvatars"])) { ShowAvatars = bool.Parse(ConfigurationSettings.AppSettings["ShowAvatars"]); } else { ShowAvatars = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["DistancePreference"])) { DistancePreference = ConfigurationSettings.AppSettings["DistancePreference"]; } else { DistancePreference = "Miles"; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["UseGPS"])) { UseGPS = bool.Parse(ConfigurationSettings.AppSettings["UseGPS"]); } else { UseGPS = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["IsMaximized"])) { IsMaximized = bool.Parse(ConfigurationSettings.AppSettings["IsMaximized"]); } else { IsMaximized = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["UserName"])) { LegacySettingsAccount.UserName = ConfigurationSettings.AppSettings["UserName"]; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["Password"])) { LegacySettingsAccount.Password = ConfigurationSettings.AppSettings["Password"]; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["CheckVersion"])) { CheckVersion = bool.Parse(ConfigurationSettings.AppSettings["CheckVersion"]); } else { CheckVersion = true; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["ShowExtra"])) { ShowExtra = bool.Parse(ConfigurationSettings.AppSettings["ShowExtra"]); } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["Server"])) { LegacySettingsAccount.Server = (Yedda.Twitter.TwitterServer)Enum.Parse(typeof(Yedda.Twitter.TwitterServer), ConfigurationSettings.AppSettings["Server"], true); } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["AnimationInterval"])) { AnimationInterval = int.Parse(ConfigurationSettings.AppSettings["AnimationInterval"],format); } else { AnimationInterval = 15; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["MaxTweets"])) { MaxTweets= int.Parse(ConfigurationSettings.AppSettings["MaxTweets"],format); } else { MaxTweets = 50; } if (!string.IsNullOrEmpty(LegacySettingsAccount.UserName)) { AccountsList.Add(LegacySettingsAccount); } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["IncludeScreenName"])) { IncludeUserName = bool.Parse(ConfigurationSettings.AppSettings["IncludeScreenName"]); } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["UseSkweezer"])) { UseSkweezer = bool.Parse(ConfigurationSettings.AppSettings["UseSkweezer"]); } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["ProxyServer"])) { ProxyServer = ConfigurationSettings.AppSettings["ProxyServer"]; } else { ProxyServer = string.Empty; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["ProxyPort"])) { ProxyPort = int.Parse(ConfigurationSettings.AppSettings["ProxyPort"]); } else { ProxyPort = 0; } if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["PortalSize"])) { PortalSize= int.Parse(ConfigurationSettings.AppSettings["PortalSize"]); } else { PortalSize = MaxTweets; } foreach (Yedda.Twitter.Account a in ConfigurationSettings.Accounts) { AccountsList.Add(a); } } catch(Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }