Beispiel #1
0
        /// <summary>
        /// Exports the state of the entity to a new instance of <see cref="UserInfo"/>.
        /// </summary>
        /// <returns>A new instance of <see cref="UserInfo"/> with the current state of the entity.</returns>
        internal UserInfo ToUserInfo()
        {
            var accounts   = Accounts.Select(a => a.ToAccountInfo()).ToList();
            var watchlists = Watchlists.Select(a => a.ToWatchlistInfo()).ToList();

            return(new UserInfo(Id, Email, DisplayName, GravatarUrl, Level, accounts, watchlists));
        }
        public void GetWatchlists()
        {
            var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Inside MMA\\settings\\watchlists";

            Directory.CreateDirectory(path);
            var files = Directory.GetFiles(path);

            if (files.Length == 0)
            {
                File.Create(path + "\\My Watchlist");
                files = new[] { path + "\\My Watchlist" };
            }
            for (var i = 0; i < files.Length; i++)
            {
                files[i] = files[i].Substring(files[i].LastIndexOf("\\")).TrimStart('\\');
            }
            List <string> missingFiles = new List <string>();

            if (files.Length != Watchlists.Count)
            {
                foreach (var item in Watchlists)
                {
                    if (!files.Contains(item.Content))
                    {
                        missingFiles.Add(item.Content.ToString());
                    }
                }
            }
            Watchlists.RemoveWhere(x => missingFiles.Contains(x.Content));
            WatchlistMenuItems = new ObservableCollection <MenuItem>();
            foreach (var name in files)
            {
                if (!Watchlists.Select(x => x.Content).Contains(name))
                {
                    Dispatcher.Invoke(() => Watchlists.Add(new ComboBoxItem
                    {
                        Content = name
                    }));
                }
                WatchlistMenuItems.Add(new MenuItem
                {
                    Header           = name,
                    Command          = AddToAnotherWatchlist,
                    CommandParameter = name
                });
            }
        }