public static PkData GetAccountInfo(string accountId, string credentials) { object[] val; IPkService proxy = XmlRpcProxyGen.Create <IPkService>(); try { val = proxy.get_account_info(accountId, credentials, ""); } catch (Exception e) { PkLogging.Logger(PkLogging.Level.Error, "Unable to connect to the Pagekite Service" + Environment.NewLine + "Exception: " + e.Message, true); val = null; } if (val == null) { return(null); } string ok = val[0].ToString(); if (!ok.Equals("ok")) { PkLogging.Logger(PkLogging.Level.Error, "Unable to update account information"); return(null); } XmlRpcStruct serviceStruct = (XmlRpcStruct)val[1]; PkData data = new PkData(); XmlRpcStruct serviceData = (XmlRpcStruct)serviceStruct["data"]; data.ServiceInfo.Secret = serviceData["_ss"].ToString(); data.ServiceInfo.DaysLeft = "unknown"; data.ServiceInfo.MbLeft = "unknown"; if (serviceData.Contains("days_left")) { data.ServiceInfo.DaysLeft = serviceData["days_left"].ToString(); } if (serviceData.Contains("quota_mb_left")) { data.ServiceInfo.MbLeft = serviceData["quota_mb_left"].ToString(); } object[] serviceKites = (object[])serviceData["kites"]; foreach (XmlRpcStruct serviceKite in serviceKites) { PkKite kite = new PkKite(); kite.Domain = serviceKite["domain"].ToString(); kite.Secret = serviceKite["ssecret"].ToString(); data.Kites.Add(kite.Domain, kite); } return(data); }
public PkMainForm() { PkSplashForm.ShowSplashScreen(); this.controller = new PkController(); this.flying = false; this.data = PkData.Load(); this.LogIn(); this.SynchronizeAccountInfo(); this.InitForm(); this.UpdateDaysLeft(); this.kitePanel.AddKites(this.data.Kites); this.StartRenewLoginThread(); PkLogging.LogPanelUpdate += new EventHandler(this.logPanel.UpdateLog); this.logPanel.UpdateLog(this, EventArgs.Empty); PkSplashForm.CloseSplashScreen(); }
public PkMainForm() { PkSplashForm.ShowSplashScreen(); this.controller = new PkController(); this.flying = false; this.data = PkData.Load(); this.LogIn(); this.SynchronizeAccountInfo(); this.InitForm(); this.UpdateDaysLeft(); this.kitePanel.AddKites(this.data.Kites); this.StartRenewLoginThread(); PkLogging.LogPanelUpdate += new EventHandler(this.logPanel.UpdateLog); this.logPanel.UpdateLog(this, EventArgs.Empty); PkSplashForm.CloseSplashScreen(); }
public static PkData Load() { PkData data = new PkData(); string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); dir = Path.Combine(dir, "PageKite"); string filepath = Path.Combine(dir, "userconfig.json"); if (File.Exists(filepath)) { try { using (StreamReader file = File.OpenText(@filepath)) { JsonSerializer serializer = new JsonSerializer(); data = (PkData)serializer.Deserialize(file, typeof(PkData)); } } catch (Exception e) { PkLogging.Logger(PkLogging.Level.Error, "Unable to load settings.", true); PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message); data = new PkData(); } } else { data = new PkData(); } if (data == null) { data = new PkData(); } return(data); }
public static PkData Load() { PkData data = new PkData(); string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); dir = Path.Combine(dir, "PageKite"); string filepath = Path.Combine(dir, "userconfig.json"); if(File.Exists(filepath)) { try { using (StreamReader file = File.OpenText(@filepath)) { JsonSerializer serializer = new JsonSerializer(); data = (PkData)serializer.Deserialize(file, typeof(PkData)); } } catch(Exception e) { PkLogging.Logger(PkLogging.Level.Error, "Unable to load settings.", true); PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message); data = new PkData(); } } else { data = new PkData(); } if(data == null) { data = new PkData(); } return data; }
public static PkData GetAccountInfo(string accountId, string credentials) { object[] val; IPkService proxy = XmlRpcProxyGen.Create<IPkService>(); try { val = proxy.get_account_info(accountId, credentials, ""); } catch (Exception e) { PkLogging.Logger(PkLogging.Level.Error, "Unable to connect to the Pagekite Service" + Environment.NewLine + "Exception: " + e.Message, true); val = null; } if(val == null) { return null; } string ok = val[0].ToString(); if(!ok.Equals("ok")) { PkLogging.Logger(PkLogging.Level.Error, "Unable to update account information"); return null; } XmlRpcStruct serviceStruct = (XmlRpcStruct)val[1]; PkData data = new PkData(); XmlRpcStruct serviceData = (XmlRpcStruct)serviceStruct["data"]; data.ServiceInfo.Secret = serviceData["_ss"].ToString(); data.ServiceInfo.DaysLeft = "unknown"; data.ServiceInfo.MbLeft = "unknown"; if (serviceData.Contains("days_left")) { data.ServiceInfo.DaysLeft = serviceData["days_left"].ToString(); } if (serviceData.Contains("quota_mb_left")) { data.ServiceInfo.MbLeft = serviceData["quota_mb_left"].ToString(); } object[] serviceKites = (object[])serviceData["kites"]; foreach (XmlRpcStruct serviceKite in serviceKites) { PkKite kite = new PkKite(); kite.Domain = serviceKite["domain"].ToString(); kite.Secret = serviceKite["ssecret"].ToString(); data.Kites.Add(kite.Domain, kite); } return data; }
private void SynchronizeAccountInfo() { PkData serviceData = PkService.GetAccountInfo(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials); Dictionary <string, double> kiteStats = PkService.GetKiteStats(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials); if (serviceData != null && kiteStats != null) { //Update info about account and kites if it has been manipulated outside of this program this.data.ServiceInfo.Secret = serviceData.ServiceInfo.Secret; this.data.ServiceInfo.DaysLeft = serviceData.ServiceInfo.DaysLeft; this.data.ServiceInfo.MbLeft = serviceData.ServiceInfo.MbLeft; List <string> removeDomain = new List <string>(); //If any kites have been removed, remove them foreach (string domain in this.data.Kites.Keys) { if (!serviceData.Kites.ContainsKey(domain)) { removeDomain.Add(domain); } } //If any kites are disabled, remove them foreach (string domain in kiteStats.Keys) { if (kiteStats[domain] < 0) { removeDomain.Add(domain); } } foreach (string domain in removeDomain) { if (this.data.Kites.ContainsKey(domain)) { this.data.Kites.Remove(domain); } } foreach (string domain in serviceData.Kites.Keys) { //If new kites have been added, add them, unless they are disabled if (!this.data.Kites.ContainsKey(domain) && kiteStats[domain] > 0) { if (String.IsNullOrEmpty(serviceData.Kites[domain].Secret)) { serviceData.Kites[domain].Secret = this.data.ServiceInfo.Secret; } this.data.Kites.Add(domain, serviceData.Kites[domain]); } if (this.data.Kites.ContainsKey(domain)) { //Update kite secret if it has changed if (!this.data.Kites[domain].Secret.Equals(serviceData.Kites[domain].Secret) && !String.IsNullOrEmpty(serviceData.Kites[domain].Secret)) { this.data.Kites[domain].Secret = serviceData.Kites[domain].Secret; } } } PkLogging.Logger(PkLogging.Level.Info, "All kites are up to date."); } if (this.data.Options.RememberMe) { this.data.Save(); } }