private static void UpdateDevicesCache(Configuration conf, string apikey, bool updateKey)
 {
     PushBulletAPI.Configure(apikey);
     try
     {
         var res = PushBulletAPI.GetDevices();
         if (updateKey)
         {
             PushBulletAPI.SetConfigurationOption(conf, "apikey", apikey, false);
         }
         var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PushBulletAPI.DevicesResponse));
         using (var writer = new System.IO.StringWriter())
         {
             serializer.Serialize(writer, res);
             PushBulletAPI.SetConfigurationOption(conf, "cachedDevices", writer.ToString(), true);
         }
         Console.WriteLine("OK");
     }
     catch (Exception e)
     {
         Console.Error.WriteLine("Invalid API key.");
         Console.Error.Write(e.ToString());
         System.Environment.Exit(1);
     }
 }
Exemple #2
0
 private void UpdateUIElements(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Result is PushBulletAPI.DevicesResponse)
     {
         var res = e.Result as PushBulletAPI.DevicesResponse;
         PushBulletAPI.SetConfigurationOption(PushBullet.conf, "apikey", apikeyInput.Text, false);
         if (doneWindowChkBox.IsChecked.HasValue)
         {
             PushBulletAPI.SetConfigurationOption(PushBullet.conf, "showDoneWindow", (bool)doneWindowChkBox.IsChecked, false);
         }
         var section = PushBulletAPI.GetResponseSection(PushBullet.conf);
         section.Devices.Clear();
         section.SharedDevices.Clear();
         foreach (PushBulletAPI.DevicesResponse.Device device in res.devices)
         {
             section.Devices.Add(device.ToDeviceConfig());
         }
         foreach (PushBulletAPI.DevicesResponse.SharedDevice sDevice in res.shared_devices)
         {
             section.SharedDevices.Add(sDevice.ToDeviceConfig());
         }
         PushBullet.conf.Save(System.Configuration.ConfigurationSaveMode.Modified);
         MessageBox.Show(Properties.Strings.SetupComplete, @"\o/", MessageBoxButton.OK, MessageBoxImage.Information);
         this.Close();
         return;
     }
     this.IsEnabled       = true;
     Mouse.OverrideCursor = null;
     apikeyInput.Clear();
 }
Exemple #3
0
 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());
     }
 }