public static void Save() { if (!Loaded) { return; } TwitterClientFactory.CopyInstances(Instance.Accounts); try { using (var file = File.OpenWrite(Program.ConfigPath)) using (var writer = new StreamWriter(file, Encoding.UTF8)) { Program.JsonSerializer.Serialize(writer, Instance); } } catch (FileNotFoundException) { } catch (DirectoryNotFoundException) { } catch (Exception ex) { SentrySdk.CaptureException(ex); } }
public static void Load() { try { using (var file = File.OpenRead(Program.ConfigPath)) using (var reader = new StreamReader(file, Encoding.UTF8)) { var inst = new Config(); Program.JsonSerializer.Populate(reader, inst); Instance = inst; } } catch (FileNotFoundException) { } catch (DirectoryNotFoundException) { } catch (Exception ex) { SentrySdk.CaptureException(ex); } Instance = Instance ?? new Config(); TwitterClientFactory.SetInstances(Instance.Accounts); Loaded = true; }
private ClientToolStripItems NewClientToolStripItems(long id, string screenName) { var st = new ClientToolStripItems { Remove = new ToolStripMenuItem(Lang.MainContext_Client_Remove) { Tag = id, }, RootItem = new ToolStripMenuItem(screenName) { Checked = false, CheckOnClick = false, }, TlHome = new ToolStripMenuItem("-") { Image = Properties.Resources.uniF053, Tag = id, }, TlAbountMe = new ToolStripMenuItem("-") { Image = Properties.Resources.uniF055, Tag = id, }, TlDm = new ToolStripMenuItem("-") { Image = Properties.Resources.uniF054, Tag = id, }, }; st.Remove.Click += new EventHandler(this.StripRemoveClient_Click); var refreshButton = new ToolStripMenuItem(Lang.MainContext_Client_Refresh) { Tag = id, }; refreshButton.Click += new EventHandler((s, e) => TwitterClientFactory.GetInsatnce((long)(s as ToolStripMenuItem).Tag)?.ForceRefresh(true, true, true)); st.TlHome.Click += new EventHandler((s, e) => TwitterClientFactory.GetInsatnce((long)(s as ToolStripMenuItem).Tag)?.ForceRefresh(true, false, false)); st.TlAbountMe.Click += new EventHandler((s, e) => TwitterClientFactory.GetInsatnce((long)(s as ToolStripMenuItem).Tag)?.ForceRefresh(false, true, false)); st.TlDm.Click += new EventHandler((s, e) => TwitterClientFactory.GetInsatnce((long)(s as ToolStripMenuItem).Tag)?.ForceRefresh(false, false, true)); st.RootItem.DropDownItems.AddRange(new ToolStripItem[] { st.Remove, new ToolStripSeparator(), refreshButton, st.TlHome, st.TlAbountMe, st.TlDm, }); this.m_contextMenuStrip.Items.Insert(this.m_contextMenuStrip.Items.IndexOf(this.m_stripSepExit), st.RootItem); return(st); }
private void SetupTwitterClient() { TwitterClient twitterClient; if (!TwitterClientFactory.TryCreateFromDefaultConfigurationFile(out twitterClient)) { return; } RegisterService(twitterClient); }
private void SetupDemo() { // Get the area from the controller. IArea area = this.GetArea(Room.ExampleRoom); // Get the single motion detector from the controller. IMotionDetector motionDetector = GetComponent <IMotionDetector>(); ITrigger motionDetectedTrigger = motionDetector.GetMotionDetectedTrigger(); // Get the single temperature and humidity sensor from the controller. ITemperatureSensor temperatureSensor = GetComponent <ITemperatureSensor>(); IHumiditySensor humiditySensor = GetComponent <IHumiditySensor>(); // Get the button with the specified ID from the area (not globally). IButton button = area.GetButton(ExampleRoom.Button1); ITrigger buttonTrigger = button.GetPressedShortlyTrigger(); // Get a test lamp from the area (not globally). ILamp lamp2 = area.GetLamp(ExampleRoom.Lamp2); ILamp lamp3 = area.GetLamp(ExampleRoom.Lamp3); // Integrate the twitter client if the configuration file is available. TwitterClient twitterClient; if (TwitterClientFactory.TryCreateFromDefaultConfigurationFile(out twitterClient)) { RegisterService(new TwitterClient()); IAction tweetAction = twitterClient.GetTweetAction($"Someone is here ({DateTime.Now})... @chkratky"); motionDetectedTrigger.Attach(tweetAction); buttonTrigger.Attach(tweetAction); } // An automation is "Fulfilled" per default. ////var automation = new Automation(new AutomationId("DemoAutomation")) //// .WithTrigger(motionDetectedTrigger) //// .WithActionIfConditionsFulfilled(lamp3.GetTurnOnAction()) //// .WithCondition(ConditionRelation.And, new ComponentIsInStateCondition(lamp2, BinaryStateId.Off)) //// .WithCondition(ConditionRelation.And, new NumericValueSensorHasValueGreaterThanCondition(humiditySensor, 80)); //AddAutomation(automation); SetupTelegramBot(); new PersonalAgentToApiDispatcher(this).ExposeToApi(ApiController); }
public static void Save() { if (Interlocked.Read(ref Load) == 0) return; TwitterClientFactory.CopyInstances(Instance.Accounts); try { using (var file = File.OpenWrite(Program.ConfigPath)) using (var writer = new StreamWriter(file, Encoding.UTF8)) { Program.JsonSerializer.Serialize(writer, Instance); } } catch (Exception ex) { SentrySdk.CaptureException(ex); } }
static Config() { try { using (var file = File.OpenRead(Program.ConfigPath)) using (var reader = new StreamReader(file, Encoding.UTF8)) { var inst = new Config(); Program.JsonSerializer.Populate(reader, inst); Instance = inst; } } catch (Exception ex) { SentrySdk.CaptureException(ex); Instance = new Config(); } TwitterClientFactory.SetInstances(Instance.Accounts); Interlocked.Exchange(ref Load, 1); }
private async Task Tweet(TimeSpan timeInLitterBox) { if (GetIsTweetingTooFrequently()) { return; } if (GetDurationIsTooShort(timeInLitterBox)) { return; } UpdateCounter(); string message = GenerateMessage(); Log.Verbose("Trying to tweet '" + message + "'."); try { TwitterClient twitterClient; if (!TwitterClientFactory.TryCreateFromDefaultConfigurationFile(out twitterClient)) { Log.Verbose("Twitter API is disabled."); return; } await twitterClient.Tweet(message); _lastTweetTimestamp = DateTime.Now; Log.Info("Successfully tweeted: " + message); } catch (Exception exception) { Log.Warning("Failed to tweet. " + exception.Message); } }
private void StripAdd_Click(object sender, EventArgs e) { Task.Factory.StartNew(() => TwitterClientFactory.AddClient(this.m_invoker)); }
private void NotifyIcon_BalloonTipClicked(object sender, EventArgs e) { Task.Factory.StartNew(() => TwitterClientFactory.AddClient(this.m_invoker)); }
private void StripRemoveClient_Click(object sender, EventArgs e) { var item = sender as ToolStripMenuItem; TwitterClientFactory.RemoveClient((long)item.Tag); }
private void StripAdd_Click(object sender, EventArgs e) { TwitterClientFactory.AddClient(); }
private void NotifyIcon_BalloonTipClicked(object sender, EventArgs e) { TwitterClientFactory.AddClient(); }