private bool InitDevices() { if (devices != null) { return(true); } try { if (conf == null) { conf = PushBulletAPI.GetSharedConfiguration("pushbullet"); } var data = PushBulletAPI.GetResponseSection(this.conf); if (data == null) { throw new Exception("Empty ResponseSection"); } this.devices = data; // avoid NPEs //if (this.devices.Devices.Count == null) this.devices.devices = new PushBulletAPI.DevicesResponse.Device[] { }; //if (this.devices.shared_devices == null) this.devices.shared_devices = new PushBulletAPI.DevicesResponse.SharedDevice[] { }; if (devices.SharedDevices.Count == 0) { MessageBox.Show("Kaboom"); } return(true); } catch (Exception e) { err("Got an Exception while retrieving the devices: " + e.ToString()); return(false); } }
/*private PushBulletAPI.DeviceCollection GetDevices() * { * if (conf == null) * conf = PushBulletAPI.GetSharedConfiguration("pushbullet"); * if (!PushBulletAPI.HasConfigurationOption(conf, "apikey")) throw new Exception("No device cache available"); * //var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PushBulletAPI.DevicesResponse)); * //return serializer.Deserialize(new System.IO.StringReader(PushBulletAPI.GetNonNullConfigurationOption(conf, "cachedDevices"))) as PushBulletAPI.DevicesResponse; * * }*/ private void TryExecute(string devId) { if (conf == null) { conf = PushBulletAPI.GetSharedConfiguration("pushbullet"); } if (!PushBulletAPI.HasConfigurationOption(conf, "mainPath")) { throw new Exception("No executable path available"); } try { Process.Start(PushBulletAPI.GetNonNullConfigurationOption(this.conf, "mainPath"), "/upload " + devId + " " + MergePaths(this.SelectedItemPaths)); } catch (Exception exa) { MessageBox.Show("An error occurred while opening the upload helper: " + exa.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { conf = PushBulletAPI.GetSharedConfiguration("pushbullet"); PushBulletAPI.SetConfigurationOption(conf, "mainPath", System.Reflection.Assembly.GetEntryAssembly().Location, true); if (args != null && args.Length > 2 && args[0].Equals("/upload")) { // enter upload mode if (!PushBulletAPI.HasConfigurationOption(conf, "apikey") || !System.Text.RegularExpressions.Regex.IsMatch(args[1], @"^\d+$")) { ShowError(Properties.Strings.InvalidParams); return; } new System.Windows.Application().Run(new UploadGUI(args[1], args.Skip(2).ToArray())); } else { new System.Windows.Application().Run(new APIGUI2()); } }
static void Main(string[] args) { if (args == null || args.Length < 1) { PrintUsage(); } Configuration conf = PushBulletAPI.GetSharedConfiguration("pushbullet"); switch (args[0].Substring(1)) { case "apikey": if (args.Length < 2 || args[1].Length != 32) { PrintUsage(); } UpdateDevicesCache(conf, args[1], true); break; case "devices": if (!PushBulletAPI.HasConfigurationOption(conf, "cachedDevices")) { Console.Error.WriteLine("No device cache available."); System.Environment.Exit(1); } Console.Write(PushBulletAPI.GetNonNullConfigurationOption(conf, "cachedDevices")); break; case "refresh": if (!PushBulletAPI.HasConfigurationOption(conf, "apikey")) { Console.Error.WriteLine("API key not set."); System.Environment.Exit(1); } UpdateDevicesCache(conf, PushBulletAPI.GetNonNullConfigurationOption(conf, "apikey"), false); break; default: PrintUsage(); break; } }