public static async Task Main(string[] args) { // Parse the arguments and execute the requested operations new Parser(with => with.AutoHelp = true) .ParseArguments <HydratorOptions>(args) .WithParsed(async options => { options.Validate(); var apiKeys = OAuth2ClientInfo.LoadFromFile(ApiKeysPath); var service = TwitterServiceFactory.GetTweetsService(apiKeys.ApplicationName, apiKeys.AccessToken); await HydratorEngine.ProcessAsync(options, service, (i, id) => ConsoleHelper.Write(MessageType.Info, $"[{i}]: {id}")); Tcs.SetResult(null); }) .WithNotParsed(errors => { foreach (var error in errors) { ConsoleHelper.Write(MessageType.Error, error.ToString()); } Tcs.SetResult(null); }); // Wait for the completion of the pending operations await Tcs.Task; Console.Beep(); Thread.Sleep(150); Console.Beep(); // Two high-pitched beeps to indicate success Console.ReadKey(); }
private void SetupTwitterClient() { TwitterService twitterService; if (!TwitterServiceFactory.TryCreateFromDefaultConfigurationFile(out twitterService)) { return; } ServiceLocator.RegisterService(typeof(TwitterService), twitterService); }
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. TwitterService twitterService; if (TwitterServiceFactory.TryCreateFromDefaultConfigurationFile(out twitterService)) { ServiceLocator.RegisterService(typeof(TwitterService), new TwitterService()); IAction tweetAction = twitterService.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); }
private async Task Tweet(TimeSpan timeInLitterBox) { if (IsTweetingTooFrequently()) { return; } if (DurationIsTooShort(timeInLitterBox)) { return; } UpdateCounter(); string message = GenerateMessage(); Log.Verbose("Trying to tweet '" + message + "'."); try { TwitterService twitterService; if (!TwitterServiceFactory.TryCreateFromDefaultConfigurationFile(out twitterService)) { Log.Verbose("Twitter API is disabled."); return; } await twitterService.Tweet(message); _lastTweetTimestamp = DateTime.Now; Log.Info("Successfully tweeted: " + message); } catch (Exception exception) { Log.Warning("Failed to tweet. " + exception.Message); } }