Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        private void SetupTwitterClient()
        {
            TwitterClient twitterClient;

            if (!TwitterClientFactory.TryCreateFromDefaultConfigurationFile(out twitterClient))
            {
                return;
            }

            RegisterService(twitterClient);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 9
0
 private void StripAdd_Click(object sender, EventArgs e)
 {
     Task.Factory.StartNew(() => TwitterClientFactory.AddClient(this.m_invoker));
 }
Exemplo n.º 10
0
 private void NotifyIcon_BalloonTipClicked(object sender, EventArgs e)
 {
     Task.Factory.StartNew(() => TwitterClientFactory.AddClient(this.m_invoker));
 }
Exemplo n.º 11
0
        private void StripRemoveClient_Click(object sender, EventArgs e)
        {
            var item = sender as ToolStripMenuItem;

            TwitterClientFactory.RemoveClient((long)item.Tag);
        }
Exemplo n.º 12
0
 private void StripAdd_Click(object sender, EventArgs e)
 {
     TwitterClientFactory.AddClient();
 }
Exemplo n.º 13
0
 private void NotifyIcon_BalloonTipClicked(object sender, EventArgs e)
 {
     TwitterClientFactory.AddClient();
 }