示例#1
0
        public ISmartView AddSmartView(string name, string rules, int?id = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (rules == null)
            {
                throw new ArgumentNullException("rules");
            }

            // make sure no smart view has this name
            if (this.SmartViews.Any(f => f.Name == name))
            {
                return(null);
            }

            var view = new Impl.SmartView {
                Name = name, Rules = rules
            };

            if (id.HasValue)
            {
                view.Id = id.Value;
            }

            ISmartView smartView = new SmartView(this, view);

            smartView.GroupAscending = true;
            smartView.TaskGroup      = TaskGroup.DueDate;
            smartView.Order          = this.SmartViews.Count;

            this.databaseContext.AddSmartView(view);
            this.databaseContext.SendChanges();

            this.smartViews.Add(smartView);

            this.StartTrackingSmartView(smartView);

            this.SmartViewAdded.Raise(this, new EventArgs <ISmartView>(smartView));

            return(smartView);
        }
示例#2
0
        public void Initialize()
        {
            foreach (var task in this.Tasks.Where(t => t.Folder == null || string.IsNullOrEmpty(t.Title)).ToList())
            {
                this.databaseContext.RemoveTask(task);
                this.databaseContext.SendChanges();

                this.tasks.Remove(task);
            }

            foreach (var folder in this.Folders)
            {
                this.StartTrackingFolder(folder);
            }

            foreach (var context in this.Contexts)
            {
                this.StartTrackingContext(context);
            }

            this.LoadViews();

            foreach (var view in this.databaseContext.SmartViews.OrderBy(f => f.Order))
            {
                if (!string.IsNullOrEmpty(view.Rules))
                {
                    var smartView = new SmartView(this, view);
                    this.smartViews.Add(smartView);
                    this.StartTrackingSmartView(smartView);
                }
            }

            foreach (var tag in this.databaseContext.Tags.OrderBy(f => f.Order))
            {
                this.tags.Add(new ViewTag(this, tag));
            }
        }