Esempio n. 1
0
        /// <summary>
        /// Add a budget to the list of recent budgets
        /// </summary>
        /// <param name="recentBudget">Recent budget to add</param>
        public void AddRecentBudget(RecentBudget recentBudget)
        {
            var existing = this.GetRecentBudgets();

            if (existing == null)
            {
                existing = new List <RecentBudget>();
            }

            // add or update position
            var matching = existing.FirstOrDefault(x => x.Identifier == recentBudget.Identifier);

            if (matching == null)
            {
                existing.Add(recentBudget);
            }
            else
            {
                matching.DisplayName = recentBudget.DisplayName;
                existing.Remove(matching);
                existing.Add(matching);
            }

            // constrain size to something reasonable
            // TODO: should be the same behaviour for each platform?
            if (existing.Count > 20)
            {
                existing.RemoveRange(0, existing.Count - 20);
            }

            var container = new RecentBudgetsContainer()
            {
                RecentBudgets = existing
            };

            string serialised;

            using (var memoryStream = new MemoryStream())
            {
                Serialiser.Serialise(container, memoryStream);
                memoryStream.Position = 0; // rewind
                var bytes = memoryStream.ToArray();
                serialised = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            }

            var settings = this.repository.GetSettings();

            settings.RecentBudgetsSerialised = serialised;
            settings.Save();
        }
Esempio n. 2
0
 /// <summary>
 /// Add a recent budget to the list of recent budgets
 /// </summary>
 /// <param name="recentBudget">Recent budget to add</param>
 public void AddRecentBudget(RecentBudget recentBudget)
 {
     this.settings.AddRecentBudget(recentBudget);
 }