public void Start(IDataFeedContext dataFeedContext, IPanelCommunicator panelCommunicators)
        {
            var bookmarkLocation = dataFeedContext.GetSettings()["ChromeBookmarkLocation"].SettingValue;

            bookmarkLocation = Environment.ExpandEnvironmentVariables(bookmarkLocation);
            SendBookmarks(bookmarkLocation, panelCommunicators);
            _watcher = new FileSystemWatcher
            {
                Path         = Path.GetDirectoryName(bookmarkLocation),
                Filter       = Path.GetFileName(bookmarkLocation),
                NotifyFilter = NotifyFilters.LastAccess |
                               NotifyFilters.LastWrite |
                               NotifyFilters.FileName |
                               NotifyFilters.DirectoryName
            };

            _watcher.Changed += (o, e) => SendBookmarks(bookmarkLocation, panelCommunicators);
            _watcher.Created += (o, e) => SendBookmarks(bookmarkLocation, panelCommunicators);
            _watcher.Renamed += (o, e) => SendBookmarks(bookmarkLocation, panelCommunicators);

            _watcher.EnableRaisingEvents = true;
        }
        private void SendBookmarks(string bookmarkLocation, IPanelCommunicator communicator)
        {
            var retryCount = 0;

            while (retryCount < 5)
            {
                try
                {
                    using (FileStream stream = File.Open(bookmarkLocation, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            var bookmarksJson = reader.ReadToEnd();
                            communicator.SendMessageToPanel(bookmarksJson);
                            break;
                        }
                    }
                }
                catch (IOException e)
                {
                    retryCount++;
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Called when data feed should start providing data. An IPanelCommunicator is provided in order to send that data
 /// to the panel. This method will be called in its own thread, so feel free to add loops and sleeps, as it will not
 /// affect the running of the Desktop Client.
 /// </summary>
 /// <param name="dataFeedContext">The context of this datafeed. Provides some useful information that may be needed for your datafeed to run</param>
 /// <param name="panelCommunicator">A communicator used to send messages to the panel.</param>
 public abstract void Start(IDataFeedContext dataFeedContext, IPanelCommunicator panelCommunicators);